summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2013-05-30 12:42:22 +0100
committerTor Andersson <tor.andersson@artifex.com>2013-05-30 16:01:58 +0200
commit880149f48e58ac93697fd19a90df6b31a2242659 (patch)
tree6c12d99d5b445d003a85dc4ecad8541361a5b867 /scripts
parentcff6f809da556624fb1de34725935278093182e1 (diff)
downloadmupdf-880149f48e58ac93697fd19a90df6b31a2242659.tar.xz
Generate C-includable version of Adobe CA certificate
Diffstat (limited to 'scripts')
-rw-r--r--scripts/bin2hex.c100
1 files changed, 100 insertions, 0 deletions
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 <stdio.h>
+#include <string.h>
+
+/* 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;
+}