program overstrike (input, output); (* DEE 2014-2016 *) (* Pascal/ASA carriage control filter. *) const BS = 8; FF = 12; PGSKIP = '1'; SKIP = ' '; NOSKIP = '+'; var c: CHAR; col, newcol, i: INTEGER; fflag: BOOLEAN; function max (x, y: integer): integer; begin if (x > y) then max := x else max := y end; (* Influenced by Software Tools in Pascal, exercise 2-5, *) (* and Systematic Programming: An Introduction. *) (* See section 14.4 of the 1978 Pascal Report. *) (* This does not support vertical tabs, double or triple spacing. *) begin col := 1; fflag := false; repeat newcol := col; read(c); while (not eof) and (c = chr(BS)) do begin newcol := max(newcol - 1, 1); read(c) end; if (newcol < col) then begin writeln; write(NOSKIP); (* Start overstrike line. *) for i := 1 to newcol - 1 do write(' '); col := newcol end else if (col = 1) and (not eof) and (not fflag) then write(SKIP); (* normal line *) (* else middle-of-line *) if not eof then begin if (c = chr(FF)) then begin writeln; (* Start page break line. *) write(PGSKIP); col := 1; fflag := true end else begin write(c); fflag := false; if eoln then begin readln; writeln; col := 1 end else col := col + 1 end end until eof end.