summaryrefslogtreecommitdiffstats
path: root/util/getdefs
blob: aa0694761ca26aa8ed32aa14f954591f6f506197 (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
#!/bin/sh
# See LICENSE file for copyright and license details.

set -e

text="$(cat)"

expr='\(0x[0-9a-fA-F]\{1,\}\|[0-9]\{1,\}\)[Ll]*[Uu]*[Ll]*'
expr='\(\*\|\/\|[+~-]\|<<\|>>\)\{0,1\}[[:space:]]*'"$expr"
expr='\('"$expr"'\|(\|)\)'
expr='[[:space:]]*\('"$expr"'[[:space:]]*\)\{1,\}'

filter () {
	sed -n 's/^[[:space:]]*#[[:space:]]*define[[:space:]]\{1,\}\('"$1"'\)[[:space:]]\{1,\}\('"$expr"'\)[[:space:]]*\(\/.*\)\{0,1\}$/\1 \2/p'
}

if test $# = 0; then
	printf '%s\n' "$text" | filter '[A-Z0-9_]\{1,\}'
else
	for prefix; do
		printf '%s\n' "$text" | filter "$prefix"'_[A-Z0-9_]\{1,\}'
	done
fi | \
while read name value; do
	value="$(printf '%s\n' "$value" | tr -d ULul)"
	value=$(printf '%s\n' "$(( $value ))" | cut -d . -f 1)
	printf '%s %s\n' "$name" "$value"
done