diff options
Diffstat (limited to 'data/gen-devices.sh')
| -rwxr-xr-x | data/gen-devices.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/data/gen-devices.sh b/data/gen-devices.sh new file mode 100755 index 0000000..6f6f9c9 --- /dev/null +++ b/data/gen-devices.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Generates the built-in device table (devices.c) from devices.txt. +# Usage: gen-devices.sh devices.txt > devices.c + +if [ $# -ne 1 ]; then + echo "usage: $0 devices.txt" >&2 + exit 1 +fi + +if ! awk '/^#!format/ { v = $2; found = 1; exit } END { exit !(found && v == 1) }' "$1"; then + echo "gen-devices.sh: $1 must declare '#!format 1'" >&2 + exit 1 +fi + +echo "/* Generated from devices.txt by gen-devices.sh. DO NOT EDIT. */" +echo "#include <stddef.h>" +echo "#include \"libirecovery.h\"" +echo "#include \"devicedb.h\"" +echo +echo "struct irecv_device irecv_devices_builtin[] = {" +awk ' +/^[ \t]*$/ { body = 1; next } +/^#/ { + if (body && $0 !~ /\*\//) { printf "\t/* %s */\n", substr($0, 3) } + next +} +{ + name = $0 + for (i = 1; i <= 4; i++) { + sub(/^[ \t]+/, "", name) + f[i] = name + sub(/[ \t].*$/, "", f[i]) + sub(/^[^ \t]+/, "", name) + } + sub(/^[ \t]+/, "", name) + sub(/[ \t\r]+$/, "", name) + if (name == "" || f[4] == "") { + printf "gen-devices.sh: malformed line %d: %s\n", NR, $0 > "/dev/stderr" + exit 1 + } + if ($0 ~ /["\\]/) { + printf "gen-devices.sh: line %d: quotes/backslashes not allowed\n", NR > "/dev/stderr" + exit 1 + } + printf "\t{ \"%s\", \"%s\", %s, %s, \"%s\" },\n", f[1], f[2], f[3], f[4], name +} +' "$1" || exit 1 +echo " { NULL, NULL, -1, -1, NULL }" +echo "};" |
