program entab_pas; (* entab -- replace blanks by tabs and blanks bibliography 'Software Tools' B.W.Kernighan & P.J.Plauger revison history 1.0 ???. ??, 1986 2.0 Feb. 7, 1987 3.0 Mar. 28, 1987 3.1 Mar. 30, 1987 *) const TAB = 9; NEWLINE = 10; BLANK = ' '; MAXL = 80; YES = TRUE; NO = FALSE; type tabstop = array[1..MAXL] of boolean; var tabs: tabstop; infile: text; {$I stdio.lib} (* initialize tabs[] *) procedure settab; var i: integer; begin for i := 1 to MAXL do if (i mod 8) = 1 then tabs[i] := YES else tabs[i] := NO; end; { of settab } (* return YES if col is tab stop *) function tabpos(col: integer; var tabs: tabstop): boolean; begin if col > MAXL then tabpos := YES else tabpos := tabs[col]; end; { of tabpos } (* entab *) procedure entab(var infile: text); var col, newcol: integer; ch: char; begin settab; col := 1; while not eof(infile) do begin newcol := col; read(infile, ch); while ch = BLANK do begin newcol := newcol + 1; if (tabpos(newcol, tabs) = YES) then begin write(stdout, chr(TAB)); col := newcol; end; read(infile, ch); end; while col < newcol do begin write(stdout, BLANK); col := col + 1; end; write(stdout, ch); if ch = chr(NEWLINE) then col := 1 else col := col + 1; end; end; { of entab } (* main *) begin openstd; if argc = 0 then begin entab(stdin); end else begin if argv(1) = '-' then begin writeln(stderr, 'Usage: ' + argv(0) + ' file'); exit(1); end else begin openf(infile, argv(1), 'r'); entab(infile); close(infile); end; end; exit(0); end. { of program }