aboutsummaryrefslogtreecommitdiff
path: root/utils/data2c/data2c.c
diff options
context:
space:
mode:
authorbhgv <bhgv.empire@gmail.com>2018-03-01 16:54:45 +0200
committerbhgv <bhgv.empire@gmail.com>2018-03-01 16:54:45 +0200
commitb786f20bbab5a59046aa78a2c6c2a11536497202 (patch)
tree0851ecdec889eb9b7ba3751cc04d4f0b474e4a9e /utils/data2c/data2c.c
inferno-os tree was separated from the inferno-os-android (separated from the Android driver)
Diffstat (limited to 'utils/data2c/data2c.c')
-rw-r--r--utils/data2c/data2c.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/utils/data2c/data2c.c b/utils/data2c/data2c.c
new file mode 100644
index 0000000..a807bc7
--- /dev/null
+++ b/utils/data2c/data2c.c
@@ -0,0 +1,52 @@
+#include <lib9.h>
+#include <bio.h>
+
+#ifdef ANDROID
+#undef malloc
+#undef free
+#undef realloc
+
+void* malloc_(size_t l){
+ return malloc(l);
+}
+
+void* realloc_(void*p, size_t l){
+ return realloc(p, l);
+}
+
+void free_(void* p) {
+ free(p);
+}
+#endif
+
+
+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);
+}