From 880149f48e58ac93697fd19a90df6b31a2242659 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Thu, 30 May 2013 12:42:22 +0100 Subject: Generate C-includable version of Adobe CA certificate --- scripts/bin2hex.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 scripts/bin2hex.c (limited to 'scripts') diff --git a/scripts/bin2hex.c b/scripts/bin2hex.c new file mode 100644 index 00000000..e02ff31a --- /dev/null +++ b/scripts/bin2hex.c @@ -0,0 +1,100 @@ +/* bin2hex.c -- Turn the contents of a file into an array of unsigned chars */ + +#include +#include + +/* We never want to build memento versions of the cquote util */ +#undef MEMENTO + +static void +clean(char *p) +{ + while (*p) + { + if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-')) + *p = '_'; + p ++; + } +} + +int +main(int argc, char **argv) +{ + FILE *fi, *fo; + char name[256]; + char *realname; + int i, j, c; + int bol = 1; + + if (argc < 3) + { + fprintf(stderr, "usage: bin2hex output.h lots of text files\n"); + return 1; + } + + fo = fopen(argv[1], "wb"); + if (!fo) + { + fprintf(stderr, "cquote: could not open output file '%s'\n", argv[1]); + return 1; + } + + fprintf(fo, "/* This is an automatically generated file. Do not edit. */\n"); + + for (i = 2; i < argc; i++) + { + realname = strrchr(argv[i], '/'); + if (!realname) + realname = strrchr(argv[i], '\\'); + if (realname) + realname ++; + else + realname = argv[i]; + + if (strlen(realname) > (sizeof name - 1)) + { + fprintf(stderr, "bin2hex: file name too long\n"); + if (fclose(fo)) + { + fprintf(stderr, "bin2hex: could not close output file '%s'\n", argv[1]); + return 1; + } + return 1; + } + + strcpy(name, realname); + clean(name); + + fi = fopen(argv[i], "rb"); + + j = 0; + while ((c = fgetc(fi)) != EOF) + { + if (j != 0) + { + fputc(',', fo); + fputc(j%8 == 0 ? '\n' : ' ', fo); + } + + fprintf(fo, "0x%02x", c); + j++; + } + + fputc('\n', fo); + + if (fclose(fi)) + { + fprintf(stderr, "bin2hex: could not close input file '%s'\n", argv[i]); + return 1; + } + + } + + if (fclose(fo)) + { + fprintf(stderr, "bin2hex: could not close output file '%s'\n", argv[1]); + return 1; + } + + return 0; +} -- cgit v1.2.3