/*====================================================================
 *
 * TXF remove ctrl-Z module
 *
 *====================================================================
 *                                   copyright(C) 1992-1994 T.Nakatani
 *====================================================================
 */
#include "txf.h"

void removeeof()
{
	int chr = NUL;
	char *tmpinname, *tmpoutname;
	FILE *tmpin, *tmpout;

	if (viewmode > 1) {
		fprintf(stderr, "TXF Remove ctrl-Z module.\n");
	}

	tmpinname = ((tmpinfile == -1) ? inputfile : tfile[tmpinfile]);
	tmpoutname = tfile[((tmpinfile > 0) ? 0 : 1)];

	if (*tmpinname != NUL) {
		tmpin = fopen(tmpinname, "rb");
	}
	else {
		errexit("Cannot open inputfile.");
	}
	tmpout = fopen(tmpoutname, "wb");
#ifdef DEBUG
	if (viewmode > 2) {
		fprintf(stderr, "Info:readfile=%s,(%d)/writefile=%s,(%d)\n",
			tmpinname, tmpin, tmpoutname, tmpout);
	}
#endif
	if ((tmpin == NULL) || (tmpout == NULL)) {
		errexit("cannot open TMP/input file(remove ctrl-Z)\n");
	}

	while (chr != EOF) {
		chr = getc(tmpin);
		if ((chr != 0x1a) && (chr != EOF)) {
			putc((char)chr, tmpout);
		}
	}

	tmpinfile = ((tmpinfile > 0) ? 0 : 1);
#ifdef DEBUG
	if (viewmode > 2) {
		fprintf(stderr, "Info:tmpinfile = %d\n",tmpinfile);
	}
#endif
	tmpinname = tfile[tmpinfile];
	tmpoutname = tfile[1 - tmpinfile];

	fclose(tmpin);
	fclose(tmpout);

}
