/***************
*
* g:\exe\txl\src\txlmain.c
*/
#define MAIN 1
#include "txl.h"
#define VERSION "V1.1R3"


#include <setjmp.h>

jmp_buf exitjmp;


void Exit(int val)
{
	free(line1);
	if (cfwork != NULL) {
		free(cfwork);
	}
	if (fpmes != NULL) {
		fclose(fpmes);
	}
	longjmp(exitjmp, val+1);
}

void errexit(char *errmes)
{
	if (fpmes != NULL) {
		fprintf(fpmes, "\nTXL:(Error)%s\n", errmes);
	}
	Exit(1);
}

void init(char *name)
{
	char *path;

	path = ((strlen(name) > 33) ? jstrrchr(name, '\\')+1 : name);
	fprintf(stderr,"%s " VERSION " copyright (C) 1994-1995  T.Nakatani\n", path);

	log_idstr[0]  = NUL;
	log_resp[0]   = NUL;
	log_handle[0] = NUL;
	log_fname[0]  = NUL;
	log_pname[0]  = NUL;
	log_pname[8]  = NUL;
	inputfile = NULL;
	outputfile = NULL;
	line1 = calloc(240, 1);
	line2 = line1 + 80;
	line3 = line2 + 80;
	fpmes = NULL;
	cfwork = NULL;

	if (line1 == NULL) {
		errexit("out of memory(init)");
	}

}

int main(int argc, char *argv[])
{
	volatile int ret;
	ret = setjmp(exitjmp);
	if (ret == 0) {
		init(argv[0]);
		cfexpand(argc - 1, &(argv[1]));
	} else {
		ret--;
	}
	return ret;
}
