File: bin2h.sh

package info (click to toggle)
schism 2%3A20250313-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 4,948 kB
  • sloc: ansic: 77,328; makefile: 545; objc: 365; python: 321; perl: 75; sh: 41; xml: 10
file content (47 lines) | stat: -rwxr-xr-x 921 bytes parent folder | download | duplicates (7)
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
44
45
46
47
#!/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="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

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