shithub: drawterm

Download patch

ref: 4fd4bb2017a76e09d8f2309211037479d6219507
parent: fffa2d3f540d81b985f2f74ab6d2e5499219a9b7
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Jan 6 19:58:50 EST 2023

devcons: cleanup kbdputc()

Make _kbdputc() to have the same signature as kbdputc().
move qproduce() from echo() to _kbdputc().
Use the Queue* argument.

--- a/kern/devcons.c
+++ b/kern/devcons.c
@@ -241,8 +241,8 @@
 static void
 echoscreen(char *buf, int n)
 {
-	char *e, *p;
 	char ebuf[128];
+	char *e, *p;
 	int x;
 
 	p = ebuf;
@@ -267,7 +267,6 @@
 static void
 echo(char *buf, int n)
 {
-	qproduce(kbdq, buf, n);
 	if(kbd.raw)
 		return;
 	if(screenputs != 0)
@@ -276,19 +275,18 @@
 		write(1, buf, n);
 }
 
-static
-void
-_kbdputc(int c)
+static int
+_kbdputc(Queue *q, int c)
 {
-	Rune r;
 	char buf[UTFmax];
+	Rune r = c;
 	int n;
 
-	r = c;
-	n = runetochar(buf, &r);
-	if(n == 0)
-		return;
-	echo(buf, n);
+	if((n = runetochar(buf, &r)) > 0){
+		echo(buf, n);
+		qproduce(q, buf, n);
+	}
+	return 0;
 }
 
 /* _kbdputc, but with compose translation */
@@ -295,9 +293,9 @@
 int
 kbdputc(Queue *q, int c)
 {
-	int	i;
 	static int collecting, nk;
 	static Rune kc[5];
+	int i;
 
 	switch(c){
 	case 0:
@@ -307,7 +305,7 @@
 	case Kaltgr:
 	case Kmod4:
 	case Kctl:
-		/* ignore modifiers */
+		/* ignore modifiers; see nextrune() of kbdfs */
 		return 0;
 
 	case Kalt:
@@ -316,10 +314,8 @@
 		return 0;
 	}
 
-	if(!collecting){
-		_kbdputc(c);
-		return 0;
-	}
+	if(!collecting)
+		return _kbdputc(q, c);
 
 	kc[nk++] = c;
 	c = latin1(kc, nk);
@@ -326,13 +322,12 @@
 	if(c < -1)  /* need more keystrokes */
 		return 0;
 	if(c != -1) /* valid sequence */
-		_kbdputc(c);
+		_kbdputc(q, c);
 	else
 		for(i=0; i<nk; i++)
-		 	_kbdputc(kc[i]);
+			_kbdputc(q, kc[i]);
 	nk = 0;
 	collecting = 0;
-
 	return 0;
 }