]>
diplodocus.org Git - nmh/blob - sbr/read_switch_multiword.c
3 * read_switch_multiword.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>
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 istat
= SIGNAL (SIGINT
, intrser
);
33 SIGNAL (SIGINT
, istat
);
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,
55 else if (ferror(stdin
)) {
60 fprintf(stderr
, "\nError %s during read\n",
62 siglongjmp (sigenv
, 1);
65 * Just for completeness's sake ...
68 fprintf(stderr
, "\nUnknown problem in getchar()\n");
69 siglongjmp (sigenv
, 1);
72 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
76 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
78 print_sw (ALL
, ansp
, "", stdout
);
81 cpp
= brkstring (ansbuf
, " ", NULL
);
82 switch (smatch (*cpp
, ansp
)) {
87 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
90 SIGNAL (SIGINT
, istat
);
103 * should this be siglongjmp?
105 siglongjmp (sigenv
, 1);