/*****************************************************************
**																**
**		Line-Feed to Carriage-Return / Line-Feed Convertor		**
**																**
**		Written By Stuart Coates - 1st December 1991			**
**																**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**																**
**	A small utility that converts 0x0A to 0x0D 0x0A codes.		**
**	Useful when porting Unix text files to DOS machines.		**
**																**
**	Written on the Atari ST in Lattice C5.						**
**	ANSI compliant source, so porting should prove easy.		**
**																**
**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
**																**
**	USAGE:		UNIX2DOS <input file> <output file>				**
**																**
**	CAVEATS:	Assumes that there is enough disk space for		**
**				the output file.								**
**																**
*****************************************************************/


#include <stdio.h>					/* Normal Headers */
#include <stdlib.h>

#define	CARRIAGE_RETURN	0x0D
#define	LINEFEED		0x0A
#define FILE_ERROR		-33

int main(int argc, char *argv[]);	/* ANSI Prototype */

int main(int argc, char *argv[])
{
	register char ch;				/* Input/Output Character */
	FILE *fpin, *fpout;				/* FILE pointers */

	puts("UNIX to DOS text file convertor - by Stuart Coates\n");
	
	if(argc != 3)	{				/* Fail if incorrect params */
		puts("Usage: UNIX2DOS  <input file> <output file>\n");
		getchar();
		exit(0);	}

	fpin=fopen(argv[1],"rb");		/* Open input file */
	if(fpin == NULL)	{
		puts("ERROR opening input file - Hit Return");
		getchar();
		exit(FILE_ERROR);	}
	
	fpout=fopen(argv[2],"wb");		/* Open output file */
	if(fpout == NULL)	{
		puts("ERROR opening output file - Hit Return");
		getchar();
		exit(FILE_ERROR);	}

	puts("Working...");				/* Friendly message */
		
	while(!feof(fpin))	{				/* While not at end of file	*/
		ch=getc(fpin);					/* get a character			*/
		if(ch == LINEFEED)				/* If it's a LINEFEED		*/
			putc(CARRIAGE_RETURN,fpout);/* ..output a Carriage Ret	*/
		if(!feof(fpin))					/* If we're not finished	*/
			putc(ch,fpout);				/* ..output input character	*/
		}
	
	fclose(fpin);					/* Close Input File */
	fclose(fpout);					/* Close Output File */

	return(0);						/* Finished OK */
}
