PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/usr.bin/kdump/mkioctls

https://bitbucket.org/freebsd/freebsd-head/
Shell | 115 lines | 100 code | 7 blank | 8 comment | 1 complexity | e2880a64fe7e78da83a6a5650871c9a7 MD5 | raw file
  1#!/bin/sh
  2#
  3# $FreeBSD$
  4#
  5# When editing this script, keep in mind that truss also uses it.
  6#
  7
  8set -e
  9
 10if [ $# -ne 2 -o \( $1 != "print" -a $1 != "return" \) ]; then
 11	echo "usage: sh $0 print|return include-dir"
 12	exit 1
 13fi
 14
 15style="$1"
 16includedir="$2"
 17
 18LC_ALL=C; export LC_ALL
 19
 20# Build a list of headers that have ioctls in them.
 21# XXX should we use an ANSI cpp?
 22ioctl_includes=$(
 23	cd $includedir
 24	find -H -s * -name '*.h' | grep -v '.*disk.*\.h' | \
 25		xargs egrep -l \
 26'^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO[^a-z0-9_]' |
 27		awk '{printf("#include <%s>\\n", $1)}'
 28)
 29
 30: ${MACHINE=$(uname -m)}
 31case "${MACHINE}" in
 32*pc98*)
 33	ioctl_includes="$ioctl_includes#include <sys/diskpc98.h>\\n"
 34	;;
 35*)
 36	ioctl_includes="$ioctl_includes#include <sys/diskmbr.h>\\n"
 37	;;
 38esac
 39
 40awk -v x="$ioctl_includes" 'BEGIN {print x}' |
 41	$CPP -I$1 -dM -DCOMPAT_43TTY - |
 42	awk -v ioctl_includes="$ioctl_includes" -v style="$style" '
 43BEGIN {
 44	print "/* XXX obnoxious prerequisites. */"
 45	print "#define COMPAT_43"
 46	print "#define COMPAT_43TTY"
 47	print "#include <sys/param.h>"
 48	print "#include <sys/devicestat.h>"
 49	print "#include <sys/disklabel.h>"
 50	print "#include <sys/socket.h>"
 51	print "#include <sys/time.h>"
 52	print "#include <sys/tty.h>"
 53	print "#include <bsm/audit.h>"
 54	print "#include <net/ethernet.h>"
 55	print "#include <net/if.h>"
 56	print "#include <net/if_var.h>"
 57	print "#include <net/pfvar.h>"
 58	print "#include <net/route.h>"
 59	print "#include <netinet/in.h>"
 60	print "#include <netinet/ip_mroute.h>"
 61	print "#include <netinet6/in6_var.h>"
 62	print "#include <netinet6/nd6.h>"
 63	print "#include <netinet6/ip6_mroute.h>"
 64	print "#include <stdio.h>"
 65	print "#include <cam/cam.h>"
 66	print "#include <stddef.h>"
 67	print "#include <stdint.h>"
 68	print ""
 69	print ioctl_includes
 70	print ""
 71	if (style == "print") {
 72		print "void ioctlname(unsigned long val, int decimal);"
 73		print ""
 74		print "void"
 75		print "ioctlname(unsigned long val, int decimal)"
 76	} else {
 77		print "const char *ioctlname(unsigned long val);"
 78		print ""
 79		print "const char *"
 80		print "ioctlname(unsigned long val)"
 81	}
 82	print "{"
 83	print "\tconst char *str = NULL;"
 84	print ""
 85}
 86
 87/^#[ 	]*define[ 	]+[A-Za-z_][A-Za-z0-9_]*[ 	]+_IO/ {
 88
 89	# find where the name starts
 90	for (i = 1; i <= NF; i++)
 91		if ($i ~ /define/)
 92			break;
 93	++i;
 94	#
 95	printf("\t");
 96	if (n++ > 0)
 97		printf("else ");
 98	printf("if (val == %s)\n", $i);
 99	printf("\t\tstr = \"%s\";\n", $i);
100}
101END {
102	print ""
103	if (style == "print") {
104		print "\tif (str != NULL)"
105		print "\t\tprintf(\"%s\", str);"
106		print "\telse if (decimal)"
107		print "\t\tprintf(\"%lu\", val);"
108		print "\telse"
109		print "\t\tprintf(\"%#lx\", val);"
110	} else {
111		print "\treturn (str);"
112	}
113	print "}"
114}
115'