home *** CD-ROM | disk | FTP | other *** search
- {---------------------------------------------------------------------------
- DETAB - remove tabs from a text file an replace them with appropiate number
- of blanks.
- ---------------------------------------------------------------------------}
- program DETAB;
- const
- MAXLINE = 255;
- TABSTOP = 4;
- TABCHAR = #09;
- NOTIFY = 10;
- BLANK = ' ';
- type
- int = integer;
- MaxString = string[MAXLINE];
- var
- tabs : array[1..MAXLINE] of boolean;
- I, col, k, kk : int;
- S, Sout : MaxString;
- File1, File2 : text;
-
- procedure Abend(msg : MaxString);
- begin
- writeln(msg);
- halt;
- end;
-
- procedure OpenFiles;
- begin
- if ParamCount < 2 then
- Abend('format is: DETAB file1 file2');
- assign(File1,ParamStr(1));
- {$I-} reset(File1); {$I+}
- if IOresult <> 0 then
- Abend('error opening input file ' + ParamStr(1));
- assign(File2,ParamStr(2));
- {$I-} rewrite(File2); {$I+}
- if IOresult <> 0 then begin
- close(File1);
- Abend('error opening output file ' + ParamStr(2));
- end;
- end;
-
- function ReadString(var S : MaxString): boolean;
- begin
- if not EOF(File1) then begin
- ReadString := true;
- ReadLn(File1,S);
- end else
- ReadString := false;
- end;
-
- procedure WriteString(var S : MaxString);
- begin
- WriteLn(File2,S);
- end;
-
- procedure CloseFiles;
- begin
- close(File1);
- close(File2);
- end;
-
-
- begin (* main program *)
- OpenFiles;
- for I:=1 to MAXLINE do (* initialize tabstops array *)
- tabs[I] := (I mod TABSTOP) = 1;
- K := 0;
- KK := 0;
- while ReadString(S) do begin
- col := 1;
- for I:=1 to length(S) do begin
- if S[I] <> TABCHAR then begin
- Sout[col] := S[I];
- col := succ(col);
- end else
- repeat
- Sout[col] := BLANK;
- col := succ(col);
- until tabs[col] or (col > MAXLINE);
- end; (* FOR *)
- Sout[0] := chr(col-1);
- WriteString(Sout);
- K := succ(K);
- KK := succ(KK);
- if K > NOTIFY then begin
- gotoxy(1,25); clreol; write(KK);
- K := 0;
- end;
- end; (* WHILE *)
- CloseFiles;
- end.