]> diplodocus.org Git - nmh/blob - docs/historical/mh-nov-1983/subs/getans.c
Update XOAUTH2 documentation.
[nmh] / docs / historical / mh-nov-1983 / subs / getans.c
1 #include "mh.h"
2 #include <signal.h>
3 #include <stdio.h>
4
5 int g_sigint; /* sensed an interrupt */
6 int g_sig();
7
8 char **getans(prompt, ansp)
9 struct swit *ansp;
10 {
11 static char ansbuf[128];
12 register char *cp, **cpp;
13 register int i;
14 struct swit *ap;
15
16 signal(SIGINT, g_sig);
17 for(;;) {
18 printf("%s", prompt);
19 fflush(stdout);
20 cp = ansbuf;
21 while((i = getchar()) != '\n') {
22 if(i == EOF || g_sigint) {
23 g_sigint = 0;
24 return(0);
25 }
26 if(cp < &ansbuf[127])
27 *cp++ = i;
28 }
29 *cp = 0;
30 if(ansbuf[0] == '?' || cp == ansbuf) {
31 printf("Options are:\n");
32 printsw(ALL, ansp, "");
33 continue;
34 }
35 cpp = brkstring(ansbuf, " ", 0);
36 switch(smatch(*cpp, ansp)) {
37 case -2:ambigsw(*cpp, ansp); /* ambiguous */
38 continue;
39 case -1: /* unknown */
40 printf(" -%s unknown. Hit <CR> for help.\n", *cpp);
41 continue;
42 default:
43 return(cpp); /* list, edit, quit, send */
44 }
45 }
46 }
47
48
49 g_sig()
50 {
51 signal(SIGINT, g_sig);
52 g_sigint = 1;
53 return;
54 }