1 /* $NetBSD: inwstr.c,v 1.2 2007/05/28 15:01:56 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: inwstr.c,v 1.2 2007/05/28 15:01:56 blymn Exp $");
43 #include "curses_private.h"
47 * Return a string of wide characters at cursor position from stdscr.
49 __warn_references(inwstr
,
50 "warning: this program uses inwstr(), which is unsafe.")
57 return winwstr(stdscr
, wstr
);
58 #endif /* HAVE_WCHAR */
62 innwstr(wchar_t *wstr
, int n
)
67 return winnwstr(stdscr
, wstr
, n
);
68 #endif /* HAVE_WCHAR */
72 * mvinwstr, mvinnwstr --
73 * Return a string of wide characters at position (y, x) from stdscr.
75 __warn_references(mvinwstr
,
76 "warning: this program uses mvinwstr(), which is unsafe.")
78 mvinwstr(int y
, int x
, wchar_t *wstr
)
83 return mvwinwstr(stdscr
, y
, x
, wstr
);
84 #endif /* HAVE_WCHAR */
88 mvinnwstr(int y
, int x
, wchar_t *wstr
, int n
)
93 return mvwinnwstr(stdscr
, y
, x
, wstr
, n
);
94 #endif /* HAVE_WCHAR */
98 * mvwinwstr, mvwinnwstr --
99 * Return an array wide characters at position (y, x) from the given window.
101 __warn_references(mvwinwstr
,
102 "warning: this program uses mvwinwstr(), which is unsafe.")
104 mvwinwstr(WINDOW
*win
, int y
, int x
, wchar_t *wstr
)
109 if (wmove(win
, y
, x
) == ERR
)
112 return winwstr(win
, wstr
);
113 #endif /* HAVE_WCHAR */
117 mvwinnwstr(WINDOW
*win
, int y
, int x
, wchar_t *wstr
, int n
)
122 if (wmove(win
, y
, x
) == ERR
)
125 return winnwstr(win
, wstr
, n
);
126 #endif /* HAVE_WCHAR */
130 * winwstr, winnwstr --
131 * Return a string of wide characters at cursor position.
133 __warn_references(winwstr
,
134 "warning: this program uses winwstr(), which is unsafe.")
136 winwstr(WINDOW
*win
, wchar_t *wstr
)
142 return winnwstr(win
, wstr
, -1);
143 #endif /* HAVE_WCHAR */
147 * - winnwstr() returns the number of characters copied only of if it is
148 * called with n >= 0 (ie, as in_wchnstr(), mvin_wchnstr(), mvwin_wchnstr()
149 * or win_wchnstr()). If N < 0, it returns `OK'.
150 * - SUSv2/xcurses doesn't document whether the trailing NUL is included
151 * in the length count or not. For safety's sake it _is_ included.
152 * - This implementation does not (yet) support multi-byte characters
156 winnwstr(WINDOW
*win
, wchar_t *wstr
, int n
)
168 start
= &win
->alines
[win
->cury
]->line
[win
->curx
];
177 /* (n - 1) to leave room for the trailing 0 element */
178 while ((x
< win
->maxx
) && ((n
< 0) || ((n
> 1) && (cnt
< n
- 1)))) {
193 #endif /* HAVE_WCHAR */