]>
diplodocus.org Git - nmh/blob - sbr/read_switch.c
3 * read_switch.c -- prompt the user for an answer from the list
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.
14 read_switch (const char *prompt
, const struct swit
*ansp
)
18 const struct swit
*ap
;
22 fputs(prompt
, stdout
);
25 while ((i
= getchar ()) != '\n') {
28 if (cp
< &ansbuf
[sizeof ansbuf
- 1]) {
34 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
36 for (ap
= ansp
; ap
->sw
; ap
++)
37 printf (" %s\n", ap
->sw
);
40 if ((i
= smatch (ansbuf
, ansp
)) < 0) {
41 printf ("%s: %s.\n", ansbuf
, i
== -1 ? "unknown" : "ambiguous");