svn commit: r226157 - head/usr.bin/kdump

Dag-Erling Smorgrav des at FreeBSD.org
Sat Oct 8 12:47:00 UTC 2011


Author: des
Date: Sat Oct  8 12:47:00 2011
New Revision: 226157
URL: http://svn.freebsd.org/changeset/base/226157

Log:
  Bring ioctlname() in line with all the other *name() functions, which
  actually print the name (or the numeric value, if they can't figure out
  the correct name) instead of just returning a pointer to it.  Also, since
  ioctl numbers are not and probably never will be unique, drop support for
  using a switch statement instead of an if/else chain.

Modified:
  head/usr.bin/kdump/kdump.c
  head/usr.bin/kdump/mkioctls

Modified: head/usr.bin/kdump/kdump.c
==============================================================================
--- head/usr.bin/kdump/kdump.c	Sat Oct  8 12:42:19 2011	(r226156)
+++ head/usr.bin/kdump/kdump.c	Sat Oct  8 12:47:00 2011	(r226157)
@@ -100,7 +100,7 @@ void ktrsockaddr(struct sockaddr *);
 void ktrstat(struct stat *);
 void ktrstruct(char *, size_t);
 void usage(void);
-const char *ioctlname(u_long);
+void ioctlname(unsigned long, int);
 
 int timestamp, decimal, fancy = 1, suppressdata, tail, threads, maxdata,
     resolv = 0, abiflag = 0;
@@ -504,14 +504,8 @@ ktrsyscall(struct ktr_syscall *ktr, u_in
 			case SYS_ioctl: {
 				const char *cp;
 				print_number(ip, narg, c);
-				if ((cp = ioctlname(*ip)) != NULL)
-					printf(",%s", cp);
-				else {
-					if (decimal)
-						printf(",%jd", (intmax_t)*ip);
-					else
-						printf(",%#jx ", (intmax_t)*ip);
-				}
+				putchar(c);
+				ioctlname(*ip, decimal);
 				c = ',';
 				ip++;
 				narg--;

Modified: head/usr.bin/kdump/mkioctls
==============================================================================
--- head/usr.bin/kdump/mkioctls	Sat Oct  8 12:42:19 2011	(r226156)
+++ head/usr.bin/kdump/mkioctls	Sat Oct  8 12:47:00 2011	(r226157)
@@ -4,15 +4,8 @@
 
 set -e
 
-if [ "x$1" = "x-s" ]; then
-	use_switch=1
-	shift
-else
-	use_switch=0
-fi
-
 if [ -z "$1" ]; then
-	echo "usage: sh $0 [-s] include-dir"
+	echo "usage: sh $0 include-dir"
 	exit 1
 fi
 
@@ -30,7 +23,7 @@ ioctl_includes=`
 
 awk -v x="$ioctl_includes" 'BEGIN {print x}' |
 	gcc -E -I$1 -dM -DCOMPAT_43TTY - |
-	awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
+	awk -v ioctl_includes="$ioctl_includes" '
 BEGIN {
 	print "/* XXX obnoxious prerequisites. */"
 	print "#define COMPAT_43"
@@ -55,16 +48,15 @@ BEGIN {
 	print "#include <stdio.h>"
 	print "#include <cam/cam.h>"
 	print ""
-	print "const char *ioctlname(u_long val);"
+	print "void ioctlname(unsigned long val, int decimal);"
 	print ""
 	print ioctl_includes
 	print ""
-	print "const char *"
-	print "ioctlname(u_long val)"
+	print "void"
+	print "ioctlname(unsigned long val, int decimal)"
 	print "{"
+	print "\tconst char *str = NULL;"
 	print ""
-	if (use_switch)
-		print "\tswitch(val) {"
 }
 
 /^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
@@ -75,16 +67,20 @@ BEGIN {
 			break;
 	++i;
 	#
-	if (use_switch)
-		printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
-	else
-		printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
-
+	print("\t");
+	if (n++ > 0)
+		print("else ");
+	printf("if (val == %s)\n", $i);
+	printf("\t\tstr = \"%s\";\n", $i);
 }
 END {
-	if (use_switch)
-		print "\t}"
-	print "\n\treturn(NULL);"
+	print "\n"
+	print "\tif (str != NULL)\n"
+	print "\t\tprintf(\"%s\", str);\n"
+	print "\telse if (decimal)\n"
+	print "\t\tprintf(\"%lu\", val);\n"
+	print "\telse\n"
+	print "\t\tprintf(\"%#lx\", val);\n"
 	print "}"
 }
 '


More information about the svn-src-all mailing list