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' && !feof(stdin); )
  22:             if (*sp == -1)  /* check for interupted system call */
  23:                 goto inter;
  24:             else if (sp != buf || *sp != ' ')
  25:                 sp++;
  26:         if (feof(stdin)) {
  27:             clearerr(stdin);
  28:             continue;
  29:         }
  30:         if (buf[0] == '?' && buf[1] == '\n') {
  31:             printf("Valid inputs are: ");
  32:             for (i = 0, match = 18; list[i]; i++) {
  33:                 if ((match+=(n_match=strlen(list[i]))) > LINE) {
  34:                     printf("\n\t");
  35:                     match = n_match + 8;
  36:                 }
  37:                 if (*list[i] == '\0') {
  38:                     match += 8;
  39:                     printf("<RETURN>");
  40:                 }
  41:                 else
  42:                     printf(list[i]);
  43:                 if (list[i+1])
  44:                     printf(", ");
  45:                 else
  46:                     putchar('\n');
  47:                 match += 2;
  48:             }
  49:             continue;
  50:         }
  51:         *sp = '\0';
  52:         for (sp = buf; *sp; sp++)
  53:             if (isupper(*sp))
  54:                 *sp = tolower(*sp);
  55:         for (i = n_match = 0; list[i]; i++)
  56:             if (comp(list[i])) {
  57:                 n_match++;
  58:                 match = i;
  59:             }
  60:         if (n_match == 1)
  61:             return match;
  62:         else if (buf[0] != '\0')
  63:             printf("Illegal response: \"%s\".  Use '?' to get list of valid answers\n", buf);
  64:     }
  65: }
  66: 
  67: static
  68: comp(s1)
  69: char    *s1; {
  70: 
  71:     reg char    *sp, *tsp, c;
  72: 
  73:     if (buf[0] != '\0')
  74:         for (sp = buf, tsp = s1; *sp; ) {
  75:             c = isupper(*tsp) ? tolower(*tsp) : *tsp;
  76:             tsp++;
  77:             if (c != *sp++)
  78:                 return 0;
  79:         }
  80:     else if (*s1 != '\0')
  81:         return 0;
  82:     return 1;
  83: }

Defined functions

comp defined in line 67; used 1 times
  • in line 56

Defined variables

buf defined in line 8; used 9 times

Defined macros

LINE defined in line 6; used 1 times
  • in line 33
reg defined in line 4; used 2 times
Last modified: 1987-08-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2712
Valid CSS Valid XHTML 1.0 Strict