]>
diplodocus.org Git - nmh/blob - sbr/read_switch_multiword.c
d13ae7a1df1432f83e4186c5f87638ca68d4e515
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.
12 #include "h/signals.h"
15 static char ansbuf
[BUFSIZ
];
16 static sigjmp_buf sigenv
;
21 static void intrser (int);
25 read_switch_multiword (const char *prompt
, const struct swit
*ansp
)
28 SIGNAL_HANDLER istat
= NULL
;
31 if (sigsetjmp(sigenv
, 1)) {
32 SIGNAL (SIGINT
, istat
);
35 istat
= SIGNAL (SIGINT
, intrser
);
38 fputs(prompt
, stdout
);
41 while ((i
= getchar ()) != '\n') {
44 * If we get an EOF, return
47 siglongjmp (sigenv
, 1);
50 * For errors, if we get an EINTR that means that we got
51 * a signal and we should retry. If we get another error,
60 fprintf(stderr
, "\nError %s during read\n",
62 siglongjmp (sigenv
, 1);
65 /* Just for completeness's sake... */
66 fprintf(stderr
, "\nUnknown problem in getchar()\n");
67 siglongjmp(sigenv
, 1);
69 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
73 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
75 print_sw (ALL
, ansp
, "", stdout
);
78 cpp
= brkstring (ansbuf
, " ", NULL
);
79 switch (smatch (*cpp
, ansp
)) {
84 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
87 SIGNAL (SIGINT
, istat
);
99 siglongjmp (sigenv
, 1);