program detab_pas; (* detab -- convert tabs into equivalent number of blanks bibliography 'Software Tools' B.W.Kernighan & P.J.Plauger revision history 1.0 ???. ??, 1986 1.1 Oct. 10, 1986 2.0 Mar. 29, 1987 2.2 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 tabs } (* detab *) procedure detab(var infile: text); var col: integer; ch: char; begin settab; col := 1; while not eof(infile) do begin read(infile, ch); if ch = chr(TAB) then repeat write(stdout, BLANK); col := col + 1 until tabpos(col, tabs) = YES else if ch = chr(NEWLINE) then begin write(stdout, chr(NEWLINE)); col := 1 end else begin write(stdout, ch); col := col + 1 end end; end; { of detab } (* main *) begin openstd; if argc = 0 then detab(stdin) else begin if argv(1) = '-' then begin writeln(stdout, 'Usage: ' + argv(0) + ' file'); exit(1); end; openf(infile, argv(1), 'r'); detab(infile); close(infile); end; exit(0); end. { of program }