mkioctls revision 74864
1set -e 2 3# $FreeBSD: head/usr.bin/kdump/mkioctls 74864 2001-03-27 16:15:25Z 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 -s * -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/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_compat.h>" 51 print "#include <netinet/ip_fil.h>" 52 print "#include <netinet/ip_auth.h>" 53 print "#include <netinet/ip_nat.h>" 54 print "#include <netinet/ip_frag.h>" 55 print "#include <netinet/ip_state.h>" 56 print "#include <netinet/ip_mroute.h>" 57 print "#include <netinet6/in6_var.h>" 58 print "#include <netinet6/nd6.h>" 59 print "#include <netinet6/ip6_mroute.h>" 60 print "#include <stdio.h>" 61 print "#include <cam/cam.h>" 62 print "" 63 print ioctl_includes 64 print "" 65 print "char *" 66 print "ioctlname(register_t val)" 67 print "{" 68 print "" 69 if (use_switch) 70 print "\tswitch(val) {" 71} 72 73/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 74 75 # find where the name starts 76 for (i = 1; i <= NF; i++) 77 if ($i ~ /define/) 78 break; 79 ++i; 80 # 81 if (use_switch) 82 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 83 else 84 printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 85 86} 87END { 88 if (use_switch) 89 print "\t}" 90 print "\n\treturn(NULL);" 91 print "}" 92} 93' 94