Back to index

tetex-bin  3.0
charable.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 2003,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 **     Support functions for wide/narrow conversion.
00031 */
00032 
00033 #include <curses.priv.h>
00034 
00035 MODULE_ID("$Id: charable.c,v 1.3 2004/09/25 21:03:44 tom Exp $")
00036 
00037 NCURSES_EXPORT(bool) _nc_is_charable(wchar_t ch)
00038 {
00039     bool result;
00040 #if HAVE_WCTOB
00041     result = (wctob(ch) == ch);
00042 #else
00043     result = (_nc_to_char(ch) >= 0);
00044 #endif
00045     return result;
00046 }
00047 
00048 NCURSES_EXPORT(int) _nc_to_char(wint_t ch)
00049 {
00050     int result;
00051 #if HAVE_WCTOB
00052     result = wctob(ch);
00053 #elif HAVE_WCTOMB
00054     char temp[MB_LEN_MAX];
00055     result = wctomb(temp, ch);
00056     if (strlen(temp) == 1)
00057        result = UChar(temp[0]);
00058     else
00059        result = -1;
00060 #endif
00061     return result;
00062 }
00063 
00064 NCURSES_EXPORT(wint_t) _nc_to_widechar(int ch)
00065 {
00066     wint_t result;
00067 #if HAVE_BTOWC
00068     result = btowc(ch);
00069 #elif HAVE_MBTOWC
00070     wchar_t convert;
00071     char temp[2];
00072     temp[0] = ch;
00073     temp[1] = '\0';
00074     if (mbtowc(&convert, temp, 1) >= 0)
00075        result = convert;
00076     else
00077        result = WEOF;
00078 #endif
00079     return result;
00080 }