DataMuseum.dk

Presents historical artifacts from the history of:

CP/M

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about CP/M

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download

⟦01b1b528a⟧ TextFile

    Length: 5714 (0x1652)
    Types: TextFile
    Names: »LISTER.PAS«

Derivation

└─⟦505fbc898⟧ Bits:30002732 Turbo Pascal 5.0 for C-DOS Partner
    └─⟦this⟧ »DEMOS\LISTER.PAS« 

TextFile


æ Copyright (c) 1985, 88 by Borland International, Inc. å

program SourceLister;
æ
          SOURCE LISTER DEMONSTRATION PROGRAM

   This is a simple program to list your TURBO PASCAL source programs.

   PSEUDO CODE
   1.  Find Pascal source file to be listed
   2.  Initialize program variables
   3.  Open main source file
   4.  Process the file
       a.  Read a character into line buffer until linebuffer full or eoln;
       b.  Search line buffer for include file.
       c.  If line contains include file command:
             Then process include file and extract command from line buffer
             Else print out the line buffer.
       d.  Repeat step 4.a thru 4.c until eof(main file);

   INSTRUCTIONS
   1. Compile and run the program:
       a. In the Development Environment load LISTER.PAS and
          press ALT-R.
       b. From the command line type TPC LISTER.PAS /R
   2. Specify the file to print.
å

uses
  Printer;

const
  PageWidth = 80;
  PrintLength = 55;
  PathLength  = 65;
  FormFeed = #12;
  VerticalTabLength = 3;

type
  WorkString = stringÆ126Å;
  FileName  = stringÆPathLengthÅ;

var
  CurRow : integer;
  MainFileName: FileName;
  MainFile: text;
  search1,
  search2,
  search3,
  search4: stringÆ5Å;

  procedure Initialize;
  begin
    CurRow := 0;
    search1 := 'æ$'+'I';    æ different forms that the include compiler å
    search2 := 'æ$'+'i';    æ directive can take. å
    search3 := '(*$'+'I';
    search4 := '(*$'+'i';
  end æinitializeå;

  function Open(var fp:text; name: Filename): boolean;
  begin
    Assign(fp,Name);
    æ$I-å
    Reset(fp);
    æ$I+å
    Open := IOResult = 0;
  end æ Open å;

  procedure OpenMain;
  begin
    if ParamCount = 0 then
    begin
      Write('Enter filename: ');
      Readln(MainFileName);
    end
    else
      MainFileName := ParamStr(1);

    if (MainFileName = '') or not Open(MainFile,MainFileName) then
    begin
      Writeln('ERROR:  file not found (', MainFileName, ')');
      Halt(1);
    end;
  end æOpen Mainå;

  procedure VerticalTab;
  var i: integer;
  begin
    for i := 1 to VerticalTabLength do Writeln(LST);
  end ævertical tabå;

  procedure ProcessLine(PrintStr: WorkString);
  begin
    CurRow := Succ(CurRow);
    if Length(PrintStr) > PageWidth then Inc(CurRow);
    if CurRow > PrintLength then
    begin
      Write(LST,FormFeed);
      VerticalTab;
      CurRow := 1;
    end;
    Writeln(LST,PrintStr);
  end æProcess lineå;

  procedure ProcessFile;
  æ This procedure displays the contents of the Turbo Pascal program on the å
  æ printer. It recursively processes include files if they are nested.     å

  var
    LineBuffer: WorkString;

     function IncludeIn(var CurStr: WorkString): boolean;
     var
       ChkChar: char;
       column: integer;
     begin
       ChkChar := '-';
       column := Pos(search1,CurStr);
       if column <> 0 then
         chkchar := CurStrÆcolumn+3Å
       else
       begin
         column := Pos(search3,CurStr);
         if column <> 0 then
           chkchar := CurStrÆcolumn+4Å
         else
         begin
           column := Pos(search2,CurStr);
           if column <> 0 then
             chkchar := CurStrÆcolumn+3Å
           else
           begin
             column := Pos(search4,CurStr);
             if column <> 0 then
               chkchar := CurStrÆcolumn+4Å
           end;
         end;
       end;
       if ChkChar in Æ'+','-'Å then IncludeIn := False
       else IncludeIn := True;
     end æ IncludeIn å;

     procedure ProcessIncludeFile(var IncStr: WorkString);

     var NameStart, NameEnd: integer;
         IncludeFile: text;
         IncludeFileName: Filename;

       Function Parse(IncStr: WorkString): WorkString;
       begin
         NameStart := Pos('$I',IncStr)+2;
         while IncStrÆNameStartÅ = ' ' do
           NameStart := Succ(NameStart);
         NameEnd := NameStart;
         while (not (IncStrÆNameEndÅ in Æ' ','å','*'Å))
              and ((NameEnd - NameStart) <= PathLength) do
           Inc(NameEnd);
         Dec(NameEnd);
         Parse := Copy(IncStr,NameStart,(NameEnd-NameStart+1));
       end æParseå;

     begin  æProcess include fileå
       IncludeFileName := Parse(IncStr);

       if not Open(IncludeFile,IncludeFileName) then
       begin
         LineBuffer := 'ERROR:  include file not found (' +
                       IncludeFileName + ')';
         ProcessLine(LineBuffer);
       end
       else
       begin
         while not EOF(IncludeFile) do
         begin
           Readln(IncludeFile,LineBuffer);
           æ Turbo Pascal 5.0 allows nested include files so we must
             check for them and do a recursive call if necessary å
           if IncludeIn(LineBuffer) then
             ProcessIncludeFile(LineBuffer)
           else
             ProcessLine(LineBuffer);
         end;
         Close(IncludeFile);
       end;
     end æProcess include fileå;

  begin  æProcess Fileå
    VerticalTab;
    Writeln('Printing . . . ');
    while not EOF(mainfile) do
    begin
      Readln(MainFile,LineBuffer);
      if IncludeIn(LineBuffer) then
         ProcessIncludeFile(LineBuffer)
      else
         ProcessLine(LineBuffer);
    end;
    Close(MainFile);
    Write(LST,FormFeed); æ move the printer to the beginning of the next å
                         æ page å
  end æProcess Fileå;


begin
  Initialize;      æ initialize some global variables å
  OpenMain;        æ open the file to print å
  ProcessFile;     æ print the program å
end.
«eof»