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>
This commit is contained in:
Linus Torvalds 2012-07-10 13:38:41 -07:00
parent 1d0cfd0276
commit 2dddd4f970
2 changed files with 17 additions and 12 deletions

View File

@ -432,6 +432,13 @@ static int reframe(struct window *wp)
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 @@ static void updone(struct window *wp)
{
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 @@ static void updone(struct window *wp)
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 @@ static void updall(struct window *wp)
{
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 @@ static void updall(struct window *wp)
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 @@ void upddex(void)
{
struct window *wp;
struct line *lp;
int i, j;
int i;
wp = wheadp;
@ -567,8 +570,7 @@ void upddex(void)
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 @@ static void updext(void)
{
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 @@ static void updext(void)
/* 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();

View File

@ -286,4 +286,9 @@ bind-to-key newline ^J
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"