]>
diplodocus.org Git - nmh/blob - sbr/read_switch_multiword.c
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.
9 #include "read_switch_multiword.h"
11 #include "brkstring.h"
14 #include "h/signals.h"
17 static char ansbuf
[BUFSIZ
];
18 static sigjmp_buf sigenv
;
23 static void intrser (int);
27 read_switch_multiword (const char *prompt
, const struct swit
*ansp
)
30 SIGNAL_HANDLER istat
= NULL
;
33 if (sigsetjmp(sigenv
, 1)) {
34 SIGNAL (SIGINT
, istat
);
37 istat
= SIGNAL (SIGINT
, intrser
);
40 fputs(prompt
, stdout
);
43 while ((i
= getchar ()) != '\n') {
46 * If we get an EOF, return
49 siglongjmp (sigenv
, 1);
52 * For errors, if we get an EINTR that means that we got
53 * a signal and we should retry. If we get another error,
62 fprintf(stderr
, "\nError %s during read\n",
64 siglongjmp (sigenv
, 1);
67 /* Just for completeness's sake... */
68 fprintf(stderr
, "\nUnknown problem in getchar()\n");
69 siglongjmp(sigenv
, 1);
71 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
75 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
77 print_sw (ALL
, ansp
, "", stdout
);
80 cpp
= brkstring (ansbuf
, " ", NULL
);
81 switch (smatch (*cpp
, ansp
)) {
86 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
89 SIGNAL (SIGINT
, istat
);
101 siglongjmp (sigenv
, 1);