1 rizwank 1.1 #! /bin/sh
2 # perl -pe 's/(.)/sprintf "%#x, ", ord $1/sge' would have done too! lovely ;p
3 # or perl -0777 -ne 'print "{", join(", ", map sprintf("%#x", ord), split //), "}"'
4
5 #trunc=`sed -e "s/\./g" "$1"`
6 echo "Exports given file to <filename.ext.hex> - as a hex array"
7 echo "(c) Rizwan Kassim 2006"
|
8 rizwank 1.4 #echo "Bugs - Appends to outputfile, doesn't check for validity"
|
9 rizwank 1.2 #echo "needs to remove any . from the arrayname when writing "
|
10 rizwank 1.4 #echo "and needs to remove final comma. "
11 #echo "later, I realized that it would be much easier to do this "
12 #echo "in perl (see code for examples"
13 #echo "appending to $1.hex!"
14 #echo "DONT FORGET TO remove final ,"
15 #echo " ============================================ "
16 #echo "static unsigned char file_$1[] = {" >> $1.hex
|
17 rizwank 1.1 #| grep "s/cab/_/"
|
18 rizwank 1.4 #od -h $1 | sed "s/^[0-9]\{7\}[ ]*//g" | sed "s/\([0-9a-f]\{2\}\)[ ]*/0x\U\1,/g" | sed "s/\([.]*\),$//" | sed "s/.*/&,/" | sed "s/^,$//g" | sed "/^$/d" >> $1.hex
|
19 rizwank 1.1 #doesnt just remove end of file but end of every line - sed "s/.$[^^]//" | sed "s/.$//" |
|
20 rizwank 1.4 #echo "};" >> $1.hex
21 #echo "static int szfile_$1 = sizeof(file_$1);" >> $1.hex
22 #sed -i "s/\./_/g" $1.hex
23
24 echo "version 3 - finally moved the damn thing to perl"
25 echo "after I realized that od -h doesn't output in left to right byte order "
26 echo "for some reason! Endianness difference between od behavior?"
27 echo ""
28 echo "appending to $1.hex! (this version isn't very good about inserting LFs"
29 echo " ============================================ "
30 echo "static unsigned char file_$1[] =" >> $1.hex
31 perl -0777 -ne 'print "{", join(", ", map sprintf("%#02.2x", ord), split //), "};\n"' < $1 | sed "s/00/0x00/g" >> $1.hex
|
32 rizwank 1.2 echo "static int szfile_$1 = sizeof(file_$1);" >> $1.hex
33 sed -i "s/\./_/g" $1.hex
|