blob: dbbfa422a9e9f7a6deb25775b095173898c9763e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
/* bin2h -- embed a binary file as the C array clectio compiles in.
* usage: bin2h <file> > text.lz.h (public domain) */
#include <stdio.h>
int main(int argc, char **argv) {
FILE *f;
int c, n = 0;
if (argc != 2 || !(f = fopen(argv[1], "rb"))) {
fprintf(stderr, "usage: bin2h <file> > out.h\n");
return 1;
}
printf("static const unsigned char text_lz[] = {");
while ((c = fgetc(f)) != EOF) {
if (n % 20 == 0)
printf("\n\t");
printf("%d,", c);
n++;
}
printf("\n};\nstatic const unsigned text_lz_len = %d;\n", n);
fclose(f);
return 0;
}
|