xref: /freebsd/contrib/ncurses/ncurses/base/lib_restart.c (revision 21817992b3314c908ab50f0bb88d2ee750b9c4ac)
1 /****************************************************************************
2  * Copyright 2020,2023 Thomas E. Dickey                                     *
3  * Copyright 1998-2012,2015 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 
30 /****************************************************************************
31  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
32  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
33  *     and: Thomas E. Dickey                        1996-on                 *
34  *     and: Juergen Pfeifer                         2008                    *
35  ****************************************************************************/
36 
37 /*
38  * Terminfo-only terminal setup routines:
39  *
40  *		int restartterm(const char *, int, int *)
41  */
42 
43 #include <curses.priv.h>
44 
45 MODULE_ID("$Id: lib_restart.c,v 1.18 2023/04/29 19:01:25 tom Exp $")
46 
NCURSES_EXPORT(int)47 NCURSES_EXPORT(int)
48 NCURSES_SP_NAME(restartterm) (NCURSES_SP_DCLx
49 			      NCURSES_CONST char *termp,
50 			      int filenum,
51 			      int *errret)
52 {
53     int result;
54 #ifdef USE_TERM_DRIVER
55     TERMINAL *new_term = 0;
56 #endif
57 
58     START_TRACE();
59     T((T_CALLED("restartterm(%p,%s,%d,%p)"),
60        (void *) SP_PARM,
61        termp,
62        filenum,
63        (void *) errret));
64 
65     if (TINFO_SETUP_TERM(&new_term, termp, filenum, errret, FALSE) != OK) {
66 	result = ERR;
67     } else if (SP_PARM != 0) {
68 	TTY_FLAGS save_flags = SP_PARM->_tty_flags;
69 
70 #ifdef USE_TERM_DRIVER
71 	SP_PARM->_term = new_term;
72 #endif
73 	if (save_flags._echo) {
74 	    NCURSES_SP_NAME(echo) (NCURSES_SP_ARG);
75 	} else {
76 	    NCURSES_SP_NAME(noecho) (NCURSES_SP_ARG);
77 	}
78 
79 	if (save_flags._cbreak) {
80 	    NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG);
81 	    NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
82 	} else if (save_flags._raw) {
83 	    NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
84 	    NCURSES_SP_NAME(raw) (NCURSES_SP_ARG);
85 	} else {
86 	    NCURSES_SP_NAME(nocbreak) (NCURSES_SP_ARG);
87 	    NCURSES_SP_NAME(noraw) (NCURSES_SP_ARG);
88 	}
89 	if (save_flags._nl) {
90 	    NCURSES_SP_NAME(nl) (NCURSES_SP_ARG);
91 	} else {
92 	    NCURSES_SP_NAME(nonl) (NCURSES_SP_ARG);
93 	}
94 
95 	NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_ARG);
96 
97 #if USE_SIZECHANGE
98 	_nc_update_screensize(SP_PARM);
99 #endif
100 
101 	result = OK;
102     } else {
103 	result = ERR;
104     }
105     returnCode(result);
106 }
107 
108 #if NCURSES_SP_FUNCS
109 NCURSES_EXPORT(int)
restartterm(NCURSES_CONST char * termp,int filenum,int * errret)110 restartterm(NCURSES_CONST char *termp, int filenum, int *errret)
111 {
112     START_TRACE();
113     return NCURSES_SP_NAME(restartterm) (CURRENT_SCREEN, termp, filenum, errret);
114 }
115 #endif
116