|
DataMuseum.dkPresents historical artifacts from the history of: CP/M |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about CP/M Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - download
Length: 5504 (0x1580) Types: TextFile Names: »LISTER.PAS«
└─⟦5e4548e7d⟧ Bits:30005778 Turbo Pascal v.3.01A (CP/M-86) └─ ⟦this⟧ »LISTER.PAS«
program SourceLister; æ SOURCE LISTER DEMONSTRATION PROGRAM Version 1.00A 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 using the TURBO.COM compiler. 2. Two ways to print a file a. Run from TURBO in memory: 1. Type "R" and enter a file name to print when prompted. 2. Specify a run-time parameter from the compiler options menu. b. Run the program from DOS 1. Type LISTER and enter a file name to print when prompted. 2. Specify a commandline parameter: A> LISTER filename å 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; clrscr; search1 := 'æ$'+'I'; æ So LISTER can list itself! å search2 := 'æ$'+'i'; search3 := '(*$'+'I'; search4 := '(*$'+'i'; end æinitializeå; Function Open(var fp:text; name: Filename): boolean; begin Assign(fp,Name); æ$I-å reset(fp); æ$I+å If IOresult <> 0 then begin Open := False; close(fp); end else Open := True; end æ Open å; Procedure OpenMain; begin If ParamCount = 0 then begin Write('Enter filename: '); readln(MainFileName); end else begin MainFileName := ParamStr(1); end; If Not Open(MainFile,MainFileName) Then begin Writeln('ERROR -- File not found: ',MainFileName); Halt; 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 CurRow := Succ(CurRow); if CurRow > PrintLength Then begin Write(lst,FormFeed); VerticalTab; CurRow := 1; end; Writeln(lst,PrintStr); end æProcess lineå; Procedure ProcessFile; 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 NameEnd := Succ(NameEnd); NameEnd := Pred(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); 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); end æProcess Fileå; BEGIN Initialize; OpenMain; ProcessFile; END. «eof»