Replaced setgid() calls with setegid() so that it works with dot
[mmh] / sbr / gans.c
1 /*
2 ** gans.c -- get an answer from the user
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11
12 int
13 gans(char *prompt, struct swit *ansp)
14 {
15         register int i;
16         register char *cp;
17         register struct swit *ap;
18         char ansbuf[BUFSIZ];
19
20         for (;;) {
21                 printf("%s", prompt);
22                 fflush(stdout);
23                 cp = ansbuf;
24                 while ((i = getchar()) != '\n') {
25                         if (i == EOF)
26                                 return 0;
27                         if (cp < &ansbuf[sizeof ansbuf - 1]) {
28                                 *cp++ = tolower(i);
29                         }
30                 }
31                 *cp = '\0';
32                 if (ansbuf[0] == '?' || cp == ansbuf) {
33                         printf("Options are:\n");
34                         for (ap = ansp; ap->sw; ap++)
35                                 printf("  %s\n", ap->sw);
36                         continue;
37                 }
38                 if ((i = smatch(ansbuf, ansp)) < 0) {
39                         printf("%s: %s.\n", ansbuf, i == -1 ? "unknown" : "ambiguous");
40                         continue;
41                 }
42                 return i;
43         }
44 }