
#include <stdlib.h>
#include <stdio.h>
#include "cvtpar.h"
#include "prsf2.h"

char fin[300], fon[300];

main(argc, argv)
	int	argc;
	char	**argv;
{
	register int c;
	static unsigned char buf[160];
	FILE *fi, *fo;
	int fmterr = 0;
	int recmark = 1;
	long rcnt = 0;
	long ccnt = 0;

	parsefiles(argc, argv, "txt", "bin", 0);
	if ((fi = fopen(fin, "r")) == NULL) {
		perror(fin);
		exit(1);
	}
	if ((fo = fopen(fon, "wb")) == NULL) {
		perror(fon);
		exit(1);
	}
	while ( (c = fgetc(fi)) != EOF ) {
		if (c == '\n') {
			recmark = 1;
			continue;
		}
		if (c == '|')
			continue;
		if (!fmterr &&
		    c != '~' &&
		    (c < ' ' || c > '_')) {
			fmterr = 1;
			fprintf(stderr, "Format error in %s\n", fin);
		}
		if (c == '~')
			c = 017;
		else
			c = (c - ' ') & 077;
		if (recmark) {
			c |= 0200;
			recmark = 0;
			rcnt++;
		}
		fputc(oddpar[c & 077] | (c & 0200), fo);
		ccnt++;
	}
	fputc(0200, fo);
	printf("%ld records, %ld characters\n", rcnt, ccnt);
}
