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

Defined functions

gans defined in line 7; used 1 times
Last modified: 1985-09-21
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 896
Valid CSS Valid XHTML 1.0 Strict