inchstr.c revision 1.2 1 1.2 blymn /* $NetBSD: inchstr.c,v 1.2 2002/01/02 10:38:28 blymn Exp $ */
2 1.1 simonb
3 1.1 simonb /*
4 1.1 simonb * Copyright 2001 Wasabi Systems, Inc.
5 1.1 simonb * All rights reserved.
6 1.1 simonb *
7 1.1 simonb * Written by Simon Burge for Wasabi Systems, Inc.
8 1.1 simonb *
9 1.1 simonb * Redistribution and use in source and binary forms, with or without
10 1.1 simonb * modification, are permitted provided that the following conditions
11 1.1 simonb * are met:
12 1.1 simonb * 1. Redistributions of source code must retain the above copyright
13 1.1 simonb * notice, this list of conditions and the following disclaimer.
14 1.1 simonb * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 simonb * notice, this list of conditions and the following disclaimer in the
16 1.1 simonb * documentation and/or other materials provided with the distribution.
17 1.1 simonb * 3. All advertising materials mentioning features or use of this software
18 1.1 simonb * must display the following acknowledgement:
19 1.1 simonb * This product includes software developed for the NetBSD Project by
20 1.1 simonb * Wasabi Systems, Inc.
21 1.1 simonb * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1 simonb * or promote products derived from this software without specific prior
23 1.1 simonb * written permission.
24 1.1 simonb *
25 1.1 simonb * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND ANY
26 1.1 simonb * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 simonb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 simonb * ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC. BE
29 1.1 simonb * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1 simonb * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1 simonb * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1 simonb * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1 simonb * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1 simonb * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
35 1.1 simonb * THE POSSIBILITY OF SUCH DAMAGE.
36 1.1 simonb */
37 1.1 simonb
38 1.1 simonb #include <sys/cdefs.h>
39 1.1 simonb #ifndef lint
40 1.2 blymn __RCSID("$NetBSD: inchstr.c,v 1.2 2002/01/02 10:38:28 blymn Exp $");
41 1.1 simonb #endif /* not lint */
42 1.1 simonb
43 1.1 simonb #include "curses.h"
44 1.1 simonb #include "curses_private.h"
45 1.1 simonb
46 1.1 simonb #ifndef _CURSES_USE_MACROS
47 1.1 simonb
48 1.1 simonb /*
49 1.1 simonb * inchstr, inchnstr --
50 1.1 simonb * Return an array of characters at cursor position from stdscr.
51 1.1 simonb */
52 1.1 simonb __warn_references(inchstr,
53 1.1 simonb "warning: this program uses inchstr(), which is unsafe.")
54 1.1 simonb int
55 1.1 simonb inchstr(chtype *chstr)
56 1.1 simonb {
57 1.1 simonb return winchstr(stdscr, chstr);
58 1.1 simonb }
59 1.1 simonb
60 1.1 simonb int
61 1.1 simonb inchnstr(chtype *chstr, int n)
62 1.1 simonb {
63 1.1 simonb return winchnstr(stdscr, chstr, n);
64 1.1 simonb }
65 1.1 simonb
66 1.1 simonb /*
67 1.1 simonb * mvinchstr, mvinchnstr --
68 1.1 simonb * Return an array of characters at position (y, x) from stdscr.
69 1.1 simonb */
70 1.1 simonb __warn_references(mvinchstr,
71 1.1 simonb "warning: this program uses mvinchstr(), which is unsafe.")
72 1.1 simonb int
73 1.1 simonb mvinchstr(int y, int x, chtype *chstr)
74 1.1 simonb {
75 1.1 simonb return mvwinchstr(stdscr, y, x, chstr);
76 1.1 simonb }
77 1.1 simonb
78 1.1 simonb int
79 1.1 simonb mvinchnstr(int y, int x, chtype *chstr, int n)
80 1.1 simonb {
81 1.1 simonb return mvwinchnstr(stdscr, y, x, chstr, n);
82 1.1 simonb }
83 1.1 simonb
84 1.1 simonb /*
85 1.1 simonb * mvwinchstr, mvwinchnstr --
86 1.1 simonb * Return an array characters at position (y, x) from the given window.
87 1.1 simonb */
88 1.1 simonb __warn_references(mvwinchstr,
89 1.1 simonb "warning: this program uses mvwinchstr(), which is unsafe.")
90 1.1 simonb int
91 1.1 simonb mvwinchstr(WINDOW *win, int y, int x, chtype *chstr)
92 1.1 simonb {
93 1.1 simonb if (wmove(win, y, x) == ERR)
94 1.1 simonb return ERR;
95 1.2 blymn
96 1.1 simonb return winchstr(win, chstr);
97 1.1 simonb }
98 1.1 simonb
99 1.1 simonb int
100 1.1 simonb mvwinchnstr(WINDOW *win, int y, int x, chtype *chstr, int n)
101 1.1 simonb {
102 1.1 simonb if (wmove(win, y, x) == ERR)
103 1.1 simonb return ERR;
104 1.2 blymn
105 1.1 simonb return winchnstr(win, chstr, n);
106 1.1 simonb }
107 1.1 simonb
108 1.1 simonb #endif /* _CURSES_USE_MACROS */
109 1.1 simonb
110 1.1 simonb /*
111 1.1 simonb * winchstr, winchnstr --
112 1.1 simonb * Return an array of characters at cursor position.
113 1.1 simonb */
114 1.1 simonb __warn_references(winchstr,
115 1.1 simonb "warning: this program uses winchstr(), which is unsafe.")
116 1.1 simonb int
117 1.1 simonb winchstr(WINDOW *win, chtype *chstr)
118 1.1 simonb {
119 1.1 simonb
120 1.1 simonb return winchnstr(win, chstr, -1);
121 1.1 simonb }
122 1.1 simonb
123 1.1 simonb /*
124 1.1 simonb * XXX: This should go in a manpage!
125 1.1 simonb * - SUSv2/xcurses doesn't document whether the trailing 0 is included
126 1.1 simonb * in the length count or not. For safety's sake it _is_ included.
127 1.1 simonb */
128 1.1 simonb int
129 1.1 simonb winchnstr(WINDOW *win, chtype *chstr, int n)
130 1.1 simonb {
131 1.1 simonb __LDATA *end, *start;
132 1.1 simonb int epos;
133 1.1 simonb
134 1.1 simonb if (chstr == NULL)
135 1.1 simonb return ERR;
136 1.1 simonb
137 1.1 simonb start = &win->lines[win->cury]->line[win->curx];
138 1.1 simonb /* (n - 1) to leave room for the trailing 0 element */
139 1.1 simonb if (n < 0 || (n - 1) > win->maxx - win->curx - 1)
140 1.1 simonb epos = win->maxx - 1;
141 1.1 simonb else
142 1.1 simonb /* extra -1 for trailing NUL */
143 1.1 simonb epos = win->curx + n -1 - 1;
144 1.1 simonb end = &win->lines[win->cury]->line[epos];
145 1.1 simonb
146 1.1 simonb while (start <= end) {
147 1.1 simonb *chstr = start->ch;
148 1.1 simonb chstr++;
149 1.1 simonb start++;
150 1.1 simonb }
151 1.1 simonb *chstr = 0;
152 1.1 simonb
153 1.1 simonb return OK;
154 1.1 simonb }
155