mirror of
https://github.com/9fans/plan9port.git
synced 2025-01-24 11:41:58 +00:00
acme: save/restore multiline tags in Dump/Load
The dump substitutes each \n in a multiline tag with a 0xff byte. Since it is not valid UTF it cannot occur in an ordinary dump file. Old acmes will just read it in as an error rune. Fixes #135. Fixes #153.
This commit is contained in:
parent
a0691bc460
commit
d28913a9e6
1 changed files with 16 additions and 4 deletions
|
@ -316,7 +316,7 @@ rowclean(Row *row)
|
||||||
void
|
void
|
||||||
rowdump(Row *row, char *file)
|
rowdump(Row *row, char *file)
|
||||||
{
|
{
|
||||||
int i, j, fd, m, n, dumped;
|
int i, j, fd, m, n, start, dumped;
|
||||||
uint q0, q1;
|
uint q0, q1;
|
||||||
Biobuf *b;
|
Biobuf *b;
|
||||||
char *buf, *a, *fontname;
|
char *buf, *a, *fontname;
|
||||||
|
@ -434,9 +434,17 @@ rowdump(Row *row, char *file)
|
||||||
m = min(RBUFSIZE, w->tag.file->b.nc);
|
m = min(RBUFSIZE, w->tag.file->b.nc);
|
||||||
bufread(&w->tag.file->b, 0, r, m);
|
bufread(&w->tag.file->b, 0, r, m);
|
||||||
n = 0;
|
n = 0;
|
||||||
while(n<m && r[n]!='\n')
|
while(n<m) {
|
||||||
n++;
|
start = n;
|
||||||
Bprint(b, "%.*S\n", n, r);
|
while(n<m && r[n]!='\n')
|
||||||
|
n++;
|
||||||
|
Bprint(b, "%.*S", n-start, r+start);
|
||||||
|
if(n<m) {
|
||||||
|
Bputc(b, 0xff); // \n in tag becomes 0xff byte (invalid UTF)
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Bprint(b, "\n");
|
||||||
if(dumped){
|
if(dumped){
|
||||||
q0 = 0;
|
q0 = 0;
|
||||||
q1 = t->file->b.nc;
|
q1 = t->file->b.nc;
|
||||||
|
@ -719,6 +727,10 @@ rowload(Row *row, char *file, int initing)
|
||||||
if(l == nil)
|
if(l == nil)
|
||||||
goto Rescue2;
|
goto Rescue2;
|
||||||
l[Blinelen(b)-1] = 0;
|
l[Blinelen(b)-1] = 0;
|
||||||
|
/* convert 0xff in multiline tag back to \n */
|
||||||
|
for(i = 0; l[i] != 0; i++)
|
||||||
|
if((uchar)l[i] == 0xff)
|
||||||
|
l[i] = '\n';
|
||||||
r = bytetorune(l+5*12, &nr);
|
r = bytetorune(l+5*12, &nr);
|
||||||
ns = -1;
|
ns = -1;
|
||||||
for(n=0; n<nr; n++){
|
for(n=0; n<nr; n++){
|
||||||
|
|
Loading…
Reference in a new issue