]> diplodocus.org Git - nmh/blob - docs/historical/mh-jun-1982/subs/gans.c
Create new mh-format function %(ordinal)
[nmh] / docs / historical / mh-jun-1982 / subs / gans.c
1 #ifdef COMMENT
2 Proprietary Rand Corporation, 1981.
3 Further distribution of this software
4 subject to the terms of the Rand
5 license agreement.
6 #endif
7
8 #include "../mh.h"
9 #include <stdio.h>
10
11 gans(prompt, ansp)
12 char *prompt;
13 struct swit *ansp;
14 {
15 char ansbuf[32];
16 register char *cp;
17 register int i;
18 struct swit *ap;
19
20 for(;;) {
21 printf("%s", prompt);
22 VOID fflush(stdout);
23 cp = ansbuf;
24 while((i = getchar()) != '\n') {
25 if(i == EOF)
26 return(0);
27 if(cp < &ansbuf[31]) {
28 if(i >= 'A' && i <= 'Z')
29 i += 'a'-'A';
30 *cp++ = i;
31 }
32 }
33 *cp = 0;
34 if(ansbuf[0] == '?' || cp == ansbuf) {
35 printf("Options are:\n");
36 for(ap = ansp; ap->sw; ap++)
37 printf(" %s\n", ap->sw);
38 continue;
39 }
40 if((i = smatch(ansbuf, ansp)) < 0) {
41 printf("%s: %s.\n", ansbuf, i == -1? "unknown":"ambiguous");
42 continue;
43 }
44 return(i);
45 }
46 }