#include <stdio.h>
#define NAME "nlfilt"
#define VERSION "1.0"
#define CR '\015'
#define LF '\012'
#define FATAL -2

main(int argc,char *argv[])
{
	int c;
	FILE *fi,*fo;
	printf("[%s:%s] Copyright (c) 1991 Andrew Gaunt.\n",NAME,VERSION);
	printf("Do not use without express permission from the author.\n");
	if (argc!=3){
		printf("usage: nlfilt infile outfile.\n");
		exit(FATAL);
	}
	if ( (fi=fopen(argv[1],"rb")) == NULL){
		printf("ERROR: can't open input file.\n");
		exit(FATAL);
	}
	if ( (fo=fopen(argv[2],"wb")) == NULL){
		printf("ERROR: can't open output file.\n");
		exit(FATAL);
	}

	printf("Processing %s->%s [%s:%s] ...\n",argv[1],argv[2],NAME,VERSION);
	while( (c=fgetc(fi)) != EOF){
		switch(c){
			case CR:
				c=fgetc(fi);
				if (c!=CR && c!=EOF){
					printf("+");
					fputc(CR,fo);
					fputc(c,fo);
				}
				else{
					printf(".");
					fputc(CR,fo);
				}
				break;
			
			default:
				fputc(c,fo);
		}
	}
	printf("\nDONE!\n");
	fclose(fi);
	fclose(fo);
}
