From d665dfeb8c64ab88cb98bc2de95fa5460a51e5bf Mon Sep 17 00:00:00 2001 From: rodrigc Date: Thu, 4 Jan 2007 04:18:03 +0000 Subject: 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(). --- usr.bin/kdump/mksubr | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'usr.bin/kdump/mksubr') diff --git a/usr.bin/kdump/mksubr b/usr.bin/kdump/mksubr index 1e9825a..8cf4f94 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("", (long)arg); +} + +_EOF_ +} + # C start cat <<_EOF_ -- cgit v1.1