mkioctls revision 191936
1#!/bin/sh 2# 3# $FreeBSD: head/usr.bin/kdump/mkioctls 191936 2009-05-09 15:09:40Z ed $ 4 5set -e 6 7if [ "x$1" = "x-s" ]; then 8 use_switch=1 9 shift 10else 11 use_switch=0 12fi 13 14if [ -z "$1" ]; then 15 echo "usage: sh $0 [-s] include-dir" 16 exit 1 17fi 18 19LC_ALL=C; export LC_ALL 20 21# include subdirs to exclude from the search 22exclude="^legacy/.*" 23 24# Build a list of headers that have ioctls in them. 25# XXX should we use an ANSI cpp? 26ioctl_includes=` 27 cd $1 28 find -H -s * -name '*.h' \! -regex $exclude | 29 xargs egrep -l \ 30'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 31 awk '{printf("#include <%s>\\\\n", $1)}' 32` 33 34awk -v x="$ioctl_includes" 'BEGIN {print x}' | 35 gcc -E -I$1 -dM - | 36 awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' 37BEGIN { 38 print "/* XXX obnoxious prerequisites. */" 39 print "#define COMPAT_43" 40 print "#define COMPAT_43TTY" 41 print "#include <sys/param.h>" 42 print "#include <sys/devicestat.h>" 43 print "#include <sys/disklabel.h>" 44 print "#include <sys/socket.h>" 45 print "#include <sys/time.h>" 46 print "#include <sys/tty.h>" 47 print "#include <bsm/audit.h>" 48 print "#include <net/ethernet.h>" 49 print "#include <net/if.h>" 50 print "#include <net/if_var.h>" 51 print "#include <net/pfvar.h>" 52 print "#include <net/route.h>" 53 print "#include <netinet/in.h>" 54 print "#include <netinet/ip_mroute.h>" 55 print "#include <netinet6/in6_var.h>" 56 print "#include <netinet6/nd6.h>" 57 print "#include <netinet6/ip6_mroute.h>" 58 print "#include <stdio.h>" 59 print "#include <cam/cam.h>" 60 print "" 61 print "const char *ioctlname(u_long val);" 62 print "" 63 print ioctl_includes 64 print "" 65 print "const char *" 66 print "ioctlname(u_long 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