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 echo "Bugs - Appends to outputfile, doesn't check for validity"
9 echo "needs to remove any . from the arrayname when writing "
10 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 . in filename and final ,"
15 echo " ============================================ "
16 echo "static unsigned char $1 = {" >> $1.hex
17 #| grep "s/cab/_/"
18 od -h $1 | sed "s/^[0-9]\{7\}[ ]*//g" | sed "s/\([0-9a-f]\{2\}\)[ ]*/00x\U\1,/g" | sed "s/\([.]*\),$//" | sed "s/.*/&,/" | sed "s/^,$//g" | sed "/$^/d" >> $1.hex
19 #doesnt just remove end of file but end of every line - sed "s/.$[^^]//" | sed "s/.$//" |
20 echo "};" >> $1.hex
21
|