xref: /illumos-gate/usr/src/lib/libcurses/screen/ripoffline.c (revision 4c87aefe8930bd07275b8dd2e96ea5f24d93a52e)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved	*/
29 
30 /*
31  * University Copyright- Copyright (c) 1982, 1986, 1988
32  * The Regents of the University of California
33  * All Rights Reserved
34  *
35  * University Acknowledgment- Portions of this document are derived from
36  * software developed by the University of California, Berkeley, and its
37  * contributors.
38  */
39 
40 #pragma ident	"%Z%%M%	%I%	%E% SMI"
41 
42 /*LINTLIBRARY*/
43 
44 /*
45  * This routine is used by initialization routines. It sets it up
46  * such that a line is removed from the user's screen by initscr. This
47  * function must be called BEFORE initscr. It works by leaving a cookie
48  * which tells initscr to reduce the size of stdscr by one for each line
49  * ripped off. This routine has been generalized so that other applications
50  * can make use of it in a straightforward manner.
51  */
52 
53 #include <sys/types.h>
54 #include "curses_inc.h"
55 
56 static	struct _ripdef
57 {
58 	int line;
59 	int (*initfunction)(WINDOW *, int);
60 } _ripstruct[5];
61 
62 static char _ripcounter;
63 
64 static	void
65 _init_rip_func(void)
66 {
67 	int	i, flag;
68 
69 	for (i = 0; i < _ripcounter; i++) {
70 		LINES = --SP->lsize;
71 /*
72  * We don't need to check for newwin returning NULL because even if
73  * we did and broke from the for loop, the application's initfunction
74  * would not be called and they would have a NULL window pointer.  Their
75  * code would then blow up if they don't check it anyway.  Therefore,
76  * we can send in the newwin and their code has to check for NULL in either
77  * case.
78  *
79  * NOTE:  The application has the responsibilty to do a delwin !!!
80  */
81 		(*_ripstruct[i].initfunction) (newwin(1, COLS,
82 		    ((flag = _ripstruct[i].line) > 0) ? 0 : LINES, 0), COLS);
83 		if (flag > 0)
84 		    SP->Yabove++;
85 	}
86 	_ripcounter = 0;
87 }
88 
89 int
90 ripoffline(int line, int (*initfunction)(WINDOW *, int))
91 {
92 	if (_ripcounter < 5) {
93 		_ripstruct[_ripcounter].line = line;
94 		_ripstruct[_ripcounter++].initfunction = initfunction;
95 	}
96 	_rip_init = _init_rip_func;
97 	return (OK);
98 }
99