home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
m
/
mod2tutr.zip
/
EXAMPLES.ZIP
/
CH08E2.MOD
< prev
next >
Wrap
Text File
|
1989-01-18
|
3KB
|
83 lines
(* Chapter 8 - Programming exercise 2 *)
MODULE CH08E2;
FROM FileSystem IMPORT Lookup, Close, File, Response, ReadChar;
FROM InOut IMPORT Write, WriteString, WriteCard, ReadString,
WriteLn, EOL;
VAR NameOfFile : ARRAY[1..15] OF CHAR;
InFile : File;
InLine : ARRAY[1..80] OF CHAR; (* Note, There is no check
for a spill out of
this line. Assumes all
lines are shorter. *)
Character : CHAR;
Count : CARDINAL;
ENDCount : CARDINAL;
PROCEDURE CheckForEND;
VAR ENDFound : BOOLEAN;
Index : INTEGER;
BEGIN
ENDFound := FALSE;
FOR Index := 1 TO (INTEGER(Count) - 2) DO
IF (InLine[Index] = 'E') AND
(InLine[Index + 1] = 'N') AND
(InLine[Index + 2] = 'D') THEN
ENDFound := TRUE;
ENDCount := ENDCount + 1;
END;
END;
IF ENDFound THEN
WriteString(InLine);
WriteLn;
END;
END CheckForEND;
BEGIN
REPEAT (* repeat until a good filename is found *)
WriteLn;
WriteString("Enter name of file to display ---> ");
ReadString(NameOfFile);
Lookup(InFile,NameOfFile,FALSE);
UNTIL InFile.res = done; (* good filename found *)
ENDCount := 0;
WriteLn;
Count := 0;
InLine[1] := 0C; (* String terminator *)
REPEAT (* character read/display loop - quit at InFile.eof *)
ReadChar(InFile,Character);
IF NOT InFile.eof THEN
IF Character # EOL THEN
Count := Count + 1;
InLine[Count] := Character;
InLine[Count + 1] := 0C; (* String terminator *)
ELSE
CheckForEND;
Count := 0;
InLine[1] := 0C; (* String terminator *)
END;
END;
UNTIL InFile.eof; (* quit when eof is found *)
Close(InFile);
WriteLn;
WriteString("There were");
WriteCard(ENDCount,5);
WriteString(" END's in the file.");
WriteLn;
END CH08E2.
(* Result of execution
(The selected file is listed on the monitor, with the character
count listed for each line, and the total number of lines.)
*)