Remove not used code (JLR define)
[mmh] / sbr / getans.c
1 /*
2 ** getans.c -- get an answer from the user and return a string array
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 #include <h/signals.h>
11 #include <setjmp.h>
12 #include <signal.h>
13 #include <unistd.h>
14
15 static char ansbuf[BUFSIZ];
16 static jmp_buf sigenv;
17
18 /*
19 ** static prototypes
20 */
21 static void intrser(int);
22
23
24 char **
25 getans(char *prompt, struct swit *ansp)
26 {
27         int i;
28         SIGNAL_HANDLER istat = NULL;
29         char *cp, **cpp;
30
31         if (!(setjmp(sigenv))) {
32                 istat = SIGNAL(SIGINT, intrser);
33         } else {
34                 SIGNAL(SIGINT, istat);
35                 return NULL;
36         }
37
38         for (;;) {
39                 printf("%s", prompt);
40                 fflush(stdout);
41                 cp = ansbuf;
42                 while ((i = getchar()) != '\n') {
43                         if (i == EOF)
44                                 longjmp(sigenv, 1);
45                         if (cp < &ansbuf[sizeof ansbuf - 1])
46                                 *cp++ = i;
47                 }
48                 *cp = '\0';
49                 if (ansbuf[0] == '?' || cp == ansbuf) {
50                         printf("Options are:\n");
51                         print_sw(ALL, ansp, "", stdout);
52                         continue;
53                 }
54                 cpp = brkstring(ansbuf, " ", NULL);
55                 switch (smatch(*cpp, ansp)) {
56                 case AMBIGSW:
57                         ambigsw(*cpp, ansp);
58                         continue;
59                 case UNKWNSW:
60                         printf(" -%s unknown. Hit <CR> for help.\n", *cpp);
61                         continue;
62                 default:
63                         SIGNAL(SIGINT, istat);
64                         return cpp;
65                 }
66         }
67 }
68
69
70 static void
71 intrser(int i)
72 {
73         /*
74         ** should this be siglongjmp?
75         */
76         close(STDIN_FILENO);
77 }