home *** CD-ROM | disk | FTP | other *** search
/ PD ROM 1 / PD ROM Volume I - Macintosh Software from BMUG (1988).iso / Programming / Programming Tools / Turbo Pascal / Utilities / FIXTAB.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-06-16  |  1.3 KB  |  58 lines  |  [TEXT/ttxt]

  1. program FixTabs;
  2.  
  3. { This simple program removes those annoying tabs from EDIT files & replaces
  4.   them with spaces. It makes life much easier when you switch to the TURBO
  5.   editor.
  6.   
  7.   The constant "tabs" contains the number of spaces per tab.
  8.   
  9.                 Mike Babulic.  87/03/15
  10. { $U FileUT}
  11.  
  12. USES MemTypes,QuickDraw,OSIntf,ToolIntf,PackIntf,FileUT;
  13.  
  14. const tabs = 8;
  15.  
  16. var inFile,outFile: text;
  17.     
  18.     c:char;
  19.     i,n,m:integer;
  20.     
  21. procedure ReplaceTabs;
  22.   const
  23.     TAB = #9;
  24.     CR  = #13;
  25.     LF  = #10;
  26.   var
  27.     c:char;
  28.     i,n,m:integer;
  29.   begin
  30.     n := 0;
  31.     while not EOF(inFile) do begin
  32.       read(inFile,c);
  33.       if c=TAB then begin
  34.         for i := tabs downto (n mod tabs)+1 do begin
  35.           write(outFile,' ');
  36.           n := succ(n);
  37.         end
  38.         end
  39.       else if c<>LF then begin  {Strip out Line Feeds}
  40.         n := succ(n);
  41.         write(outFile,c);
  42.         if c=CR then n:= 0;     {Carriage Return starts a new page}
  43.       end;
  44.     end;
  45.   end;
  46.     
  47. begin
  48.   FileBlockSize := $8000;
  49.   if SFGetReset(inFile,TextFile,'') then begin
  50.     TextCreator := 'TPAS';
  51.     if SFPutCreate(outFile,TextFile,'New '+SFDialog.r.fName) then begin
  52.       ReplaceTabs;
  53.       close(outfile);
  54.     end;
  55.     close(infile);
  56.   end;
  57. end.