acme: correct writes of runes on auspicious byte boundaries

R=rsc, r
CC=plan9port.codebot
http://codereview.appspot.com/6586067
This commit is contained in:
Erik Quanstrom 2012-10-05 16:42:25 -04:00 committed by Russ Cox
parent ca9ae08876
commit 5b6028903d
2 changed files with 35 additions and 23 deletions

View file

@ -17,6 +17,7 @@ David Jeannot <djeannot24@gmail.com>
David Swasey <david.swasey@gmail.com>
Enrique Soriano <enrique.soriano@gmail.com>
Eoghan Sherry <ejsherry@gmail.com>
Erik Quanstrom <quanstro@quanstro.net>
Fazlul Shahriar <fshahriar@gmail.com>
Ingo Dreilich <yngoto@gmail.com>
Justin Davis <jrcd83@gmail.com>

View file

@ -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){