home *** CD-ROM | disk | FTP | other *** search
- Program Reform;
- Uses Dos,
- Crt;
-
- {NORTHWESTERN UNIVERSITY TURBO USERS GROUP UTILITIES}
-
- (** NUtility FORMAT **)
-
- {(C) J. E. Hilliard 1986}
-
- PROCEDURE Reformat;
-
- (*Originally this routine was written solely for the purpose
- of deleting the tutorial comments (ie. those enclosed within
- {/ /}) from the NUTILITY files. But it later became appar-
- ent that by adding the necessary sub-procedures more general
- formatting operations could be performed. For example, the
- Procedure 'ListDeclarations' was used to generate the list of
- procedures and functions for NUTDOC.
-
- The procedure loads the files listed in 'FileNames' and, after
- formatting, writes them as files with the extension 'FOR'.
-
- The subprocedures included are: Counting {/ and /}, Del-
- ting tutorial comments, Deleting blank lines and Listing
- Procedure and Function headings. *)
-
-
- CONST
-
- NofF = 6; {Number of files. }
-
- FileNames : array [1..NofF] of string[8] =
-
- ('VIDEO', {Modify list if necessary. }
- 'MISC',
- 'DATETIME',
- 'REALFAST',
- 'DATIM',
- 'BASECON');
-
- VAR
-
- InFile, OutFile : Text;
- J, K : integer;
-
-
- Procedure ListDeclarations (FN : integer);
-
- {Searches for lines begining with 'P' or 'F', deletes the
- first word, contracts or expands line to 50 characters, adds
- the file name and then writes the line. }
-
- Var
-
- NL : integer;
- Line : string[250];
- ExpName : string[12];
-
- begin
-
- ExpName := FileNames[FN];
- while Length (ExpName) < 8 do
- ExpName := ExpName + ' ';
- ExpName := ExpName + '.PAS';
- NL := 0;
- GoToXY (5, WhereY + 1);
- write ('Running ', ExpName);
- GoToXY (26, WhereY);
- write (NL:4, ' Labels written.');
- while not EOF (InFile) do
- begin
- readln (InFile, Line);
- if Line[1] in ['P', 'F'] then
- begin
- Line :=
- Copy (Line, Pos (' ', Line) + 1, 80); {Delete first word. }
- while Pos (' ', Line) <> 0 do {Delete multiple spaces. }
- Delete (Line, Pos (' ', Line), 1);
- Delete (Line, 50, 40); {Truncate line. }
- while Length (Line) < 50 do {Fill out line. }
- Line := Line + ' ';
- Line := Line + '['+ ExpName + ']';{Add file name. }
- writeln (Outfile, Line);
- NL := succ (NL);
- GoToXY (26, WhereY);
- write (NL:4); {Up date display. }
- end; {if}
- end; {while not EOF}
-
- End; {ListDeclarations (FN : integer)}
-
-
- Procedure DeleteBlankLines (FN : integer);
-
- {As you will have noticed, I have a fondness for blank lines
- in the belief that they improve clarity. However, you may
- prefer tighter formatting (certainly it speeds up compilation).
- This sub-procedure deletes all blank lines in file number FN
- except for those occurring before a line begining with a 'P'
- or an 'F'. }
-
- {This Procedure is dedicated to Scott Lindsey. }
-
- Var
-
- BL : integer;
- Line : string[250];
-
- begin
-
- BL := 0;
- GoToXY (5, WhereY + 1);
- write ('Running ', FileNames[FN] + '.PAS');
- GoToXY (26, WhereY);
- write (BL:4, ' Blank lines deleted');
- while not EOF (InFile) do
- begin
- readln (InFile, Line);
- if Length (Line) <> 0
- then
- writeln (OutFile, Line)
- else {Line is blank. }
- begin
- repeat
- readln (InFile, Line); {Get next non-blank line. }
- BL := succ (BL);
- until (Length (Line) <> 0) or (EOF (InFile) );
- BL := pred (BL);
- if Line[1] in ['P', 'F']
- then {Retain blank line. }
- writeln (OutFile, '')
- else
- BL := succ (BL); {Blank line was deleted. }
- writeln (OutFile, Line);
- GoToXY (26, WhereY);
- write (BL:4);
- end; {else}
-
- end; {while not EOF}
-
- end; {DeleteBlankLines (FN : integer)}
-
-
- Procedure MatchBraces (FN : integer);
-
- (*This procedure scans all line in file number FN and reports
- the number of {/ and /} braces. It is advisable to check that
- the numbers match before using DeleteTutorialLines. *)
-
- Var
-
- LH, RH : integer;
- Line : string[250];
-
- begin
-
- LH := 0; RH := 0;
- GoToXY (5, WhereY + 1);
- write ('Running ', FileNames[FN] + '.PAS');
- GoToXY (26, WhereY);
- write (LH:4, ' Left braces.');
- GoToXY (45, WhereY);
- write (RH:4, ' Right braces.');
- while not EOF (InFile) do
- begin
- readln (InFile, Line);
- if Pos ('{/', Line) <> 0 then
- begin
- LH := succ (LH);
- GoToXY (26, WhereY);
- write (LH:4);
- end;
- if Pos ('/}', Line) <> 0 then
- begin
- RH := succ (RH);
- GoToXY (45, WhereY);
- write (RH:4);
- end;
- end; {while not EOF}
-
- end; {MatchBraces (FN : integer)}
-
-
- Procedure DeleteTutorialLines (FN : Integer);
-
- Var
-
- L : integer;
- Line : string[250];
-
- begin
-
- L := 0;
- GoToXY (5, WhereY + 1);
- write ('Running ', FileNames[FN] + '.PAS');
- GoToXY (26, WhereY);
- write (L:3, ' Lines deleted.');
- while not EOF (InFile) do
- begin
- readln (InFile, Line);
- if Pos ('{/', Line) = 0
- then
- writeln (OutFile, Line)
- else
- begin
- while Pos ('/}', Line) = 0 do
- begin
- readln (InFile, Line);
- L := succ (L);
- end;
- L := succ (L);
- GoToXY (26, WhereY);
- write (L:3);
- end; {else}
- end; {while not EOF}
-
- end; {DeleteTutorialLines (FN)}
-
- Begin {Main routine. }
-
- ClrScr;
- GoToXY (29, 3);
- write ('NUTILITY FILES REFORMAT');
- GoToXY (29, 4);
- write ('-----------------------');
- GoToXY (5, 6);
- for J := 1 to NofF do
- begin
- Assign (InFile, FileNames[J] + '.PAS');
- Assign (OutFile, FileNames[J] + '.FOR');
- {$I-} Reset (InFile); {$I+}
- if IOResult = 0
- then
- begin
- {$I-} ReWrite (OutFile); {$I+}
- if IOResult = 0
- then
- begin
-
- (***** UNCOMMENT PROCEDURE REQUIRED OR ADD YOUR OWN *****)
-
- {ListDeclarations (J);}
- {DeleteBlankLines (J);}
- {DeleteTutorialLines (J);}
- {MatchBraces (J);}
-
- Close (InFile);
- Close (OutFile);
- end
- else
- begin
- GoToXY (5, WhereY + 1);
- write ('*** Unable to open ', FileNames[J] + '.DEL ***');
- Close (InFile)
- end;
- end {if IOResult = 0}
- else
- begin
- GoToXY (5, WhereY + 1);
- write ('*** Unable to Find ', FileNames[J] + '.PAS ***');
- end;
- end; {for J}
-
- End; {Reformat}
-
- BEGIN
-
- Reformat
-
- END.
-