Remove RCS keywords, since they no longer work after git migration.
[mmh] / sbr / gans.c
1
2 /*
3  * gans.c -- get an answer from the user
4  *
5  * This code is Copyright (c) 2002, by the authors of nmh.  See the
6  * COPYRIGHT file in the root directory of the nmh distribution for
7  * complete copyright information.
8  */
9
10 #include <h/mh.h>
11
12
13 int
14 gans (char *prompt, struct swit *ansp)
15 {
16     register int i;
17     register char *cp;
18     register struct swit *ap;
19     char ansbuf[BUFSIZ];
20
21     for (;;) {
22         printf ("%s", prompt);
23         fflush (stdout);
24         cp = ansbuf;
25         while ((i = getchar ()) != '\n') {
26             if (i == EOF)
27                 return 0;
28             if (cp < &ansbuf[sizeof ansbuf - 1]) {
29 #ifdef LOCALE
30                 i = (isalpha(i) && isupper(i)) ? tolower(i) : i;
31 #else
32                 if (i >= 'A' && i <= 'Z')
33                     i += 'a' - 'A';
34 #endif
35                 *cp++ = i;
36             }
37         }
38         *cp = '\0';
39         if (ansbuf[0] == '?' || cp == ansbuf) {
40             printf ("Options are:\n");
41             for (ap = ansp; ap->sw; ap++)
42                 printf ("  %s\n", ap->sw);
43             continue;
44         }
45         if ((i = smatch (ansbuf, ansp)) < 0) {
46             printf ("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous");
47             continue;
48         }
49         return i;
50     }
51 }