xref: /freebsd/lib/libsysdecode/mkioctls (revision 193d9e768ba63fcfb187cfd17f461f7d41345048)
1#!/bin/sh
2#
3# $FreeBSD$
4
5set -e
6
7if [ $# -ne 1 ]; then
8	echo "usage: sh $0 include-dir"
9	exit 1
10fi
11
12includedir="$1"
13
14LC_ALL=C; export LC_ALL
15
16# Build a list of headers that have ioctls in them.
17# XXX should we use an ANSI cpp?
18ioctl_includes=$(
19	cd $includedir
20	find -H -s * -name '*.h' | \
21	egrep -v '(.*disk.*|net/pfvar|net/if_pfsync)\.h' | \
22		xargs egrep -l \
23'^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
24		awk '{printf("#include <%s>\\n", $1)}'
25)
26
27ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n"
28
29awk -v x="$ioctl_includes" 'BEGIN {print x}' |
30	$CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - |
31	awk -v ioctl_includes="$ioctl_includes" '
32BEGIN {
33	print "/* XXX obnoxious prerequisites. */"
34	print "#define COMPAT_43"
35	print "#define COMPAT_43TTY"
36	print "#include <sys/param.h>"
37	print "#include <sys/devicestat.h>"
38	print "#include <sys/disklabel.h>"
39	print "#include <sys/socket.h>"
40	print "#include <sys/time.h>"
41	print "#include <sys/tty.h>"
42	print "#include <bsm/audit.h>"
43	print "#include <net/ethernet.h>"
44	print "#include <net/if.h>"
45	print "#ifdef PF"
46	print "#include <net/pfvar.h>"
47	print "#include <net/if_pfsync.h>"
48	print "#endif"
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 <stdbool.h>"
58	print "#include <stddef.h>"
59	print "#include <stdint.h>"
60	print "#include <sysdecode.h>"
61	print ""
62	print ioctl_includes
63	print ""
64	print "const char *"
65	print "sysdecode_ioctlname(unsigned long val)"
66	print "{"
67	print "\tconst char *str = NULL;"
68	print ""
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	printf("\t");
80	if (n++ > 0)
81		printf("else ");
82	printf("if (val == %s)\n", $i);
83	printf("\t\tstr = \"%s\";\n", $i);
84}
85END {
86	print ""
87	print "\treturn (str);"
88	print "}"
89}
90'
91