static const char rcsid[] =
	"$Id: fontdump.c,v 1.4 2000/06/24 00:48:35 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_dump(FILE *, int);

int
main(int argc, char **argv) {
	FILE *fp;
	struct stat sb;
	int size;

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

	argc -= optind;
	argv += optind;

	if (argc != 1)
		usage();

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

	if (fstat(fileno(fp), &sb) < 0)
		err(1, "fstat");

	if (sb.st_size == 16 * 256)
		size = 16;
	else if (sb.st_size == 14 * 256)
		size = 14;
	else if (sb.st_size == 8 * 256)
		size = 8;
	else
		errx(1, "unknown font size");

	font_dump(fp, size);

	return (EXIT_SUCCESS);
}

void
font_dump(FILE *fp, int size) {
	int ch, li, d, bit;

	for (ch = 0; ch < 256; ch++) {
		printf("- %c ----\n", (isprint(ch) || ch > 127) ? ch : ' ');
		for (li = 0; li < size; li++) {
			d = getc(fp);

			if (d == EOF)
				errx(1, "unexpected EOF");

			for (bit = 7; bit >= 0; bit--)
				if (d & (1 << bit))
					printf("#");
				else
					printf(" ");
			printf("\n");
		}
		printf("--------\n");
	}
}

void
usage(void) {
	fprintf(stderr, "usage: fontdump <font>\n\n");
	fprintf(stderr, "This will dump the raw fontfile <font> to stdout\n");
	fprintf(stderr, "in a human readable form which can be edited and\n");
	fprintf(stderr, "turned back into a font file with 'fontmake'.\n");

	exit(EXIT_FAILURE);
}


syntax highlighted by Code2HTML, v. 0.9.1