]>
diplodocus.org Git - nmh/blob - sbr/read_switch.c
8cdbfe4ff0234a38a85d45f1ffeba0ff7af4032c
1 /* read_switch.c -- prompt the user for an answer from the list
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.
13 read_switch (const char *prompt
, const struct swit
*ansp
)
17 const struct swit
*ap
;
21 fputs(prompt
, stdout
);
24 while ((i
= getchar ()) != '\n') {
27 if (cp
< &ansbuf
[sizeof ansbuf
- 1]) {
33 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
35 for (ap
= ansp
; ap
->sw
; ap
++)
36 printf (" %s\n", ap
->sw
);
39 if ((i
= smatch (ansbuf
, ansp
)) < 0) {
40 printf ("%s: %s.\n", ansbuf
, i
== -1 ? "unknown" : "ambiguous");