- added svn props for newly added files
[openocd.git] / src / bin2char.c
blob436839bbb050407268eaece0455f15f8a1b47f93
1 #include <stdio.h>
2 #include <stdlib.h>
4 int
5 main(int argc, char **argv)
7 int c;
8 unsigned int n;
9 char *name;
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);
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");
27 fprintf(stdout, "0 /* terminate with a nil */};\n");
28 fprintf(stdout, "unsigned int %s_len = %u;\n", name, n);
29 return 0;