Category : Modula II Source Code
Archive   : M2TUTOR.ZIP
Filename : CH08E2.MOD

 
Output of file : CH08E2.MOD contained in archive : M2TUTOR.ZIP
(* 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.)

*)



  3 Responses to “Category : Modula II Source Code
Archive   : M2TUTOR.ZIP
Filename : CH08E2.MOD

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/