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