mkioctls revision 98767
1set -e 2 3# $FreeBSD: head/usr.bin/kdump/mkioctls 98767 2002-06-24 16:35:19Z markm $ 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? 21# XXX netipx conflicts with netns (leave out netns). 22ioctl_includes=` 23 cd $1 24 find -s * -name '*.h' -follow | 25 egrep -v '^(netns)/' | 26 xargs egrep -l \ 27'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 28 awk '{printf("#include <%s>\\\\n", $1)}' 29` 30 31awk -v x="$ioctl_includes" 'BEGIN {print x}' | 32 gcc -E -I$1 -dM - | 33 awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' 34BEGIN { 35 print "/* XXX obnoxious prerequisites. */" 36 print "#define COMPAT_43" 37 print "#include <sys/param.h>" 38 print "#include <sys/devicestat.h>" 39 print "#include <sys/disklabel.h>" 40 print "#include <sys/socket.h>" 41 print "#include <sys/time.h>" 42 print "#include <sys/tty.h>" 43 print "#include <net/ethernet.h>" 44 print "#include <net/if.h>" 45 print "#include <net/if_var.h>" 46 print "#include <net/route.h>" 47 print "#include <netatm/atm.h>" 48 print "#include <netatm/atm_if.h>" 49 print "#include <netatm/atm_sap.h>" 50 print "#include <netatm/atm_sys.h>" 51 print "#include <netinet/in.h>" 52 print "#include <netinet/ip_mroute.h>" 53 print "#include <netinet6/in6_var.h>" 54 print "#include <netinet6/nd6.h>" 55 print "#include <netinet6/ip6_mroute.h>" 56 print "#include <stdio.h>" 57 print "#include <cam/cam.h>" 58 print "" 59 print "const char *ioctlname(u_long val);" 60 print "" 61 print ioctl_includes 62 print "" 63 print "const char *" 64 print "ioctlname(u_long val)" 65 print "{" 66 print "" 67 if (use_switch) 68 print "\tswitch(val) {" 69} 70 71/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 72 73 # find where the name starts 74 for (i = 1; i <= NF; i++) 75 if ($i ~ /define/) 76 break; 77 ++i; 78 # 79 if (use_switch) 80 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 81 else 82 printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 83 84} 85END { 86 if (use_switch) 87 print "\t}" 88 print "\n\treturn(NULL);" 89 print "}" 90} 91' 92