File: bin2h.sh

package info (click to toggle)
schism 2%2B20061016-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 4,824 kB
  • ctags: 5,402
  • sloc: ansic: 32,841; cpp: 22,411; sh: 5,003; objc: 381; makefile: 234
file content (43 lines) | stat: -rwxr-xr-x 761 bytes parent folder | download | duplicates (2)
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
36
37
38
39
40
41
42
43
#!/bin/sh
#
# this is a bin2h-like program that is useful even when cross compiling.
#
# it requires:
# 	unix-like "od" tool
#	unix-like "sed" tool
#	unix-like "fgrep" tool
#
# it's designed to be as portable as possible and not necessarily depend on
# gnu-style versions of these tools

name=""
type="static unsigned const char"
if [ "X$1" = "X-n" ]; then
	name="$2"
	shift
	shift
fi
if [ "X$1" = "X-t" ]; then
	type="$2"
	shift
	shift
fi

if [ "X$name" = "X" ]; then
	echo "Usage: $0 -n name [-t type] files... > output.h"
fi

if [ "X$OD" = "X" ]; then
	OD="od"
fi
if [ "X$SED" = "X" ]; then
	SED="sed"
fi

echo "$type $name""[] = {"
$OD -b -v "$@" \
| $SED -e 's/^[^ ][^ ]*[ ]*//' \
| $SED -e "s/\([0-9]\{3\}\)/'\\\\\1',/g" \
| $SED -e '$ s/,$//'
echo "};"