]> git.saurik.com Git - apple/system_cmds.git/blob - kdump.tproj/mkioctls
system_cmds-230.tar.gz
[apple/system_cmds.git] / kdump.tproj / mkioctls
1 set -e
2
3 # $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.3 2001/04/07 11:09:28 ru Exp $
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 # XXX netipx conflicts with netns (leave out netns).
22 ioctl_includes=`
23 cd $1
24 find * -name '*.h' |
25 egrep -v '^(netns)/' |
26 egrep -v 'if_atm' |
27 egrep -v 'disklabel' |
28 egrep -v 'if_ppp' |
29 egrep -v 'bpf' |
30 egrep -v '^(netiso)/' |
31 egrep -v '^(netccitt)/' |
32 xargs egrep -l \
33 '^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' |
34 sed -e 's/^/#include </' -e s'/$/>/'
35 `
36
37 echo "/* XXX obnoxious prerequisites. */"
38 echo "#define COMPAT_43 1"
39 echo "#include <sys/param.h>"
40 echo "#include <sys/socket.h>"
41 echo "#include <sys/time.h>"
42 echo "#include <sys/tty.h>"
43 echo "#include <net/ethernet.h>"
44 echo "#include <net/if.h>"
45 echo "#include <net/if_var.h>"
46 echo "#include <net/route.h>"
47 echo "#include <netinet/in.h>"
48 echo "#include <netinet/ip_compat.h>"
49 echo "#include <netinet/ip_mroute.h>"
50 echo "#include <netinet6/in6_var.h>"
51 echo "#include <netinet6/nd6.h>"
52 echo "#include <netinet6/ip6_mroute.h>"
53 echo "#include <netat/appletalk.h>"
54 echo "#include <stdio.h>"
55 echo ""
56 echo "$ioctl_includes"
57 echo ""
58
59 echo "$ioctl_includes" |
60 cc -no-cpp-precomp -E -I$1 -dM - |
61 awk -v use_switch="$use_switch" '
62 BEGIN {
63 print "char *"
64 print "ioctlname(register_t val)"
65 print "{"
66 print ""
67 if (use_switch)
68 print "\tswitch(val) {"
69 }
70
71 /^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ {
72
73 # find where the name starts
74 for (i = 1; i <= NF; i++)
75 if ($i ~ /define/)
76 break;
77 ++i;
78 #
79 if (use_switch)
80 printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
81 else
82 printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i);
83
84 }
85 END {
86 if (use_switch)
87 print "\t}"
88 print "\n\treturn(NULL);"
89 print "}"
90 }
91 '