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