From 6466b2e972a50573dee03f89820dd358d68e04cf Mon Sep 17 00:00:00 2001 From: skimo Date: Mon, 17 Jul 2000 21:17:52 +0000 Subject: [PATCH] Fix some places that were assuming unsigned CHAR_T. Some preparations for actually displaying the wide characters. --- common/gs.h | 6 ++-- common/key.c | 4 +-- common/key.h | 4 +-- common/multibyte.h | 5 ++++ gtk/gtkviscreen.c | 88 ++++++++++++++++++++++++++++++++++++++++++++---------- gtk/gtkviscreen.h | 6 +++- gtk/gtkviwindow.c | 19 ++++++++---- ip/ip_funcs.c | 19 ++++++++---- ipc/ip.h | 8 ++--- ipc/ipc_cmd.c | 6 ++-- regex/regerror.c | 4 +++ regex/regex2.h | 2 +- vi/vs_line.c | 12 ++++---- 13 files changed, 132 insertions(+), 51 deletions(-) diff --git a/common/gs.h b/common/gs.h index 59127e9e..f02f0060 100644 --- a/common/gs.h +++ b/common/gs.h @@ -6,7 +6,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: gs.h,v 10.47 2000/07/14 14:29:16 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:16 $ + * $Id: gs.h,v 10.48 2000/07/17 21:17:52 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:52 $ */ #define TEMPORARY_FILE_STRING "/tmp" /* Default temporary file name. */ @@ -106,10 +106,10 @@ struct _gs { #define MAX_FAST_KEY 255 /* Max fast check character.*/ #define KEY_LEN(sp, ch) \ - ((CHAR_T)(ch) <= MAX_FAST_KEY ? \ + ((UCHAR_T)(ch) <= MAX_FAST_KEY ? \ sp->gp->cname[(unsigned char)ch].len : v_key_len(sp, ch)) #define KEY_NAME(sp, ch) \ - ((CHAR_T)(ch) <= MAX_FAST_KEY ? \ + ((UCHAR_T)(ch) <= MAX_FAST_KEY ? \ sp->gp->cname[(unsigned char)ch].name : v_key_name(sp, ch)) struct { u_char name[MAX_CHARACTER_COLUMNS + 1]; diff --git a/common/key.c b/common/key.c index 91e82ebc..72a4aa21 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.43 2000/07/15 20:26:34 skimo Exp $ (Berkeley) $Date: 2000/07/15 20:26:34 $"; +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 $"; #endif /* not lint */ #include @@ -206,7 +206,7 @@ void v_key_ilookup(sp) SCR *sp; { - CHAR_T ch; + UCHAR_T ch; char *p, *t; GS *gp; size_t len; diff --git a/common/key.h b/common/key.h index 452e6792..d977e713 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.27 2000/07/17 18:53:34 skimo Exp $ (Berkeley) $Date: 2000/07/17 18:53:34 $ + * $Id: key.h,v 10.28 2000/07/17 21:17:52 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:52 $ */ #include "multibyte.h" @@ -149,7 +149,7 @@ struct _event { typedef struct _keylist { e_key_t value; /* Special value. */ - CHAR_T ch; /* Key. */ + UCHAR_T ch; /* Key. */ } KEYLIST; extern KEYLIST keylist[]; diff --git a/common/multibyte.h b/common/multibyte.h index 235a04cc..b327483c 100644 --- a/common/multibyte.h +++ b/common/multibyte.h @@ -3,10 +3,15 @@ #ifdef USE_WIDECHAR typedef int CHAR_T; #define CHAR_T_MAX ((1 << 24)-1) +typedef u_int UCHAR_T; #else typedef char CHAR_T; #define CHAR_T_MAX CHAR_MAX +typedef u_char UCHAR_T; #endif + #define MEMCMPW(to, from, n) \ memcmp(to, from, (n) * sizeof(CHAR_T)) +#define MEMMOVE(p, t, len) memmove(p, t, (len) * sizeof(*(p))) + #endif diff --git a/gtk/gtkviscreen.c b/gtk/gtkviscreen.c index 7c88017e..b82acfef 100644 --- a/gtk/gtkviscreen.c +++ b/gtk/gtkviscreen.c @@ -4,6 +4,7 @@ #include #include #include "gtkviscreen.h" +#include "../common/conv.h" #define DEFAULT_VI_SCREEN_WIDTH_CHARS 80 #define DEFAULT_VI_SCREEN_HEIGHT_LINES 25 @@ -55,6 +56,8 @@ static void mark_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xm static GtkWidgetClass *parent_class = NULL; static guint vi_screen_signals[LAST_SIGNAL] = { 0 }; +static GdkFont *gb_font; + #define CharAt(scr,y,x) scr->chars + (y) * scr->cols + x #define FlagAt(scr,y,x) (scr->reverse + (y) * scr->cols + x) @@ -83,10 +86,20 @@ gtk_vi_screen_move(GtkViScreen *vi, gint row, gint col) mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx+1); } +static void +cleartoel (GtkViScreen *vi, guint row, guint col) +{ + CHAR_T *p, *end; + + p = CharAt(vi,row,col); + end = p + vi->cols - col; + while (p < end) *p++ = ' '; +} + void gtk_vi_screen_clrtoel (GtkViScreen *vi) { - memset(CharAt(vi,vi->cury,vi->curx), ' ', vi->cols - vi->curx); + cleartoel(vi, vi->cury, vi->curx); memset(FlagAt(vi,vi->cury,vi->curx), COLOR_STANDARD, vi->cols - vi->curx); mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->cols); } @@ -94,10 +107,28 @@ gtk_vi_screen_clrtoel (GtkViScreen *vi) void gtk_vi_screen_addstr(GtkViScreen *vi, const char *str, int len) { - /* - fprintf(stderr, "%d --%.*s--\n", len, len, str); - */ - memcpy(CharAt(vi,vi->cury,vi->curx), str, len); + CHAR_T *p, *end; + + for (p = CharAt(vi,vi->cury,vi->curx), end = p + len; p < end; ) + *p++ = *str++; + memset(FlagAt(vi,vi->cury,vi->curx), vi->color, len); + mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx + len); + if ((vi->curx += len) >= vi->cols) { + if (++vi->cury >= vi->rows) { + vi->cury = vi->rows-1; + vi->curx = vi->cols-1; + } else { + vi->curx = 0; + } + } +} + +void +gtk_vi_screen_waddstr(GtkViScreen *vi, const CHAR_T *str, int len) +{ + CHAR_T *p, *end; + + MEMMOVE(CharAt(vi,vi->cury,vi->curx),str,len); memset(FlagAt(vi,vi->cury,vi->curx), vi->color, len); mark_lines(vi, vi->cury, vi->curx, vi->cury+1, vi->curx + len); if ((vi->curx += len) >= vi->cols) { @@ -116,8 +147,8 @@ gtk_vi_screen_deleteln(GtkViScreen *vi) gint y = vi->cury; gint rows = vi->rows - (y+1); - memmove(CharAt(vi,y,0), CharAt(vi,y+1,0), rows * vi->cols); - memset(CharAt(vi,vi->rows-1,0), ' ', vi->cols); + MEMMOVE(CharAt(vi,y,0), CharAt(vi,y+1,0), rows * vi->cols); + cleartoel(vi,vi->rows-1,0); memmove(FlagAt(vi,y,0), FlagAt(vi,y+1,0), rows * vi->cols); memset(FlagAt(vi,vi->rows-1,0), COLOR_STANDARD, vi->cols); mark_lines(vi, y, 0, vi->rows, vi->cols); @@ -129,8 +160,8 @@ gtk_vi_screen_insertln(GtkViScreen *vi) gint y = vi->cury; gint rows = vi->rows - (y+1); - memmove(CharAt(vi,y+1,0), CharAt(vi,y,0), rows * vi->cols); - memset(CharAt(vi,y,0), ' ', vi->cols); + MEMMOVE(CharAt(vi,y+1,0), CharAt(vi,y,0), rows * vi->cols); + cleartoel(vi,y,0); memmove(FlagAt(vi,y+1,0), FlagAt(vi,y,0), rows * vi->cols); memset(FlagAt(vi,y,0), COLOR_STANDARD, vi->cols); mark_lines(vi, y, 0, vi->rows, vi->cols); @@ -221,6 +252,8 @@ gtk_vi_screen_class_init (GtkViScreenClass *class) class->rename = NULL; class->resized = NULL; + + gb_font = gdk_font_load ("-*-*-*-*-*-*-24-*-*-*-*-*-gb2312.1980-*"); } static void @@ -526,6 +559,7 @@ recompute_geometry (GtkViScreen* vi) gint height; gint width; gint rows, cols; + gint i; //xthickness = widget->style->klass->xthickness + VI_SCREEN_BORDER_ROOM; //ythickness = widget->style->klass->ythickness + VI_SCREEN_BORDER_ROOM; @@ -544,8 +578,9 @@ recompute_geometry (GtkViScreen* vi) vi->marked_maxy = 0; g_free(vi->chars); - vi->chars = g_new(gchar, vi->rows*vi->cols); - memset(vi->chars, ' ', vi->rows*vi->cols); + vi->chars = (CHAR_T*)g_new(gchar, vi->rows*vi->cols * sizeof(CHAR_T)); + for (i = 0; i < vi->rows*vi->cols; ++i) + vi->chars[i] = ' '; g_free(vi->reverse); vi->reverse = g_new(gchar, vi->rows*vi->cols); memset(vi->reverse, 0, vi->rows*vi->cols); @@ -577,15 +612,21 @@ static void draw_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xmax) { gint y, x, len; - gchar *line; + CHAR_T *line; GdkGC *fg, *bg; + GdkFont *font; + gchar buf[2]; + gchar *p; for (y = ymin, line = vi->chars + y*vi->cols; y < ymax; ++y, line += vi->cols) { for (x = xmin; x < xmax; x+=len) { gchar inverse; - for (inverse = Inverse(vi,y,x), len = 1; - x+len < xmax && Inverse(vi,y,x+len) == inverse; ++len); + inverse = Inverse(vi,y,x); + len = 1; + if (sizeof(CHAR_T) == sizeof(gchar)) + for (; x+len < xmax && + Inverse(vi,y,x+len) == inverse; ++len); if (inverse) { fg = vi->reverse_gc; bg = vi->gc; @@ -593,13 +634,28 @@ draw_lines(GtkViScreen *vi, gint ymin, gint xmin, gint ymax, gint xmax) bg = vi->reverse_gc; fg = vi->gc; } + if (INTIS9494(*(line+x))) { + font = gb_font; + buf[0] = INT9494R(*(line+x)); + buf[1] = INT9494C(*(line+x)); + p = buf; + len = 2; + } else { + font = GTK_WIDGET(vi)->style->font; + if (sizeof(CHAR_T) == sizeof(gchar)) + p = (gchar*)line+x; + else { + buf[0] = *(line+x); + p = buf; + } + } gdk_draw_rectangle(vi->text_area, bg, 1, x * vi->ch_width, y * vi->ch_height, len * vi->ch_width, vi->ch_height); - gdk_draw_text (vi->text_area, GTK_WIDGET(vi)->style->font, fg, + gdk_draw_text (vi->text_area, font, fg, x * vi->ch_width, y * vi->ch_height + vi->ch_ascent, - line+x, len); + p, len); } } } diff --git a/gtk/gtkviscreen.h b/gtk/gtkviscreen.h index d7345ac6..93aee4a9 100644 --- a/gtk/gtkviscreen.h +++ b/gtk/gtkviscreen.h @@ -1,6 +1,10 @@ #ifndef __GTK_VI_SCREEN_H__ #define __GTK_VI_SCREEN_H__ +#include "config.h" +#include "port.h" +#include "../common/multibyte.h" + #define GTK_TYPE_VI_SCREEN (gtk_vi_screen_get_type ()) #define GTK_VI_SCREEN(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_VI_SCREEN, GtkViScreen)) #define GTK_VI_SCREEN_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_VI_SCREEN, GtkViScreenClass)) @@ -21,7 +25,7 @@ struct _GtkViScreen GdkGC *gc; GdkGC *reverse_gc; - gchar *chars; + CHAR_T *chars; guchar *reverse; guchar color; diff --git a/gtk/gtkviwindow.c b/gtk/gtkviwindow.c index 49a6a5d4..bd67c917 100644 --- a/gtk/gtkviwindow.c +++ b/gtk/gtkviwindow.c @@ -35,6 +35,7 @@ static void vi_input_func __P((gpointer , gint , GdkInputCondition)); static void vi_init_window __P((GtkViWindow *window, int)); static int vi_addstr __P((IPVIWIN*, const char *, u_int32_t)); +static int vi_waddstr __P((IPVIWIN*, const CHAR_T *, u_int32_t)); static int vi_attribute __P((IPVIWIN*,u_int32_t ,u_int32_t )); static int vi_bell __P((IPVIWIN*)); static int vi_busyon __P((IPVIWIN*, const char *, u_int32_t)); @@ -395,11 +396,7 @@ vi_init_window (GtkViWindow *window, int fd) vi_scrollbar, vi_select, vi_split, - vi_ex_init, - vi_vi_init, -/* - vi_fork, -*/ + (IPFunc_a)vi_waddstr, }; GtkVi *vi = window->vi; @@ -425,6 +422,18 @@ vi_addstr(ipviwin, str, len) } static int +vi_waddstr(ipviwin, str, len) + IPVIWIN *ipviwin; + const CHAR_T *str; + u_int32_t len; +{ + GtkViWindow* vi = (GtkViWindow*)(ipviwin->private_data); + + gtk_vi_screen_waddstr(GTK_VI_SCREEN(vi->vi_screen), str, len/sizeof(CHAR_T)); + return (0); +} + +static int vi_attribute(ipviwin,attribute,on) IPVIWIN *ipviwin; u_int32_t attribute, on; diff --git a/ip/ip_funcs.c b/ip/ip_funcs.c index 7f51b047..0cc93c3e 100644 --- a/ip/ip_funcs.c +++ b/ip/ip_funcs.c @@ -8,7 +8,7 @@ #include "config.h" #ifndef lint -static const char sccsid[] = "$Id: ip_funcs.c,v 8.20 2000/07/14 14:29:22 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:22 $"; +static const char sccsid[] = "$Id: ip_funcs.c,v 8.21 2000/07/17 21:17:54 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:54 $"; #endif /* not lint */ #include @@ -37,11 +37,20 @@ ip_waddstr(sp, str, len) const CHAR_T *str; size_t len; { - CONST char *np; - size_t nlen; + IP_BUF ipb; + IP_PRIVATE *ipp; + int iv, rval; + + ipp = IPP(sp); - INT2CHAR(sp, str, len, np, nlen); - ip_addstr(sp, np, nlen); + ipb.code = SI_WADDSTR; + ipb.len1 = len * sizeof(CHAR_T); + ipb.str1 = (char *)str; + rval = vi_send(ipp->o_fd, "a", &ipb); + /* XXXX */ + ipp->col += len; + + return (rval); } /* diff --git a/ipc/ip.h b/ipc/ip.h index b949f483..ed579a7f 100644 --- a/ipc/ip.h +++ b/ipc/ip.h @@ -4,7 +4,7 @@ * * See the LICENSE file for redistribution information. * - * $Id: ip.h,v 8.28 2000/07/14 14:29:23 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:23 $ + * $Id: ip.h,v 8.29 2000/07/17 21:17:54 skimo Exp $ (Berkeley) $Date: 2000/07/17 21:17:54 $ */ #include @@ -108,11 +108,7 @@ typedef struct ip_si_operations { IPFunc_123 scrollbar; IPFunc_a select; IPFunc split; - IPFunc ex_init; - IPFunc vi_init; -/* - IPFunc fork; -*/ + IPFunc_a waddstr; } IPSIOPS; struct _ip_vi; diff --git a/ipc/ipc_cmd.c b/ipc/ipc_cmd.c index 54118c4a..069506fa 100644 --- a/ipc/ipc_cmd.c +++ b/ipc/ipc_cmd.c @@ -62,10 +62,8 @@ IPFUNLIST const ipfuns[] = { {"a", ipc_unmarshall_a, OFFSET(IPSIOPS, select)}, /* SI_SPLIT */ {"", ipc_unmarshall, OFFSET(IPSIOPS, split)}, -/* SI_EX_INIT */ - {"", ipc_unmarshall, OFFSET(IPSIOPS, ex_init)}, -/* SI_VI_INIT */ - {"", ipc_unmarshall, OFFSET(IPSIOPS, vi_init)}, +/* SI_WADDSTR */ + {"a", ipc_unmarshall_a, OFFSET(IPSIOPS, waddstr)}, /* SI_EVENT_SUP */ }; diff --git a/regex/regerror.c b/regex/regerror.c index 95e41904..00b5ca96 100644 --- a/regex/regerror.c +++ b/regex/regerror.c @@ -165,6 +165,7 @@ regatoi(preg, localbuf) const regex_t *preg; char *localbuf; { +#if 0 /* we don't seem to use this and it gives a warning. */ register struct rerr *r; register size_t siz; register char *p; @@ -176,5 +177,8 @@ char *localbuf; return("0"); sprintf(localbuf, "%d", r->code); +#else + *localbuf = '\0'; +#endif return(localbuf); } diff --git a/regex/regex2.h b/regex/regex2.h index e88b385a..2a5ef9a5 100644 --- a/regex/regex2.h +++ b/regex/regex2.h @@ -169,5 +169,5 @@ struct re_guts { }; /* misc utilities */ -#define OUT (CHAR_MAX+1) /* a non-character value */ +#define OUT (CHAR_T_MAX+1) /* a non-character value */ #define ISWORD(c) ((c <= 0xFF && isalnum(c)) || (c) == '_') diff --git a/vi/vs_line.c b/vi/vs_line.c index ee40d479..1ee7353c 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.23 2000/07/14 14:29:25 skimo Exp $ (Berkeley) $Date: 2000/07/14 14:29:25 $"; +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 $"; #endif /* not lint */ #include @@ -52,7 +52,7 @@ vs_line(sp, smp, yp, xp) int ch, dne, is_cached, is_partial, is_tab; int list_tab, list_dollar; CHAR_T *p; - char *cbp, *ecbp, cbuf[128]; + CHAR_T *cbp, *ecbp, cbuf[128]; #if defined(DEBUG) && 0 vtrace(sp, "vs_line: row %u: line: %u off: %u\n", @@ -139,9 +139,9 @@ vs_line(sp, smp, yp, xp) if (O_ISSET(sp, O_NUMBER)) { cols_per_screen -= O_NUMBER_LENGTH; if ((!dne || smp->lno == 1) && skip_cols == 0) { - nlen = snprintf(cbuf, + nlen = snprintf((char*)cbuf, sizeof(cbuf), O_NUMBER_FMT, smp->lno); - (void)gp->scr_addstr(sp, cbuf, nlen); + (void)gp->scr_addstr(sp, (char*)cbuf, nlen); } } } @@ -332,7 +332,7 @@ display: ecbp = (cbp = cbuf) + sizeof(cbuf) - 1; for (is_partial = 0, scno = 0; offset_in_line < len; ++offset_in_line, offset_in_char = 0) { - if ((ch = *(u_char *)p++) == '\t' && !list_tab) { + if ((ch = *(UCHAR_T *)p++) == '\t' && !list_tab) { scno += chlen = TAB_OFF(scno) - offset_in_char; is_tab = 1; } else { @@ -397,7 +397,7 @@ display: #define FLUSH { \ *cbp = '\0'; \ - (void)gp->scr_addstr(sp, cbuf, cbp - cbuf); \ + (void)gp->scr_waddstr(sp, cbuf, cbp - cbuf); \ cbp = cbuf; \ } /* -- 2.11.4.GIT