PRINT.P is a sample program that resides on the Kyan Pascal 2.x Disk 2. It is a sample program / utility used to output text files from disk to the printer, with the option of including line numbers. Here the sample run uses the utility to print itself.
Source Code
TYPE
String15 = ARRAY[1..15] OF Char;
VAR
n,x: Integer;
c: Char;
f,printer: Text;
s: String15;
BEGIN
x:=0;
n:=1;
Write('FILENAME? '); Readln(s);
Write('Line numbers(Y/N)? '); Readln(c);
Rewrite(Printer,'P:');
Reset(f,s);
WHILE NOT EOF(f) DO
BEGIN
IF (c='Y') AND (x=0) THEN
BEGIN
x:=1;
IF n<10 THEN Write(printer,'000',n,' ');
IF (n>9) AND (n<100) THEN Write(printer,'00',n,' ');
IF (n>99) AND (n<1000) THEN Write(printer,'0',n,' ');
IF n>999 THEN Write(printer,n,' ')
END;
IF EOLn(f) THEN
BEGIN
x:=0;
n:=n+1;
Writeln(printer)
END
ELSE Write(printer,f^);
Get(f);
END;
END.
Sample Run (Printer Output)
0001 PROGRAM Print;
0002 TYPE
0003 String15 = ARRAY[1..15] OF Char;
0004 VAR
0005 n,x: Integer;
0006 c: Char;
0007 f,printer: Text;
0008 s: String15;
0009
0010 BEGIN
0011 x:=0;
0012 n:=1;
0013 Write('FILENAME? '); Readln(s);
0014 Write('Line numbers(Y/N)? '); Readln(c);
0015 Rewrite(Printer,'P:');
0016 Reset(f,s);
0017 WHILE NOT EOF(f) DO
0018 BEGIN
0019 IF (c='Y') AND (x=0) THEN
0020 BEGIN
0021 x:=1;
0022 IF n<10 THEN Write(printer,'000',n,' ');
0023 IF (n>9) AND (n<100) THEN Write(printer,'00',n,' ');
0024 IF (n>99) AND (n<1000) THEN Write(printer,'0',n,' ');
0025 IF n>999 THEN Write(printer,n,' ')
0026 END;
0027 IF EOLn(f) THEN
0028 BEGIN
0029 x:=0;
0030 n:=n+1;
0031 Writeln(printer)
0032 END
0033 ELSE Write(printer,f^);
0034 Get(f);
0035 END;
No comments:
Post a Comment