static const char rcsid[] =
	"$Id: fontmake.c,v 1.4 2000/06/24 00:51:34 ben Exp $";

#include <sys/types.h>
#include <sys/stat.h>

#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void usage(void);
void font_make(FILE *);

int
main(int argc, char **argv) {
	FILE *fp;

	if (getopt(argc, argv, "") != -1)
		usage();

	argc -= optind;
	argv += optind;

	if (argc != 1)
		usage();

	if (isatty(STDOUT_FILENO))
		errx(1, "please redirect stdout to a non-terminal device");

	if ((fp = fopen(*argv, "r")) == NULL)
		err(1, "%s", *argv);

	font_make(fp);

	return (EXIT_SUCCESS);
}

void
font_make(FILE *fp) {
	char line[20];
	int byte, bit, size;

	size = 0;
	while (fgets(line, sizeof line, fp) != NULL) {
		if (strlen(line) > 4 && strcmp(line + 4, "----\n") == 0) {
			if (size != 0 && size != 8 &&
			  size != 14 && size != 16)
				errx(1, "bad file format, wrong size");
			else {
				size = 0;
				continue;
			}
		}

		size++;
		byte = 0;
		for (bit = 0; bit < 8; bit++)
			if (line[bit] == '\n')
				/* end of line, assume all spaces */
				break;
			else if (line[bit] == '#')
				byte |= 1 << (7 - bit);
			else if (line[bit] != ' ')
				errx(1, "bad file format, "
				  "bad character %#x", line[bit]);

		putc(byte, stdout);
	}

	if (size != 0 && size != 8 && size != 14 && size != 16)
		errx(1, "bad file format, wrong size %d (at end)", size);
}

void
usage(void) {
	fprintf(stderr, "usage: fontedit <font>\n\n");
	fprintf(stderr, "this will read the human readable file <font>\n");
	fprintf(stderr, "and write a raw font file to stdout which you\n");
	fprintf(stderr, "can then use as a console font.\n");

	exit(EXIT_FAILURE);
}


syntax highlighted by Code2HTML, v. 0.9.1