mkioctls revision 188978
11573Srgrimes#!/bin/sh 21573Srgrimes# 31573Srgrimes# $FreeBSD: head/usr.bin/kdump/mkioctls 188978 2009-02-24 00:53:10Z thompsa $ 41573Srgrimes 51573Srgrimesset -e 61573Srgrimes 71573Srgrimesif [ "x$1" = "x-s" ]; then 81573Srgrimes use_switch=1 91573Srgrimes shift 101573Srgrimeselse 111573Srgrimes use_switch=0 121573Srgrimesfi 131573Srgrimes 141573Srgrimesif [ -z "$1" ]; then 151573Srgrimes echo "usage: sh $0 [-s] include-dir" 161573Srgrimes exit 1 171573Srgrimesfi 181573Srgrimes 191573SrgrimesLC_ALL=C; export LC_ALL 201573Srgrimes 211573Srgrimes# include subdirs to exclude from the search 221573Srgrimesexclude="^legacy/.*" 231573Srgrimes 241573Srgrimes# Build a list of headers that have ioctls in them. 251573Srgrimes# XXX should we use an ANSI cpp? 261573Srgrimesioctl_includes=` 271573Srgrimes cd $1 281573Srgrimes find -H -s * -name '*.h' \! -regex $exclude | 2950476Speter xargs egrep -l \ 301573Srgrimes'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 31212492Sgjb awk '{printf("#include <%s>\\\\n", $1)}' 3270936Sru` 3370936Sru 3470936Sruawk -v x="$ioctl_includes" 'BEGIN {print x}' | 3570936Sru gcc -E -I$1 -dM - | 3670936Sru awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' 3770936SruBEGIN { 3884306Sru print "/* XXX obnoxious prerequisites. */" 39105404Smarkm print "#define COMPAT_43" 40105404Smarkm print "#include <sys/param.h>" 4184306Sru print "#include <sys/devicestat.h>" 4270936Sru print "#include <sys/disklabel.h>" 4370936Sru print "#include <sys/socket.h>" 4470936Sru print "#include <sys/time.h>" 45108037Sru print "#include <sys/tty.h>" 46108037Sru print "#include <bsm/audit.h>" 47108037Sru print "#include <net/ethernet.h>" 481573Srgrimes print "#include <net/if.h>" 491573Srgrimes print "#include <net/if_var.h>" 501573Srgrimes print "#include <net/pfvar.h>" 511573Srgrimes print "#include <net/route.h>" 521573Srgrimes print "#include <netinet/in.h>" 531573Srgrimes print "#include <netinet/ip_mroute.h>" 541573Srgrimes print "#include <netinet6/in6_var.h>" 551573Srgrimes print "#include <netinet6/nd6.h>" 5670936Sru print "#include <netinet6/ip6_mroute.h>" 5770936Sru print "#include <stdio.h>" 581573Srgrimes print "#include <cam/cam.h>" 5970936Sru print "" 6070936Sru print "const char *ioctlname(u_long val);" 61108037Sru print "" 62108037Sru print ioctl_includes 63108037Sru print "" 6470936Sru print "const char *" 6570936Sru print "ioctlname(u_long val)" 661573Srgrimes print "{" 671573Srgrimes print "" 68108087Sru if (use_switch) 69108087Sru print "\tswitch(val) {" 70108087Sru} 7170936Sru 7270936Sru/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 731573Srgrimes 7470936Sru # find where the name starts 751573Srgrimes for (i = 1; i <= NF; i++) 7670936Sru if ($i ~ /define/) 7770936Sru break; 781573Srgrimes ++i; 7970936Sru # 8070936Sru if (use_switch) 81212441Sgjb printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 82212441Sgjb else 8370936Sru printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 8470936Sru 8570936Sru} 8670936SruEND { 8770936Sru if (use_switch) 8870936Sru print "\t}" 891573Srgrimes print "\n\treturn(NULL);" 9070936Sru print "}" 911573Srgrimes} 9270936Sru' 931573Srgrimes