1 /* $NetBSD: inchstr.c,v 1.3 2009/07/22 16:57:14 roy Exp $ */
4 * Copyright 2001 Wasabi Systems, Inc.
7 * Written by Simon Burge for Wasabi Systems, Inc.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed for the NetBSD Project by
20 * Wasabi Systems, Inc.
21 * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 * or promote products derived from this software without specific prior
25 * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND ANY
26 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC. BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 * THE POSSIBILITY OF SUCH DAMAGE.
38 #include <sys/cdefs.h>
40 __RCSID("$NetBSD: inchstr.c,v 1.3 2009/07/22 16:57:14 roy Exp $");
44 #include "curses_private.h"
46 #ifndef _CURSES_USE_MACROS
49 * inchstr, inchnstr --
50 * Return an array of characters at cursor position from stdscr.
52 __warn_references(inchstr
,
53 "warning: this program uses inchstr(), which is unsafe.")
55 inchstr(chtype
*chstr
)
57 return winchstr(stdscr
, chstr
);
61 inchnstr(chtype
*chstr
, int n
)
63 return winchnstr(stdscr
, chstr
, n
);
67 * mvinchstr, mvinchnstr --
68 * Return an array of characters at position (y, x) from stdscr.
70 __warn_references(mvinchstr
,
71 "warning: this program uses mvinchstr(), which is unsafe.")
73 mvinchstr(int y
, int x
, chtype
*chstr
)
75 return mvwinchstr(stdscr
, y
, x
, chstr
);
79 mvinchnstr(int y
, int x
, chtype
*chstr
, int n
)
81 return mvwinchnstr(stdscr
, y
, x
, chstr
, n
);
85 * mvwinchstr, mvwinchnstr --
86 * Return an array characters at position (y, x) from the given window.
88 __warn_references(mvwinchstr
,
89 "warning: this program uses mvwinchstr(), which is unsafe.")
91 mvwinchstr(WINDOW
*win
, int y
, int x
, chtype
*chstr
)
93 if (wmove(win
, y
, x
) == ERR
)
96 return winchstr(win
, chstr
);
100 mvwinchnstr(WINDOW
*win
, int y
, int x
, chtype
*chstr
, int n
)
102 if (wmove(win
, y
, x
) == ERR
)
105 return winchnstr(win
, chstr
, n
);
108 #endif /* _CURSES_USE_MACROS */
111 * winchstr, winchnstr --
112 * Return an array of characters at cursor position.
114 __warn_references(winchstr
,
115 "warning: this program uses winchstr(), which is unsafe.")
117 winchstr(WINDOW
*win
, chtype
*chstr
)
120 return winchnstr(win
, chstr
, -1);
124 * XXX: This should go in a manpage!
125 * - SUSv2/xcurses doesn't document whether the trailing 0 is included
126 * in the length count or not. For safety's sake it _is_ included.
129 winchnstr(WINDOW
*win
, chtype
*chstr
, int n
)
131 __LDATA
*end
, *start
;
137 start
= &win
->alines
[win
->cury
]->line
[win
->curx
];
138 /* (n - 1) to leave room for the trailing 0 element */
139 if (n
< 0 || (n
- 1) > win
->maxx
- win
->curx
- 1)
140 epos
= win
->maxx
- 1;
142 /* extra -1 for trailing NUL */
143 epos
= win
->curx
+ n
-1 - 1;
144 end
= &win
->alines
[win
->cury
]->line
[epos
];
146 while (start
<= end
) {