[comp.sys.ibm.pc] Cure for Kermit Blues

farren@hoptoad.UUCP (02/14/87)

Late last night, I finished transferring 650K worth of files using good 'ol
ckermit, rm'd all of the files, and then went to my PC to decompress 'em
and put 'em away.  Of course, it was only then that I found out that I hadn't
"set file type bin", so the files were not usable.  After mucho moaning and
groaning, I wrote the following utility.  It transforms all occurances of
0x0d followed by 0x0a (the CR/LF pair ckermit translates LF's into) into
a single 0x0a.  Of course, this doesn't work will ALL files - sooner or
later you are going to run into a 0x0d 0x0a pair that belongs there - but it
did work on about 600K of the 650K.  Only one file was still messed up, and
even then, most of the data was O.K.  I hope this will be of some help to
other late night communicators.

--------

/* striplf.c - strips extraneous carriage returns from falsely transmitted
   files */

#include <stdio.h>

main(argc, argv)
int argc;
char *argv[];
{
  FILE *infile,*outfile;
  int a,b;

  infile = fopen(argv[1], "rb");
  if(infile==NULL) {
    perror("Input file open error ");
    exit(20);
  }
  outfile = fopen(argv[2], "wb");
  if(outfile==NULL) {
    perror("Output file open error ");
    exit(20);
  }

  while((a = fgetc(infile))!=EOF) {
    if(a == 0x0d) {
      if((b = fgetc(infile))!=EOF) {
	if(b==0x0a) fputc(b, outfile);
	else {
	  fputc(a, outfile);
	  fputc(b, outfile);
	}
      }
    }
    else fputc(a, outfile);
  }
  fclose(infile);
  fclose(outfile);
}

-------

A simple program, but useful.  Hope it can help some of you.
-- 
----------------
                 "... if the church put in half the time on covetousness
Mike Farren      that it does on lust, this would be a better world ..."
hoptoad!farren       Garrison Keillor, "Lake Wobegon Days"