]>
diplodocus.org Git - nmh/blob - sbr/gans.c
3 * gans.c -- get an answer from the user
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 gans (char *prompt
, struct swit
*ansp
)
18 register struct swit
*ap
;
22 printf ("%s", prompt
);
25 while ((i
= getchar ()) != '\n') {
28 if (cp
< &ansbuf
[sizeof ansbuf
- 1]) {
30 i
= (isalpha(i
) && isupper(i
)) ? tolower(i
) : i
;
32 if (i
>= 'A' && i
<= 'Z')
39 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
40 printf ("Options are:\n");
41 for (ap
= ansp
; ap
->sw
; ap
++)
42 printf (" %s\n", ap
->sw
);
45 if ((i
= smatch (ansbuf
, ansp
)) < 0) {
46 printf ("%s: %s.\n", ansbuf
, i
== -1 ? "unknown" : "ambiguous");