]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/subs/getans.c
Create new mh-format function %(ordinal)
[nmh] / docs / historical / mh-jun-1982 / subs / getans.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "../mh.h"
9 #include <signal.h>
10 #include <stdio.h>
11
12 int g_sigint; /* sensed an interrupt */
13 int g_sig();
14
15 char **
16 getans(prompt, ansp)
17 char *prompt;
18 struct swit *ansp;
19 {
20 static char ansbuf[128];
21 register char *cp, **cpp;
22 register int i;
23
24 VOID signal(SIGINT, g_sig);
25 for(;;) {
26 printf("%s", prompt);
27 VOID fflush(stdout);
28 cp = ansbuf;
29 while((i = getchar()) != '\n') {
30 if(i == EOF || g_sigint) {
31 g_sigint = 0;
32 return(0);
33 }
34 if(cp < &ansbuf[127])
35 *cp++ = i;
36 }
37 *cp = 0;
38 if(ansbuf[0] == '?' || cp == ansbuf) {
39 printf("Options are:\n");
40 printsw(ALL, ansp, "");
41 continue;
42 }
43 cpp = brkstring(ansbuf, " ", NULLCP);
44 switch(smatch(*cpp, ansp)) {
45 case -2:ambigsw(*cpp, ansp); /* ambiguous */
46 continue;
47 case -1: /* unknown */
48 printf(" -%s unknown. Hit <CR> for help.\n", *cpp);
49 continue;
50 default:
51 return(cpp); /* list, edit, quit, send */
52 }
53 }
54 }
55
56
57 g_sig()
58 {
59 VOID signal(SIGINT, g_sig);
60 g_sigint = 1;
61 return;
62 }