summaryrefslogtreecommitdiffstats
path: root/util/getdefs
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-12-03 19:23:35 +0100
committerMattias Andrée <maandree@kth.se>2023-12-03 19:23:35 +0100
commitc131f122778c62f920a99bbf854ced4a37ee8b03 (patch)
tree14c933f98f4d64dffb0a594bc40dd5121c6c5a8e /util/getdefs
downloadlibsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.gz
libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.bz2
libsyscalls-c131f122778c62f920a99bbf854ced4a37ee8b03.tar.xz
First commit
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'util/getdefs')
-rwxr-xr-xutil/getdefs27
1 files changed, 27 insertions, 0 deletions
diff --git a/util/getdefs b/util/getdefs
new file mode 100755
index 0000000..869dff6
--- /dev/null
+++ b/util/getdefs
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+text="$(cat)"
+
+expr='\(0x[0-9a-fA-F]\+\|[0-9]\+\)[Ll]*[Uu]*[Ll]*'
+expr='\(\*\|\/\|[+~-]\|<<\|>>\)\?\s*'"$expr"
+expr='\('"$expr"'\|(\|)\)'
+expr='\s*\('"$expr"'\s*\)\+'
+
+filter () {
+ sed -n 's/^\s*#\s*define\s\+\('"$1"'\)\s\+\('"$expr"'\)\s*\(\/.*\)\?$/\1 \2/p'
+}
+
+if test $# = 0; then
+ printf '%s\n' "$text" | filter '[A-Z0-9_]\+'
+else
+ for prefix; do
+ printf '%s\n' "$text" | filter "$prefix"'_[A-Z0-9_]\+'
+ 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