blob: 25bb6f7da30d892cce90eb2bd3b65668f9b4419e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#! /bin/sh
readbyte()
{
read dummy hex << EOF
$(dd bs=1 count=1 2> /dev/null | od -t xC)
EOF
printf "%s\n" $hex
}
if [ $# -ne 1 ] ; then
echo "usage: $0 in.bin > out.c"
exit
fi
varname=$(basename $1 .bin | tr -d "\n" | tr -c a-zA-Z _)
length=0
exec < $1
printf "#include <stddef.h>\n"
printf "const unsigned char %s[] = {" $varname
byte=$(readbyte)
until [ -z $byte ] ; do
[ $(($length % 12)) -eq 0 ] && printf "\n\t"
printf "0x%s," $byte
let length+=1
byte=$(readbyte)
done
[ $length -ne 0 ] && printf "\n"
printf "};\n"
printf "const size_t %s_size = %s;\n" $varname $length
|