]> git.saurik.com Git - apple/system_cmds.git/blame - kdump.tproj/mkioctls
system_cmds-300.tar.gz
[apple/system_cmds.git] / kdump.tproj / mkioctls
CommitLineData
b51d5b5f
A
1set -e
2
3# $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.3 2001/04/07 11:09:28 ru Exp $
4
5if [ "x$1" = "x-s" ]; then
6 use_switch=1
7 shift
8else
9 use_switch=0
10fi
11
12if [ -z "$1" ]; then
13 echo "usage: sh $0 [-s] include-dir"
14 exit 1
15fi
16
17LC_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).
22ioctl_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
37echo "/* XXX obnoxious prerequisites. */"
38echo "#define COMPAT_43 1"
39echo "#include <sys/param.h>"
40echo "#include <sys/socket.h>"
41echo "#include <sys/time.h>"
42echo "#include <sys/tty.h>"
43echo "#include <net/ethernet.h>"
44echo "#include <net/if.h>"
45echo "#include <net/if_var.h>"
46echo "#include <net/route.h>"
47echo "#include <netinet/in.h>"
48echo "#include <netinet/ip_compat.h>"
49echo "#include <netinet/ip_mroute.h>"
50echo "#include <netinet6/in6_var.h>"
51echo "#include <netinet6/nd6.h>"
52echo "#include <netinet6/ip6_mroute.h>"
53echo "#include <netat/appletalk.h>"
54echo "#include <stdio.h>"
55echo ""
56echo "$ioctl_includes"
57echo ""
58
59echo "$ioctl_includes" |
60 cc -no-cpp-precomp -E -I$1 -dM - |
61 awk -v use_switch="$use_switch" '
62BEGIN {
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}
85END {
86 if (use_switch)
87 print "\t}"
88 print "\n\treturn(NULL);"
89 print "}"
90}
91'