Dag-Erling Smørgrav d09e66be12 Bring ioctlname() in line with all the other *name() functions, which
actually print the name (or the numeric value, if they can't figure out
the correct name) instead of just returning a pointer to it.  Also, since
ioctl numbers are not and probably never will be unique, drop support for
using a switch statement instead of an if/else chain.
2011-10-08 12:47:00 +00:00

87 lines
1.9 KiB
Bash

#!/bin/sh
#
# $FreeBSD$
set -e
if [ -z "$1" ]; then
echo "usage: sh $0 include-dir"
exit 1
fi
LC_ALL=C; export LC_ALL
# Build a list of headers that have ioctls in them.
# XXX should we use an ANSI cpp?
ioctl_includes=`
cd $1
find -H -s * -name '*.h' |
xargs egrep -l \
'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' |
awk '{printf("#include <%s>\\\\n", $1)}'
`
awk -v x="$ioctl_includes" 'BEGIN {print x}' |
gcc -E -I$1 -dM -DCOMPAT_43TTY - |
awk -v ioctl_includes="$ioctl_includes" '
BEGIN {
print "/* XXX obnoxious prerequisites. */"
print "#define COMPAT_43"
print "#define COMPAT_43TTY"
print "#include <sys/param.h>"
print "#include <sys/devicestat.h>"
print "#include <sys/disklabel.h>"
print "#include <sys/socket.h>"
print "#include <sys/time.h>"
print "#include <sys/tty.h>"
print "#include <bsm/audit.h>"
print "#include <net/ethernet.h>"
print "#include <net/if.h>"
print "#include <net/if_var.h>"
print "#include <net/pfvar.h>"
print "#include <net/route.h>"
print "#include <netinet/in.h>"
print "#include <netinet/ip_mroute.h>"
print "#include <netinet6/in6_var.h>"
print "#include <netinet6/nd6.h>"
print "#include <netinet6/ip6_mroute.h>"
print "#include <stdio.h>"
print "#include <cam/cam.h>"
print ""
print "void ioctlname(unsigned long val, int decimal);"
print ""
print ioctl_includes
print ""
print "void"
print "ioctlname(unsigned long val, int decimal)"
print "{"
print "\tconst char *str = NULL;"
print ""
}
/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ {
# find where the name starts
for (i = 1; i <= NF; i++)
if ($i ~ /define/)
break;
++i;
#
print("\t");
if (n++ > 0)
print("else ");
printf("if (val == %s)\n", $i);
printf("\t\tstr = \"%s\";\n", $i);
}
END {
print "\n"
print "\tif (str != NULL)\n"
print "\t\tprintf(\"%s\", str);\n"
print "\telse if (decimal)\n"
print "\t\tprintf(\"%lu\", val);\n"
print "\telse\n"
print "\t\tprintf(\"%#lx\", val);\n"
print "}"
}
'