1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 1997 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1988 AT&T	*/
28*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved	*/
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate /*
31*7c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
32*7c478bd9Sstevel@tonic-gate  * The Regents of the University of California
33*7c478bd9Sstevel@tonic-gate  * All Rights Reserved
34*7c478bd9Sstevel@tonic-gate  *
35*7c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
36*7c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
37*7c478bd9Sstevel@tonic-gate  * contributors.
38*7c478bd9Sstevel@tonic-gate  */
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate /* Clean things up before exiting. */
43*7c478bd9Sstevel@tonic-gate 
44*7c478bd9Sstevel@tonic-gate #include	<stdlib.h>
45*7c478bd9Sstevel@tonic-gate #include	<sys/types.h>
46*7c478bd9Sstevel@tonic-gate #include	"curses_inc.h"
47*7c478bd9Sstevel@tonic-gate 
48*7c478bd9Sstevel@tonic-gate #ifdef	_VR2_COMPAT_CODE
49*7c478bd9Sstevel@tonic-gate char	_endwin = 0;
50*7c478bd9Sstevel@tonic-gate #endif	/* _VR2_COMPAT_CODE */
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate int
isendwin(void)53*7c478bd9Sstevel@tonic-gate isendwin(void)
54*7c478bd9Sstevel@tonic-gate {
55*7c478bd9Sstevel@tonic-gate 	/*
56*7c478bd9Sstevel@tonic-gate 	 * The test below must stay at TRUE because the value of 2
57*7c478bd9Sstevel@tonic-gate 	 * has special meaning to wrefresh but does not mean that
58*7c478bd9Sstevel@tonic-gate 	 * endwin has been called.
59*7c478bd9Sstevel@tonic-gate 	 */
60*7c478bd9Sstevel@tonic-gate 	if (SP && (SP->fl_endwin == TRUE))
61*7c478bd9Sstevel@tonic-gate 		return (TRUE);
62*7c478bd9Sstevel@tonic-gate 	else
63*7c478bd9Sstevel@tonic-gate 		return (FALSE);
64*7c478bd9Sstevel@tonic-gate }
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate int
endwin(void)67*7c478bd9Sstevel@tonic-gate endwin(void)
68*7c478bd9Sstevel@tonic-gate {
69*7c478bd9Sstevel@tonic-gate 	/* make sure we're in program mode */
70*7c478bd9Sstevel@tonic-gate 	if (SP->fl_endwin) {
71*7c478bd9Sstevel@tonic-gate 		/* If endwin is equal to 2 it means we just did a newscreen. */
72*7c478bd9Sstevel@tonic-gate 		if (SP->fl_endwin == TRUE) {
73*7c478bd9Sstevel@tonic-gate 			(void) reset_prog_mode();
74*7c478bd9Sstevel@tonic-gate 			if (SP->kp_state)
75*7c478bd9Sstevel@tonic-gate 				(void) tputs(keypad_xmit, 1, _outch);
76*7c478bd9Sstevel@tonic-gate 			if (SP->fl_meta)
77*7c478bd9Sstevel@tonic-gate 				(void) tputs(meta_on, 1, _outch);
78*7c478bd9Sstevel@tonic-gate 			if (cur_term->_cursorstate != 1)
79*7c478bd9Sstevel@tonic-gate 				_PUTS(cur_term->cursor_seq
80*7c478bd9Sstevel@tonic-gate 				    [cur_term->_cursorstate], 0);
81*7c478bd9Sstevel@tonic-gate 		}
82*7c478bd9Sstevel@tonic-gate 		_PUTS(enter_ca_mode, 1);
83*7c478bd9Sstevel@tonic-gate 		(void) tputs(ena_acs, 1, _outch);
84*7c478bd9Sstevel@tonic-gate 		if (exit_attribute_mode)
85*7c478bd9Sstevel@tonic-gate 			_PUTS(tparm_p0(exit_attribute_mode), 1);
86*7c478bd9Sstevel@tonic-gate 		else
87*7c478bd9Sstevel@tonic-gate 			/*
88*7c478bd9Sstevel@tonic-gate 			 * If there is no exit_attribute mode, then vidupdate
89*7c478bd9Sstevel@tonic-gate 			 * could only possibly turn off one of the below three
90*7c478bd9Sstevel@tonic-gate 			 * so that's all we ask it turn off.
91*7c478bd9Sstevel@tonic-gate 			 */
92*7c478bd9Sstevel@tonic-gate 			vidupdate(A_NORMAL,
93*7c478bd9Sstevel@tonic-gate 			    (A_ALTCHARSET | A_STANDOUT | A_UNDERLINE), _outch);
94*7c478bd9Sstevel@tonic-gate 
95*7c478bd9Sstevel@tonic-gate 		SP->fl_endwin = FALSE;
96*7c478bd9Sstevel@tonic-gate 
97*7c478bd9Sstevel@tonic-gate #ifdef	_VR2_COMPAT_CODE
98*7c478bd9Sstevel@tonic-gate 		_endwin = (char) FALSE;
99*7c478bd9Sstevel@tonic-gate #endif	/* _VR2_COMPAT_CODE */
100*7c478bd9Sstevel@tonic-gate 	}
101*7c478bd9Sstevel@tonic-gate 
102*7c478bd9Sstevel@tonic-gate 	/* See comment above why this test is explicitly against TRUE. */
103*7c478bd9Sstevel@tonic-gate 	if (SP->fl_endwin == TRUE)
104*7c478bd9Sstevel@tonic-gate 		return (ERR);
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	/* Flush out any output not output due to typeahead. */
107*7c478bd9Sstevel@tonic-gate 	if (_INPUTPENDING)
108*7c478bd9Sstevel@tonic-gate 		(void) force_doupdate();
109*7c478bd9Sstevel@tonic-gate 
110*7c478bd9Sstevel@tonic-gate 	/* Close things down. */
111*7c478bd9Sstevel@tonic-gate 	(void) ttimeout(-1);
112*7c478bd9Sstevel@tonic-gate 	if (SP->fl_meta)
113*7c478bd9Sstevel@tonic-gate 		(void) tputs(meta_off, 1, _outch);
114*7c478bd9Sstevel@tonic-gate 	(void) mvcur(curscr->_cury, curscr->_curx, curscr->_maxy - 1, 0);
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate 	if (SP->kp_state)
117*7c478bd9Sstevel@tonic-gate 		(void) tputs(keypad_local, 1, _outch);
118*7c478bd9Sstevel@tonic-gate 	if (cur_term->_cursorstate != 1)
119*7c478bd9Sstevel@tonic-gate 		(void) tputs(cursor_normal, 0, _outch);
120*7c478bd9Sstevel@tonic-gate 
121*7c478bd9Sstevel@tonic-gate 	/* don't bother turning off colors: it will be done later anyway */
122*7c478bd9Sstevel@tonic-gate 	curscr->_attrs &= ~A_COLOR;		/* SS: colors */
123*7c478bd9Sstevel@tonic-gate 
124*7c478bd9Sstevel@tonic-gate 	if ((curscr->_attrs != A_NORMAL) &&
125*7c478bd9Sstevel@tonic-gate 	    (magic_cookie_glitch < 0) && (!ceol_standout_glitch))
126*7c478bd9Sstevel@tonic-gate 		_VIDS(A_NORMAL, curscr->_attrs);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	if (SP->phys_irm)
129*7c478bd9Sstevel@tonic-gate 		_OFFINSERT();
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate 	SP->fl_endwin = TRUE;
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate #ifdef	_VR2_COMPAT_CODE
134*7c478bd9Sstevel@tonic-gate 	_endwin = TRUE;
135*7c478bd9Sstevel@tonic-gate #endif	/* _VR2_COMPAT_CODE */
136*7c478bd9Sstevel@tonic-gate 
137*7c478bd9Sstevel@tonic-gate 	curscr->_clear = TRUE;
138*7c478bd9Sstevel@tonic-gate 	(void) reset_shell_mode();
139*7c478bd9Sstevel@tonic-gate 	(void) tputs(exit_ca_mode, 0, _outch);
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	/* restore colors and default color pair. SS: colors	*/
142*7c478bd9Sstevel@tonic-gate 	if (orig_colors)
143*7c478bd9Sstevel@tonic-gate 		(void) tputs(orig_colors, 1, _outch);
144*7c478bd9Sstevel@tonic-gate 	if (orig_pair)
145*7c478bd9Sstevel@tonic-gate 		(void) tputs(tparm_p0(orig_pair), 1, _outch);
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	/* SS-mouse: free the mouse. */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 	if (get_mouse)
150*7c478bd9Sstevel@tonic-gate 		(void) tputs(tparm_p1(get_mouse, 0), 1, _outch);
151*7c478bd9Sstevel@tonic-gate 
152*7c478bd9Sstevel@tonic-gate 	(void) fflush(SP->term_file);
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 	return (OK);
155*7c478bd9Sstevel@tonic-gate }
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate int
force_doupdate(void)158*7c478bd9Sstevel@tonic-gate force_doupdate(void)
159*7c478bd9Sstevel@tonic-gate {
160*7c478bd9Sstevel@tonic-gate 	char	chars_onQ = cur_term->_chars_on_queue;
161*7c478bd9Sstevel@tonic-gate 	int	ret;
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 	/*
164*7c478bd9Sstevel@tonic-gate 	 * This will cause _chkinput to return FALSE which will force wrefresh
165*7c478bd9Sstevel@tonic-gate 	 * to think there is no input waiting and it will finish its refresh.
166*7c478bd9Sstevel@tonic-gate 	 */
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 	cur_term->_chars_on_queue = INP_QSIZE;
169*7c478bd9Sstevel@tonic-gate 	ret = doupdate();
170*7c478bd9Sstevel@tonic-gate 	cur_term->_chars_on_queue = chars_onQ;
171*7c478bd9Sstevel@tonic-gate 	return (ret);
172*7c478bd9Sstevel@tonic-gate }
173