-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmakeheader.c
67 lines (49 loc) · 1.03 KB
/
makeheader.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
// reads files from a directory and creates a header file
// used for embedding PNG images
// example: makeheader src/Images.H images/*.png
int main(int argc, char **argv)
{
FILE *in, *out;
int i = 1;
char s[4096];
out = fopen(argv[1], "w");
while(i++ < argc - 1)
{
strcpy(s, argv[i]);
for(int j = 0; j < strlen(s); j++)
if(s[j] == '/' || s[j] == '.')
s[j] = '_';
fprintf(out, "unsigned char const %s [] = \n", s);
fprintf(out, "{");
in = fopen(argv[i], "r");
int pos = 0;
int c = fgetc(in);
if(c == EOF)
{
fclose(in);
fclose(out);
printf("Error.\n");
return 0;
}
while(1)
{
if((pos % 8) == 0)
fprintf(out, "\n ");
pos++;
fprintf(out, "0x%02x", c);
c = fgetc(in);
if(c == EOF)
break;
else
fprintf(out, ", ");
}
fprintf(out, "\n};\n\n");
fclose(in);
}
fclose(out);
return 0;
}