Annotation of 43BSD/contrib/mh/sbr/gans.c, revision 1.1

1.1     ! root        1: /* gans.c - get an answer from the user */
        !             2: 
        !             3: #include "../h/mh.h"
        !             4: #include <stdio.h>
        !             5: 
        !             6: 
        !             7: gans (prompt, ansp)
        !             8: register char *prompt;
        !             9: register struct swit *ansp;
        !            10: {
        !            11:     register int    i;
        !            12:     register char  *cp;
        !            13:     register struct swit   *ap;
        !            14:     char    ansbuf[BUFSIZ];
        !            15: 
        !            16:     for (;;) {
        !            17:        printf ("%s", prompt);
        !            18:        (void) fflush (stdout);
        !            19:        cp = ansbuf;
        !            20:        while ((i = getchar ()) != '\n') {
        !            21:            if (i == EOF)
        !            22:                return 0;
        !            23:            if (cp < &ansbuf[sizeof ansbuf - 1]) {
        !            24:                if (i >= 'A' && i <= 'Z')
        !            25:                    i += 'a' - 'A';
        !            26:                *cp++ = i;
        !            27:            }
        !            28:        }
        !            29:        *cp = 0;
        !            30:        if (ansbuf[0] == '?' || cp == ansbuf) {
        !            31:            printf ("Options are:\n");
        !            32:            for (ap = ansp; ap -> sw; ap++)
        !            33:                printf ("  %s\n", ap -> sw);
        !            34:            continue;
        !            35:        }
        !            36:        if ((i = smatch (ansbuf, ansp)) < 0) {
        !            37:            printf ("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous");
        !            38:            continue;
        !            39:        }
        !            40:        return i;
        !            41:     }
        !            42: }

unix.superglobalmegacorp.com

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