4 * Extract a Unicode character table from a PSF font
6 * Copyright (C) 1994 H. Peter Anvin
8 * This program may be freely copied under the terms of the GNU
9 * General Public License (GPL), version 2, or at your option
22 typedef unsigned short unicode;
23 void usage(char *argv0)
25 fprintf(stderr, _("Usage: \n"
26 " %s psffont [outfile]\n"), argv0);
31 main(int argc, char *argv[])
35 struct psf_header psfhdr;
37 char buffer[65536]; /* Font data, is scratch only */
39 setlocale(LC_ALL, "");
40 bindtextdomain(PACKAGE, LOCALEDIR);
43 if ( argc < 2 || argc > 3 )
46 if ( !strcmp(argv[1],"-") )
53 in = fopen(inname = argv[1], "r");
61 if ( argc < 3 || !strcmp(argv[2],"-") )
65 out = fopen(argv[2], "w");
73 if ( fread(&psfhdr, sizeof(struct psf_header), 1, in) < 1 )
75 fprintf(stderr, _("%s: Cannot read psf header\n"), inname);
79 if (! PSF_MAGIC_OK(psfhdr) )
81 fprintf(stderr, _("%s: Bad magic number\n"), inname);
85 if ( psfhdr.mode > PSF_MAXMODE )
87 fprintf(stderr, _("%s: Unknown mode number (%d)\n"),
92 fontlen = ( psfhdr.mode & PSF_MODE512 ) ? 512 : 256;
94 if ( ! (psfhdr.mode & PSF_MODEHASTAB ) )
96 fprintf(stderr, _("%s: Font already had no character table\n"), inname);
99 psfhdr.mode &= ~PSF_MODEHASTAB; /* Clear the bit */
102 if ( fread(buffer, psfhdr.charsize, fontlen, in) < fontlen )
110 /* Write new font file */
111 fwrite(&psfhdr, sizeof(struct psf_header), 1, out);
112 fwrite(buffer, psfhdr.charsize, fontlen, out);