]>
diplodocus.org Git - nmh/blob - sbr/read_switch_multiword.c
d66bd254a85e6241104076401569352ab0a15228
1 /* read_switch_multiword.c -- get an answer from the user and return a string array
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
10 #include "h/signals.h"
13 static char ansbuf
[BUFSIZ
];
14 static sigjmp_buf sigenv
;
19 static void intrser (int);
23 read_switch_multiword (const char *prompt
, const struct swit
*ansp
)
26 SIGNAL_HANDLER istat
= NULL
;
29 if (sigsetjmp(sigenv
, 1)) {
30 SIGNAL (SIGINT
, istat
);
33 istat
= SIGNAL (SIGINT
, intrser
);
36 fputs(prompt
, stdout
);
39 while ((i
= getchar ()) != '\n') {
42 * If we get an EOF, return
45 siglongjmp (sigenv
, 1);
48 * For errors, if we get an EINTR that means that we got
49 * a signal and we should retry. If we get another error,
58 fprintf(stderr
, "\nError %s during read\n",
60 siglongjmp (sigenv
, 1);
63 /* Just for completeness's sake... */
64 fprintf(stderr
, "\nUnknown problem in getchar()\n");
65 siglongjmp(sigenv
, 1);
67 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
71 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
73 print_sw (ALL
, ansp
, "", stdout
);
76 cpp
= brkstring (ansbuf
, " ", NULL
);
77 switch (smatch (*cpp
, ansp
)) {
82 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
85 SIGNAL (SIGINT
, istat
);
97 siglongjmp (sigenv
, 1);