Skip to content

Commit 69a3a10

Browse files
author
Álvaro Jurado
committed
awk: split record into runes for empty FS
source: 9fans/plan9port@c9e157b author: fhs Signed-off-by: Álvaro Jurado <elbingmiss@gmail.com>
1 parent 8469c38 commit 69a3a10

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/cmd/awk/lib.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ THIS SOFTWARE.
2929
#include <errno.h>
3030
#include <stdlib.h>
3131
#include <stdarg.h>
32+
#include <utf.h>
3233
#include "awk.h"
3334
#include "ytab.h"
3435

@@ -306,15 +307,18 @@ void fldbld(void) /* create fields from current record */
306307
}
307308
*fr = 0;
308309
} else if ((sep = *inputFS) == 0) { /* new: FS="" => 1 char/field */
309-
for (i = 0; *r != 0; r++) {
310-
char buf[2];
310+
int nb;
311+
for (i = 0; *r != 0; r += nb) {
312+
Rune rr;
313+
char buf[UTFmax+1];
311314
i++;
312315
if (i > nfields)
313316
growfldtab(i);
314317
if (freeable(fldtab[i]))
315318
xfree(fldtab[i]->sval);
316-
buf[0] = *r;
317-
buf[1] = 0;
319+
nb = chartorune(&rr, r);
320+
memmove(buf, r, nb);
321+
buf[nb] = '\0';
318322
fldtab[i]->sval = tostring(buf);
319323
fldtab[i]->tval = FLD | STR;
320324
}

0 commit comments

Comments
 (0)