File:  [Research Unix] / researchv9 / jtools / src / blitblt / kbdstring.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:59 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv9-SUN3_old, researchv9-SUN3, HEAD
researchv9-SUN3(old)

#include <jerq.h>

#define kbdcurs(p)	rectf(&display,Rect(p.x,p.y,p.x+1,p.y+fontheight(&defont) ),F_XOR)

static echo(c,p)
Point p;
{
	static char buf[2];

	buf[0] = c;
	string(&defont, buf, &display, p, F_XOR);
}


kbdstring(str,nchmax,p)	/* read string from keyboard with echo at p */
register char *str; int nchmax; Point p;
{
	register int kbd, nchars = 0;

	*str = 0; kbdcurs(p);
	for (;;) {
		wait(KBD);
		kbdcurs(p);
		switch (kbd = kbdchar()) {
		case 0:
			break;
		case '\r':
		case '\n':
			return nchars;
		case '\b':
			if (nchars <= 0) break;
			kbd = *--str; *str = 0; nchars--;
			p.x -= fontwidth(&defont);
			echo(kbd, p);
			break;
		default:
			if (nchars >= nchmax) break;
			*str++ = kbd; *str = 0; nchars++;
			echo(kbd, p);
			p.x += fontwidth(&defont);
		}
		kbdcurs(p);
	}
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.