blob: a4d1eed727f850be360cc7903b1e5108e4e0d3cb (
plain) (
blame)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
#!/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="$(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)"
printf '%s\n' "$definitions" |
while read line; do
printf '0x%08X %s\n' $line
done |
(
prefixed="$(cat)"
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%08X\n' $num)
if ! test $last_num = $num && ! test $last_num = x; then
printf '%s %s\n' $last_num $last_name
fi
last_num=$num
last_name=$name
done
if ! test $last_num = x; then
printf '%s %s\n' $last_num $last_name
fi
) |
sort |
while read num name; do
printf '%s %u\n' $name $num;
done |
uniq -f 1 |
awk '
BEGIN {num = 0}
{
while ($2 != num) {
printf "\"'"$format"'\",\n", num
num += 1
}
printf "\"%s\",\n", $1
num += 1
}
END {
while (num <= '"$max"') {
printf "\"'"$format"'\",\n", num
num += 1
}
}' |
sed '$s/,$//'
|