]>
diplodocus.org Git - nmh/blob - sbr/getans.c
c5609053c00333ae0fa1662381d31d90770c688e
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 sigjmp_buf sigenv
;
21 static void intrser (int);
25 getans (char *prompt
, struct swit
*ansp
)
28 SIGNAL_HANDLER istat
= NULL
;
31 if (!(sigsetjmp(sigenv
, 1))) {
32 istat
= SIGNAL (SIGINT
, intrser
);
34 SIGNAL (SIGINT
, istat
);
39 printf ("%s", prompt
);
42 while ((i
= getchar ()) != '\n') {
45 * If we get an EOF, return
48 siglongjmp (sigenv
, 1);
51 * For errors, if we get an EINTR that means that we got
52 * a signal and we should retry. If we get another error,
56 else if (ferror(stdin
)) {
61 fprintf(stderr
, "\nError %s during read\n",
63 siglongjmp (sigenv
, 1);
66 * Just for completeness's sake ...
69 fprintf(stderr
, "\nUnknown problem in getchar()\n");
70 siglongjmp (sigenv
, 1);
73 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
77 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
78 printf ("Options are:\n");
79 print_sw (ALL
, ansp
, "", stdout
);
82 cpp
= brkstring (ansbuf
, " ", NULL
);
83 switch (smatch (*cpp
, ansp
)) {
88 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
91 SIGNAL (SIGINT
, istat
);
104 * should this be siglongjmp?
106 siglongjmp (sigenv
, 1);