mkioctls revision 64099
1set -e 2 3# $FreeBSD: head/usr.bin/kdump/mkioctls 64099 2000-08-01 08:15:06Z ru $ 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 17# Build a list of headers that have ioctls in them. 18# XXX should we use an ANSI cpp? 19# XXX netipx conflicts with netns (leave out netns). 20ioctl_includes=` 21 cd $1 22 find * -name '*.h' -follow | 23 egrep -v '^(netns)/' | 24 xargs egrep -l \ 25'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 26 sed -e 's/^/#include </' -e s'/$/>/' 27` 28 29echo "$ioctl_includes" | 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/if.h>" 42 print "#include <net/if_var.h>" 43 print "#include <net/route.h>" 44 print "#include <netatm/atm.h>" 45 print "#include <netatm/atm_if.h>" 46 print "#include <netatm/atm_sap.h>" 47 print "#include <netatm/atm_sys.h>" 48 print "#include <netinet/in.h>" 49 print "#include <netinet/ip_compat.h>" 50 print "#include <netinet/ip_fil.h>" 51 print "#include <netinet/ip_auth.h>" 52 print "#include <netinet/ip_nat.h>" 53 print "#include <netinet/ip_frag.h>" 54 print "#include <netinet/ip_state.h>" 55 print "#include <netinet/ip_mroute.h>" 56 print "#include <netinet6/in6_var.h>" 57 print "#include <netinet6/nd6.h>" 58 print "#include <netinet6/ip6_mroute.h>" 59 print "#include <cam/cam.h>" 60 print "#include <stdio.h>" 61 print "" 62 print ioctl_includes 63 print "" 64 print "char *" 65 print "ioctlname(register_t val)" 66 print "{" 67 print "" 68 if (use_switch) 69 print "\tswitch(val) {" 70} 71 72/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 73 74 # find where the name starts 75 for (i = 1; i <= NF; i++) 76 if ($i ~ /define/) 77 break; 78 ++i; 79 # 80 if (use_switch) 81 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 82 else 83 printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 84 85} 86END { 87 if (use_switch) 88 print "\t}" 89 print "\n\treturn(NULL);" 90 print "}" 91} 92' 93