(*2:*)MODULE SCANTEX; (*4:*)FROM InOut IMPORT WriteString , ReadString , Write , WriteCard , WriteLn ;(*:4*)(*10:*)FROM SYSTEM IMPORT DOSCALL; (*:10*)(*11:*)FROM FileSystem IMPORT Lookup ,Response, ReadChar , WriteChar , File , Close ;FROM ASCII IMPORT EOL, nul ; (*:11*)CONST(*5:*)BUFSIZE=1000;FILENAMELEN=200; (*:5*)TYPE(*6:*)ERRORLEVEL=(SPOTLESS,HARMLESSMESSAGE,ERRORMESSAGE, FATALMESSAGE);(*:6*)VAR(*7:*)HISTORY:ERRORLEVEL; (*:7*)(*12:*)BUFFER:ARRAY[0..BUFSIZE]OF CHAR;TEXFILE,OUTTEXFILE: File ; (*:12*)(*18:*)TEXLINE:CARDINAL;OUTTEXLINE:CARDINAL;LIMIT:[0..BUFSIZE]; INPUTHASENDED:BOOLEAN;OUTPUTENABLED:BOOLEAN; (*:18*)(*:2*)(*3:*)PROCEDURE INITIALIZE; VAR(*15:*)FILENAME:ARRAY[0..FILENAMELEN-1]OF CHAR; (*:15*)BEGIN(*8:*)HISTORY:=SPOTLESS;(*:8*)(*17:*)TEXLINE:=0; OUTTEXLINE:=0;LIMIT:=0;BUFFER[0]:=' ';INPUTHASENDED:=FALSE; OUTPUTENABLED:=TRUE;(*:17*)(*16:*)FILENAME[0]:=' '; WriteString ('TeX file:'); WriteLn ;; ReadString (FILENAME); WriteLn ; WriteString (FILENAME); WriteLn ;; WriteLn ;; Lookup (TEXFILE,FILENAME,FALSE); IF(TEXFILE.res<>done)THEN WriteString ('unable to open '); HISTORY:=FATALMESSAGE; WriteString (FILENAME); WriteLn ;; WriteString ('(That was a fatal '); WriteString ('error, my friend.)'); WriteLn ;;DOSCALL(76,HISTORY);;END;;FILENAME[0]:=' '; WriteString ('output TeX file:'); WriteLn ;; ReadString (FILENAME); WriteLn ; WriteString (FILENAME); WriteLn ;; WriteLn ;; Lookup (OUTTEXFILE,FILENAME,TRUE); IF(OUTTEXFILE.res<>done)THEN WriteString ('unable to open '); HISTORY:=FATALMESSAGE; WriteString (FILENAME); WriteLn ;; WriteString ('(That was a fatal '); WriteString ('error, my friend.)'); WriteLn ;;DOSCALL(76,HISTORY);;END;;(*:16*);END INITIALIZE; (*:3*)(*13:*)PROCEDURE INPUTLN(VAR F: File ):BOOLEAN; VAR FINALLIMIT:[0..BUFSIZE];CH:CHAR;LINEPRES:BOOLEAN;BEGIN LIMIT:=0; FINALLIMIT:=0;IF(F.eof)THEN LINEPRES:=FALSE ELSE ReadChar (F,CH);; WHILE NOT(CH=EOL)DO IF CH= nul THEN RETURN FALSE END;BUFFER[LIMIT]:=CH; INC(LIMIT);IF BUFFER[LIMIT-1]<>' 'THEN FINALLIMIT:=LIMIT END; IF LIMIT=BUFSIZE THEN WHILE NOT(CH=EOL)DO ReadChar (F,CH);;END;; DEC(LIMIT); WriteString ('! Input line too long'); WriteLn ;; HISTORY:=ERRORMESSAGE;;RETURN TRUE;END; ReadChar (F,CH);;END; WHILE NOT(CH=EOL)DO ReadChar (F,CH);;END;;LIMIT:=FINALLIMIT; LINEPRES:=TRUE;END;RETURN LINEPRES;END INPUTLN; (*:13*)(*14:*)PROCEDURE OUTPUTLN(VAR F: File );VAR CH:CHAR; TEMP:[0..BUFSIZE]; BEGIN IF LIMIT>0 THEN FOR TEMP:=0 TO LIMIT-1 DO CH:=BUFFER[TEMP]; WriteChar (F,CH);END;END; WriteChar (F,EOL);;END OUTPUTLN; (*:14*)(*20:*)PROCEDURE GETLINE;VAR KEEPLOOKING:BOOLEAN; TEMPINDEX:CARDINAL;BEGIN INPUTHASENDED:=NOT INPUTLN(TEXFILE); IF INPUTHASENDED THEN OUTPUTENABLED:=FALSE;RETURN;ELSE INC(TEXLINE); IF(TEXLINE MOD 100)=0 THEN Write ('.'); IF(TEXLINE MOD 2000)=0 THEN WriteLn ;END;END;(*21:*)TEMPINDEX:=1; IF(LIMIT>3)AND(BUFFER[0]='\')THEN IF((BUFFER[TEMPINDEX]='M')OR(BUFFER[ TEMPINDEX]='N'))AND((BUFFER[2]<='9')AND(BUFFER[2]>='0'))THEN(*22:*) OUTPUTENABLED:=FALSE;KEEPLOOKING:=TRUE;TEMPINDEX:=3; WHILE(NOT OUTPUTENABLED)AND KEEPLOOKING DO OUTPUTENABLED:=(BUFFER[ TEMPINDEX]='\')AND(BUFFER[TEMPINDEX+1]='*')AND(BUFFER[TEMPINDEX+2]='.'); KEEPLOOKING:=((BUFFER[TEMPINDEX]<='9')AND(BUFFER[TEMPINDEX]>='0')); INC(TEMPINDEX);END;(*:22*); ELSIF(BUFFER[TEMPINDEX]='i')AND(BUFFER[TEMPINDEX+1]='n')AND(BUFFER[ TEMPINDEX+2]='x')THEN OUTPUTENABLED:=FALSE;INPUTHASENDED:=TRUE;END;END; (*:21*);BUFFER[LIMIT]:=' ';END;END GETLINE; (*:20*)(*24:*)BEGIN WriteString ('This is SCANTEX, Version 1.0'); WriteLn ;;INITIALIZE;(*19:*)WHILE NOT INPUTHASENDED DO GETLINE; IF OUTPUTENABLED THEN OUTPUTLN(OUTTEXFILE);INC(OUTTEXLINE);END;END; (*:19*);(*23:*)BUFFER[0]:='\';BUFFER[1]:='b';BUFFER[2]:='y'; BUFFER[3]:='e';LIMIT:=4;OUTPUTLN(OUTTEXFILE);INC(OUTTEXLINE); Close (TEXFILE);; Close (OUTTEXFILE);;(*:23*);(*26:*) WriteLn ; WriteString ('Line count statistics:'); WriteLn ;; WriteCard (TEXLINE,1); WriteString (' lines in input TeX file'); WriteLn ;; WriteCard (OUTTEXLINE,1); WriteString (' lines in output TeX file'); WriteLn ;;(*:26*); (*25:*)CASE HISTORY OF SPOTLESS: WriteString ('(No errors were found.)') ; WriteLn ;|HARMLESSMESSAGE: WriteString ('(Did you see the '); WriteString ('warning message above?)'); WriteLn ; |ERRORMESSAGE: WriteString ('(Pardon me, but I think I '); WriteString ('spotted something wrong.)'); WriteLn ; |FATALMESSAGE: WriteString ('(That was a fatal '); WriteString ('error, my friend.)'); WriteLn ;END;(*:25*); (*9:*)DOSCALL(76,HISTORY);(*:9*);END SCANTEX.(*:24*)