home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / DWS.ZIP / DWS.PAS
Encoding:
Pascal/Delphi Source File  |  1985-12-28  |  2.4 KB  |  90 lines

  1. Program DeWordStar;
  2.  
  3. { A program to convert WordStar format files to normal ASCII files.  It
  4.   removes all high bits, tosses out any control characters except CR,
  5.   LF, and TAB, and optionally expands tabs.
  6.   Requires the command line argument processor in CLA.PAS.
  7.   Syntax:
  8.     DWS inputname [outputname] [/t]
  9.   -  Bela Lubkin
  10. }
  11.  
  12. {$ICLA.PAS}  { Include the command line parse routines }
  13.  
  14.   Type
  15.     FileName=String[20];
  16.  
  17.   Const
  18.     BufSize=150;
  19.     BufByteSize=19200;
  20.  
  21.   Var
  22.     Source: File;
  23.     Dest: Text;
  24.     SourceName,DestName,Switch: FileName;
  25.     Buffer: Array [1..BufByteSize] Of Byte;
  26.     B: Byte;
  27.     RecsToRead,Remaining,I,Pos: Integer;
  28.     Done,DeTab: Boolean;
  29.  
  30.   Begin
  31.     SourceName:=CommandLineArgument('Input file name: ','/',False);
  32.     DestName:=CommandLineArgument('Output file name: ','CON:',False);
  33.     Switch:='/';
  34.     DeTab:=False;
  35.     While Switch<>'' Do
  36.      Begin
  37.       Switch:=CommandLineArgument('','',True);
  38.       If Switch='' Then
  39.       Else If (Switch='/T') Or (Switch='/t') Then DeTab:=True
  40.       Else
  41.        Begin
  42.         WriteLn('Unrecognized switch "',Switch,'"');
  43.         Halt;
  44.        End;
  45.      End;
  46.     Assign(Source,SourceName);
  47.     {$I-} Reset(Source); {$I+}
  48.     If IOResult<>0 Then
  49.      Begin
  50.       WriteLn('File "',SourceName,'" not found.');
  51.       Halt;
  52.      End;
  53.     Assign(Dest,DestName);
  54.     {$I-} ReWrite(Dest); {$I+}
  55.     If IOResult<>0 Then
  56.      Begin
  57.       WriteLn('File "',DestName,'" could not be created.');
  58.       Halt;
  59.      End;
  60.     Remaining:=FileSize(Source);
  61.     While Remaining>0 Do
  62.      Begin
  63.       If BufSize<=Remaining Then RecsToRead:=BufSize
  64.       Else RecsToRead:=Remaining;
  65.       BlockRead(Source,Buffer,RecsToRead);
  66.       Pos:=0;
  67.       Done:=False;
  68.       For I:=1 To 128*RecsToRead Do
  69.        Begin
  70.         B:=Buffer[I] And $7F;
  71.         If B In [0..8,11,12,14..25,27..31,127] Then B:=128;
  72.         If Not Done And (B<>26) Then
  73.          Begin
  74.           If (B=9) And DeTab Then
  75.            Begin
  76.             Write(Dest,Copy('         ',1,8-(Pos And 7)));
  77.             Pos:=(Pos+8) And $FFF8;
  78.            End
  79.           Else If B<>128 Then Write(Dest,Chr(B));
  80.           If B=13 Then Pos:=0
  81.           Else If (B>31) And (B<127) Then Pos:=Pos+1;
  82.          End
  83.         Else Done:=True;
  84.        End;
  85.       Remaining:=Remaining-RecsToRead;
  86.      End;
  87.     Close(Source);
  88.     Close(Dest);
  89.   End.
  90.