1 /* $NetBSD: addwstr.c,v 1.2 2007/05/28 15:01:54 blymn Exp $ */
4 * Copyright (c) 2005 The NetBSD Foundation Inc.
7 * This code is derived from code donated to the NetBSD Foundation
8 * by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the NetBSD Foundation nor the names of its
20 * contributors may be used to endorse or promote products derived
21 * from this software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
24 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 #include <sys/cdefs.h>
39 __RCSID("$NetBSD: addwstr.c,v 1.2 2007/05/28 15:01:54 blymn Exp $");
45 #include "curses_private.h"
49 * Add a string to stdscr starting at (_cury, _curx).
52 addwstr(const wchar_t *s
)
57 return waddnwstr(stdscr
, s
, -1);
58 #endif /* HAVE_WCHAR */
63 * Add a string to the given window starting at (_cury, _curx).
66 waddwstr(WINDOW
*win
, const wchar_t *s
)
71 return waddnwstr(win
, s
, -1);
72 #endif /* HAVE_WCHAR */
77 * Add a string (at most n characters) to stdscr starting
78 * at (_cury, _curx). If n is negative, add the entire string.
81 addnwstr(const wchar_t *str
, int n
)
86 return waddnwstr(stdscr
, str
, n
);
87 #endif /* HAVE_WCHAR */
92 * Add a string to stdscr starting at (y, x)
95 mvaddwstr(int y
, int x
, const wchar_t *str
)
100 return mvwaddnwstr(stdscr
, y
, x
, str
, -1);
101 #endif /* HAVE_WCHAR */
106 * Add a string to the given window starting at (y, x)
109 mvwaddwstr(WINDOW
*win
, int y
, int x
, const wchar_t *str
)
114 return mvwaddnwstr(win
, y
, x
, str
, -1);
115 #endif /* HAVE_WCHAR */
120 * Add a string of at most n characters to stdscr
121 * starting at (y, x).
124 mvaddnwstr(int y
, int x
, const wchar_t *str
, int count
)
129 return mvwaddnwstr(stdscr
, y
, x
, str
, count
);
130 #endif /* HAVE_WCHAR */
135 * Add a string of at most n characters to the given window
136 * starting at (y, x).
139 mvwaddnwstr(WINDOW
*win
, int y
, int x
, const wchar_t *str
, int count
)
144 if (wmove(win
, y
, x
) == ERR
)
147 return waddnwstr(win
, str
, count
);
148 #endif /* HAVE_WCHAR */
153 * Add a string (at most n characters) to the given window
154 * starting at (_cury, _curx). If n is negative, add the
158 waddnwstr(WINDOW
*win
, const wchar_t *s
, int n
)
169 * BSD curses: if (n > 0) then "at most n", else "len = strlen(s)"
170 * ncurses: if (n >= 0) then "at most n", else "len = strlen(s)"
171 * XCURSES: if (n != -1) then "at most n", else "len = strlen(s)"
173 /* compute the length and column width of string */
177 for (p
= s
, len
= 0; n
-- && *p
++; ++len
);
181 __CTRACE(__CTRACE_INPUT
, "waddnwstr: string len=%ld\n", (long) len
);
188 if ( setcchar( &cc
, wc
, win
->wattr
, 0, NULL
) == ERR
)
190 if ( wadd_wch( win
, &cc
) == ERR
)
193 __CTRACE(__CTRACE_INPUT
, "waddnwstr: (%x,%x,%d) added\n",
194 cc
.vals
[ 0 ], cc
.attributes
, cc
.elements
);
200 #endif /* HAVE_WCHAR */