set -e # $FreeBSD: src/usr.bin/kdump/mkioctls,v 1.15.2.3 2001/04/07 11:09:28 ru Exp $ 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 LC_ALL=C; export LC_ALL # 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 * -name '*.h' | egrep -v '^(netns)/' | egrep -v 'if_atm' | egrep -v 'disklabel' | egrep -v 'if_ppp' | egrep -v 'bpf' | egrep -v '^(netiso)/' | egrep -v '^(netccitt)/' | xargs egrep -l \ '^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | sed -e 's/^/#include /' ` echo "/* XXX obnoxious prerequisites. */" echo "#define COMPAT_43_TTY 1" echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "#include " echo "" echo "$ioctl_includes" echo "" echo "$ioctl_includes" | cc -no-cpp-precomp -E -I$1 -dM - | awk -v use_switch="$use_switch" ' BEGIN { 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 ($i == "SIOCADDRT" || $i == "SIOCDELRT") { printf("#if 0\n"); } 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); if ($i == "SIOCADDRT" || $i == "SIOCDELRT") { printf("#endif\n"); } } END { if (use_switch) print "\t}" print "\n\treturn(NULL);" print "}" } '