diff options
Diffstat (limited to 'lib/enum-to-names-vals')
-rwxr-xr-x | lib/enum-to-names-vals | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/enum-to-names-vals b/lib/enum-to-names-vals new file mode 100755 index 0000000..9d27bd8 --- /dev/null +++ b/lib/enum-to-names-vals @@ -0,0 +1,33 @@ +#! /bin/sh + +if [ $# = 0 ] +then + cat 1>&2 <<EOF +Usage: $(basename $0) ENUMPREFIX [FILES] +EOF +fi + +type="$1" +shift + +cat <<EOF +static +const struct { + int value; + const char *name; +} ${type}_names_vals[] = { +EOF +awk -vtype=$type -vtype_regex="^${type}_" ' \ +BEGIN { IGNORECASE = 1; } \ +$1 ~ type_regex { \ + name=$1; \ + symbol=$1; \ + type_regex="^" type "_"; \ + gsub(/,.*$/, "", symbol); \ + gsub(type_regex, "", name); \ + gsub(/,.*$/, "", name); \ + gsub(/_/, "-", name); \ + print "\t{ " symbol ", \"" tolower(name) "\" },"; \ +}' $@ +echo " { 0, NULL }" +echo "};" |