Back to index

tetex-bin  3.0
lib_inwstr.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 2002 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  * Author: Thomas Dickey 2002                                               *
00031  ****************************************************************************/
00032 
00033 /*
00034 **     lib_inwstr.c
00035 **
00036 **     The routines winnwstr() and winwstr().
00037 **
00038 */
00039 
00040 #include <curses.priv.h>
00041 
00042 MODULE_ID("$Id: lib_inwstr.c,v 1.3 2002/10/06 00:56:36 tom Exp $")
00043 
00044 NCURSES_EXPORT(int)
00045 winnwstr(WINDOW *win, wchar_t * wstr, int n)
00046 {
00047     int row, col, inx;
00048     int count = 0;
00049     int last = 0;
00050     cchar_t *text;
00051     wchar_t wch;
00052 
00053     T((T_CALLED("winnwstr(%p,%p,%d)"), win, wstr, n));
00054     if (wstr != 0) {
00055        if (win) {
00056            getyx(win, row, col);
00057 
00058            text = win->_line[row].text;
00059            while (count < n && count != ERR) {
00060               if (!isnac(text[col])) {
00061                   for (inx = 0; (inx < CCHARW_MAX)
00062                       && ((wch = text[col].chars[inx]) != 0);
00063                       ++inx) {
00064                      if (count + 1 > n) {
00065                          if ((count = last) == 0) {
00066                             count = ERR;  /* error if we store nothing */
00067                          }
00068                          break;
00069                      }
00070                      wstr[count++] = wch;
00071                   }
00072               }
00073               last = count;
00074               if (++col > win->_maxx) {
00075                   break;
00076               }
00077            }
00078        }
00079        if (count > 0) {
00080            wstr[count] = '\0';
00081            T(("winnwstr returns %s", _nc_viswbuf(wstr)));
00082        }
00083     }
00084     returnCode(count);
00085 }
00086 
00087 /*
00088  * X/Open says winwstr() returns OK if not ERR.  If that is not a blunder, it
00089  * must have a null termination on the string (see above).  Unlike winnstr(),
00090  * it does not define what happens for a negative count with winnwstr().
00091  */
00092 NCURSES_EXPORT(int)
00093 winwstr(WINDOW *win, wchar_t * wstr)
00094 {
00095     int result = OK;
00096     T((T_CALLED("winwstr(%p,%p)"), win, wstr));
00097     if (winnwstr(win, wstr, CCHARW_MAX * (win->_maxx - win->_curx + 1)) == ERR)
00098        result = ERR;
00099     returnCode(result);
00100 }