HAMMER Utilities: Feature add
[dfdiff.git] / usr.bin / kdump / mkioctls
blob4892a2a733d45a435ac5fc223ef2b1349d90281e
1 set -e
3 # $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.5 2002/11/15 18:22:31 ru Exp $
4 # $DragonFly: src/usr.bin/kdump/mkioctls,v 1.9 2008/01/05 13:36:37 corecode Exp $
6 if [ "x$1" = "x-s" ]; then
7         use_switch=1
8         shift
9 else
10         use_switch=0
13 if [ -z "$1" ]; then
14         echo "usage: sh $0 [-s] include-dir"
15         exit 1
18 LC_ALL=C; export LC_ALL
20 # Build a list of headers that have ioctls in them.
21 # XXX should we use an ANSI cpp?
22 # XXX netipx conflicts with netns (leave out netns).
23 # XXX leave out cam/, isa/ pccard/, pci/, and usb/ because they
24 #     are fake softlinks and handled by bus/
25 ioctl_includes=`
26         cd $1
27         find -s * -name '*.h' -follow |
28                 egrep -v '^(netns/)|^(cam/)|^(isa/)|^(pccard/)|^(pci/)|^(usb/)|^(netproto/natm/)' |
29                 xargs egrep -l \
30 '^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO[^a-z0-9_]' |
31                 awk '{printf("#include <%s>\\\\n", $1)}'
34 awk -v x="$ioctl_includes" 'BEGIN {print x}' |
35         gcc -D_KERNEL_STRUCTURES -E -I$1 -dM - |
36         awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" '
37 BEGIN {
38         print "/* XXX obnoxious prerequisites. */"
39         print "#define COMPAT_43"
40         print "#define _KERNEL_STRUCTURES"
41         print "#include <sys/param.h>"
42         print "#include <sys/devicestat.h>"
43         print "#include <sys/disklabel.h>"
44         print "#include <sys/diskslice.h>"
45         print "#include <sys/socket.h>"
46         print "#include <sys/time.h>"
47         print "#include <sys/tty.h>"
48         print "#include <net/ethernet.h>"
49         print "#include <net/if.h>"
50         print "#include <net/if_var.h>"
51         print "#include <net/route.h>"
52         print "#include <netatm/atm.h>"
53         print "#include <netatm/atm_if.h>"
54         print "#include <netatm/atm_sap.h>"
55         print "#include <netatm/atm_sys.h>"
56         print "#include <netinet/in.h>"
57         print "#include <net/ip_mroute/ip_mroute.h>"
58         print "#include <netinet6/in6_var.h>"
59         print "#include <netinet6/nd6.h>"
60         print "#include <netinet6/ip6_mroute.h>"
61         print "#include <stdio.h>"
62         print "#include <cam/cam.h>"
63         print ""
64         print ioctl_includes
65         print ""
66         print "char *"
67         print "ioctlname(register_t val)"
68         print "{"
69         print ""
70         if (use_switch)
71                 print "\tswitch(val) {"
74 /^#[    ]*define[       ]+[A-Za-z_][A-Za-z0-9_]*[       ]+_IO/ {
75         
76         # find where the name starts
77         for (i = 1; i <= NF; i++)
78                 if ($i ~ /define/)
79                         break;
80         ++i;
81         # 
82         if (use_switch)
83                 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
84         else
85                 printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
88 END {
89         if (use_switch)
90                 print "\t}"
91         print "\n\treturn(NULL);"
92         print "}"