#include <stdlib.h>
#include <stdio.h>
#include <dir.h>
#include <string.h>

int main(int argc, char *argv[])
{
	FILE *infile,*outfile;
	char fname[MAXPATH];
	char line[80+1+6];
	char temp[80];
	void usage();

	if(--argc != 1) {
		usage();
		return(0);
	}

	if(strlen(*++argv) > MAXPATH-4) {
		fprintf(stderr,"File name too long: %s\n",argv);
		usage();
		return(0);
	}

	strcpy(fname,*argv);
	strcat(fname,".org");
	if((infile = fopen(fname,"r")) == NULL) {
		perror("Can't open input file");
		fprintf(stderr,"File: %s\n",fname);
		usage();
		return(0);
	}

	strcpy(fname,*argv);
	strcat(fname,".aut");
	if((outfile = fopen(fname,"w")) == NULL) {
		perror("Can't create output file");
		fprintf(stderr,"File: %s\n",fname);
		fclose(infile);
		usage();
		return(0);
	}


	while(fgets(line,81,infile) != NULL) {
		if(line[0] != '*') {
			strncpy(temp,line+7,5);
			if(strlen(line) > 13) {
				strcpy(temp+5,line+13);
			}
			else if(strlen(line) == 13) {
				temp[5] = '\n';
				temp[6] = 0;
			}
			else if(strlen(line) == 12) {
				temp[5] = 0;
			}
			line[7] = 0;
			strcat(line,"    ");
			strcat(line,temp);
		}
		fputs(line,outfile);
	}

	fclose(infile);
	fclose(outfile);
	return(1);
}

void usage()
{
	fprintf(stderr,"Usage: cvrtaut file-part (without extension)\n");
}

