]>
diplodocus.org Git - nmh/blob - sbr/gans.c
3 * gans.c -- get an answer from the user
12 gans (char *prompt
, struct swit
*ansp
)
16 register struct swit
*ap
;
20 printf ("%s", prompt
);
23 while ((i
= getchar ()) != '\n') {
26 if (cp
< &ansbuf
[sizeof ansbuf
- 1]) {
28 i
= (isalpha(i
) && isupper(i
)) ? tolower(i
) : i
;
30 if (i
>= 'A' && i
<= 'Z')
37 if (ansbuf
[0] == '?' || cp
== ansbuf
) {
38 printf ("Options are:\n");
39 for (ap
= ansp
; ap
->sw
; ap
++)
40 printf (" %s\n", ap
->sw
);
43 if ((i
= smatch (ansbuf
, ansp
)) < 0) {
44 printf ("%s: %s.\n", ansbuf
, i
== -1 ? "unknown" : "ambiguous");