From dfc2300866efe3c4e313de84f0aea5250b890236 Mon Sep 17 00:00:00 2001
From: Tor Andersson <tor@ghostscript.com>
Date: Wed, 3 Sep 2008 19:12:00 +0200
Subject: Revamp build system to compile in windows under both MSVC and MinGW.

---
 hexdump.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 hexdump.c

(limited to 'hexdump.c')

diff --git a/hexdump.c b/hexdump.c
new file mode 100644
index 00000000..5ad4452b
--- /dev/null
+++ b/hexdump.c
@@ -0,0 +1,76 @@
+/* hexdump.c -- an "xxd -i" workalike */
+
+#include <stdio.h>
+
+int
+hexdump(FILE *fo, FILE *fi)
+{
+    int c, n;
+
+    n = 0;
+    c = fgetc(fi);
+    while (c != -1)
+    {
+	fprintf(fo, "0x%02x,", c);
+	if (n % 16 == 15)
+	    fprintf(fo, "\n");
+	c = fgetc(fi);
+	n ++;
+    }
+
+    return n;
+}
+
+int
+main(int argc, char **argv)
+{
+    FILE *fo;
+    FILE *fi;
+    unsigned char name[256];
+    unsigned char *p;
+    int i, n, len;
+
+    if (argc < 3)
+    {
+	fprintf(stderr, "usage: hexdump output.c input.dat\n");
+	return 1;
+    }
+
+    fo = fopen(argv[1], "wb");
+    if (!fo)
+    {
+	fprintf(stderr, "hexdump: could not open output file\n");
+	return 1;
+    }
+
+    for (i = 2; i < argc; i++)
+    {
+	fi = fopen(argv[i], "rb");
+	if (!fi)
+	{
+	    fprintf(stderr, "hexdump: could not open input file\n");
+	    return 1;
+	}
+
+	strcpy(name, argv[i]);
+	p = name;
+	while (*p)
+	{
+	    if ((*p == '/') || (*p == '.') || (*p == '\\') || (*p == '-'))
+		*p = '_';
+	    p ++;
+	}
+
+	fprintf(fo, "const unsigned char %s[] = {\n", name);
+
+	len = hexdump(fo, fi);
+
+	fprintf(fo, "};\n");
+	fprintf(fo, "const unsigned int %s_len = %d;\n", name, len);
+
+	fclose(fi);
+    }
+
+    return 0;
+}
+
-- 
cgit v1.2.3