1 /* splitfont: extract characters from font */
2 /* this is for iso fonts, no psf header, just 256 characters */
10 dosplit (int from, int to, char *fontbuf, int size, char *fontfile) {
11 int itemsize = size/256;
16 if (from < 0 || from > 255 || to < 0 || to > 255) {
17 fprintf(stderr, "splitfont: bad argument %s,%s\n",
21 if(strlen(fontfile) >= sizeof(filename)-4) {
22 fprintf(stderr, "splitfont: ridiculously long name\n");
26 sprintf(filename, "%s.%02x", fontfile, from);
27 if ((fd = open(filename, O_WRONLY|O_CREAT, 0666)) < 0) {
29 fprintf(stderr, "cannot open %s for writing\n", filename);
31 p = &fontbuf[from*itemsize];
32 if (write(fd, p, itemsize) != itemsize) {
34 fprintf(stderr, "error writing %s\n", filename);
41 int main(int argc, char **argv) {
49 fprintf(stderr, "call: splitfont fontfile 17,23-30,...\n");
52 if (stat(argv[1], &statbuf)) {
54 fprintf(stderr, "cannot stat fontfile %s", argv[1]);
57 if (statbuf.st_size > 4096) {
58 fprintf(stderr, "splitfont: file unexpectedly large\n");
61 if (statbuf.st_size % 256) {
62 fprintf(stderr, "splitfont: file size not a multiple of 256\n");
65 if ((fd = open(argv[1], O_RDONLY)) < 0) {
67 fprintf(stderr, "cannot open fontfile %s", argv[1]);
70 if (read(fd, fontbuf, statbuf.st_size) != statbuf.st_size) {
72 fprintf(stderr, "error reading fontfile %s", argv[1]);
78 to = from = strtoul(p,&q,0);
84 fprintf(stderr, "splitfont: garbage in %s\n", p);
87 dosplit(from, to, fontbuf, statbuf.st_size, argv[1]);