1 /* $NetBSD: in_wchstr.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: in_wchstr.c,v 1.2 2007/05/28 15:01:56 blymn Exp $");
43 #include "curses_private.h"
46 * in_wchstr, in_wchnstr --
47 * Return an array of wide characters at cursor position from stdscr.
49 __warn_references(in_wchstr
,
50 "warning: this program uses in_wchstr(), which is unsafe.")
52 in_wchstr(cchar_t
*wchstr
)
57 return win_wchstr(stdscr
, wchstr
);
58 #endif /* HAVE_WCHAR */
62 in_wchnstr(cchar_t
*wchstr
, int n
)
67 return win_wchnstr(stdscr
, wchstr
, n
);
68 #endif /* HAVE_WCHAR */
72 * mvin_wchstr, mv_winchnstr --
73 * Return an array of wide characters at position (y, x) from stdscr.
75 __warn_references(mvin_wchstr
,
76 "warning: this program uses mvin_wchstr(), which is unsafe.")
78 mvin_wchstr(int y
, int x
, cchar_t
*wchstr
)
83 return mvwin_wchstr(stdscr
, y
, x
, wchstr
);
84 #endif /* HAVE_WCHAR */
88 mvin_wchnstr(int y
, int x
, cchar_t
*wchstr
, int n
)
93 return mvwin_wchnstr(stdscr
, y
, x
, wchstr
, n
);
94 #endif /* HAVE_WCHAR */
98 * mvwin_wchstr, mvwin_wchnstr --
99 * Return an array wide characters at position (y, x) from the given window.
101 __warn_references(mvwin_wchstr
,
102 "warning: this program uses mvwin_wchstr(), which is unsafe.")
104 mvwin_wchstr(WINDOW
*win
, int y
, int x
, cchar_t
*wchstr
)
109 if (wmove(win
, y
, x
) == ERR
)
112 return win_wchstr(win
, wchstr
);
113 #endif /* HAVE_WCHAR */
117 mvwin_wchnstr(WINDOW
*win
, int y
, int x
, cchar_t
*wchstr
, int n
)
122 if (wmove(win
, y
, x
) == ERR
)
125 return win_wchnstr(win
, wchstr
, n
);
126 #endif /* HAVE_WCHAR */
130 * win_wchstr, win_wchnstr --
131 * Return an array of characters at cursor position.
133 __warn_references(win_wchstr
,
134 "warning: this program uses win_wchstr(), which is unsafe.")
136 win_wchstr(WINDOW
*win
, cchar_t
*wchstr
)
142 return win_wchnstr(win
, wchstr
, -1);
143 #endif /* HAVE_WCHAR */
147 * - SUSv2/xcurses doesn't document whether the trailing 0 is included
148 * in the length count or not. For safety's sake it _is_ included.
151 win_wchnstr(WINDOW
*win
, cchar_t
*wchstr
, int n
)
157 int x
= 0, cw
= 0, cnt
= 0;
164 start
= &win
->alines
[win
->cury
]->line
[win
->curx
];
172 /* (n - 1) to leave room for the trailing 0 element */
173 while ((x
< win
->maxx
) && ((n
< 0) || ((n
> 1) && (cnt
< n
- 1)))) {
175 wcp
->vals
[ 0 ] = start
->ch
;
176 wcp
->attributes
= start
->attr
;
181 wcp
->vals
[ wcp
->elements
++ ] = np
->ch
;
191 wcp
->vals
[ 0 ] = L
'\0';
193 wcp
->attributes
= win
->wattr
;
196 #endif /* HAVE_WCHAR */