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: }

Defined functions

comp defined in line 63; used 1 times
  • in line 52

Defined variables

buf defined in line 8; used 9 times

Defined macros

LINE defined in line 6; used 1 times
  • in line 29
reg defined in line 4; used 2 times
Last modified: 1982-06-09
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1060
Valid CSS Valid XHTML 1.0 Strict