home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / PROG / PASCAL / TPSTR121.ZIP / PREEN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-12-18  |  2.0 KB  |  58 lines

  1. { Remove garbage characters from a file.  Useful for recovering damaged text }
  2. { files after disasters. Deletes everything but graphic ascii chars, CR's,   }
  3. { LF's and tabs.}
  4. { This is a demo for STRINGS.TPU copyright 1989 by Richard Winkel }
  5. program preen;
  6. uses strings;
  7. const spinner:array[0..3] of char=('/','-','\','|');
  8. type buftype=array[0..$FFF0] of char;
  9. var i,size,inlen,outlen,written:word;
  10.     tr_in,tr_out:string;
  11.     src,dest:^string;
  12.     holdlen:byte;
  13.     holdchar:char;
  14.     buf:^buftype;
  15.     infile,outfile:file;
  16.  
  17. begin
  18.    if paramcount<>2 then begin
  19.       writeln('Invalid number of parameters.');
  20.       writeln('Syntax: PREEN infile outfile');
  21.       writeln('Preen removes non-printable characters from a file.');
  22.       halt;
  23.    end;
  24.    tr_in:=' '+xrange(#0,#8)+#11+#12+xrange(#14,#31)+xrange(#127,#255);
  25.    tr_out:=#0+left('',length(tr_in)-1,' ');
  26.    assign(infile,paramstr(1));
  27.    assign(outfile,paramstr(2));
  28.    if maxavail>$FFF1 then size:=$FFF1 else size:=maxavail;
  29.    getmem(buf,size);
  30.    reset(infile,1); rewrite(outfile,1);
  31.    repeat
  32.       outlen:=0;
  33.       blockread(infile,buf^[1],size,inlen);
  34.       src:=pointer(buf); dest:=src;
  35.       for i:=1 to inlen div 255 do begin
  36.          write(spinner[i and 3],^M);
  37.          holdchar:=dest^[0];
  38.          src^[0]:=#255;
  39.          dest^:=translate(space(translate(src^,tr_in,tr_out),0),#0,#32);
  40.          holdlen:=byte(dest^[0]);
  41.          outlen:=outlen+holdlen;
  42.          dest^[0]:=holdchar;
  43.          src:=@src^[255];
  44.          dest:=@dest^[holdlen];
  45.       end;
  46.       holdchar:=dest^[0];
  47.       src^[0]:=chr(inlen mod 255);
  48.       dest^:=translate(space(translate(src^,tr_in,tr_out),0),#0,#32);
  49.       outlen:=outlen+byte(dest^[0]);
  50.       dest^[0]:=holdchar;
  51.       blockwrite(outfile,buf^[1],outlen,written);
  52.    until eof(infile) or (written<>outlen);
  53.    write(' ',#8);
  54.    if written<>outlen then writeln('Error writing ',paramstr(2),'.');
  55.    close(infile); close(outfile);
  56.    freemem(buf,size);
  57. end.
  58.