SRI-NOSC/mh/subs.dir/gans.c

Compare this file to the similar file:
Show the results in this format:

#include "mh.h"

gans(prompt, ansp)
struct swit *ansp;
{
	char ansbuf[32];
	register char *cp;
	register int i;
	struct swit *ap;

    for(;;) {
	printf("%s", prompt);
	flush();
	cp = ansbuf;
	while((i = getchar()) != '\n') {
		if(i == 0)
			return(0);
		if(cp < &ansbuf[31]) {
			if(i >= 'A' && i <= 'Z')
				i =+ 'a'-'A';
			*cp++ = i;
		}
	}
	*cp = 0;
	if(ansbuf[0] == '?' || cp == ansbuf) {
		printf("Options are:\n");
		for(ap = ansp; ap->sw; ap++)
			printf("  %s\n", ap->sw);
		continue;
	}
	if((i = smatch(ansbuf, ansp)) < 0) {
		printf("%s: %s.\n", ansbuf, i == -1? "unknown":"ambiguous");
		continue;
	}
	return(i);
    }
}