-
Notifications
You must be signed in to change notification settings - Fork 1
/
fbftoqe.c
89 lines (77 loc) · 1.65 KB
/
fbftoqe.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* convert FBF fonts into source file so that so resources are needed
* for fonts
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void dump_font(const char *filename, const char *name)
{
int c;
FILE *f;
int j;
f = fopen(filename, "r");
if (!f) {
perror(filename);
exit(1);
}
printf("static const unsigned char font_%s[] = {\n", name);
j = 0;
for(;;) {
c = fgetc(f);
if (c == EOF)
break;
j++;
printf("0x%02x,", c);
if ((j & 7) == 0)
printf("\n");
else
printf(" ");
}
if ((j & 7) != 0)
printf("\n");
printf("};\n\n");
fclose(f);
}
void getname(char *name, int name_size, const char *filename)
{
const char *p;
char *q;
p = strrchr(filename, '/');
if (!p)
p = filename;
else
p++;
strcpy(name, p);
q = strrchr(name, '.');
if (q)
*q = '\0';
}
int main(int argc, char **argv)
{
const char *filename;
char name[128];
int i;
printf("#include \"qe.h\"\n\n");
for(i=1;i<argc;i++) {
filename = argv[i];
getname(name, sizeof(name), filename);
dump_font(filename, name);
}
/* dump font list */
printf("const void *fbf_fonts[] = {\n");
for(i=1;i<argc;i++) {
FILE *f;
int size;
filename = argv[i];
f = fopen(filename, "r");
fseek(f, 0, SEEK_END);
size = ftell(f);
fclose(f);
getname(name, sizeof(name), filename);
printf("font_%s, (void *)%d,\n", name, size);
}
printf("NULL,\n");
printf("};\n");
return 0;
}