[BACK]Return to mksubr CVS log [TXT][DIR] Up to [local] / src / usr.bin / kdump

Annotation of src/usr.bin/kdump/mksubr, Revision 1.16

1.1       otto        1: #!/bin/sh
1.16    ! guenther    2: # $OpenBSD: mksubr,v 1.15 2013/06/17 19:11:54 guenther Exp $
1.1       otto        3: #
                      4: # Copyright (c) 2006 David Kirchner <dpk@dpk.net>
                      5: #
                      6: # Permission to use, copy, modify, and distribute this software for any
                      7: # purpose with or without fee is hereby granted, provided that the above
                      8: # copyright notice and this permission notice appear in all copies.
                      9: #
                     10: # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11: # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12: # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13: # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14: # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     15: # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     16: # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17: #
                     18: # $FreeBSD: src/usr.bin/kdump/mksubr,v 1.17 2011/06/06 19:00:38 dchagin Exp $
                     19: #
                     20: # Generates kdump_subr.c
                     21: # mkioctls is a special-purpose script, and works fine as it is
                     22: # now, so it remains independent. The idea behind how it generates
                     23: # its list was heavily borrowed here.
                     24: #
                     25: # Some functions here are automatically generated. This can mean
                     26: # the user will see unusual kdump output or errors while building
                     27: # if the underlying .h files are changed significantly.
                     28: #
                     29: # Key:
                     30: # AUTO: Completely auto-generated with either the "or" or the "switch"
                     31: # method.
                     32: # AUTO - Special: Generated automatically, but with some extra commands
                     33: # that the auto_*_type() functions are inappropriate for.
                     34: # MANUAL: Manually entered and must therefore be manually updated.
                     35:
                     36: set -e
                     37:
                     38: LC_ALL=C; export LC_ALL
                     39:
                     40: if [ -z "$1" ]
                     41: then
                     42:        echo "usage: sh $0 include-dir"
                     43:        exit 1
                     44: fi
                     45: include_dir=$1
                     46:
                     47: #
                     48: # Automatically generates a C function that will print out the
                     49: # numeric input as a pipe-delimited string of the appropriate
                     50: # #define keys. ex:
1.12      guenther   51: # 0x1a4<S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH>
1.1       otto       52: # The XOR is necessary to prevent including the "0"-value in every
                     53: # line.
                     54: #
                     55: auto_or_type () {
                     56:        local name grep file
                     57:        name=$1
                     58:        grep=$2
                     59:        file=$3
                     60:
                     61:        cat <<_EOF_
                     62: /* AUTO */
                     63: void
                     64: $name (int arg)
                     65: {
                     66:        int     or = 0;
                     67:        printf("%#x<", arg);
                     68: _EOF_
                     69:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                     70:                $include_dir/$file | \
                     71:        awk '{ for (i = 1; i <= NF; i++) \
                     72:                if ($i ~ /define/) \
                     73:                        break; \
                     74:                ++i; \
                     75:                printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
                     76: cat <<_EOF_
                     77:        printf(">");
                     78:        if (or == 0)
                     79:                (void)printf("<invalid>%ld", (long)arg);
                     80: }
                     81:
                     82: _EOF_
                     83: }
                     84:
                     85: #
1.8       guenther   86: # Like auto_or_type(), but a zero value is valid and prints as "0<>"
                     87: #
                     88: auto_orz_type () {
                     89:        local name grep file
                     90:        name=$1
                     91:        grep=$2
                     92:        file=$3
                     93:
                     94:        cat <<_EOF_
                     95: /* AUTO */
                     96: void
                     97: $name (int arg)
                     98: {
                     99:        int     or = 0;
                    100:        if (arg == 0) {
                    101:                printf("0<>");
                    102:                return;
                    103:        }
                    104:        printf("%#x<", arg);
                    105: _EOF_
                    106:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    107:                $include_dir/$file | \
                    108:        awk '{ for (i = 1; i <= NF; i++) \
                    109:                if ($i ~ /define/) \
                    110:                        break; \
                    111:                ++i; \
                    112:                printf "\tif(!((arg>0)^((%s)>0)))\n\t\tif_print_or(arg, %s, or);\n", $i, $i }'
                    113: cat <<_EOF_
                    114:        printf(">");
                    115:        if (or == 0)
                    116:                (void)printf("<invalid>%ld", (long)arg);
                    117: }
                    118:
                    119: _EOF_
                    120: }
                    121:
                    122: #
1.12      guenther  123: # Automatically generates a C function that will print out a
                    124: # file flags input as a pipe-delimited string of the appropriate
                    125: # #define keys. ex:
                    126: # 0x30000<O_RDONLY|O_CLOEXEC|O_DIRECTORY>
                    127: # This is different than the others to handle O_RDONLY correctly when
                    128: # other flags are present and to diagnose an invalid O_ACCMODE value
                    129: #
                    130: auto_fflags_type () {
                    131:        local name grep file
                    132:        name=$1
                    133:        grep=$2
                    134:        file=$3
                    135:
                    136:        cat <<_EOF_
                    137: /* AUTO */
                    138: void
                    139: $name (int arg)
                    140: {
                    141:        printf("%#x<", arg);
                    142:        switch (arg & O_ACCMODE) {
                    143:        case O_RDONLY:
                    144:                printf("O_RDONLY");
                    145:                break;
                    146:        case O_WRONLY:
                    147:                printf("O_WRONLY");
                    148:                break;
                    149:        case O_RDWR:
                    150:                printf("O_RDWR");
                    151:                break;
                    152:        default:
                    153:                printf("<invalid>O_ACCMODE");
                    154:                break;
                    155:        }
                    156: _EOF_
                    157:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    158:                $include_dir/$file | \
                    159:        egrep -v 'O_(RD(ONLY|WR)|WRONLY|ACCMODE)' | \
                    160:        awk '{ for (i = 1; i <= NF; i++) \
                    161:                if ($i ~ /define/) \
                    162:                        break; \
                    163:                ++i; \
                    164:                printf "\tif (arg & %s) printf (\"|%%s\", \"%s\");\n", $i, $i }'
                    165: cat <<_EOF_
                    166:        printf(">");
                    167: }
                    168:
                    169: _EOF_
                    170: }
                    171:
                    172:
                    173: #
1.1       otto      174: # Automatically generates a C function used when the argument
                    175: # maps to a single, specific #definition
                    176: #
                    177: auto_switch_type () {
                    178:        local name grep file
                    179:        name=$1
                    180:        grep=$2
                    181:        file=$3
                    182:
                    183:        cat <<_EOF_
                    184: /* AUTO */
                    185: void
                    186: $name (int arg)
                    187: {
                    188:        switch (arg) {
                    189: _EOF_
                    190:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    191:                $include_dir/$file | \
                    192:        awk '{ for (i = 1; i <= NF; i++) \
                    193:                if ($i ~ /define/) \
                    194:                        break; \
                    195:                ++i; \
                    196:                printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i }'
                    197: cat <<_EOF_
                    198:        default: /* Should not reach */
                    199:                (void)printf("<invalid=%ld>", (long)arg);
                    200:        }
                    201: }
                    202:
                    203: _EOF_
                    204: }
                    205:
                    206: #
                    207: # Automatically generates a C function used when the argument
                    208: # maps to a #definition
                    209: #
                    210: auto_if_type () {
                    211:        local name grep file
                    212:        name=$1
                    213:        grep=$2
                    214:        file=$3
                    215:
                    216:        cat <<_EOF_
                    217: /* AUTO */
                    218: void
                    219: $name (int arg)
                    220: {
                    221: _EOF_
                    222:        egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \
                    223:                $include_dir/$file | \
                    224:        awk '{ printf "\t"; \
                    225:                if (NR > 1) \
                    226:                        printf "else " ; \
                    227:                printf "if (arg == %s) \n\t\tprintf(\"%s\");\n", $2, $2 }'
                    228: cat <<_EOF_
                    229:        else /* Should not reach */
                    230:                (void)printf("<invalid=%ld>", (long)arg);
                    231: }
                    232:
                    233: _EOF_
                    234: }
                    235:
                    236: # C start
                    237:
                    238: cat <<_EOF_
                    239: #include <stdio.h>
1.2       otto      240: #include <sys/param.h>
1.1       otto      241: #include <sys/fcntl.h>
                    242: #include <sys/stat.h>
                    243: #include <sys/unistd.h>
                    244: #include <sys/mman.h>
                    245: #include <sys/wait.h>
1.2       otto      246: #include <sys/proc.h>
1.1       otto      247: #define _KERNEL
1.2       otto      248: #define COMPAT_43
1.1       otto      249: #include <sys/socket.h>
                    250: #undef _KERNEL
                    251: #include <netinet/in.h>
                    252: #include <sys/param.h>
                    253: #include <sys/mount.h>
1.14      guenther  254: #include <sys/poll.h>
1.1       otto      255: #include <sys/ptrace.h>
                    256: #include <sys/resource.h>
                    257: #include <sys/reboot.h>
                    258: #include <sched.h>
1.2       otto      259: #if 0
1.1       otto      260: #include <sys/linker.h>
                    261: #define _KERNEL
                    262: #include <sys/thr.h>
                    263: #undef _KERNEL
                    264: #include <sys/extattr.h>
                    265: #include <sys/acl.h>
                    266: #include <aio.h>
1.2       otto      267: #endif
1.1       otto      268: #include <sys/sem.h>
                    269: #include <sys/ipc.h>
1.2       otto      270: #if 0
1.1       otto      271: #include <sys/rtprio.h>
1.2       otto      272: #endif
1.1       otto      273: #include <sys/shm.h>
1.2       otto      274: #if 0
1.1       otto      275: #include <nfsserver/nfs.h>
1.2       otto      276: #endif
1.1       otto      277: #include <ufs/ufs/quota.h>
                    278:
                    279: #include "kdump_subr.h"
                    280:
                    281: /*
                    282:  * These are simple support macros. print_or utilizes a variable
                    283:  * defined in the calling function to track whether or not it should
                    284:  * print a logical-OR character ('|') before a string. if_print_or
                    285:  * simply handles the necessary "if" statement used in many lines
                    286:  * of this file.
                    287:  */
                    288: #define print_or(str,orflag) do {                  \\
                    289:        if (orflag) putchar('|'); else orflag = 1; \\
1.8       guenther  290:        printf ("%s", str); }                      \\
1.1       otto      291:        while (0)
                    292: #define if_print_or(i,flag,orflag) do {            \\
                    293:        if ((i & flag) == flag)                    \\
                    294:        print_or(#flag,orflag); }                  \\
                    295:        while (0)
                    296:
                    297: /* MANUAL */
1.2       otto      298: extern const char *const sys_signame[NSIG];
1.1       otto      299: void
                    300: signame (int sig)
                    301: {
                    302:        if (sig > 0 && sig < NSIG)
1.2       otto      303:                (void)printf("SIG%s", sys_signame[sig]);
1.1       otto      304:        else
                    305:                (void)printf("SIG %d", sig);
                    306: }
                    307:
                    308: /* MANUAL */
                    309: void
1.8       guenther  310: sigset (int ss)
                    311: {
                    312:        int     or = 0;
                    313:        int     cnt = 0;
                    314:        int     i;
                    315:
                    316:        for (i = 1; i < NSIG; i++)
                    317:                if (sigismember(&ss, i))
                    318:                        cnt++;
                    319:        if (cnt > (NSIG-1)/2) {
                    320:                ss = ~ss;
                    321:                putchar('~');
                    322:        }
                    323:
                    324:        if (ss == 0) {
                    325:                (void)printf("0<>");
                    326:                return;
                    327:        }
                    328:
                    329:        printf("%#x<", ss);
                    330:        for (i = 1; i < NSIG; i++)
                    331:                if (sigismember(&ss, i)) {
                    332:                        if (or) putchar('|'); else or=1;
                    333:                        signame(i);
                    334:                }
                    335:        printf(">");
                    336: }
                    337:
                    338: /* MANUAL */
                    339: void
1.1       otto      340: semctlname (int cmd)
                    341: {
                    342:        switch (cmd) {
                    343:        case GETNCNT:
                    344:                (void)printf("GETNCNT");
                    345:                break;
                    346:        case GETPID:
                    347:                (void)printf("GETPID");
                    348:                break;
                    349:        case GETVAL:
                    350:                (void)printf("GETVAL");
                    351:                break;
                    352:        case GETALL:
                    353:                (void)printf("GETALL");
                    354:                break;
                    355:        case GETZCNT:
                    356:                (void)printf("GETZCNT");
                    357:                break;
                    358:        case SETVAL:
                    359:                (void)printf("SETVAL");
                    360:                break;
                    361:        case SETALL:
                    362:                (void)printf("SETALL");
                    363:                break;
                    364:        case IPC_RMID:
                    365:                (void)printf("IPC_RMID");
                    366:                break;
                    367:        case IPC_SET:
                    368:                (void)printf("IPC_SET");
                    369:                break;
                    370:        case IPC_STAT:
                    371:                (void)printf("IPC_STAT");
                    372:                break;
                    373:        default: /* Should not reach */
                    374:                (void)printf("<invalid=%ld>", (long)cmd);
                    375:        }
                    376: }
                    377:
                    378: /* MANUAL */
                    379: void
                    380: shmctlname (int cmd) {
                    381:        switch (cmd) {
                    382:        case IPC_RMID:
                    383:                (void)printf("IPC_RMID");
                    384:                break;
                    385:        case IPC_SET:
                    386:                (void)printf("IPC_SET");
                    387:                break;
                    388:        case IPC_STAT:
                    389:                (void)printf("IPC_STAT");
                    390:                break;
                    391:        default: /* Should not reach */
                    392:                (void)printf("<invalid=%ld>", (long)cmd);
                    393:        }
                    394: }
                    395:
                    396: /* MANUAL */
                    397: void
                    398: semgetname (int flag) {
                    399:        int     or = 0;
                    400:        if_print_or(flag, IPC_CREAT, or);
                    401:        if_print_or(flag, IPC_EXCL, or);
                    402:        if_print_or(flag, SEM_R, or);
                    403:        if_print_or(flag, SEM_A, or);
                    404:        if_print_or(flag, (SEM_R>>3), or);
                    405:        if_print_or(flag, (SEM_A>>3), or);
                    406:        if_print_or(flag, (SEM_R>>6), or);
                    407:        if_print_or(flag, (SEM_A>>6), or);
                    408: }
                    409:
                    410: /*
                    411:  * MANUAL
                    412:  *
                    413:  * Only used by SYS_open. Unless O_CREAT is set in flags, the
                    414:  * mode argument is unused (and often bogus and misleading).
                    415:  */
                    416: void
1.4       otto      417: flagsandmodename (int flags, int mode) {
1.1       otto      418:        flagsname (flags);
                    419:        if ((flags & O_CREAT) == O_CREAT) {
1.14      guenther  420:                (void)putchar(',');
1.1       otto      421:                modename (mode);
1.14      guenther  422:        } else if (!fancy) {
                    423:                (void)putchar(',');
1.1       otto      424:                if (decimal) {
                    425:                        (void)printf("<unused>%ld", (long)mode);
                    426:                } else {
                    427:                        (void)printf("<unused>%#lx", (long)mode);
                    428:                }
                    429:        }
                    430: }
                    431:
1.15      guenther  432: void
                    433: clockname (int clockid)
                    434: {
                    435:        clocktypename(__CLOCK_TYPE(clockid));
                    436:        if (__CLOCK_PTID(clockid) != 0)
                    437:                printf("(%d)", __CLOCK_PTID(clockid));
                    438: }
                    439:
1.1       otto      440: /*
                    441:  * MANUAL
                    442:  *
                    443:  * [g|s]etsockopt's level argument can either be SOL_SOCKET or a value
                    444:  * referring to a line in /etc/protocols . It might be appropriate
                    445:  * to use getprotoent(3) here.
                    446:  */
                    447: void
1.4       otto      448: sockoptlevelname (int level)
1.1       otto      449: {
                    450:        if (level == SOL_SOCKET) {
                    451:                (void)printf("SOL_SOCKET");
                    452:        } else {
                    453:                if (decimal) {
                    454:                        (void)printf("%ld", (long)level);
                    455:                } else {
                    456:                        (void)printf("%#lx", (long)level);
                    457:                }
                    458:        }
                    459: }
                    460:
                    461: _EOF_
                    462:
1.8       guenther  463: auto_orz_type "modename" "S_[A-Z]+[[:space:]]+[0-6]{7}" "sys/stat.h"
1.12      guenther  464: auto_fflags_type "flagsname" "O_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
1.8       guenther  465: auto_orz_type "atflagsname" "AT_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/fcntl.h"
1.3       otto      466: auto_or_type "accessmodename" "[A-Z]_OK[[:space:]]+0?x?[0-9A-Fa-f]+" "sys/unistd.h"
1.1       otto      467: auto_or_type "mmapprotname" "PROT_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
1.13      matthew   468: auto_or_type "mmapflagsname" "(__)?MAP_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/mman.h"
1.8       guenther  469: auto_orz_type "wait4optname" "W[A-Z]+[[:space:]]+[0-9]+" "sys/wait.h"
                    470: #auto_or_type "timerflagsname" "TIMER_[A-Z]+[[:space:]]+0x[0-9A-Fa-f]+" "sys/time.h"
1.2       otto      471: #auto_or_type "getfsstatflagsname" "MNT_[A-Z]+[[:space:]]+[1-9][0-9]*" "sys/mount.h"
                    472: #auto_or_type "mountflagsname" "MNT_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mount.h"
                    473: #auto_or_type "rebootoptname" "RB_[A-Z]+[[:space:]]+0x[0-9]+" "sys/reboot.h"
1.3       otto      474: auto_or_type "flockname" "LOCK_[A-Z]+[[:space:]]+0x[0-9]+" "sys/fcntl.h"
1.2       otto      475: #auto_or_type "thrcreateflagsname" "THR_[A-Z]+[[:space:]]+0x[0-9]+" "sys/thr.h"
1.3       otto      476: auto_or_type "mlockallname" "MCL_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
1.8       guenther  477: auto_orz_type "shmatname" "SHM_[A-Z]+[[:space:]]+[0-9]{6}" "sys/shm.h"
1.2       otto      478: #auto_or_type "nfssvcname" "NFSSVC_[A-Z]+[[:space:]]+0x[0-9]+" "nfsserver/nfs.h"
                    479: #
1.3       otto      480: auto_switch_type "whencename" "SEEK_[A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
1.14      guenther  481: auto_switch_type "pathconfname" "_PC_[_A-Z]+[[:space:]]+[0-9]+" "sys/unistd.h"
1.3       otto      482: auto_switch_type "rlimitname" "RLIMIT_[A-Z]+[[:space:]]+[0-9]+" "sys/resource.h"
1.14      guenther  483: auto_switch_type "shutdownhowname" "SHUT_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
1.2       otto      484: #auto_switch_type "prioname" "PRIO_[A-Z]+[[:space:]]+[0-9]" "sys/resource.h"
1.3       otto      485: auto_switch_type "madvisebehavname" "_?MADV_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
                    486: auto_switch_type "msyncflagsname" "MS_[A-Z]+[[:space:]]+0x[0-9]+" "sys/mman.h"
1.15      guenther  487: auto_switch_type "clocktypename" "CLOCK_[_A-Z]+[[:space:]]+[0-9]+" "sys/_time.h"
1.2       otto      488: #auto_switch_type "schedpolicyname" "SCHED_[A-Z]+[[:space:]]+[0-9]+" "sched.h"
                    489: #auto_switch_type "kldunloadfflagsname" "LINKER_UNLOAD_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
                    490: #auto_switch_type "extattrctlname" "EXTATTR_NAMESPACE_[A-Z]+[[:space:]]+0x[0-9]+" "sys/extattr.h"
                    491: #auto_switch_type "kldsymcmdname" "KLDSYM_[A-Z]+[[:space:]]+[0-9]+" "sys/linker.h"
                    492: #auto_switch_type "sendfileflagsname" "SF_[A-Z]+[[:space:]]+[0-9]+" "sys/socket.h"
                    493: #auto_switch_type "acltypename" "ACL_TYPE_[A-Z4_]+[[:space:]]+0x[0-9]+" "sys/acl.h"
1.16    ! guenther  494: auto_switch_type "rusagewho" "RUSAGE_[A-Z]+[[:space:]]+[-0-9()]+" "sys/resource.h"
1.9       guenther  495: auto_orz_type "sigactionflagname" "SA_[A-Z]+[[:space:]]+0x[0-9]+" "sys/signal.h"
1.1       otto      496: auto_switch_type "sigprocmaskhowname" "SIG_[A-Z]+[[:space:]]+[0-9]+" "sys/signal.h"
1.7       deraadt   497: auto_switch_type "sigill_name" "ILL_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    498: auto_switch_type "sigtrap_name" "TRAP_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    499: auto_switch_type "sigemt_name" "EMT_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    500: auto_switch_type "sigfpe_name" "FPE_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    501: auto_switch_type "sigbus_name" "BUS_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    502: auto_switch_type "sigsegv_name" "SEGV_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
                    503: auto_switch_type "sigchld_name" "CLD_[A-Z]+[[:space:]]+[0-9]+" "sys/siginfo.h"
1.2       otto      504: #auto_switch_type "lio_listioname" "LIO_(NO)?WAIT[[:space:]]+[0-9]+" "aio.h"
1.3       otto      505: auto_switch_type "minheritname" "INHERIT_[A-Z]+[[:space:]]+[0-9]+" "sys/mman.h"
1.2       otto      506: #auto_switch_type "quotactlname" "Q_[A-Z]+[[:space:]]+0x[0-9]+" "ufs/ufs/quota.h"
1.3       otto      507: auto_if_type "sockdomainname" "PF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
1.5       otto      508: auto_if_type "sockfamilyname" "AF_[[:alnum:]]+[[:space:]]+" "sys/socket.h"
1.3       otto      509: auto_if_type "sockipprotoname" "IPPROTO_[[:alnum:]]+[[:space:]]+" "netinet/in.h"
                    510: auto_switch_type "sockoptname" "SO_[A-Z]+[[:space:]]+0x[0-9]+" "sys/socket.h"
                    511: auto_switch_type "socktypename" "SOCK_[A-Z]+[[:space:]]+[1-9]+[0-9]*" "sys/socket.h"
1.2       otto      512: #auto_switch_type "ptraceopname" "PT_[[:alnum:]_]+[[:space:]]+[0-9]+" "sys/ptrace.h"
1.1       otto      513:
                    514: cat <<_EOF_
                    515: /*
                    516:  * AUTO - Special
                    517:  * F_ is used to specify fcntl commands as well as arguments. Both sets are
                    518:  * grouped in fcntl.h, and this awk script grabs the first group.
                    519:  */
                    520: void
1.4       otto      521: fcntlcmdname (int cmd, int arg)
1.1       otto      522: {
                    523:        switch (cmd) {
                    524: _EOF_
1.6       matthew   525: egrep "^#[[:space:]]*define[[:space:]]+F_[A-Z_]+[[:space:]]+[0-9]+[[:space:]]*" \
1.1       otto      526:        $include_dir/sys/fcntl.h | \
                    527:        awk 'BEGIN { o=0 } { for (i = 1; i <= NF; i++) \
                    528:                if ($i ~ /define/) \
                    529:                        break; \
                    530:                ++i; \
                    531:                if (o <= $(i+1)) \
                    532:                        printf "\tcase %s:\n\t\t(void)printf(\"%s\");\n\t\tbreak;\n", $i, $i; \
                    533:                else \
                    534:                        exit; \
                    535:                o = $(i+1) }'
                    536: cat <<_EOF_
                    537:        default: /* Should not reach */
                    538:                (void)printf("<invalid=%ld>", (long)cmd);
                    539:        }
1.14      guenther  540:        if (cmd == F_SETFD) {
                    541:                (void)putchar(',');
1.1       otto      542:                if (arg == FD_CLOEXEC)
                    543:                        (void)printf("FD_CLOEXEC");
                    544:                else if (arg == 0)
                    545:                        (void)printf("0");
                    546:                else {
                    547:                        if (decimal)
                    548:                                (void)printf("<invalid>%ld", (long)arg);
                    549:                        else
                    550:                                (void)printf("<invalid>%#lx", (long)arg);
                    551:                }
1.14      guenther  552:
1.1       otto      553:        } else if (cmd == F_SETFL) {
1.14      guenther  554:                (void)putchar(',');
1.1       otto      555:                flagsname(arg);
1.14      guenther  556:        } else if (!fancy || (cmd != F_GETFD && cmd != F_GETFL)) {
                    557:                (void)putchar(',');
1.1       otto      558:                if (decimal)
                    559:                        (void)printf("%ld", (long)arg);
                    560:                else
                    561:                        (void)printf("%#lx", (long)arg);
                    562:        }
                    563: }
                    564:
                    565: /*
                    566:  * AUTO - Special
                    567:  *
                    568:  * The send and recv functions have a flags argument which can be
                    569:  * set to 0. There is no corresponding #define. The auto_ functions
                    570:  * detect this as "invalid", which is incorrect here.
                    571:  */
                    572: void
                    573: sendrecvflagsname (int flags)
                    574: {
                    575:        int     or = 0;
                    576:
                    577:        if (flags == 0) {
                    578:                (void)printf("0");
                    579:                return;
                    580:        }
                    581:
                    582:        printf("%#x<", flags);
                    583: _EOF_
                    584: egrep "^#[[:space:]]*define[[:space:]]+MSG_[A-Z]+[[:space:]]+0x[0-9]+[[:space:]]*" $include_dir/sys/socket.h | \
                    585:        awk '{ for (i = 1; i <= NF; i++) \
                    586:                if ($i ~ /define/) \
                    587:                        break; \
                    588:                ++i; \
                    589:                printf "\tif(!((flags>0)^((%s)>0)))\n\t\tif_print_or(flags, %s, or);\n", $i, $i }'
                    590: cat <<_EOF_
                    591:        printf(">");
                    592: }
                    593:
                    594: _EOF_