/* state 0: finish printing this string and return (matched!) state 1: no matching to be done; print everything state 2: continue searching for matched name  */
static int printenv(char *name, int state)
/* state 0: finish printing this string and return (matched!) state 1: no matching to be done; print everything state 2: continue searching for matched name  */
static int printenv(char *name, int state)
{
	int i, j;
	char c, buf[17];
	i = 0;
	buf[16] = '\0';
	while (state && env_get_char(i) != '\0') {
		if (state == 2 && envmatch((uchar *)name, i) >= 0)
			state = 0;
		j = 0;
		do {
			buf[j++] = c = env_get_char(i++);
			if (j == sizeof(buf) - 1) {
				if (state <= 1)
					puts(buf);
				j = 0;
			}
		} while (c != '\0');
		if (state <= 1) {
			if (j)
				puts(buf);
			putc('\n');
		}
		if (ctrlc())
			return -1;
	}
	if (state == 0)
		i = 0;
	return i;
}