3 * gans.c -- get an answer from the user
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
16 gans (char *prompt, struct swit *ansp)
20 register struct swit *ap;
24 printf ("%s", prompt);
27 while ((i = getchar ()) != '\n') {
30 if (cp < &ansbuf[sizeof ansbuf - 1]) {
32 i = (isalpha(i) && isupper(i)) ? tolower(i) : i;
34 if (i >= 'A' && i <= 'Z')
41 if (ansbuf[0] == '?' || cp == ansbuf) {
42 printf ("Options are:\n");
43 for (ap = ansp; ap->sw; ap++)
44 printf (" %s\n", ap->sw);
47 if ((i = smatch (ansbuf, ansp)) < 0) {
48 printf ("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous");