aboutsummaryrefslogtreecommitdiffstats
path: root/names.sh
diff options
context:
space:
mode:
Diffstat (limited to 'names.sh')
-rwxr-xr-xnames.sh33
1 files changed, 21 insertions, 12 deletions
diff --git a/names.sh b/names.sh
index 40ed998..a4d1eed 100755
--- a/names.sh
+++ b/names.sh
@@ -1,24 +1,33 @@
-#!/bin/sh
+#!/bin/sh -e
+
+format="$1"
+shift 1
prefix="$(printf '%s\\|' "$@" | sed 's/..$//')"
definitions_with_max="$(sed -n 's/^\s*#\s*define\s\+\(\('"$prefix"'\)_[A-Za-z0-9_]*\)\s\+\(0[xX][0-9A-Fa-f]\+\|[0-9]\+\)\(.*\)$/\3 \1/p')"
-definitions="$(echo "$definitions_with_max" | sed '/ \('"$prefix"'\)_MAX$/d')"
-max=$(printf '%u\n' $(echo "$definitions_with_max" | sed -n 's/^\(.*\) \('"$prefix"'\)_MAX$/\1/p'))
+definitions="$(printf '%s\n' "$definitions_with_max" | sed '/ \('"$prefix"'\)_MAX$/d')"
+max=$(printf '%u\n' $(printf '%s\n' "$definitions_with_max" | sed -n 's/^\(.*\) \('"$prefix"'\)_MAX$/\1/p'))
+
+nonunique="$(printf '%s\n' "$definitions" | while read num name; do printf '0x%08X\n' $num; done | sort | uniq -d)"
-nonunique="$(echo "$definitions" | while read num name; do printf '0x%03X\n' $num; done | sort | uniq -d)"
+printf '%s\n' "$definitions" |
+while read line; do
+ printf '0x%08X %s\n' $line
+done |
+(
+ prefixed="$(cat)"
-(echo "$definitions" |
- while read line; do
- printf '0x%03X %s\n' $line
- done |
- sed '/^\('"$(echo "$nonunique" | tr '\n' '|' | sed 's/|$/\n/' | sed 's/|/\\|/g')"'\) /d'
+ printf '%s\n' "$prefixed" |
+ sed '/^\('"$(printf '%s\\|' $nonunique | sed 's/..$/\n/')"'abcdef\) /d'
last_num=x
last_name=x
+ printf '%s\n' "$prefixed" |
+ sed -n 's/^\('"$(printf '%s\\|' $nonunique | sed 's/..$/\n/')"'\) .*$/&/p' |
while read num name; do
- num=$(printf '0x%03X\n' $num)
+ num=$(printf '0x%08X\n' $num)
if ! test $last_num = $num && ! test $last_num = x; then
printf '%s %s\n' $last_num $last_name
fi
@@ -38,7 +47,7 @@ awk '
BEGIN {num = 0}
{
while ($2 != num) {
- printf "\"0x%03X\",\n", num
+ printf "\"'"$format"'\",\n", num
num += 1
}
printf "\"%s\",\n", $1
@@ -46,7 +55,7 @@ BEGIN {num = 0}
}
END {
while (num <= '"$max"') {
- printf "\"0x%03X\",\n", num
+ printf "\"'"$format"'\",\n", num
num += 1
}
}' |