OSDN Git Service

new file master
authorPawel <Pawel@home>
Wed, 28 Aug 2019 08:42:22 +0000 (09:42 +0100)
committerPawel <Pawel@home>
Wed, 28 Aug 2019 08:42:22 +0000 (09:42 +0100)
bin2h [new file with mode: 0755]

diff --git a/bin2h b/bin2h
new file mode 100755 (executable)
index 0000000..363021a
--- /dev/null
+++ b/bin2h
@@ -0,0 +1,25 @@
+#!/bin/bash
+# Copyright 2014,2015 Pawel Jewstafjew Pawel<dot>Jewstafjew<at>gmail<dot>com
+# converts a binary file to a C header file
+
+binfile="$1"
+name="$2"
+out=${name}.h.tmp
+
+size=$(cat "$binfile" | wc --bytes)
+echo "name=${name}, size=${size}"
+
+echo "#ifndef _${name}_H"                      > ${out}
+echo "#define _${name}_H"                      >> ${out}
+echo "enum {${name}_size = ${size}};"          >> ${out}
+echo "const unsigned char ${name}[${size}] = {"        >> ${out}
+
+for v in $(od --output-duplicates --width=1 --address=n --format=x1 "$binfile" )
+do
+   echo "0x$v,"                                >> ${out}
+done
+
+echo "};"                                      >> ${out}
+echo "#endif // _${name}_H"                    >> ${out}
+
+mv ${out} ${name}.h