]>
diplodocus.org Git - nmh/blob - sbr/getans.c
3 * getans.c -- get an answer from the user and return a string array
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 #include <h/signals.h>
17 static char ansbuf
[BUFSIZ
];
18 static jmp_buf sigenv
;
23 static RETSIGTYPE
intrser (int);
27 getans (char *prompt
, struct swit
*ansp
)
30 SIGNAL_HANDLER istat
= NULL
;
33 if (!(setjmp (sigenv
))) {
34 istat
= SIGNAL (SIGINT
, intrser
);
36 SIGNAL (SIGINT
, istat
);
41 printf ("%s", prompt
);
44 while ((i
= getchar ()) != '\n') {
47 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
51 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
52 printf ("Options are:\n");
53 print_sw (ALL
, ansp
, "");
56 cpp
= brkstring (ansbuf
, " ", NULL
);
57 switch (smatch (*cpp
, ansp
)) {
62 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
65 SIGNAL (SIGINT
, istat
);
76 * should this be siglongjmp?