-
Notifications
You must be signed in to change notification settings - Fork 4
/
xpm2x16.c
77 lines (59 loc) · 950 Bytes
/
xpm2x16.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
#include <stdio.h>
/*
". c #000000",
"+ c #0000A8",
"@ c #00A800",
"# c #00A8A8",
"$ c #A80000",
"% c #A800A8",
"& c #A85700",
"* c #A8A8A8",
"= c #575757",
"- c #5757FF",
"; c #57FF57",
"> c #57FFFF",
", c #FF5757",
"' c #FF57FF",
") c #FFFF57",
"! c #FFFFFF"
*/
char map(int c)
{
char *m = ".+@#$%&*=-;>,')!";
char r;
for (r=0;r<16;r++) if (m[r]==(unsigned char) c) return r;
return -1;
}
int main(void)
{
char d,flag=0;
unsigned char attr=0;
int c,cnt=0;
fprintf(stdout,"unsigned char xpm[] = {\n");
while(!feof(stdin)) {
c = fgetc(stdin);
if (c == EOF) {
fprintf(stdout,"0x%02x",attr);
break;
} else if (cnt&1) {
fprintf(stdout,"0x%02x,",attr);
}
if (c == '\r' || c == '\n') {
fputc(c,stdout);
cnt=0;
continue;
}
d=map(c);
if (d == -1) {
fputc(c,stdout);
continue;
}
if (cnt&1) {
attr<<=4;
}
attr |= d;
cnt++;
}
fprintf(stdout,"};");
return 0;
}