/*
**  Copyright (C) 1987 By Robert G. Arsenault
**
**  This software is provided "as-is" and carries with it no explicit or
**  implicit promise of support by the author. Nor will the author be 
**  held liable for any damages, real or imagined, which may result 
**  from the use or abuse of this software.
**
**  The author grants permission for the non-commercial distribution of 
**  this software provided that this and other identifying information 
**  remains intact.
*/
#include <stdio.h>
#include <exec/types.h>
#include <libraries/dosextens.h>

#define LSIZE 256
#define CR  ''
#define NL  '\n'

main(argc,argv)
int argc;
char *argv[];
{
	LONG	hand;
	FILE 	*fpr, *fpw, *fopen();
	LONG	tmp_hand;
	char	*c, line[LSIZE];

	if (argc != 3) {
		hand = Open ("CON:10/10/320/28/Stip Error",MODE_NEWFILE);
		if (hand) {
			Write (hand, "\nUsage: Strip^M In_File Out_File",32);
			Delay (200);
			Close (hand);
		}
		exit(1);
	}
	if (tmp_hand = Lock (argv[2], ACCESS_READ)) {
		UnLock (tmp_hand);
		hand = Open ("CON:10/10/550/28/Stip Error",MODE_NEWFILE);
		if (hand) {
			Write (hand, "\nOutput file ",13);
			Write (hand, argv[2], strlen(argv[2]));
			Write (hand, " can not already exist",22);
			Delay (200);
			Close (hand);
		}
		exit(1);
	}

	if (!(fpr = fopen(argv[1], "r"))) {
		hand = Open ("CON:10/10/550/28/Stip Error",MODE_NEWFILE);
		if (hand) {
			Write (hand, "\nInput file ",12);
			Write (hand, argv[1], strlen(argv[1]));
			Write (hand, " can not be opened for reading",30);
			Delay (100);
			Close (hand);
		}
		exit(1);
	}

	if (!(fpw = fopen(argv[2], "w"))) {
		fclose (fpr);
		hand = Open ("CON:10/10/550/28/Stip Error",MODE_NEWFILE);
		if (hand) {
			Write (hand, "\nOutput file ",13);
			Write (hand, argv[2], strlen(argv[2]));
			Write (hand, " can not be opened for writing",30);
			Delay (100);
			Close (hand);
		}
		exit(1);
	}

	while (fgets (line, LSIZE, fpr)) {
		for (c = line; *c ; c++)
			if (*c == CR)
				fputc (NL, fpw);
			else
				fputc (*c, fpw);
	}

	fclose (fpr);
	fflush (fpw);
	fclose (fpw);
}
