home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol291 / dws.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-12-22  |  2.3 KB  |  88 lines

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