xref: /dragonfly/usr.bin/kdump/mkioctls (revision ce7a3582)
1#!/bin/sh
2#
3# $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.5 2002/11/15 18:22:31 ru Exp $
4
5set -e
6
7if [ "x$1" = "x-s" ]; then
8	use_switch=1
9	shift
10else
11	use_switch=0
12fi
13
14if [ -z "$1" ]; then
15	echo "usage: sh $0 [-s] include-dir"
16	exit 1
17fi
18
19LC_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# XXX leave out cam/, fs/, netatm/, netnatm/, netsmb/, nwfs/,
24#     and ufs/ because they are fake softlinks
25ioctl_includes=`
26	cd $1
27	find -s * -name '*.h' -follow |
28		egrep -v '^(cam/)|^(fs/)|^(netatm/)|^(netnatm/)|^(netsmb/)|^(nwfs/)|^(ufs/)' |
29		xargs egrep -l \
30'^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
31		awk '{printf("#include <%s>\\\\n", $1)}'
32`
33
34awk -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" '
37BEGIN {
38	print "/* XXX obnoxious prerequisites. */"
39	print "#define COMPAT_43"
40	print "#define _KERNEL_STRUCTURES"
41	print "#include <sys/tty.h>"
42	print "#include <net/if_arp.h>"
43	print "#include <net/route.h>"
44	print "#include <netatm/atm.h>"
45	print "#include <netatm/atm_if.h>"
46	print "#include <netatm/atm_sap.h>"
47	print "#include <netatm/atm_sys.h>"
48	print "#include <netinet/in.h>"
49	print "#include <net/ip_mroute/ip_mroute.h>"
50	print "#include <netinet6/nd6.h>"
51	print "#include <netinet6/ip6_mroute.h>"
52	print "#include <stdio.h>"
53	print "#include <cam/cam.h>"
54	print ""
55	print ioctl_includes
56	print "const char *ioctlname(u_long);"
57	print ""
58	print "const char *"
59	print "ioctlname(u_long val)"
60	print "{"
61	if (use_switch)
62		print "\tswitch(val) {"
63}
64
65/^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
66
67	# find where the name starts
68	for (i = 1; i <= NF; i++)
69		if ($i ~ /define/)
70			break;
71	++i;
72	#
73	if (use_switch)
74		printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i);
75	else
76		printf("\tif (val ==  %s)\n\t\treturn(\"%s\");\n", $i, $i);
77
78}
79END {
80	if (use_switch)
81		print "\t}"
82	print "\n\treturn(NULL);"
83	print "}"
84}
85'
86