summaryrefslogtreecommitdiffstats
path: root/util/getenum
blob: 343ce7640381adb38a41a6b20cb353e6deef22b7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/sh
# See LICENSE file for copyright and license details.

set -e

sed '1,/^\s*enum\s\+'"$1"'\b/d' | \
tr '\n' '\0' | cut -d \; -f 1 | tr '\0' '\n' | \
sed -n 's/^\s*\([A-Z0-9_]\+\)\(\s*=[^,]*\)\?\s*,\?\s*\(\/.*\)\?/\1\2/p' | \
sed 's/=/ /g' | \
(
	prev=-1
	while read name value; do
		if test -z "$value"; then
			value=$(( prev + 1 ))
		else
			value="$(printf '%s\n' "$value" | tr -d ULul)"
			value=$(printf '%s\n' "$(( $value ))" | cut -d . -f 1)
		fi
		printf '%s %s\n' "$name" "$value"
		prev=$value
	done
)