]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - usr.bin/kdump/mkioctls
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / usr.bin / kdump / mkioctls
1 set -e
2
3 # $FreeBSD$
4
5 if [ "x$1" = "x-s" ]; then
6         use_switch=1
7         shift
8 else
9         use_switch=0
10 fi
11
12 if [ -z "$1" ]; then
13         echo "usage: sh $0 [-s] include-dir"
14         exit 1
15 fi
16
17 LC_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 ioctl_includes=`
22         cd $1
23         find -H -s * -name '*.h' |
24                 xargs egrep -l \
25 '^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO[^a-z0-9_]' |
26                 awk '{printf("#include <%s>\\\\n", $1)}'
27 `
28
29 awk -v x="$ioctl_includes" 'BEGIN {print x}' |
30         gcc -E -I$1 -dM - |
31         awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
32 BEGIN {
33         print "/* XXX obnoxious prerequisites. */"
34         print "#define COMPAT_43"
35         print "#include <sys/param.h>"
36         print "#include <sys/devicestat.h>"
37         print "#include <sys/disklabel.h>"
38         print "#include <sys/socket.h>"
39         print "#include <sys/time.h>"
40         print "#include <sys/tty.h>"
41         print "#include <bsm/audit.h>"
42         print "#include <net/ethernet.h>"
43         print "#include <net/if.h>"
44         print "#include <net/if_var.h>"
45         print "#include <net/pfvar.h>"
46         print "#include <net/route.h>"
47         print "#include <netinet/in.h>"
48         print "#include <netinet/ip_mroute.h>"
49         print "#include <netinet6/in6_var.h>"
50         print "#include <netinet6/nd6.h>"
51         print "#include <netinet6/ip6_mroute.h>"
52         print "#include <stdio.h>"
53         print "#include <cam/cam.h>"
54         print ""
55         print "const char *ioctlname(u_long val);"
56         print ""
57         print ioctl_includes
58         print ""
59         print "const char *"
60         print "ioctlname(u_long val)"
61         print "{"
62         print ""
63         if (use_switch)
64                 print "\tswitch(val) {"
65 }
66
67 /^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO/ {
68         
69         # find where the name starts
70         for (i = 1; i <= NF; i++)
71                 if ($i ~ /define/)
72                         break;
73         ++i;
74         # 
75         if (use_switch)
76                 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
77         else
78                 printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
79
80 }
81 END {
82         if (use_switch)
83                 print "\t}"
84         print "\n\treturn(NULL);"
85         print "}"
86 }
87 '