Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162146363
D57993.id181176.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D57993.id181176.diff
View Options
diff --git a/lib/libsysdecode/mktables b/lib/libsysdecode/mktables
--- a/lib/libsysdecode/mktables
+++ b/lib/libsysdecode/mktables
@@ -48,17 +48,13 @@
all_headers=
#
-# Generate a table C #definitions. The including file can define the
-# TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to define what
-# the tables map to.
+# Generate a table from C preprocessor symbol definitions. The
+# including file can define the TABLE_NAME(n), TABLE_ENTRY(x), and
+# TABLE_END macros to define what the tables map to.
#
gen_table()
{
- local name grep file excl filter
- name=$1
- grep=$2
- file=$3
- excl=$4
+ local name=$1 grep=$2 file=$3 excl=$4
if [ -z "$excl" ]; then
filter="cat"
@@ -84,6 +80,37 @@
_EOF_
}
+#
+# Generate a table from C enum definitions. The including file can
+# define the TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to
+# define what the tables map to. Works with most enum definitions as
+# long as each constant is on a line by itself.
+#
+gen_table_enum()
+{
+ local name=$1 grep=$2 file=$3 excl=$4
+
+ cat <<_EOF_
+TABLE_START(${name})
+_EOF_
+ if [ -e "${include_dir}/${file}" ]; then
+ all_headers="${all_headers:+${all_headers} }${file}"
+ # preprocess the header
+ ${CPP:-${CC:-cc} -E} "${include_dir}/${file}" |
+ # filter out directives and apply exclusion
+ sed -Ee '/^#/d' ${excl:+-e "/$excl/d"} |
+ # extract all enum definitions
+ awk '/^(typedef[[:space:]]*)?enum([[:space:]].*)?\{/,
+ /^\}([[:space:]].*)?;/' |
+ # pick out the constants we want
+ sed -Ene 's/^[[:space:]]*('"${grep}"')\>.*/TABLE_ENTRY(\1)/p'
+ fi
+cat <<_EOF_
+TABLE_END
+
+_EOF_
+}
+
cat <<_EOF_
/* This file is auto-generated. */
@@ -127,7 +154,7 @@
gen_table "schedpolicy" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sys/sched.h"
gen_table "sendfileflags" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
gen_table "shmatflags" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h"
-gen_table "shutdownhow" "SHUT_[A-Z]+[[:space:]]+SHUT_[A-Z]+" "sys/socket.h"
+gen_table_enum "shutdownhow" "SHUT_[A-Z]+" "sys/socket.h"
gen_table "sigbuscode" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
gen_table "sigchldcode" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
gen_table "sigfpecode" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Jul 11, 6:53 AM (18 h, 23 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34595966
Default Alt Text
D57993.id181176.diff (2 KB)
Attached To
Mode
D57993: libsysdecode: Teach mktables to handle enums
Attached
Detach File
Event Timeline
Log In to Comment