Show lines with a single helper function, not one byte at a time

Let's see how hard it is to show UTF-8 characters properly.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
diff --git a/display.c b/display.c
index 77e05a4..e6d9a41 100644
--- a/display.c
+++ b/display.c
@@ -432,6 +432,13 @@
 	return TRUE;
 }
 
+static void show_line(struct line *lp)
+{
+	int i;
+	for (i = 0; i < llength(lp); ++i)
+		vtputc(lgetc(lp, i));
+}
+
 /*
  * updone:
  *	update the current line	to the virtual screen
@@ -442,7 +449,6 @@
 {
 	struct line *lp;	/* line to update */
 	int sline;	/* physical screen line to update */
-	int i;
 
 	/* search down the line we want */
 	lp = wp->w_linep;
@@ -456,8 +462,7 @@
 	vscreen[sline]->v_flag |= VFCHG;
 	vscreen[sline]->v_flag &= ~VFREQ;
 	vtmove(sline, 0);
-	for (i = 0; i < llength(lp); ++i)
-		vtputc(lgetc(lp, i));
+	show_line(lp);
 #if	COLOR
 	vscreen[sline]->v_rfcolor = wp->w_fcolor;
 	vscreen[sline]->v_rbcolor = wp->w_bcolor;
@@ -475,7 +480,6 @@
 {
 	struct line *lp;	/* line to update */
 	int sline;	/* physical screen line to update */
-	int i;
 
 	/* search down the lines, updating them */
 	lp = wp->w_linep;
@@ -488,8 +492,7 @@
 		vtmove(sline, 0);
 		if (lp != wp->w_bufp->b_linep) {
 			/* if we are not at the end */
-			for (i = 0; i < llength(lp); ++i)
-				vtputc(lgetc(lp, i));
+			show_line(lp);
 			lp = lforw(lp);
 		}
 
@@ -554,7 +557,7 @@
 {
 	struct window *wp;
 	struct line *lp;
-	int i, j;
+	int i;
 
 	wp = wheadp;
 
@@ -567,8 +570,7 @@
 				if ((wp != curwp) || (lp != wp->w_dotp) ||
 				    (curcol < term.t_ncol - 1)) {
 					vtmove(i, 0);
-					for (j = 0; j < llength(lp); ++j)
-						vtputc(lgetc(lp, j));
+					show_line(lp);
 					vteeol();
 
 					/* this line no longer is extended */
@@ -833,7 +835,6 @@
 {
 	int rcursor;	/* real cursor location */
 	struct line *lp;	/* pointer to current line */
-	int j;		/* index into line */
 
 	/* calculate what column the real cursor will end up in */
 	rcursor = ((curcol - term.t_ncol) % term.t_scrsiz) + term.t_margin;
@@ -843,8 +844,7 @@
 	/* once we reach the left edge                                  */
 	vtmove(currow, -lbound);	/* start scanning offscreen */
 	lp = curwp->w_dotp;	/* line to output */
-	for (j = 0; j < llength(lp); ++j)	/* until the end-of-line */
-		vtputc(lgetc(lp, j));
+	show_line(lp);
 
 	/* truncate the virtual line, restore tab offset */
 	vteeol();
diff --git a/emacs.rc b/emacs.rc
index 06c0f12..6f99f7b 100644
--- a/emacs.rc
+++ b/emacs.rc
@@ -286,4 +286,9 @@
 	add-global-mode "utf-8"
 !endif
 
+!if &gre &sin $LANG "utf8" 0
+	add-global-mode "utf-8"
+!endif
+add-global-mode "utf-8"
+
 set $discmd "TRUE"