Annotation of 43BSD/games/monop/getinp.c, revision 1.1.1.1

1.1       root        1: # include      <stdio.h>
                      2: # include      <ctype.h>
                      3: 
                      4: # define       reg     register
                      5: 
                      6: # define       LINE    70
                      7: 
                      8: static char    buf[257];
                      9: 
                     10: getinp(prompt, list)
                     11: char   *prompt, *list[]; {
                     12: 
                     13:        reg int i, n_match, match;
                     14:        char    *sp;
                     15:        int     plen;
                     16: 
                     17: 
                     18:        for (;;) {
                     19: inter:
                     20:                printf(prompt);
                     21:                for (sp = buf; (*sp=getchar()) != '\n'; )
                     22:                        if (*sp == -1)  /* check for interupted system call */
                     23:                                goto inter;
                     24:                        else if (sp != buf || *sp != ' ')
                     25:                                sp++;
                     26:                if (buf[0] == '?' && buf[1] == '\n') {
                     27:                        printf("Valid inputs are: ");
                     28:                        for (i = 0, match = 18; list[i]; i++) {
                     29:                                if ((match+=(n_match=strlen(list[i]))) > LINE) {
                     30:                                        printf("\n\t");
                     31:                                        match = n_match + 8;
                     32:                                }
                     33:                                if (*list[i] == '\0') {
                     34:                                        match += 8;
                     35:                                        printf("<RETURN>");
                     36:                                }
                     37:                                else
                     38:                                        printf(list[i]);
                     39:                                if (list[i+1])
                     40:                                        printf(", ");
                     41:                                else
                     42:                                        putchar('\n');
                     43:                                match += 2;
                     44:                        }
                     45:                        continue;
                     46:                }
                     47:                *sp = '\0';
                     48:                for (sp = buf; *sp; sp++)
                     49:                        if (isupper(*sp))
                     50:                                *sp = tolower(*sp);
                     51:                for (i = n_match = 0; list[i]; i++)
                     52:                        if (comp(list[i])) {
                     53:                                n_match++;
                     54:                                match = i;
                     55:                        }
                     56:                if (n_match == 1)
                     57:                        return match;
                     58:                else if (buf[0] != '\0')
                     59:                        printf("Illegal response: \"%s\".  Use '?' to get list of valid answers\n", buf);
                     60:        }
                     61: }
                     62: 
                     63: static
                     64: comp(s1)
                     65: char   *s1; {
                     66: 
                     67:        reg char        *sp, *tsp, c;
                     68: 
                     69:        if (buf[0] != '\0')
                     70:                for (sp = buf, tsp = s1; *sp; ) {
                     71:                        c = isupper(*tsp) ? tolower(*tsp) : *tsp;
                     72:                        tsp++;
                     73:                        if (c != *sp++)
                     74:                                return 0;
                     75:                }
                     76:        else if (*s1 != '\0')
                     77:                return 0;
                     78:        return 1;
                     79: }

unix.superglobalmegacorp.com

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