?login_element?

Subversion Repositories NedoOS

Rev

Rev 618 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. program SourceLister;
  2.  
  3. {
  4.           SOURCE LISTER DEMONSTRATION PROGRAM  Version 1.00A
  5.  
  6.    This is a simple program to list your TURBO PASCAL source programs.
  7.  
  8.  
  9.    PSEUDO CODE
  10.    1.  Find Pascal source file to be listed
  11.    2.  Initialize program variables
  12.    3.  Open main source file
  13.    4.  Process the file
  14.        a.  Read a character into line buffer until linebuffer full or eoln;
  15.        b.  Search line buffer for include file.
  16.        c.  If line contains include file command:
  17.              Then process include file and extract command from line buffer
  18.              Else print out the line buffer.
  19.        d.  Repeat step 4.a thru 4.c until eof(main file);
  20.  
  21.    INSTRUCTIONS
  22.    1.  Compile and run the program using the TURBO.COM compiler.
  23.    2.  Two ways to print a file
  24.        a.  Run from TURBO in memory:
  25.            1.  Type "R" and enter a file name to print when prompted.
  26.            2.  Specify a run-time parameter from the compiler options
  27.                menu.
  28.        b.  Run the program from DOS
  29.            1.  Type LISTER and enter a file name to print when prompted.
  30.            2.  Specify a commandline parameter: A> LISTER filename
  31.  
  32. }
  33.  
  34. Const
  35.       PageWidth = 80;
  36.       PrintLength = 55;
  37.       PathLength  = 65;
  38.       FormFeed = #12;
  39.       VerticalTabLength = 3;
  40.  
  41. Type
  42.       WorkString = String[126];
  43.       FileName  = String[PathLength];
  44.  
  45. Var
  46.       CurRow : integer;
  47.       MainFileName: FileName;
  48.       MainFile: text;
  49.       search1,
  50.       search2,
  51.       search3,
  52.       search4: string[5];
  53.  
  54.   Procedure Initialize;
  55.   begin
  56.     CurRow := 0;
  57.     clrscr;
  58.     search1 := '{$'+'I';  { So LISTER can list itself! }
  59.     search2 := '{$'+'i';
  60.     search3 := '(*$'+'I';
  61.     search4 := '(*$'+'i';
  62.   end {initialize};
  63.  
  64.   Function Open(var fp:text; name: Filename): boolean;
  65.   begin
  66.     Assign(fp,Name);
  67.     {$I-}
  68.     reset(fp);
  69.     {$I+}
  70.     If IOresult <> 0 then
  71.      begin
  72.       Open := False;
  73.       close(fp);
  74.      end
  75.     else
  76.       Open := True;
  77.   end { Open };
  78.  
  79.   Procedure OpenMain;
  80.   begin
  81.     If ParamCount = 0 then
  82.     begin
  83.       {Write('Enter filename: ');
  84.       readln(MainFileName);}
  85.     end
  86.     else
  87.     begin
  88.       MainFileName := ParamStr(1);
  89.     end;
  90.     MainFileName := 'lister.pas';
  91.     If Not Open(MainFile,MainFileName) Then
  92.     begin
  93.       Writeln('ERROR -- File not found:  ',MainFileName);
  94.       Halt;
  95.     end;
  96.   end {Open Main};
  97.  
  98.   Procedure VerticalTab;
  99.   var i: integer;
  100.   begin
  101.     for i := 1 to VerticalTabLength do writeln(lst);
  102.   end {vertical tab};
  103.  
  104.   Procedure ProcessLine(PrintStr: WorkString);
  105.   begin
  106.     CurRow := Succ(CurRow);
  107.     if length(PrintStr) > PageWidth then CurRow := Succ(CurRow);
  108.     if CurRow > PrintLength Then
  109.     begin
  110.       Write(lst,FormFeed);
  111.       VerticalTab;
  112.       CurRow := 1;
  113.     end;
  114.     Writeln(lst,PrintStr);
  115.   end {Process line};
  116.  
  117.   Procedure ProcessFile;
  118.  
  119.   var
  120.     LineBuffer: WorkString;
  121.  
  122.      Function IncludeIn(VAR CurStr: WorkString): Boolean;
  123.      Var ChkChar: char;
  124.          column: integer;
  125.      begin
  126.        ChkChar := '-';
  127.        column := pos(search1,CurStr);
  128.        if column <> 0 then
  129.          chkchar := CurStr[column+3]
  130.        else
  131.        begin
  132.          column := Pos(search3,CurStr);
  133.          if column <> 0 then
  134.            chkchar := CurStr[column+4]
  135.          else
  136.          begin
  137.            column := Pos(search2,CurStr);
  138.            if column <> 0 then
  139.              chkchar := CurStr[column+3]
  140.            else
  141.            begin
  142.              column := Pos(search4,CurStr);
  143.              if column <> 0 then
  144.                chkchar := CurStr[column+4]
  145.            end;
  146.          end;
  147.        end;
  148.        if ChkChar in ['+','-'] then IncludeIn := False
  149.        Else IncludeIn := True;
  150.      end { IncludeIn };
  151.  
  152.  
  153.      Procedure ProcessIncludeFile(VAR IncStr: WorkString);
  154.  
  155.      var NameStart, NameEnd: integer;
  156.          IncludeFile: text;
  157.          IncludeFileName: Filename;
  158.  
  159.        Function Parse(IncStr: WorkString): WorkString;
  160.        begin
  161.          NameStart := pos('$I',IncStr)+2;
  162.          while IncStr[NameStart] = ' ' do
  163.            NameStart := Succ(NameStart);
  164.          NameEnd := NameStart;
  165.          while (not (IncStr[NameEnd] in [' ','}','*']))
  166.               AND ((NameEnd - NameStart) <= PathLength)
  167.               do NameEnd := Succ(NameEnd);
  168.          NameEnd := Pred(NameEnd);
  169.          Parse := copy(IncStr,NameStart,(NameEnd-NameStart+1));
  170.        end {Parse};
  171.  
  172.      begin  {Process include file}
  173.        IncludeFileName := Parse(IncStr);
  174.  
  175.        If not Open(IncludeFile,IncludeFileName) then
  176.        begin
  177.          LineBuffer := 'ERROR -- Include file not found:  ' + IncludeFileName;
  178.          ProcessLine(LineBuffer);
  179.        end
  180.        Else
  181.        begin
  182.          while not eof(IncludeFile) do
  183.          begin
  184.            Readln(IncludeFile,LineBuffer);
  185.            ProcessLine(LineBuffer);
  186.          end;
  187.          close(IncludeFile);
  188.        end;
  189.      end {Process include file};
  190.  
  191.   begin  {Process File}
  192.     VerticalTab;
  193.     Writeln('Printing . . . ');
  194.     while not eof(mainfile) do
  195.     begin
  196.       Readln(MainFile,LineBuffer);
  197.       if IncludeIn(LineBuffer) then
  198.          ProcessIncludeFile(LineBuffer)
  199.       else
  200.          ProcessLine(LineBuffer);
  201.     end;
  202.     close(MainFile);
  203.     write(lst,FormFeed);
  204.   end {Process File};
  205.  
  206.  
  207. BEGIN
  208.   Initialize;
  209.   OpenMain;
  210.   ProcessFile;
  211. END.
  212.  
  213.