Back to index

tetex-bin  3.0
lib_add_wch.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 2004 Free Software Foundation, Inc.                        *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /*
00030 **     lib_add_wch.c
00031 **
00032 **     The routine wadd_wch().
00033 **
00034 */
00035 
00036 #include <curses.priv.h>
00037 
00038 MODULE_ID("$Id: lib_add_wch.c,v 1.4 2004/09/19 00:33:51 tom Exp $")
00039 
00040 NCURSES_EXPORT(int)
00041 wadd_wch(WINDOW *win, const cchar_t * wch)
00042 {
00043     PUTC_DATA;
00044     int n;
00045     int code = ERR;
00046 
00047     TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wadd_wch(%p, %s)"), win,
00048                                   _tracech_t(wch)));
00049 
00050     if (win != 0) {
00051        PUTC_INIT;
00052        while (PUTC_i < CCHARW_MAX) {
00053            if ((PUTC_ch = wch->chars[PUTC_i++]) == L'\0')
00054               break;
00055            if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
00056               code = ERR;
00057               if (is8bits(PUTC_ch))
00058                   code = waddch(win, UChar(PUTC_ch) | wch->attr);
00059               break;
00060            }
00061            for (n = 0; n < PUTC_n; n++) {
00062               if ((code = waddch(win, UChar(PUTC_buf[n]) | wch->attr)) == ERR) {
00063                   break;
00064               }
00065            }
00066            if (code == ERR)
00067               break;
00068        }
00069     }
00070 
00071     TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
00072     return (code);
00073 }
00074 
00075 NCURSES_EXPORT(int)
00076 wecho_wchar(WINDOW *win, const cchar_t * wch)
00077 {
00078     PUTC_DATA;
00079     int n;
00080     int code = ERR;
00081 
00082     TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_CALLED("wecho_wchar(%p, %s)"), win,
00083                                   _tracech_t(wch)));
00084 
00085     if (win != 0) {
00086        PUTC_INIT;
00087        while (PUTC_i < CCHARW_MAX) {
00088            if ((PUTC_ch = wch->chars[PUTC_i++]) == L'\0')
00089               break;
00090            if ((PUTC_n = wcrtomb(PUTC_buf, PUTC_ch, &PUT_st)) <= 0) {
00091               code = ERR;
00092               if (is8bits(PUTC_ch))
00093                   code = waddch(win, UChar(PUTC_ch) | wch->attr);
00094               break;
00095            }
00096            for (n = 0; n < PUTC_n; n++) {
00097               if ((code = waddch(win, UChar(PUTC_buf[n]) | wch->attr)) == ERR) {
00098                   break;
00099               }
00100            }
00101            if (code == ERR)
00102               break;
00103        }
00104        wrefresh(win);
00105     }
00106 
00107     TR(TRACE_VIRTPUT | TRACE_CCALLS, (T_RETURN("%d"), code));
00108     return (code);
00109 }