Sync usage with man page.
[netbsd-mini2440.git] / lib / libcurses / line.c
blob4a3654a83ec221331ddcc2a89e109d110b239765
1 /* $NetBSD: line.c,v 1.4.20.2 2007/01/21 17:43:35 jdc Exp $ */
3 /*-
4 * Copyright (c) 1998-1999 Brett Lymn
5 * (blymn@baea.com.au, brett_lymn@yahoo.com.au)
6 * All rights reserved.
8 * This code has been donated to The NetBSD Foundation by the Author.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 #ifndef lint
34 __RCSID("$NetBSD: line.c,v 1.4.20.2 2007/01/21 17:43:35 jdc Exp $");
35 #endif /* not lint */
37 #include <string.h>
39 #include "curses.h"
40 #include "curses_private.h"
43 * hline --
44 * Draw a horizontal line of character c on stdscr.
46 int
47 hline(chtype ch, int count)
49 return whline(stdscr, ch, count);
53 * mvhline --
54 * Move to location (y, x) and draw a horizontal line of character c
55 * on stdscr.
57 int
58 mvhline(int y, int x, chtype ch, int count)
60 return mvwhline(stdscr, y, x, ch, count);
64 * mvwhline --
65 * Move to location (y, x) and draw a horizontal line of character c
66 * in the given window.
68 int
69 mvwhline(WINDOW *win, int y, int x, chtype ch, int count)
71 if (wmove(win, y, x) == ERR)
72 return ERR;
74 return whline(win, ch, count);
78 * whline --
79 * Draw a horizontal line of character c in the given window moving
80 * towards the rightmost column. At most count characters are drawn
81 * or until the edge of the screen, whichever comes first.
83 int
84 whline(WINDOW *win, chtype ch, int count)
86 int ocurx, n, i;
88 n = min(count, win->maxx - win->curx);
89 ocurx = win->curx;
91 if (!(ch & __CHARTEXT))
92 ch |= ACS_HLINE;
93 for (i = 0; i < n; i++)
94 mvwaddch(win, win->cury, ocurx + i, ch);
96 wmove(win, win->cury, ocurx);
97 return OK;
101 * vline --
102 * Draw a vertical line of character ch on stdscr.
105 vline(chtype ch, int count)
107 return wvline(stdscr, ch, count);
111 * mvvline --
112 * Move to the given location an draw a vertical line of character ch.
115 mvvline(int y, int x, chtype ch, int count)
117 return mvwvline(stdscr, y, x, ch, count);
121 * mvwvline --
122 * Move to the given location and draw a vertical line of character ch
123 * on the given window.
126 mvwvline(WINDOW *win, int y, int x, chtype ch, int count)
128 if (wmove(win, y, x) == ERR)
129 return ERR;
131 return wvline(win, ch, count);
135 * wvline --
136 * Draw a vertical line of character ch in the given window moving
137 * towards the bottom of the screen. At most count characters are drawn
138 * or until the edge of the screen, whichever comes first.
141 wvline(WINDOW *win, chtype ch, int count)
143 int ocury, ocurx, n, i;
145 n = min(count, win->maxy - win->cury);
146 ocury = win->cury;
147 ocurx = win->curx;
149 if (!(ch & __CHARTEXT))
150 ch |= ACS_VLINE;
151 for (i = 0; i < n; i++)
152 mvwaddch(win, ocury + i, ocurx, ch);
154 wmove(win, ocury, ocurx);
155 return OK;
158 int hline_set(const cchar_t *wch, int n)
160 #ifndef HAVE_WCHAR
161 return ERR;
162 #else
163 return whline_set( stdscr, wch, n );
164 #endif /* HAVE_WCHAR */
167 int mvhline_set(int y, int x, const cchar_t *wch, int n)
169 #ifndef HAVE_WCHAR
170 return ERR;
171 #else
172 return mvwhline_set( stdscr, y, x, wch, n );
173 #endif /* HAVE_WCHAR */
176 int mvwhline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
178 #ifndef HAVE_WCHAR
179 return ERR;
180 #else
181 if ( wmove( win, y , x ) == ERR )
182 return ERR;
184 return whline_set( win, wch, n );
185 #endif /* HAVE_WCHAR */
188 int whline_set(WINDOW *win, const cchar_t *wch, int n)
190 #ifndef HAVE_WCHAR
191 return ERR;
192 #else
193 int ocurx, wcn, i, cw;
194 cchar_t cc;
196 cw = wcwidth( wch->vals[ 0 ]);
197 if ( ( win->maxx - win->curx ) < cw )
198 return ERR;
199 wcn = min( n, ( win->maxx - win->curx ) / cw );
200 #ifdef DEBUG
201 __CTRACE(__CTRACE_LINE, "whline_set: line of %d\n", wcn);
202 #endif /* DEBUG */
203 ocurx = win->curx;
205 memcpy( &cc, wch, sizeof( cchar_t ));
206 if (!(wch->vals[ 0 ]))
207 cc.vals[ 0 ] |= WACS_HLINE;
208 for (i = 0; i < wcn; i++ ) {
209 #ifdef DEBUG
210 __CTRACE(__CTRACE_LINE, "whline_set: (%d,%d)\n",
211 win->cury, ocurx + i * cw);
212 #endif /* DEBUG */
213 mvwadd_wch(win, win->cury, ocurx + i * cw, &cc);
216 wmove(win, win->cury, ocurx);
217 return OK;
218 #endif /* HAVE_WCHAR */
221 int vline_set(const cchar_t *wch, int n)
223 #ifndef HAVE_WCHAR
224 return ERR;
225 #else
226 return wvline_set( stdscr, wch, n );
227 #endif /* HAVE_WCHAR */
230 int mvvline_set(int y, int x, const cchar_t *wch, int n)
232 #ifndef HAVE_WCHAR
233 return ERR;
234 #else
235 return mvwvline_set( stdscr, y, x, wch, n );
236 #endif /* HAVE_WCHAR */
239 int mvwvline_set(WINDOW *win, int y, int x, const cchar_t *wch, int n)
241 #ifndef HAVE_WCHAR
242 return ERR;
243 #else
244 if ( wmove( win, y, x ) == ERR )
245 return ERR;
247 return wvline_set( win, wch, n );
248 #endif /* HAVE_WCHAR */
251 int wvline_set(WINDOW *win, const cchar_t *wch, int n)
253 #ifndef HAVE_WCHAR
254 return ERR;
255 #else
256 int ocury, ocurx, wcn, i;
257 cchar_t cc;
259 wcn = min( n, win->maxy - win->cury);
260 #ifdef DEBUG
261 __CTRACE(__CTRACE_LINE, "wvline_set: line of %d\n", wcn);
262 #endif /* DEBUG */
263 ocury = win->cury;
264 ocurx = win->curx;
266 memcpy( &cc, wch, sizeof( cchar_t ));
267 if (!(wch->vals[ 0 ]))
268 cc.vals[ 0 ] |= WACS_VLINE;
269 for (i = 0; i < wcn; i++) {
270 mvwadd_wch(win, ocury + i, ocurx, &cc);
271 #ifdef DEBUG
272 __CTRACE(__CTRACE_LINE, "wvline_set: (%d,%d)\n",
273 ocury + i, ocurx);
274 #endif /* DEBUG */
276 wmove(win, ocury, ocurx);
277 return OK;
278 #endif /* HAVE_WCHAR */