]>
diplodocus.org Git - nmh/blob - sbr/getans.c
3 * getans.c -- get an answer from the user and return a string array
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/signals.h>
15 static char ansbuf
[BUFSIZ
];
16 static jmp_buf sigenv
;
21 static RETSIGTYPE
intrser (int);
25 getans (char *prompt
, struct swit
*ansp
)
28 SIGNAL_HANDLER istat
= NULL
;
31 if (!(setjmp (sigenv
))) {
32 istat
= SIGNAL (SIGINT
, intrser
);
34 SIGNAL (SIGINT
, istat
);
39 printf ("%s", prompt
);
42 while ((i
= getchar ()) != '\n') {
45 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
49 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
50 printf ("Options are:\n");
51 print_sw (ALL
, ansp
, "", stdout
);
54 cpp
= brkstring (ansbuf
, " ", NULL
);
55 switch (smatch (*cpp
, ansp
)) {
60 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
63 SIGNAL (SIGINT
, istat
);
74 * should this be siglongjmp?