mkioctls revision 126244
1set -e 2 3# $FreeBSD: head/usr.bin/kdump/mkioctls 126244 2004-02-25 21:45:41Z des $ 4 5if [ "x$1" = "x-s" ]; then 6 use_switch=1 7 shift 8else 9 use_switch=0 10fi 11 12if [ -z "$1" ]; then 13 echo "usage: sh $0 [-s] include-dir" 14 exit 1 15fi 16 17LC_ALL=C; export LC_ALL 18 19# Build a list of headers that have ioctls in them. 20# XXX should we use an ANSI cpp? 21ioctl_includes=` 22 cd $1 23 find -H -s * -name '*.h' | 24 xargs egrep -l \ 25'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 26 awk '{printf("#include <%s>\\\\n", $1)}' 27` 28 29awk -v x="$ioctl_includes" 'BEGIN {print x}' | 30 gcc -E -I$1 -dM - | 31 awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' 32BEGIN { 33 print "/* XXX obnoxious prerequisites. */" 34 print "#define COMPAT_43" 35 print "#include <sys/param.h>" 36 print "#include <sys/devicestat.h>" 37 print "#include <sys/disklabel.h>" 38 print "#include <sys/socket.h>" 39 print "#include <sys/time.h>" 40 print "#include <sys/tty.h>" 41 print "#include <net/ethernet.h>" 42 print "#include <net/if.h>" 43 print "#include <net/if_var.h>" 44 print "#include <net/route.h>" 45 print "#include <netatm/atm.h>" 46 print "#include <netatm/atm_if.h>" 47 print "#include <netatm/atm_sap.h>" 48 print "#include <netatm/atm_sys.h>" 49 print "#include <netinet/in.h>" 50 print "#include <netinet/ip_mroute.h>" 51 print "#include <netinet6/in6_var.h>" 52 print "#include <netinet6/nd6.h>" 53 print "#include <netinet6/ip6_mroute.h>" 54 print "#include <stdio.h>" 55 print "#include <cam/cam.h>" 56 print "" 57 print "const char *ioctlname(u_long val);" 58 print "" 59 print ioctl_includes 60 print "" 61 print "const char *" 62 print "ioctlname(u_long val)" 63 print "{" 64 print "" 65 if (use_switch) 66 print "\tswitch(val) {" 67} 68 69/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 70 71 # find where the name starts 72 for (i = 1; i <= NF; i++) 73 if ($i ~ /define/) 74 break; 75 ++i; 76 # 77 if (use_switch) 78 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 79 else 80 printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 81 82} 83END { 84 if (use_switch) 85 print "\t}" 86 print "\n\treturn(NULL);" 87 print "}" 88} 89' 90