summaryrefslogtreecommitdiff
path: root/tools/writerbf.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/writerbf.c')
-rw-r--r--tools/writerbf.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/tools/writerbf.c b/tools/writerbf.c
new file mode 100644
index 0000000000..b3ba8649ac
--- /dev/null
+++ b/tools/writerbf.c
@@ -0,0 +1,107 @@
1/*
2 * writerbf - write an incore font in .rbf format.
3 * Must be compiled with -DFONT=font_name and linked
4 * with compiled in font.
5 *
6 * Copyright (c) 2002 by Greg Haerr <greg@censoft.com>
7 */
8#include <stdio.h>
9#include "../firmware/font.h"
10
11extern MWCFONT FONT;
12PMWCFONT pf = &FONT;
13
14static int
15WRITEBYTE(FILE *fp, unsigned char c)
16{
17 return putc(c, fp) != EOF;
18}
19
20static int
21WRITESHORT(FILE *fp, unsigned short s)
22{
23 putc(s, fp);
24 return putc(s>>8, fp) != EOF;
25}
26
27static int
28WRITELONG(FILE *fp, unsigned long l)
29{
30 putc(l, fp);
31 putc(l>>8, fp);
32 putc(l>>16, fp);
33 return putc(l>>24, fp) != EOF;
34}
35
36static int
37WRITESTR(FILE *fp, char *str, int count)
38{
39 return fwrite(str, 1, count, fp) == count;
40}
41
42static int
43WRITESTRPAD(FILE *fp, char *str, int totlen)
44{
45 int ret;
46
47 while (*str && totlen > 0)
48 if (*str) {
49 ret = putc(*str++, fp);
50 --totlen;
51 }
52 while (--totlen >= 0)
53 ret = putc(' ', fp);
54 return ret;
55}
56
57/* write font, < 0 return is error*/
58int
59rbf_write_font(PMWCFONT pf)
60{
61 FILE *ofp;
62 int i;
63 char name[256];
64
65 sprintf(name, "%s.fnt", pf->name);
66 ofp = fopen(name, "wb");
67 if (!ofp)
68 return -1;
69
70 /* write magic and version #*/
71 WRITESTR(ofp, VERSION, 4);
72
73 /* internal font name*/
74 WRITESTRPAD(ofp, pf->name, 64);
75
76 /* copyright - FIXME not converted with bdf2c*/
77 WRITESTRPAD(ofp, " ", 256);
78
79 /* font info*/
80 WRITESHORT(ofp, pf->maxwidth);
81 WRITESHORT(ofp, pf->height);
82 WRITESHORT(ofp, pf->ascent);
83 WRITELONG(ofp, pf->firstchar);
84 WRITELONG(ofp, pf->defaultchar);
85 WRITELONG(ofp, pf->size);
86
87 /* variable font data sizes*/
88 WRITELONG(ofp, pf->bits_size); /* # words of MWIMAGEBITS*/
89 WRITELONG(ofp, pf->offset? pf->size: 0); /* # longs of offset*/
90 WRITELONG(ofp, pf->width? pf->size: 0); /* # bytes of width*/
91
92 /* variable font data*/
93 for (i=0; i<pf->bits_size; ++i)
94 WRITESHORT(ofp, pf->bits[i]);
95 if (pf->offset)
96 for (i=0; i<pf->size; ++i)
97 WRITELONG(ofp, pf->offset[i]);
98 if (pf->width)
99 for (i=0; i<pf->size; ++i)
100 WRITEBYTE(ofp, pf->width[i]);
101}
102
103int
104main(int ac, char **av)
105{
106 rbf_write_font(pf);
107}