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

  1. program strip8;
  2.  
  3. (*************************************************)
  4. (*                                               *)
  5. (*  This program inhales a text file containing  *)
  6. (*  characters with the 8th bit set (like those  *)
  7. (*  produced by WordStar), and outputs the text  *)
  8. (*  to another file, with the 8th bit cleared.   *)
  9. (*                                               *)
  10. (*************************************************)
  11.  
  12. const
  13.   bufsize = 16384;
  14.  
  15. type
  16.   name = string[14];
  17.  
  18. var
  19.   infile, outfile: text;
  20.   inname, outname: name;
  21.   indata, inputchar: char;
  22.   buffer: array[1..bufsize] of char;
  23.   bufpoint, outpoint : integer;
  24.  
  25. function clearbit8(inchar: char): char;
  26.  
  27.   begin
  28.     clearbit8 := chr(ord(inchar) and 127);
  29.   end;
  30.  
  31. function exists(filename: name): boolean;
  32.  
  33.   var tempfile: text;
  34.       found: boolean;
  35.  
  36.   begin
  37.     assign(tempfile, filename);
  38.     (*$I-*) reset(tempfile) (*I+*);
  39.     found := (IOresult = 0);
  40.     if found then close(tempfile);
  41.     exists := found;
  42.   end;
  43.  
  44. begin
  45.   inputchar := 'Y';
  46.   clrscr;
  47.   write('Enter Name of Input text file? ');
  48.   readln(inname);
  49.   if exists(inname) then begin
  50.     write('Enter Name of Output file? ');
  51.     readln(outname);
  52.     if exists(outname) then begin
  53.       write('*File Exists: Overwrite (Y/N)? ');
  54.       read(inputchar);
  55.       writeln;
  56.     end;
  57.     if upcase(inputchar) = 'Y' then begin
  58.       assign(infile, inname);
  59.       reset(infile);
  60.       assign(outfile, outname);
  61.       rewrite(outfile);
  62.       while not eof(infile) do begin
  63.         bufpoint := 0;
  64.         while (bufpoint < bufsize) and not eof(infile) do begin
  65.           bufpoint := bufpoint + 1;
  66.           read(infile, indata);
  67.           buffer[bufpoint] := clearbit8(indata);
  68.         end;
  69.         if bufpoint > 0 then for outpoint := 1 to bufpoint do
  70.           write(outfile, buffer[outpoint]);
  71.       end;
  72.       close(infile);
  73.       close(outfile);
  74.       writeln('Conversion complete.');
  75.     end;
  76.   end
  77.   else writeln('Input file not found.');
  78. end.
  79.