From b6ad189598d2ef38baa13df55d507dae1d2e6cd7 Mon Sep 17 00:00:00 2001 From: skimo Date: Wed, 19 Jul 2000 17:05:17 +0000 Subject: [PATCH] Temporarily ntroduce KEY_COL, which basically means the same as KEY_LEN, but can also be used when displaying wide chars. Display "[]" instead of wide chars on curses for now. --- cl/cl_funcs.c | 4 ++-- common/conv.c | 27 +++++++++++++++++++++++---- common/conv.h | 7 +++++++ common/key.c | 8 ++++++-- common/key.h | 6 +++++- gtk/gtkviscreen.c | 29 ++++++++++++++++++++--------- vi/vs_line.c | 16 ++++++++++------ vi/vs_refresh.c | 14 +++++++------- vi/vs_relative.c | 6 +++--- 9 files changed, 83 insertions(+), 34 deletions(-) diff --git a/cl/cl_funcs.c b/cl/cl_funcs.c index 7811939c..e5c7ab69 100644 --- a/cl/cl_funcs.c +++ b/cl/cl_funcs.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: cl_funcs.c,v 10.60 2000/07/14 14:29:14 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:14 $"; +static const char sccsid[] = "$Id: cl_funcs.c,v 10.61 2000/07/19 17:05:17 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:17 $"; #endif /* not lint */ #include @@ -48,7 +48,7 @@ cl_waddstr(sp, str, len) CONST char *np; size_t nlen; - INT2CHAR(sp, str, len, np, nlen); + INT2DISP(sp, str, len, np, nlen); cl_addstr(sp, np, nlen); } diff --git a/common/conv.c b/common/conv.c index f9c0972e..dd77f6d8 100644 --- a/common/conv.c +++ b/common/conv.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: conv.c,v 1.1 2000/07/18 19:18:43 skimo Exp $ (Berkeley) $Date: 2000/07/18 19:18:43 $"; +static const char sccsid[] = "$Id: conv.c,v 1.2 2000/07/19 17:05:17 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:17 $"; #endif /* not lint */ #include @@ -47,7 +47,7 @@ default_int2char(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size { int i; - BINC_RET(NULL, conv->buffer, conv->size, len * 2); + BINC_RET(NULL, conv->buffer, conv->size, len); *tostr = conv->buffer; *tolen = len; @@ -58,6 +58,25 @@ default_int2char(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size } int +default_int2disp(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size_t *tolen) +{ + int i, j; + + BINC_RET(NULL, conv->buffer, conv->size, len * 2); + *tostr = conv->buffer; + + for (i = 0, j = 0; i < len; ++i) + if (CHAR_WIDTH(NULL, str[i]) > 1) { + (*tostr)[j++] = '['; + (*tostr)[j++] = ']'; + } else + (*tostr)[j++] = str[i]; + *tolen = j; + + return 0; +} + +int gb2int(CONV *conv, const char * str, ssize_t len, CHAR_T **tostr, size_t *tolen) { int i, j; @@ -103,9 +122,9 @@ int2gb(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size_t *tolen) } CONV default_conv = { 0, 0, default_char2int, default_int2char, - default_char2int, default_int2char }; + default_char2int, default_int2char, default_int2disp }; CONV gb_conv = { 0, 0, default_char2int, default_int2char, - gb2int, int2gb }; + gb2int, int2gb, default_int2disp }; void conv_init (SCR *sp) diff --git a/common/conv.h b/common/conv.h index 9eb08a64..311ad4e8 100644 --- a/common/conv.h +++ b/common/conv.h @@ -1,3 +1,9 @@ +/* temporary assumption */ +#define CHAR_WIDTH(sp, ch) \ + ((UCHAR_T)(ch) > 255) ? 2 : 1 +#define KEY_COL(sp, ch) \ + (CHAR_WIDTH(sp, ch) > 1 ? CHAR_WIDTH(sp, ch) : KEY_LEN(sp,ch)) + #define F_GB 'A' #define INT9494(f,r,c) ((f) << 16) | ((r) << 8) | (c) @@ -15,4 +21,5 @@ struct _conv { int (*int2char) (struct _conv*, const CHAR_T *, ssize_t, char **, size_t *); int (*file2int) (struct _conv*, const char *, ssize_t, CHAR_T **, size_t *); int (*int2file) (struct _conv*, const CHAR_T *, ssize_t, char **, size_t *); + int (*int2disp) (struct _conv*, const CHAR_T *, ssize_t, char **, size_t *); }; diff --git a/common/key.c b/common/key.c index 72a4aa21..a01ffbdd 100644 --- a/common/key.c +++ b/common/key.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: key.c,v 10.44 2000/07/17 21:17:52 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:52 $"; +static const char sccsid[] = "$Id: key.c,v 10.45 2000/07/19 17:05:18 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:18 $"; #endif /* not lint */ #include @@ -309,7 +309,11 @@ nopr: if (ISCNTRL(ch) && (ch < 0x20 || ch == 0x7f)) { sp->cname[0] = '\\'; sp->cname[1] = 'x'; for (len = 2, chp = (u_int8_t *)&ch, - cnt = sizeof(CHAR_T); cnt-- > 0; ++chp) { + /* sizeof(CHAR_T) conflict with MAX_CHARACTER_COLUMNS + * and code depends on big endian + * and might not be needed in the long run + */ + cnt = /*sizeof(CHAR_T)*/1; cnt-- > 0; ++chp) { sp->cname[len++] = hexdigit[(*chp & 0xf0) >> 4]; sp->cname[len++] = hexdigit[*chp & 0x0f]; } diff --git a/common/key.h b/common/key.h index d977e713..74764b6f 100644 --- a/common/key.h +++ b/common/key.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: key.h,v 10.28 2000/07/17 21:17:52 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:52 $ + * $Id: key.h,v 10.29 2000/07/19 17:05:18 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:18 $ */ #include "multibyte.h" @@ -37,6 +37,8 @@ typedef u_int ARG_CHAR_T; sp->conv->char2int(sp->conv, n, nlen, &w, &wlen) #define INT2CHAR(sp,w,wlen,n,nlen) \ sp->conv->int2char(sp->conv, w, wlen, &n, &nlen) +#define INT2DISP(sp,w,wlen,n,nlen) \ + sp->conv->int2disp(sp->conv, w, wlen, &n, &nlen) #define CONST #else #define FILE2INT(sp,n,nlen,w,wlen) \ @@ -47,6 +49,8 @@ typedef u_int ARG_CHAR_T; w = n, wlen = nlen #define INT2CHAR(sp,w,wlen,n,nlen) \ n = w, nlen = wlen +#define INT2DISP(sp,w,wlen,n,nlen) \ + n = w, nlen = wlen #define CONST const #endif diff --git a/gtk/gtkviscreen.c b/gtk/gtkviscreen.c index b82acfef..4788cf71 100644 --- a/gtk/gtkviscreen.c +++ b/gtk/gtkviscreen.c @@ -80,8 +80,15 @@ gtk_vi_screen_attribute(GtkViScreen *vi, gint attribute, gint on) void gtk_vi_screen_move(GtkViScreen *vi, gint row, gint col) { + gint x, xpos; + CHAR_T *line; + mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx+1); - vi->curx = col; + line = vi->chars + row*vi->cols; + for (x = 0, xpos = 0; xpos <= col; ++x) + xpos += INTIS9494(*(line+x)) ? 2 : 1; + xpos -= INTIS9494(*(line+--x)) ? 2 : 1; + vi->curx = x; vi->cury = row; mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx+1); } @@ -253,7 +260,7 @@ gtk_vi_screen_class_init (GtkViScreenClass *class) class->rename = NULL; class->resized = NULL; - gb_font = gdk_font_load ("-*-*-*-*-*-*-24-*-*-*-*-*-gb2312.1980-*"); + gb_font = gdk_font_load ("-*-*-*-*-*-*-12-*-*-*-*-*-gb2312.1980-*"); } static void @@ -611,7 +618,7 @@ expose_text (GtkViScreen* vi, GdkRectangle *area, gboolean cursor) static void draw_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xmax) { - gint y, x, len; + gint y, x, len, blen, xpos; CHAR_T *line; GdkGC *fg, *bg; GdkFont *font; @@ -620,7 +627,10 @@ draw_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xmax) for (y = ymin, line = vi->chars + y*vi->cols; y < ymax; ++y, line += vi->cols) { - for (x = xmin; x < xmax; x+=len) { + for (x = 0, xpos = 0; xpos <= xmin; ++x) + xpos += INTIS9494(*(line+x)) ? 2 : 1; + xpos -= INTIS9494(*(line+--x)) ? 2 : 1; + for (; xpos < xmax; x+=len, xpos+= blen) { gchar inverse; inverse = Inverse(vi,y,x); len = 1; @@ -639,7 +649,7 @@ draw_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xmax) buf[0] = INT9494R(*(line+x)); buf[1] = INT9494C(*(line+x)); p = buf; - len = 2; + blen = 2; } else { font = GTK_WIDGET(vi)->style->font; if (sizeof(CHAR_T) == sizeof(gchar)) @@ -648,14 +658,15 @@ draw_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xmax) buf[0] = *(line+x); p = buf; } + blen = len; } - gdk_draw_rectangle(vi->text_area, bg, 1, x * vi->ch_width, - y * vi->ch_height, len * vi->ch_width, + gdk_draw_rectangle(vi->text_area, bg, 1, xpos * vi->ch_width, + y * vi->ch_height, blen * vi->ch_width, vi->ch_height); gdk_draw_text (vi->text_area, font, fg, - x * vi->ch_width, + xpos * vi->ch_width, y * vi->ch_height + vi->ch_ascent, - p, len); + p, blen); } } } diff --git a/vi/vs_line.c b/vi/vs_line.c index 1ee7353c..9bf6f218 100644 --- a/vi/vs_line.c +++ b/vi/vs_line.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: vs_line.c,v 10.24 2000/07/17 21:17:55 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:55 $"; +static const char sccsid[] = "$Id: vs_line.c,v 10.25 2000/07/19 17:05:19 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:19 $"; #endif /* not lint */ #include @@ -259,7 +259,7 @@ empty: (void)gp->scr_addstr(sp, if (O_ISSET(sp, O_LEFTRIGHT)) { for (; offset_in_line < len; ++offset_in_line) { chlen = (ch = *(u_char *)p++) == '\t' && !list_tab ? - TAB_OFF(scno) : KEY_LEN(sp, ch); + TAB_OFF(scno) : KEY_COL(sp, ch); if ((scno += chlen) >= skip_cols) break; } @@ -283,7 +283,7 @@ empty: (void)gp->scr_addstr(sp, else { for (; offset_in_line < len; ++offset_in_line) { chlen = (ch = *(u_char *)p++) == '\t' && !list_tab ? - TAB_OFF(scno) : KEY_LEN(sp, ch); + TAB_OFF(scno) : KEY_COL(sp, ch); if ((scno += chlen) < cols_per_screen) continue; scno -= cols_per_screen; @@ -336,7 +336,7 @@ display: scno += chlen = TAB_OFF(scno) - offset_in_char; is_tab = 1; } else { - scno += chlen = KEY_LEN(sp, ch) - offset_in_char; + scno += chlen = KEY_COL(sp, ch) - offset_in_char; is_tab = 0; } @@ -416,8 +416,12 @@ display: else { if (cbp + chlen >= ecbp) FLUSH; - for (kp = KEY_NAME(sp, ch) + offset_in_char; chlen--;) - *cbp++ = *kp++; + if (CHAR_WIDTH(sp, ch) > 1) + *cbp++ = ch; + else + for (kp = KEY_NAME(sp, ch) + offset_in_char; + chlen--;) + *cbp++ = *kp++; } } diff --git a/vi/vs_refresh.c b/vi/vs_refresh.c index eb14a96d..16df93cd 100644 --- a/vi/vs_refresh.c +++ b/vi/vs_refresh.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: vs_refresh.c,v 10.48 2000/06/27 17:19:08 skimo Exp $ (Berkeley) $Date: 2000/06/27 17:19:08 $"; +static const char sccsid[] = "$Id: vs_refresh.c,v 10.49 2000/07/19 17:05:20 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:20 $"; #endif /* not lint */ #include @@ -485,8 +485,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) && * Count up the widths of the characters. If it's a tab * character, go do it the the slow way. */ - for (cwtotal = 0; cnt--; cwtotal += KEY_LEN(sp, ch)) - if ((ch = *(u_char *)p--) == '\t') + for (cwtotal = 0; cnt--; cwtotal += KEY_COL(sp, ch)) + if ((ch = *(UCHAR_T *)p--) == '\t') goto slow; /* @@ -499,8 +499,8 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) && * If we're moving left, and there's a wide character in the * current position, go to the end of the character. */ - if (KEY_LEN(sp, ch) > 1) - cwtotal -= KEY_LEN(sp, ch) - 1; + if (KEY_COL(sp, ch) > 1) + cwtotal -= KEY_COL(sp, ch) - 1; /* * If the new column moved us off of the current logical line, @@ -525,9 +525,9 @@ adjust: if (!O_ISSET(sp, O_LEFTRIGHT) && * screen boundary, we can quit. */ for (cwtotal = SCNO; cnt--;) { - if ((ch = *(u_char *)p++) == '\t') + if ((ch = *(UCHAR_T *)p++) == '\t') goto slow; - if ((cwtotal += KEY_LEN(sp, ch)) >= SCREEN_COLS(sp)) + if ((cwtotal += KEY_COL(sp, ch)) >= SCREEN_COLS(sp)) break; } diff --git a/vi/vs_relative.c b/vi/vs_relative.c index 2492b2ca..0e75bb1c 100644 --- a/vi/vs_relative.c +++ b/vi/vs_relative.c @@ -10,7 +10,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: vs_relative.c,v 10.15 2000/06/27 17:19:09 skimo Exp $ (Berkeley) $Date: 2000/06/27 17:19:09 $"; +static const char sccsid[] = "$Id: vs_relative.c,v 10.16 2000/07/19 17:05:20 skimo Exp $ (Berkeley) $Date: 2000/07/19 17:05:20 $"; #endif /* not lint */ #include @@ -141,8 +141,8 @@ done: if (diffp != NULL) /* XXX */ scno += O_NUMBER_LENGTH; /* Macro to return the display length of any signal character. */ -#define CHLEN(val) (ch = *(u_char *)p++) == '\t' && \ - !listset ? TAB_OFF(val) : KEY_LEN(sp, ch); +#define CHLEN(val) (ch = *(UCHAR_T *)p++) == '\t' && \ + !listset ? TAB_OFF(val) : KEY_COL(sp, ch); /* * If folding screens (the historic vi screen format), past the end -- 2.11.4.GIT