summaryrefslogblamecommitdiffstats
path: root/util/getenum
blob: b28236aca030da5b1d8682868729aa4db2a3f46c (plain) (tree)
1
2
3
4
5
6
7
8
         
                                                     


      
                                                                           
                                                
                                                                                                                                  













                                                                              
#!/bin/sh
# See LICENSE file for copyright and license details.

set -e

sed '1,/^[[:space:]]*enum[[:space:]]\{1,\}'"$1"'\([^A-Za-z0-9_]\|$\)/d' | \
tr '\n' '\0' | cut -d \; -f 1 | tr '\0' '\n' | \
sed -n 's/^[[:space:]]*\([A-Z0-9_]\{1,\}\)\([[:space:]]*=[^,]*\)\{0,1\}[[:space:]]*,\{0,1\}[[:space:]]*\(\/.*\)\{0,1\}/\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
)