xref: /openbsd-src/lib/libcurses/base/lib_box.c (revision 1fe33145a0a9b1310a0413297a8deb871918b27f)
1 /*	$OpenBSD: lib_box.c,v 1.2 2000/06/19 03:53:39 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34  ****************************************************************************/
35 
36 /*
37 **	lib_box.c
38 **
39 **	The routine wborder().
40 **
41 */
42 
43 #include <curses.priv.h>
44 
45 MODULE_ID("$From: lib_box.c,v 1.11 2000/04/29 21:12:37 tom Exp $")
46 
47 int
48 wborder(WINDOW *win,
49     chtype ls, chtype rs, chtype ts, chtype bs,
50     chtype tl, chtype tr, chtype bl, chtype br)
51 {
52     NCURSES_SIZE_T i;
53     NCURSES_SIZE_T endx, endy;
54 
55     T((T_CALLED("wborder(%p,%s,%s,%s,%s,%s,%s,%s,%s)"),
56 	    win,
57 	    _tracechtype2(1, ls),
58 	    _tracechtype2(2, rs),
59 	    _tracechtype2(3, ts),
60 	    _tracechtype2(4, bs),
61 	    _tracechtype2(5, tl),
62 	    _tracechtype2(6, tr),
63 	    _tracechtype2(7, bl),
64 	    _tracechtype2(8, br)));
65 
66     if (!win)
67 	returnCode(ERR);
68 
69     if (ls == 0)
70 	ls = ACS_VLINE;
71     if (rs == 0)
72 	rs = ACS_VLINE;
73     if (ts == 0)
74 	ts = ACS_HLINE;
75     if (bs == 0)
76 	bs = ACS_HLINE;
77     if (tl == 0)
78 	tl = ACS_ULCORNER;
79     if (tr == 0)
80 	tr = ACS_URCORNER;
81     if (bl == 0)
82 	bl = ACS_LLCORNER;
83     if (br == 0)
84 	br = ACS_LRCORNER;
85 
86     ls = _nc_render(win, ls);
87     rs = _nc_render(win, rs);
88     ts = _nc_render(win, ts);
89     bs = _nc_render(win, bs);
90     tl = _nc_render(win, tl);
91     tr = _nc_render(win, tr);
92     bl = _nc_render(win, bl);
93     br = _nc_render(win, br);
94 
95     T(("using %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx, %#lx",
96 	    ls, rs, ts, bs, tl, tr, bl, br));
97 
98     endx = win->_maxx;
99     endy = win->_maxy;
100 
101     for (i = 0; i <= endx; i++) {
102 	win->_line[0].text[i] = ts;
103 	win->_line[endy].text[i] = bs;
104     }
105     win->_line[endy].firstchar = win->_line[0].firstchar = 0;
106     win->_line[endy].lastchar = win->_line[0].lastchar = endx;
107 
108     for (i = 0; i <= endy; i++) {
109 	win->_line[i].text[0] = ls;
110 	win->_line[i].text[endx] = rs;
111 	win->_line[i].firstchar = 0;
112 	win->_line[i].lastchar = endx;
113     }
114     win->_line[0].text[0] = tl;
115     win->_line[0].text[endx] = tr;
116     win->_line[endy].text[0] = bl;
117     win->_line[endy].text[endx] = br;
118 
119     _nc_synchook(win);
120     returnCode(OK);
121 }
122