
procedure Compute;
  begin
    LastLine := CodeInt [PLi] - CodeInt [MBi];
    if CodeInt [PLi] = 0 then
      LastLine := 0;
    DataLng := CodeInt [LLi] - CodeInt [POi];
    if CodeBool [CMi] then
      DataLng := DataLng - 2;
    if CodeBool [BEi] then
      DataLng := DataLng - 3;
    if CodeBool [SQi] then
      DataLng := DataLng - 6;
    PrefixLng := CodeInt [LLi] - DataLng;
    if length (CodeStr [SXi]) < 1 then
      SXOption := 'N'
    else
      SXOption := CodeStr [SXi] [1];
    if length (CodeStr [SXi]) < 2 then
      SXDrive := 'A'
    else
      SXDrive := CodeStr [SXi] [2];
    SXName := SXDrive + ':SXREF.DAT';
  end;

procedure SkipLine (X: integer); (* Puts X blank lines to output file *)
  begin
    while X > 0 do
     begin
      writeln (ListFile);
      X := pred (X);
     end;
  end;

procedure StartPage;
  begin
    PageCt := succ (PageCt);
    LineCt := 1;
    SkipLine (CodeInt [MTi] - 1 - CodeInt [HMi]);
    WorkLine := Replace (CodeStr [HEi], '@', InName);
    str (PageCt, PageStr);
    WorkLine := Replace (WorkLine, '#', PageStr);
    WorkLine := Trim (WorkLine);
    WorkLine := LCRJust (WorkLine, DataLng);
    write (ListFile, ManyChar (Blank, CodeInt [POi]));
    if CodeBool [CMi] then
      write (ListFile, 'C ');
    if CodeBool [BEi] then
      write (ListFile, 'BE ');
    if CodeBool [SQi] then
      write (ListFile, '  SEQ ');
    writeln (ListFile, WorkLine);
    SkipLine (CodeInt [HMi]);
    LineCt := CodeInt [MTi];
    PageBegun := true;
  end;

procedure EndPage;
  begin
    if PageBegun then
     begin
      SkipLine (CodeInt [PLi] - LineCt
        - CodeInt [MBi] + CodeInt [FMi]);
      WorkLine := Replace (CodeStr [FOi], '@', InName);
      WorkLine := Replace (WorkLine, '#', PageStr);
      WorkLine := LCRJust (WorkLine, DataLng);
      write (ListFile, ManyChar (Blank, CodeInt [POi]));
      if CodeBool [CMi] then
        write (ListFile, '  ');
      if CodeBool [BEi] then
        write (ListFile, '   ');
      if CodeBool [SQi] then
        write (ListFile, '      ');
      writeln (ListFile, WorkLine);
      LineCt := succ (LineCt);
      if CodeBool [FFi] then
        write (ListFile, FF)
      else
        SkipLine (CodeInt [PLi] - LineCt);
      PageBegun := false;
     end;
  end;

procedure PutLine;
  begin
    if (LastLine > 0) and (LineCt >= LastLine) then
     begin
      EndPage;
      StartPage;
     end;
    LineCt := succ (LineCt);
    writeln (ListFile, OutLine);
  end;

procedure PrintLine;
  var
    WorkStr : string [6];
  begin
    if (LineToPrint and PrintingLines
      and ((CodeBool [CCi]) or (not FormatOnLine))) then
     begin
      TempLine := ManyChar (Blank, CodeInt [POi]);
      if CodeBool [CMi] then
       begin
        if KCount > 0 then
          WorkStr := '*'
        else
          WorkStr := Blank;
        TempLine := TempLine + WorkStr + Blank;
       end;
      if CodeBool [BEi] then
       begin
        str (BCount:2, WorkStr);
        TempLine := TempLine + WorkStr + Blank;
       end;
      if CodeBool [SQi] then
       begin
        str (SeqCt:5, WorkStr);
        TempLine := TempLine + WorkStr;
        if IncOn then
          TempLine := TempLine + '+'
        else
          TempLine := TempLine + blank;
       end;
      TempLine := TempLine + InRec;
      J := PrefixLng + 1;
      while ((J <= length (TempLine)) and (TempLine [J] = Blank)) do
        J := succ (J);
      if J > length (TempLine) then
        J := PrefixLng + 1;
      J := succ (J);
      while length (TempLine) > CodeInt [LLi] do
       begin
        I := CodeInt [LLi];
        while ((I > PrefixLng) and (TempLine [I] <> Blank)) do
          I := pred (I);
        if I = PrefixLng then
          I := CodeInt [LLi];
        OutLine := copy (TempLine, 1, I);
        PutLine;
        delete (TempLine, 1, I);
        TempLine := ManyChar (Blank, J) + TempLine;
       end;
      OutLine := TempLine;
      PutLine;
     end;
    LineToPrint := false;
  end;

procedure GetLine;
  begin
    PrintLine;
    FormatOnLine := false;
    if IncOn then
      if eof (IncFile) then
       begin
        IncOn := false;
        close (IncFile);
        WriteFileLine (InName);
       end
      else
       begin
        readln (IncFile, InRec);
        LineToPrint := true;
       end;
    if not IncOn then
     begin
      if eof (InFile) then
       begin
        InRec := EndFile;
       end
      else
       begin
        readln (InFile, InRec);
        LineToPrint := true;
       end;
     end;
    NextSeqCt := succ (NextSeqCt);
    if (NextSeqCt > (SeqCtWritten + 10)) then
      WriteSeqCt;
    InLng := length (InRec);
    CI := 1;
  end;

procedure GetChar;
  begin
    LastChar := CurrChar;
    CurrChar := NextChar;
    LastCI   := CurrCI;
    CurrCI   := NextCI;
    SeqCt    := NextSeqCt;
    if OldLineDone then
      begin
       GetLine;
       OldLineDone := false;
      end;
    NextCI := CI;
    if CI > InLng then
     begin
      if CurrChar = EndFile then
        NextChar := EndFile
      else
        NextChar := Blank;
      OldLineDone := true;
     end
    else
     begin
      NextChar := upcase (InRec [CI]);
      CI := succ (CI);
     end;
  end;
