-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathtxt2c.c
49 lines (41 loc) · 829 Bytes
/
txt2c.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
/*
Small utility that reads from stdin and outputs an
C table with the data to stdout.
*/
#include <stdio.h>
int main(int argc, char **argv)
{
int c, f;
int i = 0;
FILE *input;
printf("typedef struct\n");
printf("{\n");
printf("\tconst char *filename;\n");
printf("\tconst char *content;\n");
printf("} INTERNALFILE;\n");
printf("\n");
for(f = 1; f < argc; f++)
{
printf("const char internal_file_%d[] = {", f);
input = fopen(argv[f], "r");
while(1)
{
c = fgetc(input);
if(feof(input))
break;
printf("0x%x, ", c);
i = (i+1)&0xf;
if(i == 0)
printf("\n\t");
}
fclose(input);
printf("0};\n");
}
printf("INTERNALFILE internal_files[] = {");
for(f = 1; f < argc; f++)
{
printf("{\"%s\", internal_file_%d },\n", argv[f], f);
}
printf("{0}};\n");
return 0;
}