aboutsummaryrefslogtreecommitdiff
path: root/ncurses/widechar
diff options
context:
space:
mode:
authorRong-En Fan <rafan@FreeBSD.org>2008-11-09 09:06:04 +0000
committerRong-En Fan <rafan@FreeBSD.org>2008-11-09 09:06:04 +0000
commita388f199193767bacbb38b172ab89cb84369736c (patch)
treea1816f5667d2280b970ca44e407bac8cc4496c0a /ncurses/widechar
parentaa59d4d4c5dda7e1c6f9dc0cc6edc58992a525c7 (diff)
downloadsrc-a388f199193767bacbb38b172ab89cb84369736c.tar.gz
src-a388f199193767bacbb38b172ab89cb84369736c.zip
- Flatten the vendor area
Notes
Notes: svn path=/vendor/ncurses/dist/; revision=184786
Diffstat (limited to 'ncurses/widechar')
-rw-r--r--ncurses/widechar/charable.c80
-rw-r--r--ncurses/widechar/lib_add_wch.c113
-rw-r--r--ncurses/widechar/lib_box_set.c113
-rw-r--r--ncurses/widechar/lib_cchar.c129
-rw-r--r--ncurses/widechar/lib_erasewchar.c77
-rw-r--r--ncurses/widechar/lib_get_wch.c119
-rw-r--r--ncurses/widechar/lib_get_wstr.c231
-rw-r--r--ncurses/widechar/lib_hline_set.c79
-rw-r--r--ncurses/widechar/lib_in_wch.c62
-rw-r--r--ncurses/widechar/lib_in_wchnstr.c76
-rw-r--r--ncurses/widechar/lib_ins_wch.c144
-rw-r--r--ncurses/widechar/lib_inwstr.c100
-rw-r--r--ncurses/widechar/lib_key_name.c62
-rw-r--r--ncurses/widechar/lib_pecho_wchar.c57
-rw-r--r--ncurses/widechar/lib_slk_wset.c72
-rw-r--r--ncurses/widechar/lib_unget_wch.c103
-rw-r--r--ncurses/widechar/lib_vid_attr.c275
-rw-r--r--ncurses/widechar/lib_vline_set.c78
-rw-r--r--ncurses/widechar/lib_wacs.c117
-rw-r--r--ncurses/widechar/lib_wunctrl.c55
20 files changed, 2142 insertions, 0 deletions
diff --git a/ncurses/widechar/charable.c b/ncurses/widechar/charable.c
new file mode 100644
index 000000000000..cf7240780883
--- /dev/null
+++ b/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/ncurses/widechar/lib_add_wch.c b/ncurses/widechar/lib_add_wch.c
new file mode 100644
index 000000000000..93b41bb4930c
--- /dev/null
+++ b/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/ncurses/widechar/lib_box_set.c b/ncurses/widechar/lib_box_set.c
new file mode 100644
index 000000000000..35fce46d8d40
--- /dev/null
+++ b/ncurses/widechar/lib_box_set.c
@@ -0,0 +1,113 @@
+/****************************************************************************
+ * Copyright (c) 2002 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. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Authors: Sven Verdoolaege and Thomas Dickey 2001,2002 *
+ ****************************************************************************/
+
+/*
+** lib_box_set.c
+**
+** The routine wborder_set().
+**
+*/
+
+#include <curses.priv.h>
+
+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,
+ const ARG_CH_T ls, const ARG_CH_T rs,
+ const ARG_CH_T ts, const ARG_CH_T bs,
+ const ARG_CH_T tl, const ARG_CH_T tr,
+ const ARG_CH_T bl, const ARG_CH_T br)
+{
+ NCURSES_SIZE_T i;
+ NCURSES_SIZE_T endx, endy;
+ NCURSES_CH_T wls, wrs, wts, wbs, wtl, wtr, wbl, wbr;
+
+ T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
+ win,
+ _tracech_t2(1, ls),
+ _tracech_t2(2, rs),
+ _tracech_t2(3, ts),
+ _tracech_t2(4, bs),
+ _tracech_t2(5, tl),
+ _tracech_t2(6, tr),
+ _tracech_t2(7, bl),
+ _tracech_t2(8, br)));
+
+ if (!win)
+ returnCode(ERR);
+
+#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);
+ RENDER_WITH_DEFAULT(ts, WACS_HLINE);
+ RENDER_WITH_DEFAULT(bs, WACS_HLINE);
+ RENDER_WITH_DEFAULT(tl, WACS_ULCORNER);
+ RENDER_WITH_DEFAULT(tr, WACS_URCORNER);
+ RENDER_WITH_DEFAULT(bl, WACS_LLCORNER);
+ RENDER_WITH_DEFAULT(br, WACS_LRCORNER);
+
+ T(("using %s, %s, %s, %s, %s, %s, %s, %s",
+ _tracech_t2(1, CHREF(wls)),
+ _tracech_t2(2, CHREF(wrs)),
+ _tracech_t2(3, CHREF(wts)),
+ _tracech_t2(4, CHREF(wbs)),
+ _tracech_t2(5, CHREF(wtl)),
+ _tracech_t2(6, CHREF(wtr)),
+ _tracech_t2(7, CHREF(wbl)),
+ _tracech_t2(8, CHREF(wbr))));
+
+ endx = win->_maxx;
+ endy = win->_maxy;
+
+ for (i = 0; i <= endx; i++) {
+ win->_line[0].text[i] = wts;
+ win->_line[endy].text[i] = wbs;
+ }
+ win->_line[endy].firstchar = win->_line[0].firstchar = 0;
+ win->_line[endy].lastchar = win->_line[0].lastchar = endx;
+
+ for (i = 0; i <= endy; i++) {
+ win->_line[i].text[0] = wls;
+ win->_line[i].text[endx] = wrs;
+ win->_line[i].firstchar = 0;
+ win->_line[i].lastchar = endx;
+ }
+ win->_line[0].text[0] = wtl;
+ win->_line[0].text[endx] = wtr;
+ win->_line[endy].text[0] = wbl;
+ win->_line[endy].text[endx] = wbr;
+
+ _nc_synchook(win);
+ returnCode(OK);
+}
diff --git a/ncurses/widechar/lib_cchar.c b/ncurses/widechar/lib_cchar.c
new file mode 100644
index 000000000000..b4a0c37a285f
--- /dev/null
+++ b/ncurses/widechar/lib_cchar.c
@@ -0,0 +1,129 @@
+/****************************************************************************
+ * Copyright (c) 2001-2005,2007 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_cchar.c
+**
+** The routines setcchar() and getcchar().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_cchar.c,v 1.12 2007/05/12 19:03:06 tom Exp $")
+
+/*
+ * The SuSv2 description leaves some room for interpretation. We'll assume wch
+ * 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)
+{
+ int i;
+ int len;
+ int code = OK;
+
+ TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"),
+ wcval, _nc_viswbuf(wch),
+ (unsigned long) attrs, color_pair, opts));
+
+ 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) {
+ len = i;
+ break;
+ }
+ }
+
+ memset(wcval, 0, sizeof(*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)));
+ }
+ }
+
+ TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
+
+NCURSES_EXPORT(int)
+getcchar(const cchar_t *wcval,
+ wchar_t *wch,
+ attr_t *attrs,
+ short *color_pair,
+ void *opts)
+{
+ wchar_t *wp;
+ int len;
+ int code = ERR;
+
+ TR(TRACE_CCALLS, (T_CALLED("getcchar(%p,%p,%p,%p,%p)"),
+ wcval, wch, attrs, color_pair, opts));
+
+ if (opts == NULL) {
+ len = (wp = wmemchr(wcval->chars, L'\0', CCHARW_MAX))
+ ? wp - wcval->chars
+ : CCHARW_MAX;
+
+ 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 = GetPair(*wcval);
+ wmemcpy(wch, wcval->chars, (unsigned) len);
+ wch[len] = L'\0';
+ code = OK;
+ }
+ }
+
+ TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
diff --git a/ncurses/widechar/lib_erasewchar.c b/ncurses/widechar/lib_erasewchar.c
new file mode 100644
index 000000000000..7d6455370ff9
--- /dev/null
+++ b/ncurses/widechar/lib_erasewchar.c
@@ -0,0 +1,77 @@
+/****************************************************************************
+ * Copyright (c) 2002 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 2002 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_erasewchar.c,v 1.1 2002/05/11 20:38:06 tom Exp $")
+
+/*
+ * erasewchar()
+ *
+ * Return erase character as given in cur_term->Ottyb.
+ *
+ */
+
+NCURSES_EXPORT(int)
+erasewchar(wchar_t * wch)
+{
+ int value;
+ int result = ERR;
+
+ T((T_CALLED("erasewchar()")));
+ if ((value = erasechar()) != ERR) {
+ *wch = value;
+ result = OK;
+ }
+ returnCode(result);
+}
+
+/*
+ * killwchar()
+ *
+ * Return kill character as given in cur_term->Ottyb.
+ *
+ */
+
+NCURSES_EXPORT(int)
+killwchar(wchar_t * wch)
+{
+ int value;
+ int result = ERR;
+
+ T((T_CALLED("killwchar()")));
+ if ((value = killchar()) != ERR) {
+ *wch = value;
+ result = OK;
+ }
+ returnCode(result);
+}
diff --git a/ncurses/widechar/lib_get_wch.c b/ncurses/widechar/lib_get_wch.c
new file mode 100644
index 000000000000..7985df2571db
--- /dev/null
+++ b/ncurses/widechar/lib_get_wch.c
@@ -0,0 +1,119 @@
+/****************************************************************************
+ * Copyright (c) 2002-2006,2007 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 2002-on *
+ ****************************************************************************/
+
+/*
+** lib_get_wch.c
+**
+** The routine get_wch().
+**
+*/
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_get_wch.c,v 1.14 2007/05/12 19:03:16 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)
+{
+ int code;
+ char buffer[(MB_LEN_MAX * 9) + 1]; /* allow some redundant shifts */
+ int status;
+ 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", (int) count + 1, (int) sizeof(buffer)));
+ code = _nc_wgetch(win, &value, TRUE EVENTLIST_2nd((_nc_eventlist *) 0));
+ if (code == ERR) {
+ break;
+ } else if (code == KEY_CODE_YES) {
+ /*
+ * If we were processing an incomplete multibyte character, return
+ * an error since we have a KEY_xxx code which interrupts it. For
+ * some cases, we could improve this by writing a new version of
+ * lib_getch.c(!), but it is not clear whether the improvement
+ * would be worth the effort.
+ */
+ if (count != 0) {
+ ungetch((int) value);
+ code = ERR;
+ }
+ break;
+ } else if (count + 1 >= sizeof(buffer)) {
+ ungetch((int) value);
+ code = ERR;
+ break;
+ } else {
+ buffer[count++] = UChar(value);
+ reset_mbytes(state);
+ status = count_mbytes(buffer, count, state);
+ if (status >= 0) {
+ reset_mbytes(state);
+ if (check_mbytes(wch, buffer, count, state) != status) {
+ code = ERR; /* the two calls should match */
+ ungetch((int) value);
+ }
+ value = wch;
+ break;
+ }
+ }
+ }
+ *result = value;
+ T(("result %#lo", value));
+ returnCode(code);
+}
diff --git a/ncurses/widechar/lib_get_wstr.c b/ncurses/widechar/lib_get_wstr.c
new file mode 100644
index 000000000000..bf39aa1a188b
--- /dev/null
+++ b/ncurses/widechar/lib_get_wstr.c
@@ -0,0 +1,231 @@
+/****************************************************************************
+ * 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 *
+ * "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_get_wstr.c
+**
+** The routine wgetn_wstr().
+**
+*/
+
+#include <curses.priv.h>
+#include <term.h>
+
+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 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);
+ 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))
+ waddch(win, (chtype) ' ');
+
+ wmove(win, y, x);
+ }
+ }
+ return last;
+}
+
+NCURSES_EXPORT(int)
+wgetn_wstr(WINDOW *win, wint_t *str, int maxlen)
+{
+ TTY buf;
+ bool oldnl, oldecho, oldraw, oldcbreak;
+ wint_t erasec;
+ wint_t killc;
+ wint_t *oldstr = str;
+ wint_t *tmpstr = str;
+ wint_t ch;
+ int y, x, code;
+
+ T((T_CALLED("wgetn_wstr(%p,%p, %d)"), win, str, maxlen));
+
+ if (!win)
+ returnCode(ERR);
+
+ _nc_get_tty_mode(&buf);
+
+ oldnl = SP->_nl;
+ oldecho = SP->_echo;
+ oldraw = SP->_raw;
+ oldcbreak = SP->_cbreak;
+ nl();
+ noecho();
+ noraw();
+ cbreak();
+
+ erasec = erasechar();
+ killc = killchar();
+
+ 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
+ * from the down-arrow key. With this logic, it's the user's
+ * choice whether to set kcud=\n for wget_wch(); terminating
+ * *getn_wstr() with \n should work either way.
+ */
+ if (ch == KEY_DOWN || ch == KEY_ENTER) {
+ if (oldecho == TRUE
+ && win->_cury == win->_maxy
+ && win->_scroll)
+ wechochar(win, (chtype) '\n');
+ break;
+ }
+ if (ch == KEY_LEFT || ch == KEY_BACKSPACE) {
+ if (tmpstr > oldstr) {
+ tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+ }
+ } else if (ch == KEY_EOL) {
+ while (tmpstr > oldstr) {
+ tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+ }
+ } else {
+ beep();
+ }
+ } else if (maxlen >= 0 && tmpstr - oldstr >= maxlen) {
+ beep();
+ } else {
+ *tmpstr++ = ch;
+ *tmpstr = 0;
+ if (oldecho == TRUE) {
+ int oldy = win->_cury;
+
+ 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.
+ */
+ win->_flags &= ~_WRAPPED;
+ waddch(win, (chtype) ' ');
+ tmpstr = WipeOut(win, y, x, oldstr, tmpstr, oldecho);
+ continue;
+ } else if (win->_flags & _WRAPPED) {
+ /*
+ * If the last waddch forced a wrap & scroll, adjust our
+ * reference point for erasures.
+ */
+ if (win->_scroll
+ && oldy == win->_maxy
+ && win->_cury == win->_maxy) {
+ if (--y <= 0) {
+ y = 0;
+ }
+ }
+ win->_flags &= ~_WRAPPED;
+ }
+ wrefresh(win);
+ }
+ }
+ }
+
+ win->_curx = 0;
+ win->_flags &= ~_WRAPPED;
+ if (win->_cury < win->_maxy)
+ win->_cury++;
+ wrefresh(win);
+
+ /* Restore with a single I/O call, to fix minor asymmetry between
+ * raw/noraw, etc.
+ */
+ SP->_nl = oldnl;
+ SP->_echo = oldecho;
+ SP->_raw = oldraw;
+ SP->_cbreak = oldcbreak;
+
+ (void) _nc_set_tty_mode(&buf);
+
+ *tmpstr = 0;
+ if (code == ERR) {
+ if (tmpstr == oldstr) {
+ *tmpstr++ = WEOF;
+ *tmpstr = 0;
+ }
+ returnCode(ERR);
+ }
+
+ T(("wgetn_wstr returns %s", _nc_viswibuf(oldstr)));
+
+ returnCode(OK);
+}
diff --git a/ncurses/widechar/lib_hline_set.c b/ncurses/widechar/lib_hline_set.c
new file mode 100644
index 000000000000..43175de83464
--- /dev/null
+++ b/ncurses/widechar/lib_hline_set.c
@@ -0,0 +1,79 @@
+/****************************************************************************
+ * Copyright (c) 2002 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 Dickey 2002 *
+ ****************************************************************************/
+
+/*
+** lib_hline_set.c
+**
+** The routine whline_set().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_hline_set.c,v 1.2 2002/03/23 21:35:34 tom Exp $")
+
+NCURSES_EXPORT(int)
+whline_set(WINDOW *win, const cchar_t * ch, int n)
+{
+ int code = ERR;
+ NCURSES_SIZE_T start;
+ NCURSES_SIZE_T end;
+
+ T((T_CALLED("whline_set(%p,%s,%d)"), win, _tracecchar_t(ch), n));
+
+ if (win) {
+ struct ldat *line = &(win->_line[win->_cury]);
+ NCURSES_CH_T wch;
+
+ start = win->_curx;
+ end = start + n - 1;
+ if (end > win->_maxx)
+ end = win->_maxx;
+
+ CHANGED_RANGE(line, start, end);
+
+ if (ch == 0)
+ wch = *WACS_HLINE;
+ else
+ wch = *ch;
+ wch = _nc_render(win, wch);
+
+ while (end >= start) {
+ line->text[end] = wch;
+ end--;
+ }
+
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/widechar/lib_in_wch.c b/ncurses/widechar/lib_in_wch.c
new file mode 100644
index 000000000000..5cd92e382de4
--- /dev/null
+++ b/ncurses/widechar/lib_in_wch.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * 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 *
+ * "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 Dickey *
+ ****************************************************************************/
+
+/*
+** lib_in_wch.c
+**
+** The routine win_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+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, cchar_t *wcval)
+{
+ int row, col;
+ int code = OK;
+
+ TR(TRACE_CCALLS, (T_CALLED("win_wch(%p,%p)"), win, wcval));
+ if (win != 0
+ && wcval != 0) {
+ getyx(win, row, col);
+
+ *wcval = win->_line[row].text[col];
+ TR(TRACE_CCALLS, ("data %s", _tracecchar_t(wcval)));
+ } else {
+ code = ERR;
+ }
+ TR(TRACE_CCALLS, (T_RETURN("%d"), code));
+ return (code);
+}
diff --git a/ncurses/widechar/lib_in_wchnstr.c b/ncurses/widechar/lib_in_wchnstr.c
new file mode 100644
index 000000000000..e9f0646ea66a
--- /dev/null
+++ b/ncurses/widechar/lib_in_wchnstr.c
@@ -0,0 +1,76 @@
+/****************************************************************************
+ * Copyright (c) 2002-2004-2007 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 Dickey *
+ ****************************************************************************/
+
+/*
+** lib_in_wchnstr.c
+**
+** The routine win_wchnstr().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_in_wchnstr.c,v 1.7 2007/02/11 01:00:00 tom Exp $")
+
+NCURSES_EXPORT(int)
+win_wchnstr(WINDOW *win, cchar_t *wchstr, int n)
+{
+ int code = OK;
+
+ T((T_CALLED("win_wchnstr(%p,%p,%d)"), win, wchstr, n));
+ if (win != 0
+ && wchstr != 0) {
+ NCURSES_CH_T *src;
+ int row, col;
+ int j, k, limit;
+
+ getyx(win, row, col);
+ limit = getmaxx(win) - col;
+ src = &(win->_line[row].text[col]);
+
+ if (n < 0) {
+ n = limit;
+ } else if (n > limit) {
+ n = limit;
+ }
+ for (j = k = 0; j < n; ++j) {
+ if (j == 0 || !WidecExt(src[j]) || isWidecBase(src[j])) {
+ wchstr[k++] = src[j];
+ }
+ }
+ memset(&(wchstr[k]), 0, sizeof(*wchstr));
+ T(("result = %s", _nc_viscbuf(wchstr, n)));
+ } else {
+ code = ERR;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/widechar/lib_ins_wch.c b/ncurses/widechar/lib_ins_wch.c
new file mode 100644
index 000000000000..c3d0420e53b8
--- /dev/null
+++ b/ncurses/widechar/lib_ins_wch.c
@@ -0,0 +1,144 @@
+/****************************************************************************
+ * 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 *
+ * "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 Dickey 2002 *
+ ****************************************************************************/
+
+/*
+** lib_ins_wch.c
+**
+** The routine wins_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_ins_wch.c,v 1.8 2005/12/03 20:24:19 tom Exp $")
+
+/*
+ * 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 cells = wcwidth(CharOf(CHDEREF(wch)));
+ int cell;
+
+ if (cells <= 0)
+ cells = 1;
+
+ 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 - 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/ncurses/widechar/lib_inwstr.c b/ncurses/widechar/lib_inwstr.c
new file mode 100644
index 000000000000..2207a5f5d19f
--- /dev/null
+++ b/ncurses/widechar/lib_inwstr.c
@@ -0,0 +1,100 @@
+/****************************************************************************
+ * 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 *
+ * "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 Dickey *
+ ****************************************************************************/
+
+/*
+** lib_inwstr.c
+**
+** The routines winnwstr() and winwstr().
+**
+*/
+
+#include <curses.priv.h>
+
+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)
+{
+ int row, col, inx;
+ int count = 0;
+ int last = 0;
+ cchar_t *text;
+ wchar_t wch;
+
+ 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) {
+ 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;
+ }
+ wstr[count++] = wch;
+ }
+ }
+ last = count;
+ if (++col > win->_maxx) {
+ break;
+ }
+ }
+ }
+ if (count > 0) {
+ wstr[count] = '\0';
+ T(("winnwstr returns %s", _nc_viswbuf(wstr)));
+ }
+ }
+ returnCode(count);
+}
+
+/*
+ * X/Open says winwstr() returns OK if not ERR. If that is not a blunder, it
+ * must have a null termination on the string (see above). Unlike winnstr(),
+ * it does not define what happens for a negative count with winnwstr().
+ */
+NCURSES_EXPORT(int)
+winwstr(WINDOW *win, wchar_t *wstr)
+{
+ int result = OK;
+ 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/ncurses/widechar/lib_key_name.c b/ncurses/widechar/lib_key_name.c
new file mode 100644
index 000000000000..e24c9654d564
--- /dev/null
+++ b/ncurses/widechar/lib_key_name.c
@@ -0,0 +1,62 @@
+/****************************************************************************
+ * Copyright (c) 2007 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_key_name.c
+**
+** The routine key_name().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_key_name.c,v 1.2 2007/06/12 21:01:13 tom Exp $")
+
+NCURSES_EXPORT(NCURSES_CONST char *)
+key_name(wchar_t c)
+{
+ cchar_t my_cchar;
+ wchar_t *my_wchars;
+ size_t len;
+
+ /* FIXME: move to _nc_globals */
+ static char result[MB_LEN_MAX + 1];
+
+ memset(&my_cchar, 0, sizeof(my_cchar));
+ my_cchar.chars[0] = c;
+ my_cchar.chars[1] = L'\0';
+
+ my_wchars = wunctrl(&my_cchar);
+ len = wcstombs(result, my_wchars, sizeof(result) - 1);
+ if (isEILSEQ(len) || (len == 0)) {
+ return "UNKNOWN KEY";
+ }
+
+ result[len] = '\0';
+ return result;
+}
diff --git a/ncurses/widechar/lib_pecho_wchar.c b/ncurses/widechar/lib_pecho_wchar.c
new file mode 100644
index 000000000000..e61277574311
--- /dev/null
+++ b/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/ncurses/widechar/lib_slk_wset.c b/ncurses/widechar/lib_slk_wset.c
new file mode 100644
index 000000000000..646b5d9e2fa8
--- /dev/null
+++ b/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/ncurses/widechar/lib_unget_wch.c b/ncurses/widechar/lib_unget_wch.c
new file mode 100644
index 000000000000..b2dc7ff96f1b
--- /dev/null
+++ b/ncurses/widechar/lib_unget_wch.c
@@ -0,0 +1,103 @@
+/****************************************************************************
+ * Copyright (c) 2002-2004,2007 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 2002 *
+ ****************************************************************************/
+
+/*
+** lib_unget_wch.c
+**
+** The routine unget_wch().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_unget_wch.c,v 1.9 2007/11/25 00:57:00 tom Exp $")
+
+/*
+ * Wrapper for wcrtomb() which obtains the length needed for the given
+ * wide-character 'source'.
+ */
+NCURSES_EXPORT(size_t)
+_nc_wcrtomb(char *target, wchar_t source, mbstate_t * state)
+{
+ int result;
+
+ if (target == 0) {
+ wchar_t temp[2];
+ const wchar_t *tempp = temp;
+ temp[0] = source;
+ temp[1] = 0;
+ result = wcsrtombs(NULL, &tempp, 0, state);
+ } else {
+ result = wcrtomb(target, source, state);
+ }
+ if (!isEILSEQ(result) && (result == 0))
+ result = 1;
+ return result;
+}
+
+NCURSES_EXPORT(int)
+unget_wch(const wchar_t wch)
+{
+ int result = OK;
+ mbstate_t state;
+ size_t length;
+ int n;
+
+ T((T_CALLED("unget_wch(%#lx)"), (unsigned long) wch));
+
+ init_mb(state);
+ length = _nc_wcrtomb(0, wch, &state);
+
+ if (length != (size_t) (-1)
+ && length != 0) {
+ char *string;
+
+ 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;
+ }
+ }
+ free(string);
+ } else {
+ result = ERR;
+ }
+ } else {
+ result = ERR;
+ }
+
+ returnCode(result);
+}
diff --git a/ncurses/widechar/lib_vid_attr.c b/ncurses/widechar/lib_vid_attr.c
new file mode 100644
index 000000000000..1dc679e6d907
--- /dev/null
+++ b/ncurses/widechar/lib_vid_attr.c
@@ -0,0 +1,275 @@
+/****************************************************************************
+ * Copyright (c) 2002-2006,2007 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>
+#include <term.h>
+
+MODULE_ID("$Id: lib_vid_attr.c,v 1.5 2007/06/30 22:03:02 tom Exp $")
+
+#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
+
+ newmode &= A_ATTRIBUTES;
+ 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)
+{
+ T((T_CALLED("vid_attr(%s,%d)"), _traceattr(newmode), pair));
+ 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;
+
+ T((T_CALLED("term_attrs()")));
+ attrs = termattrs();
+
+ /* 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/ncurses/widechar/lib_vline_set.c b/ncurses/widechar/lib_vline_set.c
new file mode 100644
index 000000000000..af42df1f24ab
--- /dev/null
+++ b/ncurses/widechar/lib_vline_set.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 2002 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 Dickey 2002 *
+ ****************************************************************************/
+
+/*
+** lib_vline_set.c
+**
+** The routine wvline_set().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_vline_set.c,v 1.2 2002/03/23 21:36:01 tom Exp $")
+
+NCURSES_EXPORT(int)
+wvline_set(WINDOW *win, const cchar_t * ch, int n)
+{
+ int code = ERR;
+ NCURSES_SIZE_T row, col;
+ NCURSES_SIZE_T end;
+
+ T((T_CALLED("wvline(%p,%s,%d)"), win, _tracecchar_t(ch), n));
+
+ if (win) {
+ NCURSES_CH_T wch;
+ row = win->_cury;
+ col = win->_curx;
+ end = row + n - 1;
+ if (end > win->_maxy)
+ end = win->_maxy;
+
+ if (ch == 0)
+ wch = *WACS_VLINE;
+ else
+ wch = *ch;
+ wch = _nc_render(win, wch);
+
+ while (end >= row) {
+ struct ldat *line = &(win->_line[end]);
+ line->text[col] = wch;
+ CHANGED_CELL(line, col);
+ end--;
+ }
+
+ _nc_synchook(win);
+ code = OK;
+ }
+ returnCode(code);
+}
diff --git a/ncurses/widechar/lib_wacs.c b/ncurses/widechar/lib_wacs.c
new file mode 100644
index 000000000000..fe893b4d2f8b
--- /dev/null
+++ b/ncurses/widechar/lib_wacs.c
@@ -0,0 +1,117 @@
+/****************************************************************************
+ * 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 *
+ * "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 Dickey 2002 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h>
+
+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;
+
+NCURSES_EXPORT(void)
+_nc_init_wacs(void)
+{
+ /* *INDENT-OFF* */
+ static const struct {
+ int map;
+ int value[2];
+ } table[] = {
+ /* VT100 symbols */
+ { 'l', { '+', 0x250c }}, /* upper left corner */
+ { 'm', { '+', 0x2514 }}, /* lower left corner */
+ { 'k', { '+', 0x2510 }}, /* upper right corner */
+ { 'j', { '+', 0x2518 }}, /* lower right corner */
+ { 't', { '+', 0x251c }}, /* tee pointing left */
+ { 'u', { '+', 0x2524 }}, /* tee pointing right */
+ { 'v', { '+', 0x2534 }}, /* tee pointing up */
+ { 'w', { '+', 0x252c }}, /* tee pointing down */
+ { 'q', { '-', 0x2500 }}, /* horizontal line */
+ { 'x', { '|', 0x2502 }}, /* vertical line */
+ { 'n', { '+', 0x253c }}, /* large plus or crossover */
+ { 'o', { '~', 0x23ba }}, /* scan line 1 */
+ { 's', { '_', 0x23bd }}, /* scan line 9 */
+ { '`', { '+', 0x25c6 }}, /* diamond */
+ { 'a', { ':', 0x2592 }}, /* checker board (stipple) */
+ { 'f', { '\'', 0x00b0 }}, /* degree symbol */
+ { 'g', { '#', 0x00b1 }}, /* plus/minus */
+ { '~', { 'o', 0x00b7 }}, /* bullet */
+ /* Teletype 5410v1 symbols */
+ { ',', { '<', 0x2190 }}, /* arrow pointing left */
+ { '+', { '>', 0x2192 }}, /* arrow pointing right */
+ { '.', { 'v', 0x2193 }}, /* arrow pointing down */
+ { '-', { '^', 0x2191 }}, /* arrow pointing up */
+ { 'h', { '#', 0x2592 }}, /* board of squares */
+ { 'i', { '#', 0x2603 }}, /* lantern symbol */
+ { '0', { '#', 0x25ae }}, /* solid square block */
+ /* these defaults were invented for ncurses */
+ { 'p', { '-', 0x23bb }}, /* scan line 3 */
+ { 'r', { '-', 0x23bc }}, /* scan line 7 */
+ { 'y', { '<', 0x2264 }}, /* less-than-or-equal-to */
+ { 'z', { '>', 0x2265 }}, /* greater-than-or-equal-to */
+ { '{', { '*', 0x03c0 }}, /* greek pi */
+ { '|', { '!', 0x2260 }}, /* not-equal */
+ { '}', { 'f', 0x00a3 }}, /* pound-sterling symbol */
+ };
+ /* *INDENT-ON* */
+
+ 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"));
+
+ _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;
+ 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],
+ _tracecchar_t(&_nc_wacs[m])));
+ }
+}
diff --git a/ncurses/widechar/lib_wunctrl.c b/ncurses/widechar/lib_wunctrl.c
new file mode 100644
index 000000000000..be2259acdcff
--- /dev/null
+++ b/ncurses/widechar/lib_wunctrl.c
@@ -0,0 +1,55 @@
+/****************************************************************************
+ * Copyright (c) 2001-2005,2007 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_wunctrl.c
+**
+** The routine wunctrl().
+**
+*/
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_wunctrl.c,v 1.12 2007/06/12 20:22:32 tom Exp $")
+
+NCURSES_EXPORT(wchar_t *)
+wunctrl(cchar_t *wc)
+{
+ static wchar_t str[CCHARW_MAX + 1], *sp;
+
+ if (Charable(*wc)) {
+ const char *p = unctrl((unsigned) _nc_to_char((wint_t) CharOf(*wc)));
+
+ for (sp = str; *p; ++p) {
+ *sp++ = _nc_to_widechar(*p);
+ }
+ *sp = 0;
+ return str;
+ } else
+ return wc->chars;
+}