shithub: riscv

Download patch

ref: e3a43c4f2b3751da67d24e40a77d8bcac3957520
parent: db911d4fef8d2bcfc6c314fcd3c06f35f5b4249c
author: Ori Bernstein <[email protected]>
date: Wed Oct 9 13:36:02 EDT 2019

awk: make empty FS unicodely-correct.

--- a/sys/src/cmd/awk/lib.c
+++ b/sys/src/cmd/awk/lib.c
@@ -249,7 +249,7 @@
 	/* the fields are all stored in this one array with \0's */
 	char *r, *fr, sep;
 	Cell *p;
-	int i, j, n;
+	int i, j, n, w;
 
 	if (donefld)
 		return;
@@ -287,15 +287,18 @@
 		}
 		*fr = 0;
 	} else if ((sep = *inputFS) == 0) {		/* new: FS="" => 1 char/field */
-		for (i = 0; *r != 0; r++) {
-			char buf[2];
+		for (i = 0; *r != 0; r += w) {
+			char buf[UTFmax + 1];
+			Rune chr;
+
 			i++;
 			if (i > nfields)
 				growfldtab(i);
 			if (freeable(fldtab[i]))
 				xfree(fldtab[i]->sval);
-			buf[0] = *r;
-			buf[1] = 0;
+			w = chartorune(&chr, r);
+			n = runetochar(buf, &chr);
+			buf[n] = 0;
 			fldtab[i]->sval = tostring(buf);
 			fldtab[i]->tval = FLD | STR;
 		}