mkioctls revision 188978
1175936Sdes#!/bin/sh 2175936Sdes# 3175936Sdes# $FreeBSD: head/usr.bin/kdump/mkioctls 188978 2009-02-24 00:53:10Z thompsa $ 4175936Sdes 540455Sbdeset -e 640455Sbde 754081Smarcelif [ "x$1" = "x-s" ]; then 854081Smarcel use_switch=1 954081Smarcel shift 1054081Smarcelelse 1154081Smarcel use_switch=0 1254081Smarcelfi 1354081Smarcel 1454081Smarcelif [ -z "$1" ]; then 1554081Smarcel echo "usage: sh $0 [-s] include-dir" 1654081Smarcel exit 1 1754081Smarcelfi 1854081Smarcel 1975261SruLC_ALL=C; export LC_ALL 2075261Sru 21188978Sthompsa# include subdirs to exclude from the search 22188978Sthompsaexclude="^legacy/.*" 23188978Sthompsa 2440455Sbde# Build a list of headers that have ioctls in them. 2516631Sbde# XXX should we use an ANSI cpp? 2640455Sbdeioctl_includes=` 2754081Smarcel cd $1 28188978Sthompsa find -H -s * -name '*.h' \! -regex $exclude | 2940455Sbde xargs egrep -l \ 3064099Sru'^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO[^a-z0-9_]' | 3185796Sobrien awk '{printf("#include <%s>\\\\n", $1)}' 3240455Sbde` 3340455Sbde 3485796Sobrienawk -v x="$ioctl_includes" 'BEGIN {print x}' | 3554081Smarcel gcc -E -I$1 -dM - | 3685796Sobrien awk -v ioctl_includes="$ioctl_includes" -v use_switch="$use_switch" ' 371590SrgrimesBEGIN { 3840455Sbde print "/* XXX obnoxious prerequisites. */" 3940455Sbde print "#define COMPAT_43" 401590Srgrimes print "#include <sys/param.h>" 4140455Sbde print "#include <sys/devicestat.h>" 4240455Sbde print "#include <sys/disklabel.h>" 431590Srgrimes print "#include <sys/socket.h>" 4420287Swollman print "#include <sys/time.h>" 4540455Sbde print "#include <sys/tty.h>" 46159247Srwatson print "#include <bsm/audit.h>" 4764121Sru print "#include <net/ethernet.h>" 4840455Sbde print "#include <net/if.h>" 4940455Sbde print "#include <net/if_var.h>" 50130617Smlaier print "#include <net/pfvar.h>" 511590Srgrimes print "#include <net/route.h>" 5216631Sbde print "#include <netinet/in.h>" 5352130Speter print "#include <netinet/ip_mroute.h>" 5462585Sitojun print "#include <netinet6/in6_var.h>" 5562585Sitojun print "#include <netinet6/nd6.h>" 5662585Sitojun print "#include <netinet6/ip6_mroute.h>" 5774840Sken print "#include <stdio.h>" 5840455Sbde print "#include <cam/cam.h>" 591590Srgrimes print "" 6098767Smarkm print "const char *ioctlname(u_long val);" 6193522Sdwmalone print "" 6240455Sbde print ioctl_includes 6340455Sbde print "" 6493522Sdwmalone print "const char *" 6598767Smarkm print "ioctlname(u_long val)" 661590Srgrimes print "{" 671590Srgrimes print "" 6854081Smarcel if (use_switch) 6940455Sbde print "\tswitch(val) {" 701590Srgrimes} 711590Srgrimes 7240455Sbde/^#[ ]*define[ ]+[A-Za-z_][A-Za-z0-9_]*[ ]+_IO/ { 73175936Sdes 741590Srgrimes # find where the name starts 751590Srgrimes for (i = 1; i <= NF; i++) 761590Srgrimes if ($i ~ /define/) 771590Srgrimes break; 781590Srgrimes ++i; 79175936Sdes # 8054081Smarcel if (use_switch) 8140455Sbde printf("\tcase %s:\n\t\treturn(\"%s\");\n", $i, $i); 8240455Sbde else 8398767Smarkm printf("\tif (val == %s)\n\t\treturn(\"%s\");\n", $i, $i); 841590Srgrimes 851590Srgrimes} 861590SrgrimesEND { 8754081Smarcel if (use_switch) 8840455Sbde print "\t}" 891590Srgrimes print "\n\treturn(NULL);" 901590Srgrimes print "}" 911590Srgrimes} 9216631Sbde' 93