/*
	TxtCvt
	Convert PC document files of Microsoft Word for DOS & Windows & Windows Write
	to a pure ASCII-format 

	N Fisketjøn 190793
*/

#include "txtcvt.h"

extern getfiletype(FILE *ifp);
extern readmsfile(FILE *ifp, FILE *ofp, int filetype);

void version(void)
{
	printf("$VER: TxtCvt 1.0");
}

void main (argc,argv)
int argc;
char *argv[];
{
	FILE *ifp;
	FILE *ofp;
	int filetype;

    if (argc != 3) {
        printf("Usage: TxtCvt \033[3minputfile\033[0m \033[3moutputfile\033[0m\n");
        exit(0);
    }
    else {
		ifp=fopen(argv[1],"r");
		if(ifp == NULL) {
			printf("Inputfile not found.\n");
		}
		else {
			filetype = getfiletype(ifp);
			if(filetype == NULL) {
				printf("Unable to determine input filetype.\n");
			}
			else {
				ofp=fopen(argv[2],"w");
				if(ofp == NULL) {
					printf("Unable to open outputfile '%s'.\n",argv[2]);
				}
				else {
					printf("Reading '%s'...\n",argv[1]);
					switch (filetype) {
						case DOSWORD: {
							readmsfile(ifp, ofp, filetype);
							break;
						}
						case WINWORD1: {
							readmsfile(ifp, ofp, filetype);
							break;
						}
						case WINWORD2: {
							readmsfile(ifp, ofp, filetype);
							break;
						}
						case WINWRITE: {
							readmsfile(ifp, ofp, filetype);
							break;
						}
						default: {
							printf("Unable to process inputfile\n");
							break;
						}
					}
					fclose(ofp);
				}
			}
			fclose(ifp);
		}
	}
}
