set -e # $FreeBSD$ if [ "x$1" = "x-s" ]; then use_switch=1 shift else use_switch=0 fi if [ -z "$1" ]; then echo "usage: sh $0 [-s] include-dir" exit 1 fi # Build a list of headers that have ioctls in them. # XXX should we use an ANSI cpp? # XXX netipx conflicts with netns (leave out netns). ioctl_includes=` cd $1 find -s * -name '*.h' -follow | egrep -v '^(netns)/' | xargs egrep -l \ '^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | sed -e 's/^/#include /' ` echo "$ioctl_includes" | gcc -E -I$1 -dM - | awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' BEGIN { print "/* XXX obnoxious prerequisites. */" print "#define COMPAT_43" print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "#include " print "" print ioctl_includes print "" print "char *" print "ioctlname(register_t val)" print "{" print "" if (use_switch) print "\tswitch(val) {" } /^#[ ]*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; # if (use_switch) printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); else printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); } END { if (use_switch) print "\t}" print "\n\treturn(NULL);" print "}" } '