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