1#!/bin/sh 2# 3# $FreeBSD$ 4 5set -e 6 7if [ $# -ne 1 ]; then 8 echo "usage: sh $0 include-dir" 9 exit 1 10fi 11 12includedir="$1" 13 14LC_ALL=C; export LC_ALL 15 16# Build a list of headers that have ioctls in them. 17# XXX should we use an ANSI cpp? 18ioctl_includes=$( 19 cd $includedir 20 21 filter='tee' 22 if [ "${MK_PF}" == "no" ]; then 23 filter='egrep -v (net/pfvar|net/if_pfsync)\.h' 24 fi 25 26 find -H -s * -name '*.h' | \ 27 $filter | \ 28 xargs egrep -l \ 29'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 30 awk '{printf("#include <%s>\\n", $1)}' 31) 32 33awk -v x="$ioctl_includes" 'BEGIN {print x}' | 34 $CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - | 35 awk -v ioctl_includes="$ioctl_includes" ' 36BEGIN { 37 print "/* XXX obnoxious prerequisites. */" 38 print "#define COMPAT_43" 39 print "#define COMPAT_43TTY" 40 print "#include <sys/param.h>" 41 print "#include <sys/devicestat.h>" 42 print "#include <sys/disklabel.h>" 43 print "#include <sys/socket.h>" 44 print "#include <sys/time.h>" 45 print "#include <sys/tty.h>" 46 print "#include <bsm/audit.h>" 47 print "#include <net/ethernet.h>" 48 print "#include <net/if.h>" 49 print "#ifdef PF" 50 print "#include <net/pfvar.h>" 51 print "#include <net/if_pfsync.h>" 52 print "#endif" 53 print "#include <net/route.h>" 54 print "#include <netinet/in.h>" 55 print "#include <netinet/ip_mroute.h>" 56 print "#include <netinet6/in6_var.h>" 57 print "#include <netinet6/nd6.h>" 58 print "#include <netinet6/ip6_mroute.h>" 59 print "#include <stdio.h>" 60 print "#include <cam/cam.h>" 61 print "#include <stdbool.h>" 62 print "#include <stddef.h>" 63 print "#include <stdint.h>" 64 print "#include <sysdecode.h>" 65 print "" 66 print ioctl_includes 67 print "" 68 print "const char *" 69 print "sysdecode_ioctlname(unsigned long val)" 70 print "{" 71 print "\tconst char *str = NULL;" 72 print "" 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 printf("\t"); 84 if (n++ > 0) 85 printf("else "); 86 printf("if (val == %s)\n", $i); 87 printf("\t\tstr = \"%s\";\n", $i); 88} 89END { 90 print "" 91 print "\treturn (str);" 92 print "}" 93} 94' 95