From c033ff498448193e96dfc12c3ab4884ccfd233b3 Mon Sep 17 00:00:00 2001 From: skimo Date: Sat, 21 Apr 2001 06:36:24 +0000 Subject: [PATCH] use addnwstr --- cl/cl.h | 9 ++++--- cl/cl_funcs.c | 75 ++++++++++++++++++++++++++++++++++------------------------- common/conv.c | 30 +++++++++++++++++++++++- 3 files changed, 78 insertions(+), 36 deletions(-) diff --git a/cl/cl.h b/cl/cl.h index 016e94c8..ecc89551 100644 --- a/cl/cl.h +++ b/cl/cl.h @@ -6,16 +6,19 @@ * * See the LICENSE file for redistribution information. * - * $Id: cl.h,v 10.25 2000/09/02 12:31:42 skimo Exp $ (Berkeley) $Date: 2000/09/02 12:31:42 $ + * $Id: cl.h,v 10.26 2001/04/21 06:36:24 skimo Exp $ (Berkeley) $Date: 2001/04/21 06:36:24 $ */ #ifdef USE_SLANG_CURSES #include #else -#ifdef HAVE_NCURSES_H +#ifdef HAVE_NCURSES_H /* { */ #include +#ifndef HAVE_CURSES_ADDNWSTR /* { */ +#define waddnwstr waddchnstr +#endif /* } */ #else #include -#endif +#endif /* } */ #endif typedef struct _cl_private { diff --git a/cl/cl_funcs.c b/cl/cl_funcs.c index 5c3e5268..04ed6ed0 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.62 2000/07/23 11:14:44 skimo Exp $ (Berkeley) $Date: 2000/07/23 11:14:44 $"; +static const char sccsid[] = "$Id: cl_funcs.c,v 10.63 2001/04/21 06:36:24 skimo Exp $ (Berkeley) $Date: 2001/04/21 06:36:24 $"; #endif /* not lint */ #include @@ -32,36 +32,8 @@ static const char sccsid[] = "$Id: cl_funcs.c,v 10.62 2000/07/23 11:14:44 skimo static void cl_rdiv __P((SCR *)); -/* - * cl_addstr -- - * Add len bytes from the string at the cursor, advancing the cursor. - * - * PUBLIC: int cl_waddstr __P((SCR *, const CHAR_T *, size_t)); - */ -int -cl_waddstr(sp, str, len) - SCR *sp; - const CHAR_T *str; - size_t len; -{ - CONST char *np; - size_t nlen; - - INT2DISP(sp, str, len, np, nlen); - cl_addstr(sp, np, nlen); -} - -/* - * cl_addstr -- - * Add len bytes from the string at the cursor, advancing the cursor. - * - * PUBLIC: int cl_addstr __P((SCR *, const char *, size_t)); - */ -int -cl_addstr(sp, str, len) - SCR *sp; - const char *str; - size_t len; +static int +addstr4(SCR *sp, void *str, size_t len, int wide) { CL_PRIVATE *clp; WINDOW *win; @@ -83,8 +55,17 @@ cl_addstr(sp, str, len) (void)wstandout(win); } - if (waddnstr(win, str, len) == ERR) +#ifdef USE_WIDECHAR + if (wide) { + wchar_t *dstr; + size_t dlen; + INT2DISP(sp, str, len, dstr, dlen); + if (waddnwstr(win, (wchar_t*) str, len) == ERR) return (1); + } else +#endif + if (waddnstr(win, str, len) == ERR) + return (1); if (iv) (void)wstandend(win); @@ -92,6 +73,36 @@ cl_addstr(sp, str, len) } /* + * cl_waddstr -- + * Add len bytes from the string at the cursor, advancing the cursor. + * + * PUBLIC: int cl_waddstr __P((SCR *, const CHAR_T *, size_t)); + */ +int +cl_waddstr(sp, str, len) + SCR *sp; + const CHAR_T *str; + size_t len; +{ + addstr4(sp, (void *)str, len, 1); +} + +/* + * cl_addstr -- + * Add len bytes from the string at the cursor, advancing the cursor. + * + * PUBLIC: int cl_addstr __P((SCR *, const char *, size_t)); + */ +int +cl_addstr(sp, str, len) + SCR *sp; + const char *str; + size_t len; +{ + addstr4(sp, (void *)str, len, 0); +} + +/* * cl_attr -- * Toggle a screen attribute on/off. * diff --git a/common/conv.c b/common/conv.c index 6d8dc3d8..d736e4b2 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.7 2000/08/27 17:15:04 skimo Exp $ (Berkeley) $Date: 2000/08/27 17:15:04 $"; +static const char sccsid[] = "$Id: conv.c,v 1.8 2001/04/21 06:36:25 skimo Exp $ (Berkeley) $Date: 2001/04/21 06:36:25 $"; #endif /* not lint */ #include @@ -26,6 +26,9 @@ static const char sccsid[] = "$Id: conv.c,v 1.7 2000/08/27 17:15:04 skimo Exp $ #include #include "common.h" +#ifdef HAVE_NCURSESW +#include +#endif int default_char2int(CONV *conv, const char * str, ssize_t len, CHAR_T **tostr, size_t *tolen, size_t *blen) @@ -55,6 +58,30 @@ default_int2char(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size return 0; } +//#ifdef HAVE_NCURSESW +#ifdef HAVE_ADDNWSTR +int +default_int2disp(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size_t *tolen, size_t *blen) +{ + int i, j; + chtype *dest; + + BINC_RET(NULL, *tostr, *blen, len * sizeof(chtype)); + + dest = *tostr; + + for (i = 0, j = 0; i < len; ++i) + if (str[i] > 0xffff) { + dest[j++] = 0xfffd; + } else + dest[j++] = str[i]; + *tolen = j; + + return 0; +} + +#else + int default_int2disp(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size_t *tolen, size_t *blen) { @@ -72,6 +99,7 @@ default_int2disp(CONV *conv, const CHAR_T * str, ssize_t len, char **tostr, size return 0; } +#endif int gb2int(CONV *conv, const char * str, ssize_t len, CHAR_T **tostr, size_t *tolen, size_t *blen) -- 2.11.4.GIT