11b780f51Sotto#!/bin/sh 2*4841054fSguenther# $OpenBSD: mksubr,v 1.22 2014/09/17 19:12:55 guenther Exp $ 31b780f51Sotto# 41b780f51Sotto# Copyright (c) 2006 David Kirchner <dpk@dpk.net> 51b780f51Sotto# 61b780f51Sotto# Permission to use, copy, modify, and distribute this software for any 71b780f51Sotto# purpose with or without fee is hereby granted, provided that the above 81b780f51Sotto# copyright notice and this permission notice appear in all copies. 91b780f51Sotto# 101b780f51Sotto# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 111b780f51Sotto# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 121b780f51Sotto# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 131b780f51Sotto# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 141b780f51Sotto# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 151b780f51Sotto# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 161b780f51Sotto# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 171b780f51Sotto# 181b780f51Sotto# $FreeBSD: src/usr.bin/kdump/mksubr,v 1.17 2011/06/06 19:00:38 dchagin Exp $ 191b780f51Sotto# 201b780f51Sotto# Generates kdump_subr.c 211b780f51Sotto# mkioctls is a special-purpose script, and works fine as it is 221b780f51Sotto# now, so it remains independent. The idea behind how it generates 231b780f51Sotto# its list was heavily borrowed here. 241b780f51Sotto# 251b780f51Sotto# Some functions here are automatically generated. This can mean 261b780f51Sotto# the user will see unusual kdump output or errors while building 271b780f51Sotto# if the underlying .h files are changed significantly. 281b780f51Sotto# 291b780f51Sotto# Key: 301b780f51Sotto# AUTO: Completely auto-generated with either the "or" or the "switch" 311b780f51Sotto# method. 321b780f51Sotto# AUTO - Special: Generated automatically, but with some extra commands 331b780f51Sotto# that the auto_*_type() functions are inappropriate for. 341b780f51Sotto# MANUAL: Manually entered and must therefore be manually updated. 351b780f51Sotto 361b780f51Sottoset -e 371b780f51Sotto 381b780f51SottoLC_ALL=C; export LC_ALL 391b780f51Sotto 401b780f51Sottoif [ -z "$1" ] 411b780f51Sottothen 421b780f51Sotto echo "usage: sh $0 include-dir" 431b780f51Sotto exit 1 441b780f51Sottofi 451b780f51Sottoinclude_dir=$1 461b780f51Sotto 471b780f51Sotto# 481b780f51Sotto# Automatically generates a C function that will print out the 491b780f51Sotto# numeric input as a pipe-delimited string of the appropriate 501b780f51Sotto# #define keys. ex: 51256998b4Sguenther# 0x1a4<S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH> 521b780f51Sotto# The XOR is necessary to prevent including the "0"-value in every 531b780f51Sotto# line. 541b780f51Sotto# 551b780f51Sottoauto_or_type () { 561b780f51Sotto local name grep file 571b780f51Sotto name=$1 581b780f51Sotto grep=$2 591b780f51Sotto file=$3 60fd279959Sguenther format=${4-%#x} 611b780f51Sotto 621b780f51Sotto cat <<_EOF_ 631b780f51Sotto/* AUTO */ 641b780f51Sottovoid 651b780f51Sotto$name (int arg) 661b780f51Sotto{ 671b780f51Sotto int or = 0; 68fd279959Sguenther printf("$format<", arg); 691b780f51Sotto_EOF_ 701b780f51Sotto egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 711b780f51Sotto $include_dir/$file | \ 721b780f51Sotto awk '{ for (i = 1; i <= NF; i++) \ 731b780f51Sotto if ($i ~ /define/) \ 741b780f51Sotto break; \ 751b780f51Sotto ++i; \ 761b780f51Sotto printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }' 771b780f51Sottocat <<_EOF_ 781b780f51Sotto printf(">"); 791b780f51Sotto if (or == 0) 801b780f51Sotto (void)printf("<invalid>%ld", (long)arg); 811b780f51Sotto} 821b780f51Sotto 831b780f51Sotto_EOF_ 841b780f51Sotto} 851b780f51Sotto 861b780f51Sotto# 8715c06776Sguenther# Like auto_or_type(), but a zero value is valid and prints as "0<>" 8815c06776Sguenther# 8915c06776Sguentherauto_orz_type () { 9015c06776Sguenther local name grep file 9115c06776Sguenther name=$1 9215c06776Sguenther grep=$2 9315c06776Sguenther file=$3 94fd279959Sguenther format=${4-%#x} 9515c06776Sguenther 9615c06776Sguenther cat <<_EOF_ 9715c06776Sguenther/* AUTO */ 9815c06776Sguenthervoid 9915c06776Sguenther$name (int arg) 10015c06776Sguenther{ 10115c06776Sguenther int or = 0; 10215c06776Sguenther if (arg == 0) { 10315c06776Sguenther printf("0<>"); 10415c06776Sguenther return; 10515c06776Sguenther } 106fd279959Sguenther printf("$format<", arg); 10715c06776Sguenther_EOF_ 10815c06776Sguenther egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 10915c06776Sguenther $include_dir/$file | \ 11015c06776Sguenther awk '{ for (i = 1; i <= NF; i++) \ 11115c06776Sguenther if ($i ~ /define/) \ 11215c06776Sguenther break; \ 11315c06776Sguenther ++i; \ 11415c06776Sguenther printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }' 11515c06776Sguenthercat <<_EOF_ 11615c06776Sguenther printf(">"); 11715c06776Sguenther if (or == 0) 11815c06776Sguenther (void)printf("<invalid>%ld", (long)arg); 11915c06776Sguenther} 12015c06776Sguenther 12115c06776Sguenther_EOF_ 12215c06776Sguenther} 12315c06776Sguenther 12415c06776Sguenther# 125256998b4Sguenther# Automatically generates a C function that will print out a 126256998b4Sguenther# file flags input as a pipe-delimited string of the appropriate 127256998b4Sguenther# #define keys. ex: 128256998b4Sguenther# 0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY> 129256998b4Sguenther# This is different than the others to handle O_RDONLY correctly when 130256998b4Sguenther# other flags are present and to diagnose an invalid O_ACCMODE value 131256998b4Sguenther# 132256998b4Sguentherauto_fflags_type () { 133256998b4Sguenther local name grep file 134256998b4Sguenther name=$1 135256998b4Sguenther grep=$2 136256998b4Sguenther file=$3 137256998b4Sguenther 138256998b4Sguenther cat <<_EOF_ 139256998b4Sguenther/* AUTO */ 140256998b4Sguenthervoid 141*4841054fSguenther$name (int arg, int show_accmode) 142256998b4Sguenther{ 143*4841054fSguenther int or = 0; 144*4841054fSguenther 145256998b4Sguenther printf("%#x<", arg); 146*4841054fSguenther if (show_accmode || (arg & O_ACCMODE)) { 147*4841054fSguenther or = 1; 148256998b4Sguenther switch (arg & O_ACCMODE) { 149256998b4Sguenther case O_RDONLY: 150256998b4Sguenther printf("O_RDONLY"); 151256998b4Sguenther break; 152256998b4Sguenther case O_WRONLY: 153256998b4Sguenther printf("O_WRONLY"); 154256998b4Sguenther break; 155256998b4Sguenther case O_RDWR: 156256998b4Sguenther printf("O_RDWR"); 157256998b4Sguenther break; 158256998b4Sguenther default: 159256998b4Sguenther printf("<invalid>O_ACCMODE"); 160256998b4Sguenther break; 161256998b4Sguenther } 162*4841054fSguenther } 163256998b4Sguenther_EOF_ 164256998b4Sguenther egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 165256998b4Sguenther $include_dir/$file | \ 166256998b4Sguenther egrep -v 'O_(RD(ONLY|WR)|WRONLY|ACCMODE)' | \ 167256998b4Sguenther awk '{ for (i = 1; i <= NF; i++) \ 168256998b4Sguenther if ($i ~ /define/) \ 169256998b4Sguenther break; \ 170256998b4Sguenther ++i; \ 171*4841054fSguenther printf "\tif_print_or(arg, %s, or);\n", $i }' 172256998b4Sguenthercat <<_EOF_ 173256998b4Sguenther printf(">"); 174256998b4Sguenther} 175256998b4Sguenther 176*4841054fSguenther/* 177*4841054fSguenther * A wrapper of the above to use with pn() 178*4841054fSguenther */ 179*4841054fSguenthervoid 180*4841054fSguentherflagsname(int flags) 181*4841054fSguenther{ 182*4841054fSguenther doflagsname(flags, 0); 183*4841054fSguenther} 184*4841054fSguenther 185*4841054fSguenther 186256998b4Sguenther_EOF_ 187256998b4Sguenther} 188256998b4Sguenther 189256998b4Sguenther 190256998b4Sguenther# 1911b780f51Sotto# Automatically generates a C function used when the argument 1921b780f51Sotto# maps to a single, specific #definition 1931b780f51Sotto# 1941b780f51Sottoauto_switch_type () { 1951b780f51Sotto local name grep file 1961b780f51Sotto name=$1 1971b780f51Sotto grep=$2 1981b780f51Sotto file=$3 1991b780f51Sotto 2001b780f51Sotto cat <<_EOF_ 2011b780f51Sotto/* AUTO */ 2021b780f51Sottovoid 2031b780f51Sotto$name (int arg) 2041b780f51Sotto{ 2051b780f51Sotto switch (arg) { 2061b780f51Sotto_EOF_ 2071b780f51Sotto egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 2081b780f51Sotto $include_dir/$file | \ 2091b780f51Sotto awk '{ for (i = 1; i <= NF; i++) \ 2101b780f51Sotto if ($i ~ /define/) \ 2111b780f51Sotto break; \ 2121b780f51Sotto ++i; \ 2131b780f51Sotto printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }' 2141b780f51Sottocat <<_EOF_ 2151b780f51Sotto default: /* Should not reach */ 2161b780f51Sotto (void)printf("<invalid=%ld>", (long)arg); 2171b780f51Sotto } 2181b780f51Sotto} 2191b780f51Sotto 2201b780f51Sotto_EOF_ 2211b780f51Sotto} 2221b780f51Sotto 2231b780f51Sotto# 2241b780f51Sotto# Automatically generates a C function used when the argument 2251b780f51Sotto# maps to a #definition 2261b780f51Sotto# 2271b780f51Sottoauto_if_type () { 2281b780f51Sotto local name grep file 2291b780f51Sotto name=$1 2301b780f51Sotto grep=$2 2311b780f51Sotto file=$3 2321b780f51Sotto 2331b780f51Sotto cat <<_EOF_ 2341b780f51Sotto/* AUTO */ 2351b780f51Sottovoid 2361b780f51Sotto$name (int arg) 2371b780f51Sotto{ 2381b780f51Sotto_EOF_ 2391b780f51Sotto egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ 2401b780f51Sotto $include_dir/$file | \ 2411b780f51Sotto awk '{ printf "\t"; \ 2421b780f51Sotto if (NR > 1) \ 2431b780f51Sotto printf "else " ; \ 2441b780f51Sotto printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }' 2451b780f51Sottocat <<_EOF_ 2461b780f51Sotto else /* Should not reach */ 2471b780f51Sotto (void)printf("<invalid=%ld>", (long)arg); 2481b780f51Sotto} 2491b780f51Sotto 2501b780f51Sotto_EOF_ 2511b780f51Sotto} 2521b780f51Sotto 2531b780f51Sotto# C start 2541b780f51Sotto 2551b780f51Sottocat <<_EOF_ 2561b780f51Sotto#include <stdio.h> 2574f9d0979Sotto#include <sys/param.h> 2581b780f51Sotto#include <sys/fcntl.h> 2591b780f51Sotto#include <sys/stat.h> 2601b780f51Sotto#include <sys/unistd.h> 261391dcabbSmatthew#define _KERNEL 2621b780f51Sotto#include <sys/mman.h> 263391dcabbSmatthew#undef _KERNEL 2641b780f51Sotto#include <sys/wait.h> 2654f9d0979Sotto#include <sys/proc.h> 2661b780f51Sotto#define _KERNEL 2674f9d0979Sotto#define COMPAT_43 2681b780f51Sotto#include <sys/socket.h> 2691b780f51Sotto#undef _KERNEL 2701b780f51Sotto#include <netinet/in.h> 2711b780f51Sotto#include <sys/param.h> 2721b780f51Sotto#include <sys/mount.h> 273ee6ae511Sguenther#include <sys/poll.h> 2741b780f51Sotto#include <sys/ptrace.h> 2751b780f51Sotto#include <sys/resource.h> 2761b780f51Sotto#include <sys/reboot.h> 277a70ae221Sguenther#include <sys/uio.h> 278a70ae221Sguenther#include <sys/ktrace.h> 2791b780f51Sotto#include <sched.h> 2804f9d0979Sotto#if 0 2811b780f51Sotto#include <sys/linker.h> 2821b780f51Sotto#define _KERNEL 2831b780f51Sotto#include <sys/thr.h> 2841b780f51Sotto#undef _KERNEL 2851b780f51Sotto#include <sys/extattr.h> 2861b780f51Sotto#include <sys/acl.h> 2871b780f51Sotto#include <aio.h> 2884f9d0979Sotto#endif 2891b780f51Sotto#include <sys/sem.h> 2901b780f51Sotto#include <sys/ipc.h> 2914f9d0979Sotto#if 0 2921b780f51Sotto#include <sys/rtprio.h> 2934f9d0979Sotto#endif 2941b780f51Sotto#include <sys/shm.h> 2954f9d0979Sotto#if 0 2961b780f51Sotto#include <nfsserver/nfs.h> 2974f9d0979Sotto#endif 2981b780f51Sotto#include <ufs/ufs/quota.h> 2991b780f51Sotto 3001b780f51Sotto#include "kdump_subr.h" 3011b780f51Sotto 3021b780f51Sotto_EOF_ 3031b780f51Sotto 304fd279959Sguentherauto_orz_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h" "%#o" 305*4841054fSguentherauto_fflags_type "doflagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h" 30615c06776Sguentherauto_orz_type "atflagsname" "AT_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h" 307b8dac8f2Sottoauto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h" 3081b780f51Sottoauto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h" 309653a2889Smatthewauto_or_type "mmapflagsname" "(__)?MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h" 31015c06776Sguentherauto_orz_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h" 31115c06776Sguenther#auto_or_type "timerflagsname" "TIMER_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/time.h" 3124f9d0979Sotto#auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h" 3134f9d0979Sotto#auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h" 3144f9d0979Sotto#auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h" 315b8dac8f2Sottoauto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h" 3164f9d0979Sotto#auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h" 317b8dac8f2Sottoauto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" 31815c06776Sguentherauto_orz_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h" 3194f9d0979Sotto#auto_or_type "nfssvcname" "NFSSVC_[A-Z]+[[:space:]]+0x[0-9]+" "nfsserver/nfs.h" 3204f9d0979Sotto# 321b8dac8f2Sottoauto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h" 322ee6ae511Sguentherauto_switch_type "pathconfname" "_PC_[_A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h" 323b8dac8f2Sottoauto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h" 324ee6ae511Sguentherauto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" 3254f9d0979Sotto#auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h" 326b8dac8f2Sottoauto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" 327b8dac8f2Sottoauto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h" 3287b36c281Sguentherauto_switch_type "clocktypename" "CLOCK_[_A-Z]+[[:space:]]+[0-9]+" "sys/_time.h" 3294f9d0979Sotto#auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h" 3304f9d0979Sotto#auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h" 3314f9d0979Sotto#auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h" 3324f9d0979Sotto#auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h" 3334f9d0979Sotto#auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h" 3344f9d0979Sotto#auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h" 335ec5a39e0Sguentherauto_switch_type "rusagewho" "RUSAGE_[A-Z]+[[:space:]]+[-0-9()]+" "sys/resource.h" 3369ece112bSguentherauto_orz_type "sigactionflagname" "SA_[A-Z]+[[:space:]]+0x[0-9]+" "sys/signal.h" 3371b780f51Sottoauto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h" 3388b7c6933Sderaadtauto_switch_type "sigill_name" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3398b7c6933Sderaadtauto_switch_type "sigtrap_name" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3408b7c6933Sderaadtauto_switch_type "sigemt_name" "EMT_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3418b7c6933Sderaadtauto_switch_type "sigfpe_name" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3428b7c6933Sderaadtauto_switch_type "sigbus_name" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3438b7c6933Sderaadtauto_switch_type "sigsegv_name" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3448b7c6933Sderaadtauto_switch_type "sigchld_name" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h" 3454f9d0979Sotto#auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h" 346b59026c7Sottoauto_switch_type "minheritname" "MAP_INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h" 3474f9d0979Sotto#auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h" 348b8dac8f2Sottoauto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" 349f980d548Sottoauto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h" 350b8dac8f2Sottoauto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h" 351b8dac8f2Sottoauto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h" 3524f9d0979Sotto#auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h" 353a70ae221Sguentherauto_orz_type "ktracefacname" "KTRFAC_[^M][[:alnum:]_]+" "sys/ktrace.h" 354a70ae221Sguentherauto_switch_type "itimername" "ITIMER_[[:alnum:]_]+" "sys/time.h" 3551b780f51Sotto 3561b780f51Sottocat <<_EOF_ 3571b780f51Sotto/* 3581b780f51Sotto * AUTO - Special 3591b780f51Sotto * F_ is used to specify fcntl commands as well as arguments. Both sets are 3601b780f51Sotto * grouped in fcntl.h, and this awk script grabs the first group. 3611b780f51Sotto */ 3621b780f51Sottovoid 363dd52b3caSottofcntlcmdname (int cmd, int arg) 3641b780f51Sotto{ 3651b780f51Sotto switch (cmd) { 3661b780f51Sotto_EOF_ 3674805374fSmatthewegrep "^#[[:space:]]*define[[:space:]]+F_[A-Z_]+[[:space:]]+[0-9]+[[:space:]]*" \ 3681b780f51Sotto $include_dir/sys/fcntl.h | \ 3691b780f51Sotto awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \ 3701b780f51Sotto if ($i ~ /define/) \ 3711b780f51Sotto break; \ 3721b780f51Sotto ++i; \ 3731b780f51Sotto if (o <= $(i+1)) \ 3741b780f51Sotto printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i; \ 3751b780f51Sotto else \ 3761b780f51Sotto exit; \ 3771b780f51Sotto o = $(i+1) }' 3781b780f51Sottocat <<_EOF_ 3791b780f51Sotto default: /* Should not reach */ 3801b780f51Sotto (void)printf("<invalid=%ld>", (long)cmd); 3811b780f51Sotto } 382ee6ae511Sguenther if (cmd == F_SETFD) { 3831b780f51Sotto (void)putchar(','); 3841b780f51Sotto if (arg == FD_CLOEXEC) 3851b780f51Sotto (void)printf("FD_CLOEXEC"); 3861b780f51Sotto else if (arg == 0) 3871b780f51Sotto (void)printf("0"); 3881b780f51Sotto else { 3891b780f51Sotto if (decimal) 3901b780f51Sotto (void)printf("<invalid>%ld", (long)arg); 3911b780f51Sotto else 3921b780f51Sotto (void)printf("<invalid>%#lx", (long)arg); 3931b780f51Sotto } 394ee6ae511Sguenther 3951b780f51Sotto } else if (cmd == F_SETFL) { 396ee6ae511Sguenther (void)putchar(','); 3971b780f51Sotto flagsname(arg); 398ee6ae511Sguenther } else if (!fancy || (cmd != F_GETFD && cmd != F_GETFL)) { 399ee6ae511Sguenther (void)putchar(','); 4001b780f51Sotto if (decimal) 4011b780f51Sotto (void)printf("%ld", (long)arg); 4021b780f51Sotto else 4031b780f51Sotto (void)printf("%#lx", (long)arg); 4041b780f51Sotto } 4051b780f51Sotto} 4061b780f51Sotto 4071b780f51Sotto/* 4081b780f51Sotto * AUTO - Special 4091b780f51Sotto * 4101b780f51Sotto * The send and recv functions have a flags argument which can be 4111b780f51Sotto * set to 0. There is no corresponding #define. The auto_ functions 4121b780f51Sotto * detect this as "invalid", which is incorrect here. 4131b780f51Sotto */ 4141b780f51Sottovoid 4151b780f51Sottosendrecvflagsname (int flags) 4161b780f51Sotto{ 4171b780f51Sotto int or = 0; 4181b780f51Sotto 4191b780f51Sotto if (flags == 0) { 4201b780f51Sotto (void)printf("0"); 4211b780f51Sotto return; 4221b780f51Sotto } 4231b780f51Sotto 4241b780f51Sotto printf("%#x<", flags); 4251b780f51Sotto_EOF_ 426*4841054fSguentheregrep "^#[[:space:]]*define[[:space:]]+MSG_[_A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \ 4271b780f51Sotto awk '{ for (i = 1; i <= NF; i++) \ 4281b780f51Sotto if ($i ~ /define/) \ 4291b780f51Sotto break; \ 4301b780f51Sotto ++i; \ 4311b780f51Sotto printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }' 4321b780f51Sottocat <<_EOF_ 4331b780f51Sotto printf(">"); 4341b780f51Sotto} 4351b780f51Sotto 436*4841054fSguenther/* 437*4841054fSguenther * AUTO - Special 438*4841054fSguenther * 439*4841054fSguenther * SOCK_NONBLOCK and SOCK_CLOEXEC are or'ed into the type 440*4841054fSguenther */ 441*4841054fSguentherstatic void 442*4841054fSguentherdosocktypename (int arg, int show_type) 443*4841054fSguenther{ 444*4841054fSguenther int type = arg & 0xff; /* XXX */ 445*4841054fSguenther int or = 0; 446*4841054fSguenther 447*4841054fSguenther printf("%#x<", arg); 448*4841054fSguenther if (show_type || type) { 449*4841054fSguenther or = 1; 450*4841054fSguenther switch (type) { 451*4841054fSguenther_EOF_ 452*4841054fSguenther egrep "^#[[:space:]]*define[[:space:]]+SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*[[:space:]]*" \ 453*4841054fSguenther $include_dir/sys/socket.h | \ 454*4841054fSguenther awk '{ for (i = 1; i <= NF; i++) \ 455*4841054fSguenther if ($i ~ /define/) \ 456*4841054fSguenther break; \ 457*4841054fSguenther ++i; \ 458*4841054fSguenther printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }' 459*4841054fSguenthercat <<_EOF_ 460*4841054fSguenther default: /* Should not reach */ 461*4841054fSguenther (void)printf("<invalid=%d>", arg); 462*4841054fSguenther } 463*4841054fSguenther } 464*4841054fSguenther 465*4841054fSguenther_EOF_ 466*4841054fSguenther egrep "^#[[:space:]]*define[[:space:]]+SOCK_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" \ 467*4841054fSguenther $include_dir/sys/socket.h | \ 468*4841054fSguenther awk '{ for (i = 1; i <= NF; i++) \ 469*4841054fSguenther if ($i ~ /define/) \ 470*4841054fSguenther break; \ 471*4841054fSguenther ++i; \ 472*4841054fSguenther printf "\tif_print_or(arg, %s, or);\n", $i }' 473*4841054fSguenthercat <<_EOF_ 474*4841054fSguenther printf(">"); 475*4841054fSguenther} 476*4841054fSguenther 477*4841054fSguenthervoid 478*4841054fSguenthersocktypename (int arg) 479*4841054fSguenther{ 480*4841054fSguenther dosocktypename(arg, 1); 481*4841054fSguenther} 482*4841054fSguenther 483*4841054fSguenthervoid 484*4841054fSguenthersockflagsname (int arg) 485*4841054fSguenther{ 486*4841054fSguenther dosocktypename(arg, 0); 487*4841054fSguenther} 488*4841054fSguenther 4891b780f51Sotto_EOF_ 490