#ifndef lint
static char *sccsid = "@(#)chargen.c	1.2 (UKC) 22/7/86";
#endif  lint

/*
 *	Program to convert ascii character rasters into C initialisers
 *	for inclusion in dbbc2.c of the ditroff previewer
 */

#include <stdio.h>

char line[256];
char *gets();

main()
{
	register int i, j, n, bit;
	register char *res;
	register int lineno;	/* for erro reporting */

	puts("#include \"bbcplot.h\"\n");	/* for typedef grid */
	puts("#include \"types.h\"\n");
	puts("struct charraster charraster[] = {");
	lineno = 0;
	while (1) {
		/* Gobble blank lines and comments */
		while ((lineno++, res=gets(line)) != NULL && (line[0] == '\0' || line[0] == '#'));
		if (res == NULL) {
			/* EOF in the right place */
			break;
		}
		if (strlen(line) != 2) {
			fprintf(stderr, "chargen: Line %d is not a 2-char name.\n", lineno);
			exit(1);
		}
		printf("\t{ '%s', {", line);
		for (i=0; i<8; i++) {
			res = gets(line);
			lineno++;
			if (res == NULL) {
				fputs("chargen: unexpected EOF.\n", stderr);
				putchar('\n');
				exit(1);
			}
			if (strlen(line) > 8) {
				fprintf (stderr, "chargen: Warning: line %d is longer than 8 characters.\n", lineno);
			}
			bit = 128; n=0;
			for (j=0; j<8; j++) {
				if (line[j] == '\0') break;
				switch (line[j]) {
				case ' ':
					break;
				default:
					n = n | bit;
				}
				bit >>= 1;
			}
			printf( i<7 ? "%4d," : "%4d } },\n", n);
		}
	}
	puts("\t{ 0, 0 }");
	puts("};");
	exit(0);
}
