aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@swtch.com>2020-01-14 16:38:34 -0500
committerRuss Cox <rsc@swtch.com>2020-01-14 16:49:43 -0500
commitd28913a9e6609fef96f5baf6e9f4d5055ede744c (patch)
tree40bd3e0d2cb17315cf190796d3e9b6d6653f2809 /src
parenta0691bc460cbef889d017a640034f3321bd36b9d (diff)
downloadplan9port-d28913a9e6609fef96f5baf6e9f4d5055ede744c.tar.gz
plan9port-d28913a9e6609fef96f5baf6e9f4d5055ede744c.tar.bz2
plan9port-d28913a9e6609fef96f5baf6e9f4d5055ede744c.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/cmd/acme/rows.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/cmd/acme/rows.c b/src/cmd/acme/rows.c
index 83c64594..7a64fabf 100644
--- a/src/cmd/acme/rows.c
+++ b/src/cmd/acme/rows.c
@@ -316,7 +316,7 @@ rowclean(Row *row)
void
rowdump(Row *row, char *file)
{
- int i, j, fd, m, n, dumped;
+ int i, j, fd, m, n, start, dumped;
uint q0, q1;
Biobuf *b;
char *buf, *a, *fontname;
@@ -434,9 +434,17 @@ rowdump(Row *row, char *file)
m = min(RBUFSIZE, w->tag.file->b.nc);
bufread(&w->tag.file->b, 0, r, m);
n = 0;
- while(n<m && r[n]!='\n')
- n++;
- Bprint(b, "%.*S\n", n, r);
+ while(n<m) {
+ start = n;
+ 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){
q0 = 0;
q1 = t->file->b.nc;
@@ -719,6 +727,10 @@ rowload(Row *row, char *file, int initing)
if(l == nil)
goto Rescue2;
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);
ns = -1;
for(n=0; n<nr; n++){