mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-12 11:10:07 +00:00
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.
This commit is contained in:
parent
3850e6e177
commit
95220bf887
2 changed files with 42 additions and 11 deletions
|
@ -441,10 +441,18 @@ a backspace as
|
||||||
.LR \eb ,
|
.LR \eb ,
|
||||||
backslashes as
|
backslashes as
|
||||||
.LR \e\e ,
|
.LR \e\e ,
|
||||||
and non-printing characters as
|
and non-printing ASCII characters as
|
||||||
a backslash, an
|
a backslash, an
|
||||||
.LR x ,
|
.LR x ,
|
||||||
and four hexadecimal digits.
|
and two hexadecimal digits.
|
||||||
|
non-ASCII characters in the Basic Multilingual Plane
|
||||||
|
are printed as a backslash, a small
|
||||||
|
.LR u ,
|
||||||
|
and four hexadecimal digits; and characters above the
|
||||||
|
Basic Multilingual Plane are printed as a backslash,
|
||||||
|
a big
|
||||||
|
.LR U ,
|
||||||
|
and six hexadecimal digits.
|
||||||
Long lines are folded,
|
Long lines are folded,
|
||||||
with the second and subsequent sub-lines indented one tab stop.
|
with the second and subsequent sub-lines indented one tab stop.
|
||||||
If the last character in the line is a blank,
|
If the last character in the line is a blank,
|
||||||
|
|
41
src/cmd/ed.c
41
src/cmd/ed.c
|
@ -21,6 +21,12 @@ enum
|
||||||
EOF = -1
|
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 (*oldhup)(int);
|
||||||
void (*oldquit)(int);
|
void (*oldquit)(int);
|
||||||
int* addr1;
|
int* addr1;
|
||||||
|
@ -40,7 +46,7 @@ int ichanged;
|
||||||
int io;
|
int io;
|
||||||
Biobuf iobuf;
|
Biobuf iobuf;
|
||||||
int lastc;
|
int lastc;
|
||||||
char line[70];
|
char line[LINELEN];
|
||||||
Rune* linebp;
|
Rune* linebp;
|
||||||
Rune linebuf[LBSIZE];
|
Rune linebuf[LBSIZE];
|
||||||
int listf;
|
int listf;
|
||||||
|
@ -1543,7 +1549,7 @@ putchr(int ac)
|
||||||
*lp++ = 'n';
|
*lp++ = 'n';
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if(col > (72-6-2)) {
|
if(col > (LINELEN-BELL)) {
|
||||||
col = 8;
|
col = 8;
|
||||||
*lp++ = '\\';
|
*lp++ = '\\';
|
||||||
*lp++ = '\n';
|
*lp++ = '\n';
|
||||||
|
@ -1558,15 +1564,32 @@ putchr(int ac)
|
||||||
if(c == '\t')
|
if(c == '\t')
|
||||||
c = 't';
|
c = 't';
|
||||||
col++;
|
col++;
|
||||||
} else
|
} else if (c<' ' || c=='\177') {
|
||||||
if(c<' ' || c>='\177') {
|
|
||||||
*lp++ = '\\';
|
*lp++ = '\\';
|
||||||
*lp++ = 'x';
|
*lp++ = 'x';
|
||||||
*lp++ = hex[c>>12];
|
*lp++ = hex[(c>>4)&0xF];
|
||||||
*lp++ = hex[c>>8&0xF];
|
c = hex[c&0xF];
|
||||||
*lp++ = hex[c>>4&0xF];
|
col += 3;
|
||||||
c = hex[c&0xF];
|
} 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;
|
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;
|
rune = c;
|
||||||
lp += runetochar(lp, &rune);
|
lp += runetochar(lp, &rune);
|
||||||
|
|
||||||
if(c == '\n' || lp >= &line[sizeof(line)-5]) {
|
if(c == '\n' || lp >= &line[LINELEN-BELL]) {
|
||||||
linp = line;
|
linp = line;
|
||||||
write(oflag? 2: 1, line, lp-line);
|
write(oflag? 2: 1, line, lp-line);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue