aboutsummaryrefslogtreecommitdiff
path: root/contrib/ncurses/ncurses/widechar
diff options
context:
space:
mode:
authorRong-En Fan <rafan@FreeBSD.org>2007-01-20 07:32:02 +0000
committerRong-En Fan <rafan@FreeBSD.org>2007-01-20 07:32:02 +0000
commit4a1a95108dd76c4259fe6c37c4471f7969b17983 (patch)
tree1c6c3b549401156e1dbd96b9a6b18521f63ffb58 /contrib/ncurses/ncurses/widechar
parent555c9cae3cf9146482732c28c06a73314b618149 (diff)
downloadsrc-4a1a95108dd76c4259fe6c37c4471f7969b17983.tar.gz
src-4a1a95108dd76c4259fe6c37c4471f7969b17983.zip
Import ncurses 5.6-20061217 onto the vender branch
Approved by: delphij
Notes
Notes: svn path=/vendor/ncurses/dist/; revision=166124
Diffstat (limited to 'contrib/ncurses/ncurses/widechar')
-rw-r--r--contrib/ncurses/ncurses/widechar/charable.c80
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_add_wch.c113
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_box_set.c4
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_cchar.c56
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_get_wch.c50
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_get_wstr.c76
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_in_wch.c12
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c20
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_ins_wch.c95
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_inwstr.c36
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c57
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_slk_wset.c72
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_unget_wch.c49
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_vid_attr.c252
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_wacs.c43
-rw-r--r--contrib/ncurses/ncurses/widechar/lib_wunctrl.c13
16 files changed, 851 insertions, 177 deletions
diff --git a/contrib/ncurses/ncurses/widechar/charable.c b/contrib/ncurses/ncurses/widechar/charable.c
new file mode 100644
index 000000000000..cf7240780883
--- /dev/null
+++ b/contrib/ncurses/ncurses/widechar/charable.c
@@ -0,0 +1,80 @@
+/****************************************************************************
+ * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/*
+** Support functions for wide/narrow conversion.
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: charable.c,v 1.4 2005/04/16 18:08:56 tom Exp $")
+
+NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch)
+{
+ bool result;
+#if HAVE_WCTOB
+ result = (wctob((wint_t) ch) == ch);
+#else
+ result = (_nc_to_char(ch) >= 0);
+#endif
+ return result;
+}
+
+NCURSES_EXPORT(int) _nc_to_char(wint_t ch)
+{
+ int result;
+#if HAVE_WCTOB
+ result = wctob(ch);
+#elif HAVE_WCTOMB
+ char temp[MB_LEN_MAX];
+ result = wctomb(temp, ch);
+ if (strlen(temp) == 1)
+ result = UChar(temp[0]);
+ else
+ result = -1;
+#endif
+ return result;
+}
+
+NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch)
+{
+ wint_t result;
+#if HAVE_BTOWC
+ result = btowc(ch);
+#elif HAVE_MBTOWC
+ wchar_t convert;
+ char temp[2];
+ temp[0] = ch;
+ temp[1] = '\0';
+ if (mbtowc(&convert, temp, 1) >= 0)
+ result = convert;
+ else
+ result = WEOF;
+#endif
+ return result;
+}
diff --git a/contrib/ncurses/ncurses/widechar/lib_add_wch.c b/contrib/ncurses/ncurses/widechar/lib_add_wch.c
new file mode 100644
index 000000000000..93b41bb4930c
--- /dev/null
+++ b/contrib/ncurses/ncurses/widechar/lib_add_wch.c
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * Copyright (c) 2004,2006 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/*
+** lib_add_wch.c
+**
+** The routine wadd_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_add_wch.c,v 1.6 2006/12/02 21:19:17 tom Exp $")
+
+NCURSES_EXPORT(int)
+wadd_wch(WINDOW *win, const cchar_t *wch)
+{
+ PUTC_DATA;
+ int n;
+ int code = ERR;
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win,
+ _tracech_t(wch)));
+
+ if (win != 0) {
+ PUTC_INIT;
+ for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+ attr_t attrs = (wch->attr & A_ATTRIBUTES);
+
+ if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
+ break;
+ if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
+ code = ERR;
+ if (is8bits(PUTC_ch))
+ code = waddch(win, UChar(PUTC_ch) | attrs);
+ break;
+ }
+ for (n = 0; n < PUTC_n; n++) {
+ if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
+ break;
+ }
+ }
+ if (code == ERR)
+ break;
+ }
+ }
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
+
+NCURSES_EXPORT(int)
+wecho_wchar(WINDOW *win, const cchar_t *wch)
+{
+ PUTC_DATA;
+ int n;
+ int code = ERR;
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win,
+ _tracech_t(wch)));
+
+ if (win != 0) {
+ PUTC_INIT;
+ for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+ attr_t attrs = (wch->attr & A_ATTRIBUTES);
+
+ if ((PUTC_ch = wch->chars[PUTC_i]) == L'\0')
+ break;
+ if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
+ code = ERR;
+ if (is8bits(PUTC_ch))
+ code = waddch(win, UChar(PUTC_ch) | attrs);
+ break;
+ }
+ for (n = 0; n < PUTC_n; n++) {
+ if ((code = waddch(win, UChar(PUTC_buf[n]) | attrs)) == ERR) {
+ break;
+ }
+ }
+ if (code == ERR)
+ break;
+ }
+ wrefresh(win);
+ }
+
+ TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
diff --git a/contrib/ncurses/ncurses/widechar/lib_box_set.c b/contrib/ncurses/ncurses/widechar/lib_box_set.c
index 7f69e5aa5113..35fce46d8d40 100644
--- a/contrib/ncurses/ncurses/widechar/lib_box_set.c
+++ b/contrib/ncurses/ncurses/widechar/lib_box_set.c
@@ -39,7 +39,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_box_set.c,v 1.2 2002/03/23 21:35:24 tom Exp $")
+MODULE_ID("$Id: lib_box_set.c,v 1.4 2003/12/06 18:02:13 tom Exp $")
NCURSES_EXPORT(int)
wborder_set(WINDOW *win,
@@ -66,7 +66,7 @@ wborder_set(WINDOW *win,
if (!win)
returnCode(ERR);
-#define RENDER_WITH_DEFAULT(ch,def) w ##ch = (ch == 0) ? *def : *ch
+#define RENDER_WITH_DEFAULT(ch,def) w ##ch = _nc_render(win, (ch == 0) ? *(const ARG_CH_T)def : *ch)
RENDER_WITH_DEFAULT(ls, WACS_VLINE);
RENDER_WITH_DEFAULT(rs, WACS_VLINE);
diff --git a/contrib/ncurses/ncurses/widechar/lib_cchar.c b/contrib/ncurses/ncurses/widechar/lib_cchar.c
index efbfc69b1c0f..b6458ee4a1f4 100644
--- a/contrib/ncurses/ncurses/widechar/lib_cchar.c
+++ b/contrib/ncurses/ncurses/widechar/lib_cchar.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2001,2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-2004,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -35,17 +35,20 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_cchar.c,v 1.5 2002/04/27 22:35:46 tom Exp $")
+MODULE_ID("$Id: lib_cchar.c,v 1.11 2005/01/29 21:29:16 tom Exp $")
/*
* The SuSv2 description leaves some room for interpretation. We'll assume wch
- * is L'\0' terminated, contains at most one character with strictly positive
- * width, which must be the first, and contains no characters of negative
- * width.
+ * points to a string which is L'\0' terminated, contains at least one
+ * character with strictly positive width, which must be the first, and
+ * contains no characters of negative width.
*/
NCURSES_EXPORT(int)
-setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs,
- short color_pair, const void *opts)
+setcchar(cchar_t *wcval,
+ const wchar_t *wch,
+ const attr_t attrs,
+ short color_pair,
+ const void *opts)
{
int i;
int len;
@@ -54,27 +57,33 @@ setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs,
TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%ld,%d,%p)"),
wcval, _nc_viswbuf(wch), attrs, color_pair, opts));
- if (opts != NULL || (len = wcslen(wch)) > CCHARW_MAX
- || (len > 0 && wcwidth(wch[0]) < 0)) {
+ len = wcslen(wch);
+ if (opts != NULL
+ || (len > 1 && wcwidth(wch[0]) < 0)) {
code = ERR;
} else {
+ if (len > CCHARW_MAX)
+ len = CCHARW_MAX;
+ /*
+ * If we have a following spacing-character, stop at that point. We
+ * are only interested in adding non-spacing characters.
+ */
for (i = 1; i < len; ++i) {
if (wcwidth(wch[i]) != 0) {
- code = ERR;
+ len = i;
break;
}
}
- if (code != ERR) {
- memset(wcval, 0, sizeof(*wcval));
+ memset(wcval, 0, sizeof(*wcval));
- if (len != 0) {
- SetAttr(*wcval, attrs | color_pair);
- memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
- TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
- _tracecchar_t(wcval)));
- }
+ if (len != 0) {
+ SetAttr(*wcval, attrs | COLOR_PAIR(color_pair));
+ SetPair(CHDEREF(wcval), color_pair);
+ memcpy(&wcval->chars, wch, len * sizeof(wchar_t));
+ TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len,
+ _tracecchar_t(wcval)));
}
}
@@ -83,8 +92,11 @@ setcchar(cchar_t * wcval, const wchar_t * wch, const attr_t attrs,
}
NCURSES_EXPORT(int)
-getcchar(const cchar_t * wcval, wchar_t * wch, attr_t * attrs,
- short *color_pair, void *opts)
+getcchar(const cchar_t *wcval,
+ wchar_t *wch,
+ attr_t *attrs,
+ short *color_pair,
+ void *opts)
{
wchar_t *wp;
int len;
@@ -100,9 +112,11 @@ getcchar(const cchar_t * wcval, wchar_t * wch, attr_t * attrs,
if (wch == NULL) {
code = len;
+ } else if (attrs == 0 || color_pair == 0) {
+ code = ERR;
} else if (len >= 0) {
*attrs = AttrOf(*wcval) & A_ATTRIBUTES;
- *color_pair = AttrOf(*wcval) & A_COLOR;
+ *color_pair = GetPair(*wcval);
wmemcpy(wch, wcval->chars, (unsigned) len);
wch[len] = L'\0';
code = OK;
diff --git a/contrib/ncurses/ncurses/widechar/lib_get_wch.c b/contrib/ncurses/ncurses/widechar/lib_get_wch.c
index 21c40a506ccc..c73c363be531 100644
--- a/contrib/ncurses/ncurses/widechar/lib_get_wch.c
+++ b/contrib/ncurses/ncurses/widechar/lib_get_wch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey 2002 *
+ * Author: Thomas E. Dickey 2002-on *
****************************************************************************/
/*
@@ -38,28 +38,47 @@
*/
#include <curses.priv.h>
+#include <ctype.h>
-MODULE_ID("$Id: lib_get_wch.c,v 1.3 2002/03/17 16:14:45 tom Exp $")
+MODULE_ID("$Id: lib_get_wch.c,v 1.13 2006/06/03 17:27:57 tom Exp $")
+
+#if HAVE_MBTOWC && HAVE_MBLEN
+#define reset_mbytes(state) mblen(NULL, 0), mbtowc(NULL, NULL, 0)
+#define count_mbytes(buffer,length,state) mblen(buffer,length)
+#define check_mbytes(wch,buffer,length,state) \
+ (int) mbtowc(&wch, buffer, length)
+#define state_unused
+#elif HAVE_MBRTOWC && HAVE_MBRLEN
+#define reset_mbytes(state) init_mb(state)
+#define count_mbytes(buffer,length,state) mbrlen(buffer,length,&state)
+#define check_mbytes(wch,buffer,length,state) \
+ (int) mbrtowc(&wch, buffer, length, &state)
+#else
+make an error
+#endif
NCURSES_EXPORT(int)
-wget_wch(WINDOW *win, wint_t * result)
+wget_wch(WINDOW *win, wint_t *result)
{
int code;
- char buffer[(MB_CUR_MAX * 9) + 1]; /* allow some redundant shifts */
+ char buffer[(MB_LEN_MAX * 9) + 1]; /* allow some redundant shifts */
int status;
- mbstate_t state;
size_t count = 0;
unsigned long value;
wchar_t wch;
+#ifndef state_unused
+ mbstate_t state;
+#endif
T((T_CALLED("wget_wch(%p)"), win));
+
/*
* We can get a stream of single-byte characters and KEY_xxx codes from
* _nc_wgetch(), while we want to return a wide character or KEY_xxx code.
*/
for (;;) {
- T(("reading %d of %d", count + 1, sizeof(buffer)));
- code = _nc_wgetch(win, &value, TRUE);
+ T(("reading %d of %d", count + 1, sizeof(buffer)));
+ code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist *) 0));
if (code == ERR) {
break;
} else if (code == KEY_CODE_YES) {
@@ -71,22 +90,23 @@ wget_wch(WINDOW *win, wint_t * result)
* would be worth the effort.
*/
if (count != 0) {
- ungetch(value);
+ ungetch((int) value);
code = ERR;
}
break;
} else if (count + 1 >= sizeof(buffer)) {
- ungetch(value);
+ ungetch((int) value);
code = ERR;
break;
} else {
buffer[count++] = UChar(value);
- memset(&state, 0, sizeof(state));
- status = mbrlen(buffer, count, &state);
+ reset_mbytes(state);
+ status = count_mbytes(buffer, count, state);
if (status >= 0) {
- memset(&state, 0, sizeof(state));
- if ((int) mbrtowc(&wch, buffer, count, &state) != status) {
+ reset_mbytes(state);
+ if (check_mbytes(wch, buffer, count, state) != status) {
code = ERR; /* the two calls should match */
+ ungetch((int) value);
}
value = wch;
break;
@@ -94,6 +114,6 @@ wget_wch(WINDOW *win, wint_t * result)
}
}
*result = value;
- T(("result %#o", value));
+ T(("result %#lo", value));
returnCode(code);
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_get_wstr.c b/contrib/ncurses/ncurses/widechar/lib_get_wstr.c
index 426381cce0a5..bf39aa1a188b 100644
--- a/contrib/ncurses/ncurses/widechar/lib_get_wstr.c
+++ b/contrib/ncurses/ncurses/widechar/lib_get_wstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2003,2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey 2002 *
+ * Author: Thomas E. Dickey *
****************************************************************************/
/*
@@ -40,23 +40,38 @@
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$Id: lib_get_wstr.c,v 1.3 2002/05/11 22:29:43 tom Exp $")
+MODULE_ID("$Id: lib_get_wstr.c,v 1.8 2004/10/16 21:55:36 tom Exp $")
+
+static int
+wadd_wint(WINDOW *win, wint_t *src)
+{
+ cchar_t tmp;
+ wchar_t wch[2];
+
+ wch[0] = *src;
+ wch[1] = 0;
+ setcchar(&tmp, wch, A_NORMAL, 0, NULL);
+ return wadd_wch(win, &tmp);
+}
/*
* This wipes out the last character, no matter whether it was a tab, control
* or other character, and handles reverse wraparound.
*/
-static wchar_t *
-WipeOut(WINDOW *win, int y, int x, wchar_t * first, wchar_t * last, bool echoed)
+static wint_t *
+WipeOut(WINDOW *win, int y, int x, wint_t *first, wint_t *last, bool echoed)
{
if (last > first) {
*--last = '\0';
if (echoed) {
int y1 = win->_cury;
int x1 = win->_curx;
+ int n;
wmove(win, y, x);
- waddwstr(win, first);
+ for (n = 0; first[n] != 0; ++n) {
+ wadd_wint(win, first + n);
+ }
getyx(win, y, x);
while (win->_cury < y1
|| (win->_cury == y1 && win->_curx < x1))
@@ -69,14 +84,14 @@ WipeOut(WINDOW *win, int y, int x, wchar_t * first, wchar_t * last, bool echoed)
}
NCURSES_EXPORT(int)
-wgetn_wstr(WINDOW *win, wint_t * str, int maxlen)
+wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
{
TTY buf;
bool oldnl, oldecho, oldraw, oldcbreak;
wint_t erasec;
wint_t killc;
- wchar_t *oldstr;
- wchar_t *tmpstr;
+ wint_t *oldstr = str;
+ wint_t *tmpstr = str;
wint_t ch;
int y, x, code;
@@ -99,16 +114,31 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen)
erasec = erasechar();
killc = killchar();
- assert(sizeof(wchar_t) == sizeof(wint_t));
- oldstr = (wchar_t *) str;
- tmpstr = (wchar_t *) str;
-
getyx(win, y, x);
if (is_wintouched(win) || (win->_flags & _HASMOVED))
wrefresh(win);
while ((code = wget_wch(win, &ch)) != ERR) {
+ /*
+ * Map special characters into key-codes.
+ */
+ if (ch == '\r')
+ ch = '\n';
+ if (ch == '\n') {
+ code = KEY_CODE_YES;
+ ch = KEY_ENTER;
+ }
+ if (ch < KEY_MIN) {
+ if (ch == erasec) {
+ ch = KEY_BACKSPACE;
+ code = KEY_CODE_YES;
+ }
+ if (ch == killc) {
+ ch = KEY_EOL;
+ code = KEY_CODE_YES;
+ }
+ }
if (code == KEY_CODE_YES) {
/*
* Some terminals (the Wyse-50 is the most common) generate a \n
@@ -116,21 +146,18 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen)
* choice whether to set kcud=\n for wget_wch(); terminating
* *getn_wstr() with \n should work either way.
*/
- if (ch == '\n'
- || ch == '\r'
- || ch == KEY_DOWN
- || ch == KEY_ENTER) {
+ if (ch == KEY_DOWN || ch == KEY_ENTER) {
if (oldecho == TRUE
&& win->_cury == win->_maxy
&& win->_scroll)
wechochar(win, (chtype) '\n');
break;
}
- if (ch == erasec || ch == KEY_LEFT || ch == KEY_BACKSPACE) {
+ if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
if (tmpstr > oldstr) {
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
}
- } else if (ch == killc) {
+ } else if (ch == KEY_EOL) {
while (tmpstr > oldstr) {
tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
}
@@ -141,12 +168,11 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen)
beep();
} else {
*tmpstr++ = ch;
+ *tmpstr = 0;
if (oldecho == TRUE) {
int oldy = win->_cury;
- cchar_t tmp;
- setcchar(&tmp, tmpstr - 1, A_NORMAL, 0, NULL);
- if (wadd_wch(win, &tmp) == ERR) {
+ if (wadd_wint(win, tmpstr - 1) == ERR) {
/*
* We can't really use the lower-right corner for input,
* since it'll mess up bookkeeping for erases.
@@ -188,18 +214,18 @@ wgetn_wstr(WINDOW *win, wint_t * str, int maxlen)
SP->_raw = oldraw;
SP->_cbreak = oldcbreak;
- _nc_set_tty_mode(&buf);
+ (void) _nc_set_tty_mode(&buf);
*tmpstr = 0;
if (code == ERR) {
if (tmpstr == oldstr) {
- *tmpstr++ = (wchar_t)WEOF;
+ *tmpstr++ = WEOF;
*tmpstr = 0;
}
returnCode(ERR);
}
- T(("wgetn_wstr returns %s", _nc_viswbuf(oldstr)));
+ T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr)));
returnCode(OK);
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_in_wch.c b/contrib/ncurses/ncurses/widechar/lib_in_wch.c
index 562fa82602fe..5cd92e382de4 100644
--- a/contrib/ncurses/ncurses/widechar/lib_in_wch.c
+++ b/contrib/ncurses/ncurses/widechar/lib_in_wch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2004,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas Dickey 2002 *
+ * Author: Thomas Dickey *
****************************************************************************/
/*
@@ -39,10 +39,10 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_in_wch.c,v 1.1 2002/03/10 20:22:00 tom Exp $")
+MODULE_ID("$Id: lib_in_wch.c,v 1.4 2006/09/03 15:41:22 tom Exp $")
NCURSES_EXPORT(int)
-win_wch(WINDOW *win, NCURSES_CONST cchar_t * wcval)
+win_wch(WINDOW *win, cchar_t *wcval)
{
int row, col;
int code = OK;
@@ -53,8 +53,10 @@ win_wch(WINDOW *win, NCURSES_CONST cchar_t * wcval)
getyx(win, row, col);
*wcval = win->_line[row].text[col];
+ TR(TRACE_CCALLS, ("data %s", _tracecchar_t(wcval)));
} else {
code = ERR;
}
- returnCode(code);
+ TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c b/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c
index 42268ec3e025..41ba18ccdf00 100644
--- a/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c
+++ b/contrib/ncurses/ncurses/widechar/lib_in_wchnstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002,2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas Dickey 2002 *
+ * Author: Thomas Dickey 2002,2004 *
****************************************************************************/
/*
@@ -39,22 +39,28 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_in_wchnstr.c,v 1.1 2002/04/13 19:33:57 tom Exp $")
+MODULE_ID("$Id: lib_in_wchnstr.c,v 1.3 2004/05/16 00:12:30 tom Exp $")
NCURSES_EXPORT(int)
-win_wchnstr(WINDOW *win, NCURSES_CONST cchar_t * wchstr, int n)
+win_wchnstr(WINDOW *win, cchar_t * wchstr, int n)
{
int code = OK;
- TR(TRACE_CCALLS, (T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n));
+ TR(TRACE_CALLS, (T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n));
if (win != 0
&& wchstr != 0) {
+ int row, col;
+ int j;
+
+ getyx(win, row, col);
if (n < 0) {
n = getmaxx(win) + 1 - getcurx(win);
}
- while (n-- > 0)
- win_wch(win, wchstr++);
+ for (j = 0; j < n; ++j) {
+ wchstr[j] = win->_line[row].text[col + j];
+ }
+ T(("result = %s", _nc_viscbuf(wchstr, n)));
} else {
code = ERR;
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_ins_wch.c b/contrib/ncurses/ncurses/widechar/lib_ins_wch.c
index 0821ee590bf8..c3d0420e53b8 100644
--- a/contrib/ncurses/ncurses/widechar/lib_ins_wch.c
+++ b/contrib/ncurses/ncurses/widechar/lib_ins_wch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2003,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -39,27 +39,106 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_ins_wch.c,v 1.1 2002/03/10 22:25:06 tom Exp $")
+MODULE_ID("$Id: lib_ins_wch.c,v 1.8 2005/12/03 20:24:19 tom Exp $")
-NCURSES_EXPORT(int)
-wins_wch(WINDOW *win, const cchar_t * wch)
+/*
+ * Insert the given character, updating the current location to simplify
+ * inserting a string.
+ */
+static int
+_nc_insert_wch(WINDOW *win, const cchar_t *wch)
{
- int code = ERR;
+ int cells = wcwidth(CharOf(CHDEREF(wch)));
+ int cell;
- T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch)));
+ if (cells <= 0)
+ cells = 1;
- if (win) {
+ if (win->_curx <= win->_maxx) {
struct ldat *line = &(win->_line[win->_cury]);
NCURSES_CH_T *end = &(line->text[win->_curx]);
NCURSES_CH_T *temp1 = &(line->text[win->_maxx]);
- NCURSES_CH_T *temp2 = temp1 - 1;
+ NCURSES_CH_T *temp2 = temp1 - cells;
CHANGED_TO_EOL(line, win->_curx, win->_maxx);
while (temp1 > end)
*temp1-- = *temp2--;
*temp1 = _nc_render(win, *wch);
+ for (cell = 1; cell < cells; ++cell) {
+ SetWidecExt(temp1[cell], cell);
+ }
+
+ win->_curx++;
+ }
+ return OK;
+}
+
+NCURSES_EXPORT(int)
+wins_wch(WINDOW *win, const cchar_t *wch)
+{
+ NCURSES_SIZE_T oy;
+ NCURSES_SIZE_T ox;
+ int code = ERR;
+
+ T((T_CALLED("wins_wch(%p, %s)"), win, _tracecchar_t(wch)));
+
+ if (win != 0) {
+ oy = win->_cury;
+ ox = win->_curx;
+
+ code = _nc_insert_wch(win, wch);
+
+ win->_curx = ox;
+ win->_cury = oy;
+ _nc_synchook(win);
+ }
+ returnCode(code);
+}
+
+NCURSES_EXPORT(int)
+wins_nwstr(WINDOW *win, const wchar_t *wstr, int n)
+{
+ int code = ERR;
+ NCURSES_SIZE_T oy;
+ NCURSES_SIZE_T ox;
+ const wchar_t *cp;
+
+ T((T_CALLED("wins_nwstr(%p,%s,%d)"), win, _nc_viswbufn(wstr, n), n));
+
+ if (win != 0
+ && wstr != 0) {
+ if (n < 1)
+ n = wcslen(wstr);
code = OK;
+ if (n > 0) {
+ oy = win->_cury;
+ ox = win->_curx;
+ for (cp = wstr; *cp && ((cp - wstr) < n); cp++) {
+ int len = wcwidth(*cp);
+
+ if (len != 1 || !is8bits(*cp)) {
+ cchar_t tmp_cchar;
+ wchar_t tmp_wchar = *cp;
+ memset(&tmp_cchar, 0, sizeof(tmp_cchar));
+ (void) setcchar(&tmp_cchar,
+ &tmp_wchar,
+ WA_NORMAL,
+ 0,
+ (void *) 0);
+ code = _nc_insert_wch(win, &tmp_cchar);
+ } else {
+ /* tabs, other ASCII stuff */
+ code = _nc_insert_ch(win, (chtype) (*cp));
+ }
+ if (code != OK)
+ break;
+ }
+
+ win->_curx = ox;
+ win->_cury = oy;
+ _nc_synchook(win);
+ }
}
returnCode(code);
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_inwstr.c b/contrib/ncurses/ncurses/widechar/lib_inwstr.c
index c3c46fa9e554..2207a5f5d19f 100644
--- a/contrib/ncurses/ncurses/widechar/lib_inwstr.c
+++ b/contrib/ncurses/ncurses/widechar/lib_inwstr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002,2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas Dickey 2002 *
+ * Author: Thomas Dickey *
****************************************************************************/
/*
@@ -39,10 +39,10 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_inwstr.c,v 1.1 2002/03/10 00:25:27 tom Exp $")
+MODULE_ID("$Id: lib_inwstr.c,v 1.4 2004/10/23 20:41:28 tom Exp $")
NCURSES_EXPORT(int)
-winnwstr(WINDOW *win, wchar_t * wstr, int n)
+winnwstr(WINDOW *win, wchar_t *wstr, int n)
{
int row, col, inx;
int count = 0;
@@ -50,23 +50,25 @@ winnwstr(WINDOW *win, wchar_t * wstr, int n)
cchar_t *text;
wchar_t wch;
- TR(TRACE_CCALLS, (T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n));
+ T((T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n));
if (wstr != 0) {
if (win) {
getyx(win, row, col);
text = win->_line[row].text;
while (count < n && count != ERR) {
- for (inx = 0; (inx < CCHARW_MAX)
- && ((wch = text[col].chars[inx]) != 0);
- ++inx) {
- if (count + 1 >= n) {
- if ((count = last) == 0) {
- count = ERR; /* error if we t store nothing */
+ if (!isWidecExt(text[col])) {
+ for (inx = 0; (inx < CCHARW_MAX)
+ && ((wch = text[col].chars[inx]) != 0);
+ ++inx) {
+ if (count + 1 > n) {
+ if ((count = last) == 0) {
+ count = ERR; /* error if we store nothing */
+ }
+ break;
}
- break;
+ wstr[count++] = wch;
}
- wstr[count++] = wch;
}
last = count;
if (++col > win->_maxx) {
@@ -74,8 +76,10 @@ winnwstr(WINDOW *win, wchar_t * wstr, int n)
}
}
}
- if (count > 0)
+ if (count > 0) {
wstr[count] = '\0';
+ T(("winnwstr returns %s", _nc_viswbuf(wstr)));
+ }
}
returnCode(count);
}
@@ -86,10 +90,10 @@ winnwstr(WINDOW *win, wchar_t * wstr, int n)
* it does not define what happens for a negative count with winnwstr().
*/
NCURSES_EXPORT(int)
-winwstr(WINDOW *win, wchar_t * wstr)
+winwstr(WINDOW *win, wchar_t *wstr)
{
int result = OK;
- TR(TRACE_CCALLS, (T_CALLED("winwstr(%p,%p)"), win, wstr));
+ T((T_CALLED("winwstr(%p,%p)"), win, wstr));
if (winnwstr(win, wstr, CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR)
result = ERR;
returnCode(result);
diff --git a/contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c b/contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c
new file mode 100644
index 000000000000..e61277574311
--- /dev/null
+++ b/contrib/ncurses/ncurses/widechar/lib_pecho_wchar.c
@@ -0,0 +1,57 @@
+/****************************************************************************
+ * Copyright (c) 2004 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_pecho_wchar.c,v 1.1 2004/01/03 21:42:01 tom Exp $")
+
+NCURSES_EXPORT(int)
+pecho_wchar(WINDOW *pad, const cchar_t * wch)
+{
+ T((T_CALLED("pecho_wchar(%p, %s)"), pad, _tracech_t(wch)));
+
+ if (pad == 0)
+ returnCode(ERR);
+
+ if (!(pad->_flags & _ISPAD))
+ returnCode(wecho_wchar(pad, wch));
+
+ wadd_wch(pad, wch);
+ prefresh(pad, pad->_pad._pad_y,
+ pad->_pad._pad_x,
+ pad->_pad._pad_top,
+ pad->_pad._pad_left,
+ pad->_pad._pad_bottom,
+ pad->_pad._pad_right);
+
+ returnCode(OK);
+}
diff --git a/contrib/ncurses/ncurses/widechar/lib_slk_wset.c b/contrib/ncurses/ncurses/widechar/lib_slk_wset.c
new file mode 100644
index 000000000000..646b5d9e2fa8
--- /dev/null
+++ b/contrib/ncurses/ncurses/widechar/lib_slk_wset.c
@@ -0,0 +1,72 @@
+/****************************************************************************
+ * Copyright (c) 2003-2004,2005 Free Software Foundation, Inc. *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a *
+ * copy of this software and associated documentation files (the *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey *
+ ****************************************************************************/
+
+/*
+ * lib_slk_wset.c
+ * Set soft label text.
+ */
+#include <curses.priv.h>
+
+#if HAVE_WCTYPE_H
+#include <wctype.h>
+#endif
+
+MODULE_ID("$Id: lib_slk_wset.c,v 1.11 2005/01/16 01:03:53 tom Exp $")
+
+NCURSES_EXPORT(int)
+slk_wset(int i, const wchar_t *astr, int format)
+{
+ int result = ERR;
+ size_t arglen;
+ const wchar_t *str;
+ char *mystr;
+ mbstate_t state;
+
+ T((T_CALLED("slk_wset(%d, %s, %d)"), i, _nc_viswbuf(astr), format));
+
+ init_mb(state);
+ str = astr;
+ if ((arglen = wcsrtombs(NULL, &str, 0, &state)) != (size_t) -1) {
+ if ((mystr = (char *) _nc_doalloc(0, arglen + 1)) != 0) {
+ str = astr;
+ if (wcsrtombs(mystr, &str, arglen, &state) != (size_t) -1) {
+ /* glibc documentation claims that the terminating L'\0'
+ * is written, but it is not...
+ */
+ mystr[arglen] = 0;
+ result = slk_set(i, mystr, format);
+ }
+ free(mystr);
+ }
+ }
+ returnCode(result);
+}
diff --git a/contrib/ncurses/ncurses/widechar/lib_unget_wch.c b/contrib/ncurses/ncurses/widechar/lib_unget_wch.c
index b4b3433519c1..62ec89d75014 100644
--- a/contrib/ncurses/ncurses/widechar/lib_unget_wch.c
+++ b/contrib/ncurses/ncurses/widechar/lib_unget_wch.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2003,2004 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -39,7 +39,26 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_unget_wch.c,v 1.2 2002/03/17 00:01:38 tom Exp $")
+MODULE_ID("$Id: lib_unget_wch.c,v 1.7 2004/12/05 01:21:31 tom Exp $")
+
+#ifdef linux
+/*
+ * glibc's wcrtomb() function is broken - does not return the proper value
+ * when target is null (noted for glibc 2.3.2). This is a workaround.
+ */
+NCURSES_EXPORT(size_t)
+_nc_wcrtomb(char *target, wchar_t source, mbstate_t * state)
+{
+ if (target == 0) {
+ wchar_t temp[2];
+ const wchar_t *tempp = temp;
+ temp[0] = source;
+ temp[1] = 0;
+ return wcsrtombs(NULL, &tempp, 0, state);
+ }
+ return wcrtomb(target, source, state);
+}
+#endif
NCURSES_EXPORT(int)
unget_wch(const wchar_t wch)
@@ -49,25 +68,29 @@ unget_wch(const wchar_t wch)
size_t length;
int n;
- T((T_CALLED("unget_wch(%d)"), wch));
+ T((T_CALLED("unget_wch(%#lx)"), (unsigned long) wch));
- memset(&state, 0, sizeof(state));
- length = wcrtomb(0, wch, &state);
+ init_mb(state);
+ length = _nc_wcrtomb(0, wch, &state);
if (length != (size_t) (-1)
&& length != 0) {
- char *string = malloc(length);
+ char *string;
- memset(&state, 0, sizeof(state));
- wcrtomb(string, wch, &state);
+ if ((string = (char *) malloc(length)) != 0) {
+ init_mb(state);
+ wcrtomb(string, wch, &state);
- for (n = (int) (length - 1); n >= 0; --n) {
- if (ungetch(string[n]) != OK) {
- result = ERR;
- break;
+ for (n = (int) (length - 1); n >= 0; --n) {
+ if (ungetch(string[n]) != OK) {
+ result = ERR;
+ break;
+ }
}
+ free(string);
+ } else {
+ result = ERR;
}
- free(string);
} else {
result = ERR;
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_vid_attr.c b/contrib/ncurses/ncurses/widechar/lib_vid_attr.c
index 06e7880dd4d0..2ba16b5cf924 100644
--- a/contrib/ncurses/ncurses/widechar/lib_vid_attr.c
+++ b/contrib/ncurses/ncurses/widechar/lib_vid_attr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002-2005,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -27,68 +27,248 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey 2002 *
+ * Author: Thomas E. Dickey *
****************************************************************************/
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$Id: lib_vid_attr.c,v 1.1 2002/05/11 20:55:26 tom Exp $")
+MODULE_ID("$Id: lib_vid_attr.c,v 1.4 2006/11/26 00:26:00 tom Exp $")
-#define set_color(mode, pair) mode &= ~A_COLOR; mode |= COLOR_PAIR(pair)
+#define doPut(mode) TPUTS_TRACE(#mode); tputs(mode, 1, outc)
+
+#define TurnOn(mask,mode) \
+ if ((turn_on & mask) && mode) { doPut(mode); }
+
+#define TurnOff(mask,mode) \
+ if ((turn_off & mask) && mode) { doPut(mode); turn_off &= ~mask; }
+
+ /* if there is no current screen, assume we *can* do color */
+#define SetColorsIf(why, old_attr, old_pair) \
+ if (can_color && (why)) { \
+ TR(TRACE_ATTRS, ("old pair = %d -- new pair = %d", old_pair, pair)); \
+ if ((pair != old_pair) \
+ || (fix_pair0 && (pair == 0)) \
+ || (reverse ^ ((old_attr & A_REVERSE) != 0))) { \
+ _nc_do_color(old_pair, pair, reverse, outc); \
+ } \
+ }
+
+#define set_color(mode, pair) mode &= ALL_BUT_COLOR; mode |= COLOR_PAIR(pair)
NCURSES_EXPORT(int)
vid_puts(attr_t newmode, short pair, void *opts GCC_UNUSED, int (*outc) (int))
{
+#if NCURSES_EXT_COLORS
+ static attr_t previous_attr = A_NORMAL;
+ static int previous_pair = 0;
+
+ attr_t turn_on, turn_off;
+ bool reverse = FALSE;
+ bool can_color = (SP == 0 || SP->_coloron);
+#if NCURSES_EXT_FUNCS
+ bool fix_pair0 = (SP != 0 && SP->_coloron && !SP->_default_color);
+#else
+#define fix_pair0 FALSE
+#endif
+
+ T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair));
+
+ /* this allows us to go on whether or not newterm() has been called */
+ if (SP) {
+ previous_attr = AttrOf(SCREEN_ATTRS(SP));
+ previous_pair = GetPair(SCREEN_ATTRS(SP));
+ }
+
+ TR(TRACE_ATTRS, ("previous attribute was %s, %d",
+ _traceattr(previous_attr), previous_pair));
+
+#if !USE_XMC_SUPPORT
+ if ((SP != 0)
+ && (magic_cookie_glitch > 0))
+ newmode &= ~(SP->_xmc_suppress);
+#endif
+
+ /*
+ * If we have a terminal that cannot combine color with video
+ * attributes, use the colors in preference.
+ */
+ if ((pair != 0
+ || fix_pair0)
+ && (no_color_video > 0)) {
+ /*
+ * If we had chosen the A_xxx definitions to correspond to the
+ * no_color_video mask, we could simply shift it up and mask off the
+ * attributes. But we did not (actually copied Solaris' definitions).
+ * However, this is still simpler/faster than a lookup table.
+ *
+ * The 63 corresponds to A_STANDOUT, A_UNDERLINE, A_REVERSE, A_BLINK,
+ * A_DIM, A_BOLD which are 1:1 with no_color_video. The bits that
+ * correspond to A_INVIS, A_PROTECT (192) must be shifted up 1 and
+ * A_ALTCHARSET (256) down 2 to line up. We use the NCURSES_BITS
+ * macro so this will work properly for the wide-character layout.
+ */
+ unsigned value = no_color_video;
+ attr_t mask = NCURSES_BITS((value & 63)
+ | ((value & 192) << 1)
+ | ((value & 256) >> 2), 8);
+
+ if ((mask & A_REVERSE) != 0
+ && (newmode & A_REVERSE) != 0) {
+ reverse = TRUE;
+ mask &= ~A_REVERSE;
+ }
+ newmode &= ~mask;
+ }
+
+ if (newmode == previous_attr
+ && pair == previous_pair)
+ returnCode(OK);
+
+ if (reverse) {
+ newmode &= ~A_REVERSE;
+ }
+
+ turn_off = (~newmode & previous_attr) & ALL_BUT_COLOR;
+ turn_on = (newmode & ~previous_attr) & ALL_BUT_COLOR;
+
+ SetColorsIf(((pair == 0) && !fix_pair0), previous_attr, previous_pair);
+
+ if (newmode == A_NORMAL) {
+ if ((previous_attr & A_ALTCHARSET) && exit_alt_charset_mode) {
+ doPut(exit_alt_charset_mode);
+ previous_attr &= ~A_ALTCHARSET;
+ }
+ if (previous_attr) {
+ if (exit_attribute_mode) {
+ doPut(exit_attribute_mode);
+ } else {
+ if (!SP || SP->_use_rmul) {
+ TurnOff(A_UNDERLINE, exit_underline_mode);
+ }
+ if (!SP || SP->_use_rmso) {
+ TurnOff(A_STANDOUT, exit_standout_mode);
+ }
+ }
+ previous_attr &= ALL_BUT_COLOR;
+ previous_pair = 0;
+ }
+
+ SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+ } else if (set_attributes) {
+ if (turn_on || turn_off) {
+ TPUTS_TRACE("set_attributes");
+ tputs(TPARM_9(set_attributes,
+ (newmode & A_STANDOUT) != 0,
+ (newmode & A_UNDERLINE) != 0,
+ (newmode & A_REVERSE) != 0,
+ (newmode & A_BLINK) != 0,
+ (newmode & A_DIM) != 0,
+ (newmode & A_BOLD) != 0,
+ (newmode & A_INVIS) != 0,
+ (newmode & A_PROTECT) != 0,
+ (newmode & A_ALTCHARSET) != 0), 1, outc);
+ previous_attr &= ALL_BUT_COLOR;
+ previous_pair = 0;
+ }
+ SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+ } else {
+
+ TR(TRACE_ATTRS, ("turning %s off", _traceattr(turn_off)));
+
+ TurnOff(A_ALTCHARSET, exit_alt_charset_mode);
+
+ if (!SP || SP->_use_rmul) {
+ TurnOff(A_UNDERLINE, exit_underline_mode);
+ }
+
+ if (!SP || SP->_use_rmso) {
+ TurnOff(A_STANDOUT, exit_standout_mode);
+ }
+
+ if (turn_off && exit_attribute_mode) {
+ doPut(exit_attribute_mode);
+ turn_on |= (newmode & ALL_BUT_COLOR);
+ previous_attr &= ALL_BUT_COLOR;
+ previous_pair = 0;
+ }
+ SetColorsIf((pair != 0) || fix_pair0, previous_attr, previous_pair);
+
+ TR(TRACE_ATTRS, ("turning %s on", _traceattr(turn_on)));
+ /* *INDENT-OFF* */
+ TurnOn(A_ALTCHARSET, enter_alt_charset_mode);
+ TurnOn(A_BLINK, enter_blink_mode);
+ TurnOn(A_BOLD, enter_bold_mode);
+ TurnOn(A_DIM, enter_dim_mode);
+ TurnOn(A_REVERSE, enter_reverse_mode);
+ TurnOn(A_STANDOUT, enter_standout_mode);
+ TurnOn(A_PROTECT, enter_protected_mode);
+ TurnOn(A_INVIS, enter_secure_mode);
+ TurnOn(A_UNDERLINE, enter_underline_mode);
+#if USE_WIDEC_SUPPORT
+ TurnOn(A_HORIZONTAL, enter_horizontal_hl_mode);
+ TurnOn(A_LEFT, enter_left_hl_mode);
+ TurnOn(A_LOW, enter_low_hl_mode);
+ TurnOn(A_RIGHT, enter_right_hl_mode);
+ TurnOn(A_TOP, enter_top_hl_mode);
+ TurnOn(A_VERTICAL, enter_vertical_hl_mode);
+#endif
+ /* *INDENT-ON* */
+
+ }
+
+ if (reverse)
+ newmode |= A_REVERSE;
+
+ if (SP) {
+ SetAttr(SCREEN_ATTRS(SP), newmode);
+ SetPair(SCREEN_ATTRS(SP), pair);
+ } else {
+ previous_attr = newmode;
+ previous_pair = pair;
+ }
+
+ returnCode(OK);
+#else
T((T_CALLED("vid_puts(%s,%d)"), _traceattr(newmode), pair));
set_color(newmode, pair);
returnCode(vidputs(newmode, outc));
+#endif
}
#undef vid_attr
NCURSES_EXPORT(int)
-vid_attr(attr_t newmode, short pair, void *opts GCC_UNUSED)
+vid_attr(attr_t newmode, short pair, void *opts)
{
T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), pair));
- set_color(newmode, pair);
- returnCode(vidputs(newmode, _nc_outch));
+ returnCode(vid_puts(newmode, pair, opts, _nc_outch));
}
+/*
+ * This implementation uses the same mask values for A_xxx and WA_xxx, so
+ * we can use termattrs() for part of the logic.
+ */
NCURSES_EXPORT(attr_t)
term_attrs(void)
{
- attr_t attrs = WA_NORMAL;
+ attr_t attrs;
T((T_CALLED("term_attrs()")));
- if (enter_alt_charset_mode)
- attrs |= WA_ALTCHARSET;
-
- if (enter_blink_mode)
- attrs |= WA_BLINK;
-
- if (enter_bold_mode)
- attrs |= WA_BOLD;
-
- if (enter_dim_mode)
- attrs |= WA_DIM;
-
- if (enter_reverse_mode)
- attrs |= WA_REVERSE;
-
- if (enter_standout_mode)
- attrs |= WA_STANDOUT;
-
- if (enter_protected_mode)
- attrs |= WA_PROTECT;
-
- if (enter_secure_mode)
- attrs |= WA_INVIS;
-
- if (enter_underline_mode)
- attrs |= WA_UNDERLINE;
+ attrs = termattrs();
- if (SP->_coloron)
- attrs |= A_COLOR;
+ /* these are only supported for wide-character mode */
+ if (enter_horizontal_hl_mode)
+ attrs |= WA_HORIZONTAL;
+ if (enter_left_hl_mode)
+ attrs |= WA_LEFT;
+ if (enter_low_hl_mode)
+ attrs |= WA_LOW;
+ if (enter_right_hl_mode)
+ attrs |= WA_RIGHT;
+ if (enter_top_hl_mode)
+ attrs |= WA_TOP;
+ if (enter_vertical_hl_mode)
+ attrs |= WA_VERTICAL;
returnAttr(attrs);
}
diff --git a/contrib/ncurses/ncurses/widechar/lib_wacs.c b/contrib/ncurses/ncurses/widechar/lib_wacs.c
index 05fa329dd9fa..fe893b4d2f8b 100644
--- a/contrib/ncurses/ncurses/widechar/lib_wacs.c
+++ b/contrib/ncurses/ncurses/widechar/lib_wacs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2002 Free Software Foundation, Inc. *
+ * Copyright (c) 2002,2006 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -33,23 +33,10 @@
#include <curses.priv.h>
#include <term.h>
-MODULE_ID("$Id: lib_wacs.c,v 1.2 2002/02/17 00:02:15 tom Exp $")
+MODULE_ID("$Id: lib_wacs.c,v 1.7 2006/12/17 15:16:17 tom Exp $")
NCURSES_EXPORT_VAR(cchar_t) * _nc_wacs = 0;
-static int
-_nc_unicode_locale(void)
-{
- char *s;
- if (((s = getenv("LC_ALL")) != 0 && *s != '\0')
- || ((s = getenv("LC_ALL")) != 0 && *s != '\0')
- || ((s = getenv("LC_ALL")) != 0 && *s != '\0')) {
- if (strstr(s, ".UTF-8") != 0)
- return 1;
- }
- return 0;
-}
-
NCURSES_EXPORT(void)
_nc_init_wacs(void)
{
@@ -72,7 +59,7 @@ _nc_init_wacs(void)
{ 'n', { '+', 0x253c }}, /* large plus or crossover */
{ 'o', { '~', 0x23ba }}, /* scan line 1 */
{ 's', { '_', 0x23bd }}, /* scan line 9 */
- { '\'', { '+', 0x25c6 }}, /* diamond */
+ { '`', { '+', 0x25c6 }}, /* diamond */
{ 'a', { ':', 0x2592 }}, /* checker board (stipple) */
{ 'f', { '\'', 0x00b0 }}, /* degree symbol */
{ 'g', { '#', 0x00b1 }}, /* plus/minus */
@@ -99,19 +86,29 @@ _nc_init_wacs(void)
unsigned n, m;
int active = _nc_unicode_locale();
+ /*
+ * If we're running in a UTF-8 locale, will use the Unicode equivalents
+ * rather than the terminfo information. Actually the terminfo should
+ * be the rule, but there are people who are offended by the notion that
+ * a Unicode-capable terminal would have something resembling a mode.
+ * So the smacs/rmacs may be disabled -- sometime.
+ */
T(("initializing WIDE-ACS map (Unicode is%s active)",
active ? "" : " not"));
- if (active) {
- enter_alt_charset_mode = "";
- exit_alt_charset_mode = "";
- acs_chars = "";
- ena_acs = "";
- }
_nc_wacs = typeCalloc(cchar_t, ACS_LEN);
for (n = 0; n < SIZEOF(table); ++n) {
+ int wide = wcwidth(table[n].value[active]);
+
m = table[n].map;
- SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL);
+ if (active && (wide == 1)) {
+ SetChar(_nc_wacs[m], table[n].value[active], A_NORMAL);
+ } else if (acs_map[m] & A_ALTCHARSET) {
+ SetChar(_nc_wacs[m], m, A_ALTCHARSET);
+ } else {
+ SetChar(_nc_wacs[m], table[n].value[0], A_NORMAL);
+ }
+
T(("#%d, SetChar(%c, %#04x) = %s",
n, m,
table[n].value[active],
diff --git a/contrib/ncurses/ncurses/widechar/lib_wunctrl.c b/contrib/ncurses/ncurses/widechar/lib_wunctrl.c
index f4887d125fcf..cd7c56ca73f4 100644
--- a/contrib/ncurses/ncurses/widechar/lib_wunctrl.c
+++ b/contrib/ncurses/ncurses/widechar/lib_wunctrl.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2001 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-2003,2005 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
@@ -37,17 +37,18 @@
#if USE_WIDEC_SUPPORT
-MODULE_ID("$Id: lib_wunctrl.c,v 1.6 2001/09/22 19:18:02 tom Exp $")
+MODULE_ID("$Id: lib_wunctrl.c,v 1.8 2005/04/16 18:10:44 tom Exp $")
NCURSES_EXPORT(wchar_t *)
-wunctrl(cchar_t * wc)
+wunctrl(cchar_t *wc)
{
static wchar_t str[5], *sp;
if (Charable(*wc)) {
- const char *p;
- for (p = unctrl(wctob(CharOf(*wc))), sp = str; *p;)
- *sp++ = btowc(*p++);
+ const char *p = unctrl((unsigned) _nc_to_char((wint_t) CharOf(*wc)));
+
+ for (sp = str; *p;)
+ *sp++ = _nc_to_widechar(*p++);
return str;
} else
return wc->chars;