]>
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.
12 static char ansbuf
[BUFSIZ
];
13 static sigjmp_buf sigenv
;
18 static void intrser (int);
22 read_switch_multiword (const char *prompt
, const struct swit
*ansp
)
25 SIGNAL_HANDLER istat
= NULL
;
28 if (!(sigsetjmp(sigenv
, 1))) {
29 istat
= SIGNAL (SIGINT
, intrser
);
31 SIGNAL (SIGINT
, istat
);
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,
53 else if (ferror(stdin
)) {
58 fprintf(stderr
, "\nError %s during read\n",
60 siglongjmp (sigenv
, 1);
63 * Just for completeness's sake ...
66 fprintf(stderr
, "\nUnknown problem in getchar()\n");
67 siglongjmp (sigenv
, 1);
70 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
74 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
76 print_sw (ALL
, ansp
, "", stdout
);
79 cpp
= brkstring (ansbuf
, " ", NULL
);
80 switch (smatch (*cpp
, ansp
)) {
85 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
88 SIGNAL (SIGINT
, istat
);
101 * should this be siglongjmp?
103 siglongjmp (sigenv
, 1);