Charles Hardin <ckhardin@gmail.com> - hopefully final word on startup.tcl => c conversion
[openocd.git] / src / bin2char.c
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 int
5 main(int argc, char **argv)
6 {
7 int c;
8 unsigned int n;
9 char *name;
10
11 if (argc == 1) {
12 fprintf(stderr, "bin2char <varname>\n");
13 fprintf(stderr, "read from standard input and write a char"
14 " array out to standard output\n");
15 exit(1);
16 }
17
18 n = 0;
19 name = argv[1];
20 fprintf(stdout, "/* autogenerated from %s */\n", argv[0]);
21 fprintf(stdout, "unsigned const char %s[] = {\n", name);
22 while ((c = getc(stdin)) != EOF) {
23 fprintf(stdout, "0x%02x,", c & 0xff);
24 if ((++n % 16) == 0)
25 fprintf(stdout, "\n");
26 }
27 fprintf(stdout, "0 /* terminate with a nil */};\n");
28 fprintf(stdout, "unsigned int %s_len = %u;\n", name, n);
29 return 0;
30 }