150276Speter/****************************************************************************
2178866Srafan * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
350276Speter *                                                                          *
450276Speter * Permission is hereby granted, free of charge, to any person obtaining a  *
550276Speter * copy of this software and associated documentation files (the            *
650276Speter * "Software"), to deal in the Software without restriction, including      *
750276Speter * without limitation the rights to use, copy, modify, merge, publish,      *
850276Speter * distribute, distribute with modifications, sublicense, and/or sell       *
950276Speter * copies of the Software, and to permit persons to whom the Software is    *
1050276Speter * furnished to do so, subject to the following conditions:                 *
1150276Speter *                                                                          *
1250276Speter * The above copyright notice and this permission notice shall be included  *
1350276Speter * in all copies or substantial portions of the Software.                   *
1450276Speter *                                                                          *
1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
2250276Speter *                                                                          *
2350276Speter * Except as contained in this notice, the name(s) of the above copyright   *
2450276Speter * holders shall not be used in advertising or otherwise to promote the     *
2550276Speter * sale, use or other dealings in this Software without prior written       *
2650276Speter * authorization.                                                           *
2750276Speter ****************************************************************************/
2850276Speter
2950276Speter/****************************************************************************
3050276Speter *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
3150276Speter *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32166124Srafan *     and: Thomas E. Dickey                        1996-on                 *
3350276Speter ****************************************************************************/
3450276Speter
3550276Speter/*
3650276Speter * Terminfo-only terminal setup routines:
3750276Speter *
3850276Speter *		int restartterm(const char *, int, int *)
3950276Speter */
4050276Speter
4150276Speter#include <curses.priv.h>
4250276Speter
4366963Speter#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
4450276Speter#define _POSIX_SOURCE
4550276Speter#endif
4650276Speter
4766963Speter#include <term.h>		/* lines, columns, cur_term */
4850276Speter
49184989SrafanMODULE_ID("$Id: lib_restart.c,v 1.10 2008/06/21 17:31:22 tom Exp $")
5050276Speter
5176726SpeterNCURSES_EXPORT(int)
52166124Srafanrestartterm(NCURSES_CONST char *termp, int filenum, int *errret)
5350276Speter{
54166124Srafan    int result;
5550276Speter
5666963Speter    T((T_CALLED("restartterm(%s,%d,%p)"), termp, filenum, errret));
5750276Speter
58166124Srafan    if (setupterm(termp, filenum, errret) != OK) {
59166124Srafan	result = ERR;
60174993Srafan    } else if (SP != 0) {
61174993Srafan	int saveecho = SP->_echo;
62174993Srafan	int savecbreak = SP->_cbreak;
63174993Srafan	int saveraw = SP->_raw;
64174993Srafan	int savenl = SP->_nl;
6550276Speter
66166124Srafan	if (saveecho)
67166124Srafan	    echo();
68166124Srafan	else
69166124Srafan	    noecho();
7050276Speter
71166124Srafan	if (savecbreak) {
72166124Srafan	    cbreak();
73166124Srafan	    noraw();
74166124Srafan	} else if (saveraw) {
75166124Srafan	    nocbreak();
76166124Srafan	    raw();
77166124Srafan	} else {
78166124Srafan	    nocbreak();
79166124Srafan	    noraw();
80166124Srafan	}
81166124Srafan	if (savenl)
82166124Srafan	    nl();
83166124Srafan	else
84166124Srafan	    nonl();
8550276Speter
86166124Srafan	reset_prog_mode();
8750276Speter
8850276Speter#if USE_SIZECHANGE
89178866Srafan	_nc_update_screensize(SP);
9050276Speter#endif
9150276Speter
92166124Srafan	result = OK;
93174993Srafan    } else {
94174993Srafan	result = ERR;
95166124Srafan    }
96166124Srafan    returnCode(result);
9750276Speter}
98