summaryrefslogtreecommitdiff
path: root/utils/data2c/data2c.c
diff options
context:
space:
mode:
authorCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
committerCharles.Forsyth <devnull@localhost>2006-12-22 21:39:35 +0000
commit74a4d8c26dd3c1e9febcb717cfd6cb6512991a7a (patch)
treec6e220ba61db3a6ea4052e6841296d829654e664 /utils/data2c/data2c.c
parent46439007cf417cbd9ac8049bb4122c890097a0fa (diff)
20060303
Diffstat (limited to 'utils/data2c/data2c.c')
-rw-r--r--utils/data2c/data2c.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/utils/data2c/data2c.c b/utils/data2c/data2c.c
new file mode 100644
index 00000000..faf597c5
--- /dev/null
+++ b/utils/data2c/data2c.c
@@ -0,0 +1,33 @@
+#include <lib9.h>
+#include <bio.h>
+
+void
+main(int argc, char *argv[])
+{
+ Biobuf bin, bout;
+ long len;
+ int n;
+ uchar block[16], *c;
+
+ if(argc != 2){
+ fprint(2, "usage: data2s name\n");
+ exits("usage");
+ }
+ setbinmode();
+ Binit(&bin, 0, OREAD);
+ Binit(&bout, 1, OWRITE);
+ Bprint(&bout, "unsigned char %scode[] = {\n", argv[1]);
+ for(len=0; (n=Bread(&bin, block, sizeof(block))) > 0; len += n){
+ for(c=block; c < block+n; c++)
+ if(*c)
+ Bprint(&bout, "0x%ux,", *c);
+ else
+ Bprint(&bout, "0,");
+ Bprint(&bout, "\n");
+ }
+ if(len == 0)
+ Bprint(&bout, "0\n"); /* avoid empty initialiser */
+ Bprint(&bout, "};\n");
+ Bprint(&bout, "int %slen = %ld;\n", argv[1], len);
+ exits(0);
+}