]> diplodocus.org Git - nmh/blob - docs/historical/SRI-NOSC/subs.dir/gans.c
expect this commit to be force-replaced periodically
[nmh] / docs / historical / SRI-NOSC / subs.dir / gans.c
1 #include "mh.h"
2
3 gans(prompt, ansp)
4 struct swit *ansp;
5 {
6 char ansbuf[32];
7 register char *cp;
8 register int i;
9 struct swit *ap;
10
11 for(;;) {
12 printf("%s", prompt);
13 flush();
14 cp = ansbuf;
15 while((i = getchar()) != '\n') {
16 if(i == 0)
17 return(0);
18 if(cp < &ansbuf[31]) {
19 if(i >= 'A' && i <= 'Z')
20 i =+ 'a'-'A';
21 *cp++ = i;
22 }
23 }
24 *cp = 0;
25 if(ansbuf[0] == '?' || cp == ansbuf) {
26 printf("Options are:\n");
27 for(ap = ansp; ap->sw; ap++)
28 printf(" %s\n", ap->sw);
29 continue;
30 }
31 if((i = smatch(ansbuf, ansp)) < 0) {
32 printf("%s: %s.\n", ansbuf, i == -1? "unknown":"ambiguous");
33 continue;
34 }
35 return(i);
36 }
37 }