#!/bin/sh # Generate a table that describes the socket options in the tree. We assume # that the socket options are of the form # #define OPT 123 /* type,type; rest */ # in the listed files. if [ $# -ne 1 ]; then echo "usage: $(basename $0) freebsd-sys-dir" exit 1 fi sysdir=$1 gen_table() { unifdef -k -D__BSD_VISIBLE__=1 -U_KERNEL < ${sysdir}/$1 | \ sed -n '/#define[[:space:]]*.*\/\*.*;.*\*\//p' | \ awk -vlevel=$2 ' BEGIN { printf("static struct sockopt_entry %s[] = {\n", tolower(level)); } { s=$5; if (match(s, ";$") == 0) { s=$6; } gsub(";", "", s); if (match(s, "^buf") == 0) { s = toupper(s); printf ("\t{ %-12s, %-20s, {", level, $2); split(s, a, ","); for (t in a) { printf (" SOCKOPT_TYPE_%s,", a[t]); } printf(" } },\n"); } } END { printf("\t{ SOCK_LEVEL_NONE }\n};\n\n"); } ' } gen_types() { unifdef -k -D__BSD_VISIBLE__=1 -U_KERNEL | \ sed -n '/#define[[:space:]]*.*\/\*.*;.*\*\//p' | \ awk ' { s=$5; if (match(s, ";$") == 0) { s=$6; } gsub(";", "", s); if (match(s, "^buf") == 0) { s = toupper(s); split(s, a, ","); for (t in a) { printf ("\tSOCKOPT_TYPE_%s, \n", a[t]); } } }' } cat < #include #include #include #include enum sockopt_type { SOCKOPT_TYPE_NONE = 0, EOF cat ${sysdir}/sys/socket.h ${sysdir}/netinet/in.h ${sysdir}/netinet6/in6.h \ ${sysdir}/netinet/tcp.h ${sysdir}/netinet/udp.h ${sysdir}/sys/un.h | \ gen_types | sort -u cat <