code: plan9front

Download patch

ref: 4e3e6f11a5771c15d9083ab6bdfd2286eb53a8e4
parent: 65f4f6919fe4a680609eba456cd404ea6eb26d35
author: Jacob Moody <moody@posixcafe.org>
date: Sat May 27 17:20:32 EDT 2023

aux/kbdfs: accept names for layers in writes to kbmap

--- a/sys/src/cmd/aux/kbdfs/kbdfs.c
+++ b/sys/src/cmd/aux/kbdfs/kbdfs.c
@@ -135,6 +135,19 @@
 Channel *kbdchan;	/* chan(char*) */
 Channel *intchan;	/* chan(int) */
 
+char *layertab[Nlayers] = {
+	[Lnone]		"none",
+	[Lshift]	"shift",
+	[Lesc1]		"esc",
+	[Laltgr]	"altgr",
+	[Lctl]		"ctl",
+	[Lctrlesc1]	"ctlesc",
+	[Lshiftesc1]	"shiftesc",
+	[Lshiftaltgr]	"shiftaltgr",
+	[Lmod4]		"mod4",
+	[Laltgrmod4]	"altgrmod4",
+};
+
 /* /sys/lib/kbmap/ascii defaults */
 Rune ascii[Nlayers][Nscan] = {
 
@@ -1208,7 +1221,7 @@
 void
 kbmapwrite(Req *req)
 {
-	char line[100], *lp, *b;
+	char line[100], *lp, *b, *e;
 	Rune r, *rp;
 	int sc, t, l;
 	Fid *f;
@@ -1232,14 +1245,24 @@
 				respond(req, Ebadarg);
 				return;
 			}
-			if(*line == '\n' || *line == '#'){
-				lp = line;
-				continue;
-			}
 			lp = line;
+			if(*line == '\n' || *line == '#')
+				continue;
 			while(*lp == ' ' || *lp == '\t')
 				lp++;
-			t = strtoul(line, &lp, 0);
+			for(e = lp; strchr("\t ", *e) == nil; e++)
+				;
+			if(e == lp)
+				goto Badarg;
+			*e = '\0';
+			for(t = 0; t < nelem(layertab); t++){
+				if(strcmp(lp, layertab[t]) != 0)
+					continue;
+				break;
+			}
+			if(t == nelem(layertab))
+				t = strtoul(lp, nil, 0);
+			lp = e + 1;
 			sc = strtoul(lp, &lp, 0);
 			while(*lp == ' ' || *lp == '\t')
 				lp++;