{$B-}    { Standard input/output is TRM: instead of CON: }
program dtabprog (input,output);
{ 09.05.1987 A.Herrmann }

const
    ENDFILE = -1;
    NEWLINE = 10;   { ASCII value }
    BLANK = 32;
    TAB = 9;
type
    character = -1..127;        { ASCII, plus ENDFILE }

{ getc -- get one character from standard input }
function getc(var c: character): character;
var
    ch: char;
begin
if (eof) then
    c := ENDFILE
else if (eoln) then
    begin
    readln;
    c := NEWLINE;
    end
else
    begin
    read(ch);
    c := ord(ch)
    end;
getc := c;
end;

{ putc -- put one character on standard output }
procedure putc(c: character);
begin
if (c = NEWLINE) then
    writeln
else
    write(chr(c))
end;

{ detab -- convert tabs to equivalent number of blanks }
procedure detab;
const
    MAXLINE = 1000; { or whatever }
type
    tabtype = array [1..MAXLINE] of boolean;
var
    c: character;
    col: integer;
    tabstops: tabtype;
{$I tabpos.pas}
{$I settabs.pas}
begin
settabs(tabstops);   { set initial tab stops }
col:=1;
while (getc(c) <> ENDFILE) do
    if (c = TAB) then
        repeat
            putc(BLANK);
            col:=col+1
        until (tabpos(col,tabstops))
    else if (c = NEWLINE) then
        begin
        putc(NEWLINE);
        col:=1
        end
    else
        begin
        putc(c);
        col:=col+1
        end
end;

begin   { main program }
detab
end.
