2 * getans.c -- get an answer from the user and return a string array
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.
10 #include <h/signals.h>
14 static char ansbuf[BUFSIZ];
15 static jmp_buf sigenv;
20 static RETSIGTYPE intrser (int);
24 getans (char *prompt, struct swit *ansp)
27 SIGNAL_HANDLER istat = NULL;
30 if (!(setjmp (sigenv))) {
31 istat = SIGNAL (SIGINT, intrser);
33 SIGNAL (SIGINT, istat);
38 printf ("%s", prompt);
41 while ((i = getchar ()) != '\n') {
44 if (cp < &ansbuf[sizeof ansbuf - 1])
48 if (ansbuf[0] == '?' || cp == ansbuf) {
49 printf ("Options are:\n");
50 print_sw (ALL, ansp, "", stdout);
53 cpp = brkstring (ansbuf, " ", NULL);
54 switch (smatch (*cpp, ansp)) {
59 printf (" -%s unknown. Hit <CR> for help.\n", *cpp);
62 SIGNAL (SIGINT, istat);
73 * should this be siglongjmp?