MODULE overstrike; (*DEE 2014-08-06/2015-12-02*) (*Software Tools in Pascal, exercise 2-5. * Compare with Systematic Programming: An Introduction, program 10.24, * pg. 79, as well as the same program, updated for J&W Pascal, called * insert on pg. 61 of the Second Edition. *) FROM ST IMPORT getc, putc; FROM STchars IMPORT BACKSPACE, BLANK, ENDFILE, FF, NEWLINE, PLUS, character; FROM STutility IMPORT max; (* overstrike: convert backspaces into multiple lines. *) PROCEDURE overstrike; CONST NOSKIP = PLUS; SKIP = BLANK; (* Skip to the next line *) PGSKIP = 49; (* ANSI page skip, i.e. '1' *) VAR col, i, newcol: INTEGER; c: character; fflag: BOOLEAN; (* form feed flag *) BEGIN col := 1; fflag := FALSE; REPEAT newcol := col; WHILE (getc(c) = BACKSPACE) DO (* Eat backspaces. *) newcol := max(newcol - 1, 1) END; IF (newcol < col) THEN putc(NEWLINE); putc(NOSKIP); (* Start overstrike line. *) FOR i := 1 TO newcol - 1 DO putc(BLANK) END; col := newcol ELSIF (col = 1) AND (c # ENDFILE) AND ~fflag THEN putc(SKIP) (* normal line *) (* ELSE middle of line *) END; IF (c # ENDFILE) THEN IF (c = FF) THEN putc(NEWLINE); (*Start page break line.*) putc(PGSKIP); col := 1; fflag := TRUE ELSE putc(c); (* normal character *) fflag := FALSE; IF (c = NEWLINE) THEN col := 1 ELSE INC(col) END; END END UNTIL (c = ENDFILE) END overstrike; BEGIN overstrike END overstrike.