Current Notes May 1987 A SAMPLE PASCAL PROGRAM by Alan Friedman Here is a neat little proram written in Kyan Pascal that reads text files and formats them into pages of 60 lines and then skips to the top of the next page, prints a page number and then starts printing again. One other great feature of this program is if the text is 40 columns, you can instruct the program to print two 40-column lines before issuing a line feed. This really cleans up 40-column text from disk documentation or from downloaded files. The program is written as four separate procedures that are called from the body of the program as needed. As you can see, the body of the program is only eight lines long located at the end of the listing. The procedure NewPage is a good utility that can be saved as a text file and used in other programs when proper page formatting is needed. In procedures Convert and NoConvert, a standard Pascal format of check for end of file, check for end of line, read a character and then write a character is used. Also notice that following the END; forthe WHILE NOT EOLN(InFile), there is a ReadLn(InFile) and then a WriteLn(Printer) statement. This is where the line being read is cleared out and the carriage return is issued to the printer. This is a good routine to remember for use in other programs that require text processing. PROGRAM PrFile(Input,Output); (*This program converts 40 colummn*) (*files to 80 column output to printer*) TYPE String15=ARRAY[1..15] OF CHAR; VAR Filename:STRING15; Ch:CHAR; LineCount,PageNumber:INTEGER; InFile,Printer:TEXT; Answer:CHAR; PROCEDURE NewPage; VAR i:INTEGER; BEGIN For i:=1 TO 3 DO Writeln(PRINTER); Writeln(Printer,' ':38,'-',PAGENUMBER,'-'); Writeln(Printer); Writeln(Printer); PAGENUMBER:=PAGENUMBER+1; ____________________________________________________________________ XL - 1 - XE Current Notes May 1987 LineCount:=0; END;(*Procedure NewPage*) PROCEDURE Initialize; BEGIN Writeln('Place disk with file on it in Drive #1'); Writeln; Writeln; Write('Enter the name of the file to'); Writeln('be printed.'); Readln(FileName); Writeln; Writeln; Writeln('Is this a 40 column file? (Y/N)'); Readln(Answer); END; PROCEDURE Convert; BEGIN LineCount:=0; PageNumber:=2; Reset(InFile,FileName); WHILE NOT EOF(InFile) DO BEGIN WHILE NOT EOLN(InFile) DO BEGIN Read(InFile,Ch); Write(Printer,Ch); END; READLN(INFILE); LineCount:=LineCOunt +1; IF LineCount MOD 2 =0 THEN Writeln(Printer) ELSE Write(Printer,' '); IF LineCount=120 THEN NewPage; END; END;(*Procedure Convert*) PROCEDURE NoConvert; BEGIN PageNumber:=2; LineCount:=0; Reset(InFile,FileName); WHILE NOT EOF(InFile) DO BEGIN WHILE NOT EOLN (InFile) DO BEGIN Read(InFile,Ch); Write(Printer,Ch); END; LineCount:=LineCount+1; ____________________________________________________________________ XL - 2 - XE Current Notes May 1987 Writeln(Printer); Readln(Infile); IF LineCount=60 THEN NewPage; END; END; BEGIN (*PROGRAM PrFile*) Rewrite(Printer,'P:'); Initialize; IF (Answer='Y') OR (ANSWER='y') THEN Convert ELSE NoConvert; END. (*PrFile) ____________________________________________________________________ XL - 3 - XE Write('+'); LetterArray[LetterCount]:=Ch; END; Write(Chr(125)); Writeln('Put