aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/kdump
diff options
context:
space:
mode:
authorCraig Rodrigues <rodrigc@FreeBSD.org>2007-01-04 04:18:03 +0000
committerCraig Rodrigues <rodrigc@FreeBSD.org>2007-01-04 04:18:03 +0000
commit4c8dc49a4a58ec65c21fd52d1b3e05287897bce1 (patch)
tree587e43c69b20455de707f7e7466011fef48edb8f /usr.bin/kdump
parentb1fa343faec4e5af24ffc3c4d83c0125f2796334 (diff)
downloadsrc-4c8dc49a4a58ec65c21fd52d1b3e05287897bce1.tar.gz
src-4c8dc49a4a58ec65c21fd52d1b3e05287897bce1.zip
Add auto_if_type() function, which is similar to auto_switch_type().
However, auto_if_type() uses if/else statements in C instead of a single switch statement, when mapping an integer value to a #define. For certain cases where multiple #define constants alias to a single integer value, auto_if_type() makes things easier to parse than auto_switch_type().
Notes
Notes: svn path=/head/; revision=165756
Diffstat (limited to 'usr.bin/kdump')
-rw-r--r--usr.bin/kdump/mksubr30
1 files changed, 30 insertions, 0 deletions
diff --git a/usr.bin/kdump/mksubr b/usr.bin/kdump/mksubr
index 1e9825aca311..8cf4f946564f 100644
--- a/usr.bin/kdump/mksubr
+++ b/usr.bin/kdump/mksubr
@@ -96,6 +96,36 @@ cat <<_EOF_
_EOF_
}
+#
+# Automatically generates a C function used when the argument
+# maps to a #definition
+#
+auto_if_type () {
+ local name grep file
+ name=$1
+ grep=$2
+ file=$3
+
+ cat <<_EOF_
+/* AUTO */
+void
+$name (int arg)
+{
+_EOF_
+ egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
+ $include_dir/$file | \
+ awk '{ printf "\t"; \
+ if (NR > 1) \
+ printf "else " ; \
+ printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
+cat <<_EOF_
+ else /* Should not reach */
+ (void)printf("<invalid=%ld>", (long)arg);
+}
+
+_EOF_
+}
+
# C start
cat <<_EOF_