diff options
author | Erik Quanstrom <quanstro@quanstro.net> | 2012-10-05 16:42:25 -0400 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2012-10-05 16:42:25 -0400 |
commit | 5b6028903dc9a0d1561a54764a520aaa1b1100e4 (patch) | |
tree | 8265b7232abd9cb99bd89945bce43124f011a782 /src | |
parent | ca9ae08876bc9ce2107fac50cf703760ecf10901 (diff) | |
download | plan9port-5b6028903dc9a0d1561a54764a520aaa1b1100e4.tar.gz plan9port-5b6028903dc9a0d1561a54764a520aaa1b1100e4.tar.bz2 plan9port-5b6028903dc9a0d1561a54764a520aaa1b1100e4.zip |
acme: correct writes of runes on auspicious byte boundaries
R=rsc, r
CC=plan9port.codebot
http://codereview.appspot.com/6586067
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/acme/xfid.c | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/src/cmd/acme/xfid.c b/src/cmd/acme/xfid.c index a1cc3848..671b324f 100644 --- a/src/cmd/acme/xfid.c +++ b/src/cmd/acme/xfid.c @@ -403,11 +403,42 @@ shouldscroll(Text *t, uint q0, int qid) return t->org <= q0 && q0 <= t->org+t->fr.nchars; } +static Rune* +fullrunewrite(Xfid *x, int *inr) +{ + int q, cnt, c, nb, nr; + Rune *r; + + q = x->f->nrpart; + cnt = x->fcall.count; + if(q > 0){ + memmove(x->fcall.data+q, x->fcall.data, cnt); /* there's room; see fsysproc */ + memmove(x->fcall.data, x->f->rpart, q); + cnt += q; + x->f->nrpart = 0; + } + r = runemalloc(cnt); + cvttorunes(x->fcall.data, cnt-UTFmax, r, &nb, &nr, nil); + /* approach end of buffer */ + while(fullrune(x->fcall.data+nb, cnt-nb)){ + c = nb; + nb += chartorune(&r[nr], x->fcall.data+c); + if(r[nr]) + nr++; + } + if(nb < cnt){ + memmove(x->f->rpart, x->fcall.data+nb, cnt-nb); + x->f->nrpart = cnt-nb; + } + *inr = nr; + return r; +} + void xfidwrite(Xfid *x) { Fcall fc; - int c, cnt, qid, q, nb, nr, eval; + int c, qid, nb, nr, eval; char buf[64], *err; Window *w; Rune *r; @@ -463,7 +494,7 @@ xfidwrite(Xfid *x) case Qeditout: case QWeditout: - r = bytetorune(x->fcall.data, &nr); + r = fullrunewrite(x, &nr); if(w) err = edittext(w, w->wrselrange.q1, r, nr); else @@ -538,27 +569,7 @@ xfidwrite(Xfid *x) goto BodyTag; BodyTag: - q = x->f->nrpart; - cnt = x->fcall.count; - if(q > 0){ - memmove(x->fcall.data+q, x->fcall.data, cnt); /* there's room; see fsysproc */ - memmove(x->fcall.data, x->f->rpart, q); - cnt += q; - x->f->nrpart = 0; - } - r = runemalloc(cnt); - cvttorunes(x->fcall.data, cnt-UTFmax, r, &nb, &nr, nil); - /* approach end of buffer */ - while(fullrune(x->fcall.data+nb, cnt-nb)){ - c = nb; - nb += chartorune(&r[nr], x->fcall.data+c); - if(r[nr]) - nr++; - } - if(nb < cnt){ - memmove(x->f->rpart, x->fcall.data+nb, cnt-nb); - x->f->nrpart = cnt-nb; - } + r = fullrunewrite(x, &nr); if(nr > 0){ wincommit(w, t); if(qid == QWwrsel){ |