Path: utzoo!mnetor!uunet!husc6!think!ames!oliveb!stratus!cloud9!bob From: bob@cloud9.UUCP (Bob Toxen) Newsgroups: comp.unix.wizards Subject: Re: tset (BSD?) Message-ID: <352@cloud9.UUCP> Date: 6 May 88 00:54:26 GMT References: <8776@sol.ARPA> <4493@hoptoad.uucp> <98@skep2.ATT.COM> Organization: Stratus Computer, Inc., Marlboro, MA Lines: 55 Summary: System V VMIN/VTIME allow you to do this efficiently In article <98@skep2.ATT.COM>, wcs@skep2.ATT.COM (Bill.Stewart.) 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 #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?