- Make iofuncs.h standalone.
[reactos.git] / reactos / tools / bin2c.c
1 #include <stdio.h>
2
3 FILE *in;
4 FILE *out;
5
6 int main(int argc, char *argv[])
7 {
8 unsigned char ch;
9 int cnt = 0;
10
11 if (argc < 4)
12 {
13 printf("usage: bin2c infile.bin outfile.h array_name\n");
14 return -1;
15 }
16
17 if ((in = fopen(argv[1], "rb")) == NULL)
18 {
19 printf("Couldn't open data file.\n");
20 return -1;
21 }
22 if ((out = fopen(argv[2], "wb")) == NULL)
23 {
24 printf("Couldn't open output file.\n");
25 return -1;
26 }
27
28 fprintf(out, "unsigned char %s[] = {\n", argv[3]);
29
30 ch = fgetc(in);
31 while (!feof(in))
32 {
33 if (cnt != 0)
34 fprintf(out, ", ");
35 if (!(cnt % 16))
36 fprintf(out, "\n");
37 fprintf(out, "0x%02x", (int)ch);
38 cnt++;
39 ch = fgetc(in);
40 }
41
42 fprintf(out, "\n};\n");
43
44 fclose(in);
45 fclose(out);
46
47 return 0;
48 }