home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_07 / HISPEED1.ZIP / DOSDEMO / NOTABS.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-02  |  3KB  |  101 lines

  1. {---------------------------------------------------------------------}
  2. {                     HighSpeed Pascal Demo Program                   }
  3. {                                                                     }
  4. {              Copyright (C) 1990 by D-House I Aps, Denmark           }
  5. {                                                                     }
  6. {                     Programmed by Jacob V. Pedersen                 }
  7. {                                                                     }
  8. {                                                                     }
  9. { The program: Expands tabulator signs, and removes any unnessecary   }
  10. {              spaces at the end of each line in the program. The     }
  11. {              original file is renamed to nnnn.BAK before processed. }
  12. {              Output is an nnnn.PAS file.                            }
  13. {---------------------------------------------------------------------}
  14. Program NoTabs;
  15.  
  16. Uses Dos,UtilUnit;
  17.  
  18. Const
  19.         MaxLnLng = 127;
  20.         TabSize  =   8;
  21.  
  22.                                            
  23. Procedure Process(N : Byte);                
  24. Var
  25.         Data    : String[MaxLnLng];
  26.         I,O     : Text;
  27.         Dir     : DirStr;
  28.         Name    : NameStr;
  29.         Ext     : ExtStr;
  30.         InName,
  31.         OutName : PathStr;
  32.         Line    : Integer;
  33.            
  34. Procedure Expand;
  35. Const
  36.         Spaces  = '                      ';
  37. Var
  38.         TabPos  : Byte;
  39.         ToIns   : Byte;
  40. Begin
  41.   While Pos(#9,Data) > 0 Do
  42.     Begin
  43.       TabPos := Pos(#9,Data);
  44.       ToIns  := Succ(TabSize)-(TabPos MOD TabSize);
  45.       Delete(Data,TabPos,1);
  46.       If ToIns < Succ(TabSize) then
  47.         Insert(Copy(Spaces,1,ToIns),Data,TabPos)
  48.       Else
  49.         Insert(' ',Data,Tabpos);
  50.     End;
  51.   While Copy(Data,Length(Data),1) = #32 Do 
  52.     Delete(Data,Length(Data),1);
  53. End; { Expand }
  54.                                                                 
  55. Begin { Process }
  56.   FSplit(ParamStr(N),Dir,Name,Ext);
  57.   InName := Dir+Name+'.BAK';
  58.   OutName:= Dir+Name+'.PAS';
  59.   
  60.   If Exist(InName) then
  61.     Writeln('Backup file "',InName,'" already exists. Cannot continiue.')
  62.   Else
  63.   If Not(Exist(OutName)) then
  64.     Writeln('Cannot open input file: "',OutName,'"')
  65.   Else
  66.     Begin
  67.       Rename(OutName,InName);     { From .PAS to .BAK }
  68.       Reset(I,InName);            { Read from .BAK }
  69.       Rewrite(O,OutName);         { Write to .PAS }
  70.       Line := 0;
  71.       While Not(Eof(I)) Do
  72.         Begin
  73.           ReadLn(I,Data);
  74.           Expand;
  75.           WriteLn(O,Data);
  76.           Inc(Line);
  77.           GotoXy(1,WhereY); Write(OutName,' (',Line,')');
  78.           If (Length(Data) = MaxLnLng) then
  79.             Writeln(#7,' ERROR: Long line found. Data may be lost!');
  80.         End;
  81.       Close(I);
  82.       Close(O);
  83.       Writeln;
  84.       Writeln('Done.');
  85.     End;
  86. End; { Process }
  87.  
  88.  
  89. Var
  90.         X        : Byte;       
  91. BEGIN
  92.   Clrscr;
  93.   Writeln('HighSpeed Pascal tab-sign expander.');
  94.   Writeln;
  95.   If ParamCount = 0 then
  96.     Writeln('Please specify filename(s) on command line.')
  97.   Else
  98.     For X := 1 to ParamCount Do
  99.       Process(X);
  100. END.
  101.