]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.bin/kdump/mkioctls
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.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         $CPP -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 "#include <stddef.h>"
58         print "#include <stdint.h>"
59         print ""
60         print "const char *ioctlname(u_long val);"
61         print ""
62         print ioctl_includes
63         print ""
64         print "const char *"
65         print "ioctlname(u_long val)"
66         print "{"
67         print ""
68         if (use_switch)
69                 print "\tswitch(val) {"
70 }
71
72 /^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO/ {
73
74         # find where the name starts
75         for (i = 1; i <= NF; i++)
76                 if ($i ~ /define/)
77                         break;
78         ++i;
79         #
80         if (use_switch)
81                 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
82         else
83                 printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
84
85 }
86 END {
87         if (use_switch)
88                 print "\t}"
89         print "\n\treturn(NULL);"
90         print "}"
91 }
92 '