1166124Srafan/****************************************************************************
2262629Sdelphij * Copyright (c) 2004,2009 Free Software Foundation, Inc.                   *
3166124Srafan *                                                                          *
4166124Srafan * Permission is hereby granted, free of charge, to any person obtaining a  *
5166124Srafan * copy of this software and associated documentation files (the            *
6166124Srafan * "Software"), to deal in the Software without restriction, including      *
7166124Srafan * without limitation the rights to use, copy, modify, merge, publish,      *
8166124Srafan * distribute, distribute with modifications, sublicense, and/or sell       *
9166124Srafan * copies of the Software, and to permit persons to whom the Software is    *
10166124Srafan * furnished to do so, subject to the following conditions:                 *
11166124Srafan *                                                                          *
12166124Srafan * The above copyright notice and this permission notice shall be included  *
13166124Srafan * in all copies or substantial portions of the Software.                   *
14166124Srafan *                                                                          *
15166124Srafan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16166124Srafan * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17166124Srafan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18166124Srafan * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19166124Srafan * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20166124Srafan * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21166124Srafan * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22166124Srafan *                                                                          *
23166124Srafan * Except as contained in this notice, the name(s) of the above copyright   *
24166124Srafan * holders shall not be used in advertising or otherwise to promote the     *
25166124Srafan * sale, use or other dealings in this Software without prior written       *
26166124Srafan * authorization.                                                           *
27166124Srafan ****************************************************************************/
28166124Srafan
29166124Srafan/****************************************************************************
30166124Srafan *  Author: Thomas E. Dickey                                                *
31166124Srafan ****************************************************************************/
32166124Srafan
33166124Srafan/*
34166124Srafan**	lib_insnstr.c
35166124Srafan**
36166124Srafan**	The routine winsnstr().
37166124Srafan**
38166124Srafan*/
39166124Srafan
40166124Srafan#include <curses.priv.h>
41166124Srafan#include <ctype.h>
42166124Srafan
43262629SdelphijMODULE_ID("$Id: lib_insnstr.c,v 1.3 2009/10/24 22:04:35 tom Exp $")
44166124Srafan
45166124SrafanNCURSES_EXPORT(int)
46166124Srafanwinsnstr(WINDOW *win, const char *s, int n)
47166124Srafan{
48166124Srafan    int code = ERR;
49166124Srafan    NCURSES_SIZE_T oy;
50166124Srafan    NCURSES_SIZE_T ox;
51166124Srafan    const unsigned char *str = (const unsigned char *) s;
52166124Srafan    const unsigned char *cp;
53166124Srafan
54262629Sdelphij    T((T_CALLED("winsnstr(%p,%s,%d)"), (void *) win, _nc_visbufn(s, n), n));
55166124Srafan
56166124Srafan    if (win != 0 && str != 0) {
57262629Sdelphij	SCREEN *sp = _nc_screen_of(win);
58262629Sdelphij
59166124Srafan	oy = win->_cury;
60166124Srafan	ox = win->_curx;
61166124Srafan	for (cp = str; *cp && (n <= 0 || (cp - str) < n); cp++) {
62262629Sdelphij	    _nc_insert_ch(sp, win, (chtype) UChar(*cp));
63166124Srafan	}
64166124Srafan	win->_curx = ox;
65166124Srafan	win->_cury = oy;
66166124Srafan	_nc_synchook(win);
67166124Srafan	code = OK;
68166124Srafan    }
69166124Srafan    returnCode(code);
70166124Srafan}
71