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