Turbo Pascal 5.5

Download

 

Wrote only a handful of Pascal Programs in 1997 when I needed a quick way to run an executable program on a PC.  This program stripped high-order ASCII characters from the file name passed in.

program STRPCTRL;
{ remove control and high order ascii characters  -- ray 08-97 }

uses
  dos;

const
  tempname = 'temp.xxx';

var
  infile   : text;
  outfile  : text;
  ch       : char;
  leave    : boolean;
  crtn     : boolean;
  c10      : boolean;
  asval    : integer;
  sr       : searchrec;
  stamp    : longint;

(*---------------------------------------------------------------*)
begin
  findfirst('*.lo?', 0, sr);
  while doserror = 0 do
    with sr do
    begin
      ASSIGN(infile, name);
      RESET(infile);
      getftime(infile, stamp);
      ASSIGN(outfile, tempname);
      REWRITE(outfile);
      while not eof(infile) do
        begin
          READ(infile, ch);
          asval := ord(ch);
          leave := (asval > 26) and (128 > asval);
          crtn := (asval = 13);
          c10 := (asval = 10);
          if crtn
            then
            { time for new line }
              WRITELN(outfile)
            else
              if leave
                then
                { within the range, write it out }
                  WRITE(outfile, ch)
                else
                  if c10
                    then
                    { linefeed, do nothing }
                    else
                    { replace the non-printable with a space }
                      WRITE(outfile, ' ');
        end; {while}
      CLOSE(infile);
      CLOSE(outfile);
      { get rid of the temp file we kept in case we were aborted }
      ERASE(infile);
      { write out the 'real' file }
      RENAME(outfile, name);
      ASSIGN(outfile, name);
      RESET(outfile);
      setftime(outfile, stamp);
      findnext(sr);
    end;
end.

 

Email: raykelly@rakelly.com

TOP