Annotation of 43BSDReno/contrib/mh/sbr/getans.c, revision 1.1

1.1     ! root        1: /* getans.c - get an answer from the user and return a string array */
        !             2: 
        !             3: #include "../h/mh.h"
        !             4: #ifdef BSD42
        !             5: #include <setjmp.h>
        !             6: #endif BSD42
        !             7: #include <signal.h>
        !             8: #include <stdio.h>
        !             9: 
        !            10: 
        !            11: static char ansbuf[BUFSIZ];
        !            12: #ifndef        BSD42
        !            13: static int interrupted;
        !            14: #else  BSD42
        !            15: static jmp_buf sigenv;
        !            16: #endif BSD42
        !            17: static SIGDECL intrser();
        !            18: 
        !            19: char **
        !            20: getans(prompt, ansp)
        !            21:        register char *prompt;
        !            22:        register struct swit *ansp;
        !            23: {
        !            24:     register int    i;
        !            25:     SIGDECL (*istat)();
        !            26:     register char  *cp,
        !            27:                   **cpp;
        !            28: 
        !            29: #ifndef        BSD42
        !            30:     interrupted = 0;
        !            31:     istat = signal (SIGINT, intrser);
        !            32: #else  BSD42
        !            33:     switch (setjmp (sigenv)) {
        !            34:        case OK: 
        !            35:            istat = signal (SIGINT, intrser);
        !            36:            break;
        !            37: 
        !            38:        default: 
        !            39:            (void) signal (SIGINT, istat);
        !            40:            return NULL;
        !            41:     }
        !            42: #endif BSD42
        !            43:     for (;;) {
        !            44:        printf ("%s", prompt);
        !            45:        (void) fflush (stdout);
        !            46:        cp = ansbuf;
        !            47:        while ((i = getchar ()) != '\n') {
        !            48: #ifndef        BSD42
        !            49:            if (i == EOF || interrupted) {
        !            50:                interrupted = 0;
        !            51:                (void) signal (SIGINT, istat);
        !            52:                return NULL;
        !            53:            }
        !            54: #else  BSD42
        !            55:            if (i == EOF)
        !            56:                longjmp (sigenv, DONE);
        !            57: #endif BSD42
        !            58:            if (cp < &ansbuf[sizeof ansbuf - 1])
        !            59:                *cp++ = i;
        !            60:        }
        !            61:        *cp = 0;
        !            62:        if (ansbuf[0] == '?' || cp == ansbuf) {
        !            63:            printf ("Options are:\n");
        !            64:            printsw (ALL, ansp, "");
        !            65:            continue;
        !            66:        }
        !            67:        cpp = brkstring (ansbuf, " ", NULLCP);
        !            68:        switch (smatch (*cpp, ansp)) {
        !            69:            case AMBIGSW: 
        !            70:                ambigsw (*cpp, ansp);
        !            71:                continue;
        !            72:            case UNKWNSW: 
        !            73:                printf (" -%s unknown. Hit <CR> for help.\n", *cpp);
        !            74:                continue;
        !            75:            default: 
        !            76:                (void) signal (SIGINT, istat);
        !            77:                return cpp;
        !            78:        }
        !            79:     }
        !            80: }
        !            81: 
        !            82: 
        !            83: static SIGDECL
        !            84: intrser()
        !            85: {
        !            86: #ifndef        BSD42
        !            87:        (void) signal(SIGINT, intrser);
        !            88:        interrupted = 1;
        !            89: #else  BSD42
        !            90:        longjmp (sigenv, NOTOK);
        !            91: #endif BSD42
        !            92: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.