1 /* bin2hex.c -- Turn the contents of a file into an array of unsigned chars */
6 /* We never want to build memento versions of the cquote util */
14 if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-'))
21 main(int argc, char **argv)
30 fprintf(stderr, "usage: bin2hex output.h lots of text files\n");
34 fo = fopen(argv[1], "wb");
37 fprintf(stderr, "cquote: could not open output file '%s'\n", argv[1]);
41 fprintf(fo, "/* This is an automatically generated file. Do not edit. */\n");
43 for (i = 2; i < argc; i++)
45 realname = strrchr(argv[i], '/');
47 realname = strrchr(argv[i], '\\');
53 if (strlen(realname) > (sizeof name - 1))
55 fprintf(stderr, "bin2hex: file name too long\n");
58 fprintf(stderr, "bin2hex: could not close output file '%s'\n", argv[1]);
64 strcpy(name, realname);
67 fi = fopen(argv[i], "rb");
70 while ((c = fgetc(fi)) != EOF)
75 fputc(j%8 == 0 ? '\n' : ' ', fo);
78 fprintf(fo, "0x%02x", c);
86 fprintf(stderr, "bin2hex: could not close input file '%s'\n", argv[i]);
94 fprintf(stderr, "bin2hex: could not close output file '%s'\n", argv[1]);