]>
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 SIGNAL (SIGINT
, istat
);
32 istat
= SIGNAL (SIGINT
, intrser
);
35 fputs(prompt
, stdout
);
38 while ((i
= getchar ()) != '\n') {
41 * If we get an EOF, return
44 siglongjmp (sigenv
, 1);
47 * For errors, if we get an EINTR that means that we got
48 * a signal and we should retry. If we get another error,
57 fprintf(stderr
, "\nError %s during read\n",
59 siglongjmp (sigenv
, 1);
62 /* Just for completeness's sake... */
63 fprintf(stderr
, "\nUnknown problem in getchar()\n");
64 siglongjmp(sigenv
, 1);
66 if (cp
< &ansbuf
[sizeof ansbuf
- 1])
70 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
72 print_sw (ALL
, ansp
, "", stdout
);
75 cpp
= brkstring (ansbuf
, " ", NULL
);
76 switch (smatch (*cpp
, ansp
)) {
81 printf (" -%s unknown. Hit <CR> for help.\n", *cpp
);
84 SIGNAL (SIGINT
, istat
);
96 siglongjmp (sigenv
, 1);