aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorsean <phonologus@gmail.com>2020-05-21 16:10:30 +0100
committerRuss Cox <rsc@swtch.com>2020-05-29 21:42:23 -0400
commit95220bf88775deab4a037264d08b21bacc612d70 (patch)
treeb59a298f557139643dc27050723a67e587e9681b /src/cmd
parent3850e6e177677885074c8896ef24534894726ad5 (diff)
downloadplan9port-95220bf88775deab4a037264d08b21bacc612d70.tar.gz
plan9port-95220bf88775deab4a037264d08b21bacc612d70.tar.bz2
plan9port-95220bf88775deab4a037264d08b21bacc612d70.zip
ed: handle Unicode beyond the BMP correctly in list mode.
List mode was constrained to the BMP. This change introduces the following new list mode convention, using Go string literal syntax: Non-printing ASCII characters display as \xhh. Non-ASCII characters in the BMP display as \uhhhh. Characters beyond the BMP display as \Uhhhhhhhh.
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/ed.c41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/cmd/ed.c b/src/cmd/ed.c
index 8b0f36e5..a04f0d3f 100644
--- a/src/cmd/ed.c
+++ b/src/cmd/ed.c
@@ -21,6 +21,12 @@ enum
EOF = -1
};
+enum
+{
+ LINELEN = 70, /* max number of glyphs in a display line */
+ BELL = 6 /* A char could require up to BELL glyphs to display */
+};
+
void (*oldhup)(int);
void (*oldquit)(int);
int* addr1;
@@ -40,7 +46,7 @@ int ichanged;
int io;
Biobuf iobuf;
int lastc;
-char line[70];
+char line[LINELEN];
Rune* linebp;
Rune linebuf[LBSIZE];
int listf;
@@ -1543,7 +1549,7 @@ putchr(int ac)
*lp++ = 'n';
}
} else {
- if(col > (72-6-2)) {
+ if(col > (LINELEN-BELL)) {
col = 8;
*lp++ = '\\';
*lp++ = '\n';
@@ -1558,15 +1564,32 @@ putchr(int ac)
if(c == '\t')
c = 't';
col++;
- } else
- if(c<' ' || c>='\177') {
+ } else if (c<' ' || c=='\177') {
*lp++ = '\\';
*lp++ = 'x';
- *lp++ = hex[c>>12];
- *lp++ = hex[c>>8&0xF];
- *lp++ = hex[c>>4&0xF];
- c = hex[c&0xF];
+ *lp++ = hex[(c>>4)&0xF];
+ c = hex[c&0xF];
+ col += 3;
+ } else if (c>'\177' && c<=0xFFFF) {
+ *lp++ = '\\';
+ *lp++ = 'u';
+ *lp++ = hex[(c>>12)&0xF];
+ *lp++ = hex[(c>>8)&0xF];
+ *lp++ = hex[(c>>4)&0xF];
+ c = hex[c&0xF];
col += 5;
+ } else if (c>0xFFFF) {
+ *lp++ = '\\';
+ *lp++ = 'U';
+ *lp++ = hex[(c>>28)&0xF];
+ *lp++ = hex[(c>>24)&0xF];
+ *lp++ = hex[(c>>20)&0xF];
+ *lp++ = hex[(c>>16)&0xF];
+ *lp++ = hex[(c>>12)&0xF];
+ *lp++ = hex[(c>>8)&0xF];
+ *lp++ = hex[(c>>4)&0xF];
+ c = hex[c&0xF];
+ col += 9;
}
}
}
@@ -1574,7 +1597,7 @@ putchr(int ac)
rune = c;
lp += runetochar(lp, &rune);
- if(c == '\n' || lp >= &line[sizeof(line)-5]) {
+ if(c == '\n' || lp >= &line[LINELEN-BELL]) {
linp = line;
write(oflag? 2: 1, line, lp-line);
return;