Plan 9 from Bell Labs’s /usr/web/sources/contrib/uriel/changes/2005/1112/1

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


Allow rawon/rawoff during reads.
 [rsc] --rw-rw-r-- M 118305 rsc sys 6806 Nov 12 08:22 sys/src/cmd/vnc/devcons.c
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:230,236 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:230,236
	  		qunlock(&kbd);
	  		break;
	  	case Qsnarf:
	- 		if(c->mode == OWRITE || c->mode == ORDWR)
	+ 		if((c->mode&3) == OWRITE || (c->mode&3) == ORDWR)
	  			c->aux = smalloc(sizeof(Snarf));
	  		break;
	  	}
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:289,296 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:289,297
	  static long
	  consread(Chan *c, void *buf, long n, vlong off)
	  {
	- 	char *cbuf;
	- 	int i, ch, eol;
	+ 	char *cbuf, ch;
	+ 	int i, eol;
	+ 	int	send;
	  
	  	if(n <= 0)
	  		return n;
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:315,362 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:316,355
	  			qunlock(&kbd);
	  			nexterror();
	  		}
	- 		if(kbd.raw){
	- 			cbuf = buf;
	- 			if(qcanread(lineq))
	- 				n = qread(lineq, buf, n);
	- 			else {
	- 				/* read as much as possible */
	- 				do {
	- 					i = qread(kbdq, cbuf, n);
	- 					cbuf += i;
	- 					n -= i;
	- 				} while (n>0 && qcanread(kbdq));
	- 				n = cbuf - (char*)buf;
	- 			}
	- 		} else {
	- 			while(!qcanread(lineq)){
	- 				qread(kbdq, &kbd.line[kbd.x], 1);
	- 				ch = kbd.line[kbd.x];
	- 				eol = 0;
	+ 		while(!qcanread(lineq)){
	+ 			qread(kbdq, &ch, 1);
	+ 			send = 0;
	+ 			if(ch == 0){
	+ 				/* flush output on rawoff -> rawon */
	+ 				if(kbd.x > 0)
	+ 					send = !qcanread(kbdq);
	+ 			}else if(kbd.raw){
	+ 				kbd.line[kbd.x++] = ch;
	+ 				send = !qcanread(kbdq);
	+ 			}else{
	  				switch(ch){
	  				case '\b':
	- 					if(kbd.x)
	+ 					if(kbd.x > 0)
	  						kbd.x--;
	  					break;
	- 				case 0x15:
	+ 				case 0x15:	/* ^U */
	  					kbd.x = 0;
	  					break;
	  				case '\n':
	- 				case 0x04:
	- 					eol = 1;
	+ 				case 0x04:	/* ^D */
	+ 					send = 1;
	  				default:
	- 					kbd.line[kbd.x++] = ch;
	+ 					if(ch != 0x04)
	+ 						kbd.line[kbd.x++] = ch;
	  					break;
	  				}
	- 				if(kbd.x == sizeof(kbd.line) || eol){
	- 					if(ch == 0x04)
	- 						kbd.x--;
	- 					qwrite(lineq, kbd.line, kbd.x);
	- 					kbd.x = 0;
	- 				}
	  			}
	- 			n = qread(lineq, buf, n);
	+ 			if(send || kbd.x == sizeof kbd.line){
	+ 				qwrite(lineq, kbd.line, kbd.x);
	+ 				kbd.x = 0;
	+ 			}
	  		}
	+ 		n = qread(lineq, buf, n);
	  		qunlock(&kbd);
	  		poperror();
	  		return n;
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:373,378 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:366,372
	  {
	  	Snarf *t;
	  	char buf[256], *a;
	+ 	char ch;
	  
	  	switch((ulong)c->qid.path){
	  	case Qcons:
	/n/sourcesdump/2005/1112/plan9/sys/src/cmd/vnc/devcons.c:386,403 - 
	/n/sourcesdump/2005/1113/plan9/sys/src/cmd/vnc/devcons.c:380,391
	  		buf[n] = 0;
	  		for(a = buf; a;){
	  			if(strncmp(a, "rawon", 5) == 0){
	- 				qlock(&kbd);
	- 				if(kbd.x){
	- 					qwrite(kbdq, kbd.line, kbd.x);
	- 					kbd.x = 0;
	- 				}
	  				kbd.raw = 1;
	- 				qunlock(&kbd);
	+ 				/* clumsy hack - wake up reader */
	+ 				ch = 0;
	+ 				qwrite(kbdq, &ch, 1);			
	  			} else if(strncmp(a, "rawoff", 6) == 0){
	- 				qlock(&kbd);
	  				kbd.raw = 0;
	- 				kbd.x = 0;
	- 				qunlock(&kbd);
	  			}
	  			if(a = strchr(a, ' '))
	  				a++;


Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.