]> diplodocus.org Git - nmh/blob - sbr/gans.c
Cope with sasl_decode64() returning SASL_CONTINUE as well as SASL_OK.
[nmh] / sbr / gans.c
1
2 /*
3 * gans.c -- get an answer from the user
4 *
5 * $Id$
6 *
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.
10 */
11
12 #include <h/mh.h>
13
14
15 int
16 gans (char *prompt, struct swit *ansp)
17 {
18 register int i;
19 register char *cp;
20 register struct swit *ap;
21 char ansbuf[BUFSIZ];
22
23 for (;;) {
24 printf ("%s", prompt);
25 fflush (stdout);
26 cp = ansbuf;
27 while ((i = getchar ()) != '\n') {
28 if (i == EOF)
29 return 0;
30 if (cp < &ansbuf[sizeof ansbuf - 1]) {
31 #ifdef LOCALE
32 i = (isalpha(i) && isupper(i)) ? tolower(i) : i;
33 #else
34 if (i >= 'A' && i <= 'Z')
35 i += 'a' - 'A';
36 #endif
37 *cp++ = i;
38 }
39 }
40 *cp = '\0';
41 if (ansbuf[0] == '?' || cp == ansbuf) {
42 printf ("Options are:\n");
43 for (ap = ansp; ap->sw; ap++)
44 printf (" %s\n", ap->sw);
45 continue;
46 }
47 if ((i = smatch (ansbuf, ansp)) < 0) {
48 printf ("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous");
49 continue;
50 }
51 return i;
52 }
53 }