tset (BSD?)

Bob Toxen bob at cloud9.UUCP
Fri May 6 10:54:26 AEST 1988


In article <98 at skep2.ATT.COM>, wcs at skep2.ATT.COM (Bill.Stewart.<ho95c>) writes:
> One feature I've wished was available in a TTY driver is the ability to
> specify a bunch of characters (e.g. control characters), and tell it
> to "read until N input characters or a special character" [For forms.]
> # Bill Stewart, AT&T Bell Labs Holmdel NJ 1-201-949-0705 ihnp4!ho95c!wcs

For forms and such that use raw mode, the System V tty driver's VMIN &
VTIME allow you to simulate this without much CPU/code cost.  Also, you
can specify alternate characters that tell the read() "I got enough,
return."  Generally, one of these is set to NUL so that BREAKs are handled
well.  The code fragment illustrates this.  [I haven't actually tried the
concept or this code.]  Permission to steal granted.

#include <termio.h>
#ifndef	VEOL2
#define	VEOL2	(VEOL+1)
#endif
	char	line[200];
	char	*p;

	c_cc[VMIN]   = 10;
	c_cc[VTIME]  = 5;
	c_cc[VERASE] = CTRL(H);
	c_cc[VKILL]  = CTRL(U);
	c_cc[VEOL]   = 0177;
	c_cc[VEOL2]  = CTRL(X);
	ioctl(these_things);
	raw_mode();
	p = line;

loop:
	switch (*p++ = getchar()) {
		case CTRL(EOL):
			p--;
			if (p > line) {
				p--;
				printf("\b \b");
			}
			break;
		case CTRL(X):
			while (--p > line)
				if (p[-1] >= ' ' && p[-1] < 0177)
					printf("\b \b");
			break;
		default:
			if (p[-1] >= ' ' && p[-1] < 0177)
				putchar(p[-1]);
	}
	process();
	goto loop;
-- 

Bob Toxen	{ucbvax!ihnp4,harvard,cloud9!es}!anvil!cavu!bob
Stratus Computer, Marlboro, MA
Pilot to Copilot: What's a mountain goat doing way up here in a cloud bank?



More information about the Comp.unix.wizards mailing list