aboutsummaryrefslogtreecommitdiff
path: root/bin2h.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin2h.c')
-rw-r--r--bin2h.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/bin2h.c b/bin2h.c
new file mode 100644
index 0000000..dbbfa42
--- /dev/null
+++ b/bin2h.c
@@ -0,0 +1,22 @@
+/* bin2h -- embed a binary file as the C array clectio compiles in.
+ * usage: bin2h <file> > text.lz.h (public domain) */
+#include <stdio.h>
+
+int main(int argc, char **argv) {
+ FILE *f;
+ int c, n = 0;
+ if (argc != 2 || !(f = fopen(argv[1], "rb"))) {
+ fprintf(stderr, "usage: bin2h <file> > out.h\n");
+ return 1;
+ }
+ printf("static const unsigned char text_lz[] = {");
+ while ((c = fgetc(f)) != EOF) {
+ if (n % 20 == 0)
+ printf("\n\t");
+ printf("%d,", c);
+ n++;
+ }
+ printf("\n};\nstatic const unsigned text_lz_len = %d;\n", n);
+ fclose(f);
+ return 0;
+}