xref: /freebsd/lib/libsysdecode/mkioctls (revision 792bbaba989533a1fc93823df1720c8c4aaf0442)
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
27: ${MACHINE=$(uname -m)}
28case "${MACHINE}" in
29*pc98*)
30	ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n"
31	;;
32*)
33	ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n"
34	;;
35esac
36
37awk -v x="$ioctl_includes" 'BEGIN {print x}' |
38	$CPP -nostdinc -I$includedir -dM -DCOMPAT_43TTY - |
39	awk -v ioctl_includes="$ioctl_includes" '
40BEGIN {
41	print "/* XXX obnoxious prerequisites. */"
42	print "#define COMPAT_43"
43	print "#define COMPAT_43TTY"
44	print "#include <sys/param.h>"
45	print "#include <sys/devicestat.h>"
46	print "#include <sys/disklabel.h>"
47	print "#include <sys/socket.h>"
48	print "#include <sys/time.h>"
49	print "#include <sys/tty.h>"
50	print "#include <bsm/audit.h>"
51	print "#include <net/ethernet.h>"
52	print "#include <net/if.h>"
53	print "#ifdef PF"
54	print "#include <net/pfvar.h>"
55	print "#include <net/if_pfsync.h>"
56	print "#endif"
57	print "#include <net/route.h>"
58	print "#include <netinet/in.h>"
59	print "#include <netinet/ip_mroute.h>"
60	print "#include <netinet6/in6_var.h>"
61	print "#include <netinet6/nd6.h>"
62	print "#include <netinet6/ip6_mroute.h>"
63	print "#include <stdio.h>"
64	print "#include <cam/cam.h>"
65	print "#include <stdbool.h>"
66	print "#include <stddef.h>"
67	print "#include <stdint.h>"
68	print "#include <sysdecode.h>"
69	print ""
70	print ioctl_includes
71	print ""
72	print "const char *"
73	print "sysdecode_ioctlname(unsigned long val)"
74	print "{"
75	print "\tconst char *str = NULL;"
76	print ""
77}
78
79/^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
80
81	# find where the name starts
82	for (i = 1; i <= NF; i++)
83		if ($i ~ /define/)
84			break;
85	++i;
86	#
87	printf("\t");
88	if (n++ > 0)
89		printf("else ");
90	printf("if (val == %s)\n", $i);
91	printf("\t\tstr = \"%s\";\n", $i);
92}
93END {
94	print ""
95	print "\treturn (str);"
96	print "}"
97}
98'
99