]>
diplodocus.org Git - nmh/blob - sbr/read_switch.c
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.
12 read_switch (const char *prompt
, const struct swit
*ansp
)
16 const struct swit
*ap
;
20 fputs(prompt
, stdout
);
23 while ((i
= getchar ()) != '\n') {
26 if (cp
< &ansbuf
[sizeof ansbuf
- 1]) {
32 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
34 for (ap
= ansp
; ap
->sw
; ap
++)
35 printf (" %s\n", ap
->sw
);
38 if ((i
= smatch (ansbuf
, ansp
)) < 0) {
39 printf ("%s: %s.\n", ansbuf
, i
== -1 ? "unknown" : "ambiguous");