mkioctls revision 75261
150479Speterset -e 246432Sphk 3185435Sbz# $FreeBSD: head/usr.bin/kdump/mkioctls 75261 2001-04-06 14:40:26Z ru $ 4185435Sbz 546155Sphkif [ "x$1" = "x-s" ]; then 6234712Sjamie use_switch=1 7234712Sjamie shift 846155Sphkelse 9234712Sjamie use_switch=0 10234712Sjamiefi 11234712Sjamie 12234712Sjamieif [ -z "$1" ]; then 13234712Sjamie echo "usage: sh $0 [-s] include-dir" 14234712Sjamie exit 1 15185435Sbzfi 16185435Sbz 17185435SbzLC_ALL=C; export LC_ALL 18222465Sbz 19222465Sbz# Build a list of headers that have ioctls in them. 20222465Sbz# XXX should we use an ANSI cpp? 21185435Sbz# XXX netipx conflicts with netns (leave out netns). 22234712Sjamieioctl_includes=` 23234712Sjamie cd $1 2480029Sobrien 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 sed -e 's/^/#include </' -e s'/$/>/' 29` 30 31echo "$ioctl_includes" | 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