shithub: riscv

Download patch

ref: 98dd0aebef1c3bbc05750d534582392695f801f5
parent: 180e04ee41f988e707078620bae65d598c91314c
author: cinap_lenrek <[email protected]>
date: Fri Jan 25 11:45:04 EST 2013

acme: fix unicode handling for editout (from sources)

--- a/sys/src/cmd/acme/xfid.c
+++ b/sys/src/cmd/acme/xfid.c
@@ -260,7 +260,7 @@
 	int n, q;
 	uint off;
 	char *b;
-	char buf[128];
+	char buf[256];
 	Window *w;
 
 	q = FILE(x->f->qid);
@@ -369,11 +369,42 @@
 	winunlock(w);
 }
 
+static Rune*
+fullrunewrite(Xfid *x, int *inr)
+{
+	int q, cnt, c, nb, nr;
+	Rune *r;
+
+	q = x->f->nrpart;
+	cnt = x->count;
+	if(q > 0){
+		memmove(x->data+q, x->data, cnt);	/* there's room; see fsysproc */
+		memmove(x->data, x->f->rpart, q);
+		cnt += q;
+		x->f->nrpart = 0;
+	}
+	r = runemalloc(cnt);
+	cvttorunes(x->data, cnt-UTFmax, r, &nb, &nr, nil);
+	/* approach end of buffer */
+	while(fullrune(x->data+nb, cnt-nb)){
+		c = nb;
+		nb += chartorune(&r[nr], x->data+c);
+		if(r[nr])
+			nr++;
+	}
+	if(nb < cnt){
+		memmove(x->f->rpart, x->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;
@@ -429,7 +460,7 @@
 
 	case Qeditout:
 	case QWeditout:
-		r = bytetorune(x->data, &nr);
+		r = fullrunewrite(x, &nr);
 		if(w)
 			err = edittext(w, w->wrselrange.q1, r, nr);
 		else
@@ -504,27 +535,7 @@
 		goto BodyTag;
 
 	BodyTag:
-		q = x->f->nrpart;
-		cnt = x->count;
-		if(q > 0){
-			memmove(x->data+q, x->data, cnt);	/* there's room; see fsysproc */
-			memmove(x->data, x->f->rpart, q);
-			cnt += q;
-			x->f->nrpart = 0;
-		}
-		r = runemalloc(cnt);
-		cvttorunes(x->data, cnt-UTFmax, r, &nb, &nr, nil);
-		/* approach end of buffer */
-		while(fullrune(x->data+nb, cnt-nb)){
-			c = nb;
-			nb += chartorune(&r[nr], x->data+c);
-			if(r[nr])
-				nr++;
-		}
-		if(nb < cnt){
-			memmove(x->f->rpart, x->data+nb, cnt-nb);
-			x->f->nrpart = cnt-nb;
-		}
+		r = fullrunewrite(x, &nr);
 		if(nr > 0){
 			wincommit(w, t);
 			if(qid == QWwrsel){