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 (c) 1995-1999 by Sun Microsystems, Inc.
24*7c478bd9Sstevel@tonic-gate  * All rights reserved.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate /* LINTLIBRARY */
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate /*
30*7c478bd9Sstevel@tonic-gate  * setupterm.c
31*7c478bd9Sstevel@tonic-gate  *
32*7c478bd9Sstevel@tonic-gate  * XCurses Library
33*7c478bd9Sstevel@tonic-gate  *
34*7c478bd9Sstevel@tonic-gate  * Copyright 1990, 1995 by Mortice Kern Systems Inc.  All rights reserved.
35*7c478bd9Sstevel@tonic-gate  *
36*7c478bd9Sstevel@tonic-gate  */
37*7c478bd9Sstevel@tonic-gate 
38*7c478bd9Sstevel@tonic-gate #ifdef M_RCSID
39*7c478bd9Sstevel@tonic-gate #ifndef lint
40*7c478bd9Sstevel@tonic-gate static char const rcsID[] =
41*7c478bd9Sstevel@tonic-gate "$Header: /team/ps/sun_xcurses/archive/local_changes/xcurses/src/lib/"
42*7c478bd9Sstevel@tonic-gate "libxcurses/src/libc/xcurses/rcs/setup.c 1.16 1998/06/05 14:35:33 "
43*7c478bd9Sstevel@tonic-gate "cbates Exp $";
44*7c478bd9Sstevel@tonic-gate #endif
45*7c478bd9Sstevel@tonic-gate #endif
46*7c478bd9Sstevel@tonic-gate 
47*7c478bd9Sstevel@tonic-gate #include <private.h>
48*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
49*7c478bd9Sstevel@tonic-gate #ifdef TIOCGWINSZ
50*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
51*7c478bd9Sstevel@tonic-gate #endif
52*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
53*7c478bd9Sstevel@tonic-gate #include <limits.h>
54*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
55*7c478bd9Sstevel@tonic-gate #include <string.h>
56*7c478bd9Sstevel@tonic-gate #include <unistd.h>
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate TERMINAL	*cur_term;
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate /*
61*7c478bd9Sstevel@tonic-gate  * Any version number should be placed in this file, since setupterm()
62*7c478bd9Sstevel@tonic-gate  * must be called in order to initialize Curses or Terminfo.
63*7c478bd9Sstevel@tonic-gate  */
64*7c478bd9Sstevel@tonic-gate char	__m_curses_version[] = M_CURSES_VERSION;
65*7c478bd9Sstevel@tonic-gate 
66*7c478bd9Sstevel@tonic-gate /*
67*7c478bd9Sstevel@tonic-gate  * True if __m_setupterm() should use either the window settings from
68*7c478bd9Sstevel@tonic-gate  * ioctl(), or the environment variables LINES and COLUMNS to override
69*7c478bd9Sstevel@tonic-gate  * the terminfo database entries for 'lines' and 'columns'.
70*7c478bd9Sstevel@tonic-gate  *
71*7c478bd9Sstevel@tonic-gate  * Call use_env(flag) before either setupterm(), newterm(), or initscr().
72*7c478bd9Sstevel@tonic-gate  */
73*7c478bd9Sstevel@tonic-gate static bool	use_environment = TRUE;
74*7c478bd9Sstevel@tonic-gate 
75*7c478bd9Sstevel@tonic-gate static const char	e_terminal[] =
76*7c478bd9Sstevel@tonic-gate 	"No memory for TERMINAL structure.\n";
77*7c478bd9Sstevel@tonic-gate static const char	e_unknown[] =
78*7c478bd9Sstevel@tonic-gate 	"\"%s\": Unknown terminal type.\n";
79*7c478bd9Sstevel@tonic-gate static const char	e_pathmax[] =
80*7c478bd9Sstevel@tonic-gate 	"\"%s\": terminfo database path too long.\n";
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate /*
84*7c478bd9Sstevel@tonic-gate  * These globals are used so that macro arguments are evaluated
85*7c478bd9Sstevel@tonic-gate  * exactly once
86*7c478bd9Sstevel@tonic-gate  */
87*7c478bd9Sstevel@tonic-gate /* The downside is that it is not really thread-safe. Oh well... */
88*7c478bd9Sstevel@tonic-gate WINDOW	*__w1;
89*7c478bd9Sstevel@tonic-gate chtype	__cht1;
90*7c478bd9Sstevel@tonic-gate chtype	__cht2;
91*7c478bd9Sstevel@tonic-gate cchar_t	*__pcht1;
92*7c478bd9Sstevel@tonic-gate cchar_t	*__pcht2;
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate /*
95*7c478bd9Sstevel@tonic-gate  * Take the real command character out of the CC environment variable
96*7c478bd9Sstevel@tonic-gate  * and substitute it in for the prototype given in 'command_character'.
97*7c478bd9Sstevel@tonic-gate  */
98*7c478bd9Sstevel@tonic-gate static void
do_prototype(void)99*7c478bd9Sstevel@tonic-gate do_prototype(void)
100*7c478bd9Sstevel@tonic-gate {
101*7c478bd9Sstevel@tonic-gate 	int	i, j;
102*7c478bd9Sstevel@tonic-gate 	char	proto;
103*7c478bd9Sstevel@tonic-gate 	char	*CC;
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate 	CC = getenv("CC");
106*7c478bd9Sstevel@tonic-gate 	proto = *command_character;
107*7c478bd9Sstevel@tonic-gate 
108*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < __COUNT_STR; i++)
109*7c478bd9Sstevel@tonic-gate 		for (j = 0; cur_term->_str[i][j]; ++j)
110*7c478bd9Sstevel@tonic-gate 			if (cur_term->_str[i][j] == proto)
111*7c478bd9Sstevel@tonic-gate 				cur_term->_str[i][j] = *CC;
112*7c478bd9Sstevel@tonic-gate }
113*7c478bd9Sstevel@tonic-gate 
114*7c478bd9Sstevel@tonic-gate #define	min(a, b)		((a) < (b) ? (a) : (b))
115*7c478bd9Sstevel@tonic-gate 
116*7c478bd9Sstevel@tonic-gate /*
117*7c478bd9Sstevel@tonic-gate  * Return a number from a terminfo file.  Numbers in a terminfo
118*7c478bd9Sstevel@tonic-gate  * file are stored as two bytes with low-high ordering.
119*7c478bd9Sstevel@tonic-gate  */
120*7c478bd9Sstevel@tonic-gate static short
getnum(int fd)121*7c478bd9Sstevel@tonic-gate getnum(int fd)
122*7c478bd9Sstevel@tonic-gate {
123*7c478bd9Sstevel@tonic-gate 	unsigned char	bytes[2];
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (read(fd, bytes, 2) != 2)
126*7c478bd9Sstevel@tonic-gate 		return (SHRT_MIN);
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	return ((short) (bytes[0] + bytes[1] * 256));
129*7c478bd9Sstevel@tonic-gate }
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate /*
132*7c478bd9Sstevel@tonic-gate  * MKS Header format for terminfo database files.
133*7c478bd9Sstevel@tonic-gate  *
134*7c478bd9Sstevel@tonic-gate  * The header consists of six short integers, stored using VAX/PDP style
135*7c478bd9Sstevel@tonic-gate  * byte swapping (least-significant byte first).  The integers are
136*7c478bd9Sstevel@tonic-gate  *
137*7c478bd9Sstevel@tonic-gate  *  1) magic number (octal 0432);
138*7c478bd9Sstevel@tonic-gate  *  2) the size, in bytes, of the names sections;
139*7c478bd9Sstevel@tonic-gate  *  3) the number of bytes in the boolean section;
140*7c478bd9Sstevel@tonic-gate  *  4) the number of short integers in the numbers section;
141*7c478bd9Sstevel@tonic-gate  *  5) the number of offsets (short integers) in the strings section;
142*7c478bd9Sstevel@tonic-gate  *  6) the size, in bytes, of the string table.
143*7c478bd9Sstevel@tonic-gate  *
144*7c478bd9Sstevel@tonic-gate  * Between the boolean and number sections, a null byte is inserted, if
145*7c478bd9Sstevel@tonic-gate  * necessary, to ensure that the number section begins on an even byte
146*7c478bd9Sstevel@tonic-gate  * offset.  All short integers are aligned on a short word boundary.
147*7c478bd9Sstevel@tonic-gate  */
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate #define	__TERMINFO_MAGIC		0432
150*7c478bd9Sstevel@tonic-gate 
151*7c478bd9Sstevel@tonic-gate typedef struct {
152*7c478bd9Sstevel@tonic-gate 	short	magic;
153*7c478bd9Sstevel@tonic-gate 	short	name_size;
154*7c478bd9Sstevel@tonic-gate 	short	bool_count;
155*7c478bd9Sstevel@tonic-gate 	short	num_count;
156*7c478bd9Sstevel@tonic-gate 	short	str_count;
157*7c478bd9Sstevel@tonic-gate 	short	str_size;
158*7c478bd9Sstevel@tonic-gate } terminfo_header_t;
159*7c478bd9Sstevel@tonic-gate 
160*7c478bd9Sstevel@tonic-gate /*
161*7c478bd9Sstevel@tonic-gate  * Read the compiled terminfo entry in the given file into the
162*7c478bd9Sstevel@tonic-gate  * structure pointed to by ptr, allocating space for the string
163*7c478bd9Sstevel@tonic-gate  * table and placing its address in ptr->str_table.
164*7c478bd9Sstevel@tonic-gate  */
165*7c478bd9Sstevel@tonic-gate int
__m_read_terminfo(const char * filename,TERMINAL * tp)166*7c478bd9Sstevel@tonic-gate __m_read_terminfo(const char *filename, TERMINAL *tp)
167*7c478bd9Sstevel@tonic-gate {
168*7c478bd9Sstevel@tonic-gate 	int	fd;
169*7c478bd9Sstevel@tonic-gate 	short	offset;
170*7c478bd9Sstevel@tonic-gate 	size_t	i, len;
171*7c478bd9Sstevel@tonic-gate 	terminfo_header_t	header;
172*7c478bd9Sstevel@tonic-gate 	unsigned char	ch;
173*7c478bd9Sstevel@tonic-gate 
174*7c478bd9Sstevel@tonic-gate 	/* Get compiled terminfo file header. */
175*7c478bd9Sstevel@tonic-gate 	if ((fd = open(filename, 0)) < 0) {
176*7c478bd9Sstevel@tonic-gate 		goto error_1;
177*7c478bd9Sstevel@tonic-gate 	}
178*7c478bd9Sstevel@tonic-gate 
179*7c478bd9Sstevel@tonic-gate 	if ((header.magic = getnum(fd)) != __TERMINFO_MAGIC ||
180*7c478bd9Sstevel@tonic-gate 		(header.name_size = getnum(fd)) < 0 ||
181*7c478bd9Sstevel@tonic-gate 		(header.bool_count = getnum(fd)) < 0 ||
182*7c478bd9Sstevel@tonic-gate 		(header.num_count = getnum(fd)) < 0 ||
183*7c478bd9Sstevel@tonic-gate 		(header.str_count = getnum(fd)) < 0 ||
184*7c478bd9Sstevel@tonic-gate 		(header.str_size = getnum(fd)) < 0) {
185*7c478bd9Sstevel@tonic-gate 		goto error_2;
186*7c478bd9Sstevel@tonic-gate 	}
187*7c478bd9Sstevel@tonic-gate 
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate 	/* Allocate and fetch terminal names. */
190*7c478bd9Sstevel@tonic-gate 	len = min(127, header.name_size);
191*7c478bd9Sstevel@tonic-gate 	if ((tp->_names = (char *) malloc(len + 1)) == NULL)
192*7c478bd9Sstevel@tonic-gate 		goto error_2;
193*7c478bd9Sstevel@tonic-gate 	if (read(fd, tp->_names, len) != len)
194*7c478bd9Sstevel@tonic-gate 		goto error_3;
195*7c478bd9Sstevel@tonic-gate 	tp->_names[len] = '\0';
196*7c478bd9Sstevel@tonic-gate 
197*7c478bd9Sstevel@tonic-gate 	if (127 < header.name_size)
198*7c478bd9Sstevel@tonic-gate 		(void) lseek(fd, (off_t) (header.name_size - 127), SEEK_CUR);
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 	/* Fetch booleans. */
201*7c478bd9Sstevel@tonic-gate 	len = min(__COUNT_BOOL, header.bool_count);
202*7c478bd9Sstevel@tonic-gate 	if (read(fd, tp->_bool, len) != len)
203*7c478bd9Sstevel@tonic-gate 		goto error_3;
204*7c478bd9Sstevel@tonic-gate 
205*7c478bd9Sstevel@tonic-gate 	if (__COUNT_BOOL < header.bool_count) {
206*7c478bd9Sstevel@tonic-gate 		(void) lseek(fd, (off_t) (header.bool_count - __COUNT_BOOL),
207*7c478bd9Sstevel@tonic-gate 			SEEK_CUR);
208*7c478bd9Sstevel@tonic-gate 	} else {
209*7c478bd9Sstevel@tonic-gate 		for (len = header.bool_count; len < __COUNT_BOOL; ++len)
210*7c478bd9Sstevel@tonic-gate 			tp->_bool[len] = 0;
211*7c478bd9Sstevel@tonic-gate 	}
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate 	/* Eat padding byte. */
214*7c478bd9Sstevel@tonic-gate 	if ((header.name_size + header.bool_count) % 2 != 0)
215*7c478bd9Sstevel@tonic-gate 		(void) read(fd, &ch, sizeof (ch));
216*7c478bd9Sstevel@tonic-gate 
217*7c478bd9Sstevel@tonic-gate 	/* Fetch numbers. */
218*7c478bd9Sstevel@tonic-gate 	len = min(__COUNT_NUM, header.num_count);
219*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; ++i)
220*7c478bd9Sstevel@tonic-gate 		tp->_num[i] = getnum(fd);
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	if (__COUNT_NUM < header.num_count) {
223*7c478bd9Sstevel@tonic-gate 		(void) lseek(fd, (off_t) (2 *
224*7c478bd9Sstevel@tonic-gate 			(header.num_count - __COUNT_NUM)), SEEK_CUR);
225*7c478bd9Sstevel@tonic-gate 	} else {
226*7c478bd9Sstevel@tonic-gate 		for (len = header.num_count; len < __COUNT_NUM; ++len)
227*7c478bd9Sstevel@tonic-gate 			tp->_num[len] = -1;
228*7c478bd9Sstevel@tonic-gate 	}
229*7c478bd9Sstevel@tonic-gate 
230*7c478bd9Sstevel@tonic-gate 	/* Allocate and fetch strings. */
231*7c478bd9Sstevel@tonic-gate 	if ((tp->_str_table = (char *) malloc(header.str_size)) == NULL)
232*7c478bd9Sstevel@tonic-gate 		goto error_3;
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate 	/* Read in string offset section setting pointers to strings. */
235*7c478bd9Sstevel@tonic-gate 	len = min(__COUNT_STR, header.str_count);
236*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < len; ++i) {
237*7c478bd9Sstevel@tonic-gate 		if ((offset = getnum(fd)) == SHRT_MIN)
238*7c478bd9Sstevel@tonic-gate 			goto error_4;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 		if (offset < 0)
241*7c478bd9Sstevel@tonic-gate 			tp->_str[i] = NULL;
242*7c478bd9Sstevel@tonic-gate 		else
243*7c478bd9Sstevel@tonic-gate 			tp->_str[i] = tp->_str_table + offset;
244*7c478bd9Sstevel@tonic-gate 	}
245*7c478bd9Sstevel@tonic-gate 
246*7c478bd9Sstevel@tonic-gate 	if (__COUNT_STR < header.str_count) {
247*7c478bd9Sstevel@tonic-gate 		(void) lseek(fd, (off_t) (2 *
248*7c478bd9Sstevel@tonic-gate 			(header.str_count - __COUNT_STR)), SEEK_CUR);
249*7c478bd9Sstevel@tonic-gate 	} else {
250*7c478bd9Sstevel@tonic-gate 		for (; i < __COUNT_STR; ++i)
251*7c478bd9Sstevel@tonic-gate 			tp->_str[i] = NULL;
252*7c478bd9Sstevel@tonic-gate 	}
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate 	if (read(fd, tp->_str_table, header.str_size) != header.str_size)
255*7c478bd9Sstevel@tonic-gate 		goto error_4;
256*7c478bd9Sstevel@tonic-gate 	(void) close(fd);
257*7c478bd9Sstevel@tonic-gate 
258*7c478bd9Sstevel@tonic-gate 	return (0);
259*7c478bd9Sstevel@tonic-gate error_4:
260*7c478bd9Sstevel@tonic-gate 	free(tp->_str_table);
261*7c478bd9Sstevel@tonic-gate error_3:
262*7c478bd9Sstevel@tonic-gate 	free(tp->_names);
263*7c478bd9Sstevel@tonic-gate error_2:
264*7c478bd9Sstevel@tonic-gate 	(void) close(fd);
265*7c478bd9Sstevel@tonic-gate error_1:
266*7c478bd9Sstevel@tonic-gate 	return (-1);
267*7c478bd9Sstevel@tonic-gate }
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate void
use_env(bool bf)270*7c478bd9Sstevel@tonic-gate use_env(bool bf)
271*7c478bd9Sstevel@tonic-gate {
272*7c478bd9Sstevel@tonic-gate 	use_environment = bf;
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate 
275*7c478bd9Sstevel@tonic-gate /*
276*7c478bd9Sstevel@tonic-gate  * Set up terminal.
277*7c478bd9Sstevel@tonic-gate  *
278*7c478bd9Sstevel@tonic-gate  * Reads in the terminfo database pointed to by $TERMINFO env. var.
279*7c478bd9Sstevel@tonic-gate  * for the given terminal, but does not set up the output virtualization
280*7c478bd9Sstevel@tonic-gate  * structues used by CURSES.  If the terminal name pointer is NULL,
281*7c478bd9Sstevel@tonic-gate  * the $TERM env. var. is used for the terminal.  All output is to
282*7c478bd9Sstevel@tonic-gate  * the given file descriptor which is initialized for output.
283*7c478bd9Sstevel@tonic-gate  *
284*7c478bd9Sstevel@tonic-gate  * On error, if errret != NULL then setupterm() returns OK
285*7c478bd9Sstevel@tonic-gate  * or ERR and stores a status value in the integer pointed to by
286*7c478bd9Sstevel@tonic-gate  * errret.  A status of 1 is normal, 0 means the terminal could
287*7c478bd9Sstevel@tonic-gate  * not be found, and -1 means the terminfo database could not be
288*7c478bd9Sstevel@tonic-gate  * found.  If errret == NULL then setupterm() prints an error
289*7c478bd9Sstevel@tonic-gate  * message upon and exit().
290*7c478bd9Sstevel@tonic-gate  *
291*7c478bd9Sstevel@tonic-gate  * On success, cur_term set to a terminfo structure and OK returned.
292*7c478bd9Sstevel@tonic-gate  */
293*7c478bd9Sstevel@tonic-gate int
__m_setupterm(char * termname,int ifd,int ofd,int * err_return)294*7c478bd9Sstevel@tonic-gate __m_setupterm(char *termname, int ifd, int ofd, int *err_return)
295*7c478bd9Sstevel@tonic-gate {
296*7c478bd9Sstevel@tonic-gate 	int	err_code = 1;
297*7c478bd9Sstevel@tonic-gate 	TERMINAL	*old_term;
298*7c478bd9Sstevel@tonic-gate 	const char 	*err_msg;
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate 	/*
301*7c478bd9Sstevel@tonic-gate 	 * It is possible to call setupterm() for multiple terminals,
302*7c478bd9Sstevel@tonic-gate 	 * in which case we have to be able to restore cur_term in
303*7c478bd9Sstevel@tonic-gate 	 * case of error.
304*7c478bd9Sstevel@tonic-gate 	 */
305*7c478bd9Sstevel@tonic-gate 	old_term = cur_term;
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate 	cur_term = (TERMINAL *) calloc(1, sizeof (*cur_term));
308*7c478bd9Sstevel@tonic-gate 	if (cur_term == NULL) {
309*7c478bd9Sstevel@tonic-gate 		err_code = -1;
310*7c478bd9Sstevel@tonic-gate 		goto error;
311*7c478bd9Sstevel@tonic-gate 	}
312*7c478bd9Sstevel@tonic-gate 
313*7c478bd9Sstevel@tonic-gate 	if (isatty(cur_term->_ifd = ifd))
314*7c478bd9Sstevel@tonic-gate 		cur_term->_flags |= __TERM_ISATTY_IN;
315*7c478bd9Sstevel@tonic-gate 	if (isatty(cur_term->_ofd = ofd))
316*7c478bd9Sstevel@tonic-gate 		cur_term->_flags |= __TERM_ISATTY_OUT;
317*7c478bd9Sstevel@tonic-gate 
318*7c478bd9Sstevel@tonic-gate 	cur_term->_shell	= (void *) calloc(1, sizeof (struct termios));
319*7c478bd9Sstevel@tonic-gate 	cur_term->_prog		= (void *) calloc(1, sizeof (struct termios));
320*7c478bd9Sstevel@tonic-gate 	cur_term->_save		= (void *) calloc(1, sizeof (struct termios));
321*7c478bd9Sstevel@tonic-gate 	cur_term->_actual	= (void *) calloc(1, sizeof (struct termios));
322*7c478bd9Sstevel@tonic-gate 	cur_term->_term		= NULL;
323*7c478bd9Sstevel@tonic-gate 	cur_term->_names	= NULL;
324*7c478bd9Sstevel@tonic-gate 	cur_term->_str_table	= NULL;
325*7c478bd9Sstevel@tonic-gate 	(void) def_shell_mode();
326*7c478bd9Sstevel@tonic-gate 	(void) def_prog_mode();
327*7c478bd9Sstevel@tonic-gate 	(void) __m_tty_get(PTERMIOS(_actual));	/* Synch cached value */
328*7c478bd9Sstevel@tonic-gate 
329*7c478bd9Sstevel@tonic-gate #ifdef ONLCR
330*7c478bd9Sstevel@tonic-gate 	if ((PTERMIOS(_prog)->c_oflag & (OPOST | ONLCR)) == (OPOST | ONLCR))
331*7c478bd9Sstevel@tonic-gate #else
332*7c478bd9Sstevel@tonic-gate 	if (PTERMIOS(_prog)->c_oflag & OPOST)
333*7c478bd9Sstevel@tonic-gate #endif
334*7c478bd9Sstevel@tonic-gate 		cur_term->_flags |= __TERM_NL_IS_CRLF;
335*7c478bd9Sstevel@tonic-gate 
336*7c478bd9Sstevel@tonic-gate 	(void) restartterm(termname, ofd, &err_code);
337*7c478bd9Sstevel@tonic-gate error:
338*7c478bd9Sstevel@tonic-gate 	switch (err_code) {
339*7c478bd9Sstevel@tonic-gate 	case -1:
340*7c478bd9Sstevel@tonic-gate 		err_msg = e_terminal;
341*7c478bd9Sstevel@tonic-gate 		break;
342*7c478bd9Sstevel@tonic-gate 	case 0:
343*7c478bd9Sstevel@tonic-gate 		err_msg = e_unknown;
344*7c478bd9Sstevel@tonic-gate 		break;
345*7c478bd9Sstevel@tonic-gate 	case 1:
346*7c478bd9Sstevel@tonic-gate 		break;
347*7c478bd9Sstevel@tonic-gate 	case 2:
348*7c478bd9Sstevel@tonic-gate 		err_msg = e_pathmax;
349*7c478bd9Sstevel@tonic-gate 		err_code = -1;
350*7c478bd9Sstevel@tonic-gate 		break;
351*7c478bd9Sstevel@tonic-gate 	}
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate 	if (err_return != NULL) {
354*7c478bd9Sstevel@tonic-gate 		*err_return = err_code;
355*7c478bd9Sstevel@tonic-gate 
356*7c478bd9Sstevel@tonic-gate 		if (err_code == 1) {
357*7c478bd9Sstevel@tonic-gate 			err_code = OK;
358*7c478bd9Sstevel@tonic-gate 		} else {
359*7c478bd9Sstevel@tonic-gate 			err_code = ERR;
360*7c478bd9Sstevel@tonic-gate 			free(cur_term);
361*7c478bd9Sstevel@tonic-gate 			cur_term = old_term;
362*7c478bd9Sstevel@tonic-gate 		}
363*7c478bd9Sstevel@tonic-gate 	} else if (err_code != 1) {
364*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, err_msg, termname);
365*7c478bd9Sstevel@tonic-gate 		exit(1);
366*7c478bd9Sstevel@tonic-gate 	}
367*7c478bd9Sstevel@tonic-gate 
368*7c478bd9Sstevel@tonic-gate 	return (err_code);
369*7c478bd9Sstevel@tonic-gate }
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate int
setupterm(char * term,int out,int * err)372*7c478bd9Sstevel@tonic-gate setupterm(char *term, int out, int *err)
373*7c478bd9Sstevel@tonic-gate {
374*7c478bd9Sstevel@tonic-gate 	int	code;
375*7c478bd9Sstevel@tonic-gate 
376*7c478bd9Sstevel@tonic-gate 	code = __m_setupterm(term, STDIN_FILENO, out, err);
377*7c478bd9Sstevel@tonic-gate 
378*7c478bd9Sstevel@tonic-gate 	return (code);
379*7c478bd9Sstevel@tonic-gate }
380*7c478bd9Sstevel@tonic-gate 
381*7c478bd9Sstevel@tonic-gate int
del_curterm(TERMINAL * tp)382*7c478bd9Sstevel@tonic-gate del_curterm(TERMINAL *tp)
383*7c478bd9Sstevel@tonic-gate {
384*7c478bd9Sstevel@tonic-gate 	if (tp != NULL) {
385*7c478bd9Sstevel@tonic-gate 		if (cur_term == tp)
386*7c478bd9Sstevel@tonic-gate 			cur_term = NULL;
387*7c478bd9Sstevel@tonic-gate 		if (tp->_str_table != NULL)
388*7c478bd9Sstevel@tonic-gate 			free(tp->_str_table);
389*7c478bd9Sstevel@tonic-gate 		if (tp->_names != NULL)
390*7c478bd9Sstevel@tonic-gate 			free(tp->_names);
391*7c478bd9Sstevel@tonic-gate 		if (tp->_term != NULL)
392*7c478bd9Sstevel@tonic-gate 			free(tp->_term);
393*7c478bd9Sstevel@tonic-gate 		if (tp->_pair != (short (*)[2]) 0)
394*7c478bd9Sstevel@tonic-gate 			free(tp->_pair);
395*7c478bd9Sstevel@tonic-gate 		if (tp->_color != (short (*)[3]) 0)
396*7c478bd9Sstevel@tonic-gate 			free(tp->_color);
397*7c478bd9Sstevel@tonic-gate 		if (tp->_shell)
398*7c478bd9Sstevel@tonic-gate 			free(tp->_shell);
399*7c478bd9Sstevel@tonic-gate 		if (tp->_prog)
400*7c478bd9Sstevel@tonic-gate 			free(tp->_prog);
401*7c478bd9Sstevel@tonic-gate 		if (tp->_save)
402*7c478bd9Sstevel@tonic-gate 			free(tp->_save);
403*7c478bd9Sstevel@tonic-gate 		if (tp->_actual)
404*7c478bd9Sstevel@tonic-gate 			free(tp->_actual);
405*7c478bd9Sstevel@tonic-gate 		free(tp);
406*7c478bd9Sstevel@tonic-gate 	}
407*7c478bd9Sstevel@tonic-gate 
408*7c478bd9Sstevel@tonic-gate 	return (OK);
409*7c478bd9Sstevel@tonic-gate }
410*7c478bd9Sstevel@tonic-gate 
411*7c478bd9Sstevel@tonic-gate TERMINAL *
set_curterm(TERMINAL * tp)412*7c478bd9Sstevel@tonic-gate set_curterm(TERMINAL *tp)
413*7c478bd9Sstevel@tonic-gate {
414*7c478bd9Sstevel@tonic-gate 	TERMINAL	*old;
415*7c478bd9Sstevel@tonic-gate 
416*7c478bd9Sstevel@tonic-gate 	old = cur_term;
417*7c478bd9Sstevel@tonic-gate 	cur_term = tp;
418*7c478bd9Sstevel@tonic-gate 
419*7c478bd9Sstevel@tonic-gate 	return (old);
420*7c478bd9Sstevel@tonic-gate }
421*7c478bd9Sstevel@tonic-gate 
422*7c478bd9Sstevel@tonic-gate int
restartterm(char * tm,int fd,int * err_return)423*7c478bd9Sstevel@tonic-gate restartterm(char *tm, int fd, int *err_return)
424*7c478bd9Sstevel@tonic-gate {
425*7c478bd9Sstevel@tonic-gate 	size_t	len;
426*7c478bd9Sstevel@tonic-gate 	int	err_code;
427*7c478bd9Sstevel@tonic-gate 	const char	*err_msg, *terminfo;
428*7c478bd9Sstevel@tonic-gate 	char	*old_names, *old_strings, *old_term, *filename;
429*7c478bd9Sstevel@tonic-gate 	static const char	def_termname[] = M_TERM_NAME;
430*7c478bd9Sstevel@tonic-gate 	static const char	def_terminfo[] = M_TERMINFO_DIR;
431*7c478bd9Sstevel@tonic-gate 
432*7c478bd9Sstevel@tonic-gate 	err_code = 1;
433*7c478bd9Sstevel@tonic-gate 	filename = NULL;
434*7c478bd9Sstevel@tonic-gate 	old_term = cur_term->_term;
435*7c478bd9Sstevel@tonic-gate 	old_names = cur_term->_names;
436*7c478bd9Sstevel@tonic-gate 	old_strings = cur_term->_str_table;
437*7c478bd9Sstevel@tonic-gate 
438*7c478bd9Sstevel@tonic-gate 	terminfo = getenv("TERMINFO");
439*7c478bd9Sstevel@tonic-gate 	if (terminfo == NULL || terminfo[0] == '\0') {
440*7c478bd9Sstevel@tonic-gate 		terminfo = def_terminfo;
441*7c478bd9Sstevel@tonic-gate 	} else {
442*7c478bd9Sstevel@tonic-gate 		terminfo = (const char *) strdup((char *) terminfo);
443*7c478bd9Sstevel@tonic-gate 		if (terminfo == NULL) {
444*7c478bd9Sstevel@tonic-gate 			/* Not really true... */
445*7c478bd9Sstevel@tonic-gate 			err_msg = e_terminal;
446*7c478bd9Sstevel@tonic-gate 			err_code = 2;
447*7c478bd9Sstevel@tonic-gate 			goto error;
448*7c478bd9Sstevel@tonic-gate 		}
449*7c478bd9Sstevel@tonic-gate 	}
450*7c478bd9Sstevel@tonic-gate 
451*7c478bd9Sstevel@tonic-gate 	if ((tm == NULL) &&
452*7c478bd9Sstevel@tonic-gate 		(((tm = getenv("TERM")) == NULL) || (*tm == '\0'))) {
453*7c478bd9Sstevel@tonic-gate 		tm = (char *)def_termname;
454*7c478bd9Sstevel@tonic-gate 	}
455*7c478bd9Sstevel@tonic-gate 
456*7c478bd9Sstevel@tonic-gate 	/* Remember the terminal name being loaded. */
457*7c478bd9Sstevel@tonic-gate 	cur_term->_term = strdup(tm);
458*7c478bd9Sstevel@tonic-gate 	if (cur_term->_term == NULL) {
459*7c478bd9Sstevel@tonic-gate 		err_msg = e_terminal;
460*7c478bd9Sstevel@tonic-gate 		err_code = 2;
461*7c478bd9Sstevel@tonic-gate 		goto error;
462*7c478bd9Sstevel@tonic-gate 	}
463*7c478bd9Sstevel@tonic-gate 
464*7c478bd9Sstevel@tonic-gate 	/* Length of path we're going to construct. */
465*7c478bd9Sstevel@tonic-gate 	len = strlen(terminfo) + 3 + strlen(tm);
466*7c478bd9Sstevel@tonic-gate 
467*7c478bd9Sstevel@tonic-gate 	if ((len > PATH_MAX) ||
468*7c478bd9Sstevel@tonic-gate 		((filename = (char *)malloc(PATH_MAX + 1)) == NULL)) {
469*7c478bd9Sstevel@tonic-gate 		err_msg = e_pathmax;
470*7c478bd9Sstevel@tonic-gate 		err_code = 2;
471*7c478bd9Sstevel@tonic-gate 		goto error;
472*7c478bd9Sstevel@tonic-gate 	}
473*7c478bd9Sstevel@tonic-gate 
474*7c478bd9Sstevel@tonic-gate 	/* Construct terminfo filename. */
475*7c478bd9Sstevel@tonic-gate 	(void) sprintf(filename, "%s/%c/%s", terminfo, tm[0], tm);
476*7c478bd9Sstevel@tonic-gate 
477*7c478bd9Sstevel@tonic-gate 	/* Go looking for compiled terminal definition. */
478*7c478bd9Sstevel@tonic-gate 	if (__m_read_terminfo(filename, cur_term) < 0) {
479*7c478bd9Sstevel@tonic-gate 		/* Length of default terminfo path. */
480*7c478bd9Sstevel@tonic-gate 		len = strlen(def_terminfo) + 3 + strlen(tm);
481*7c478bd9Sstevel@tonic-gate 
482*7c478bd9Sstevel@tonic-gate 		if (len > PATH_MAX) {
483*7c478bd9Sstevel@tonic-gate 			err_msg = e_pathmax;
484*7c478bd9Sstevel@tonic-gate 			err_code = 2;
485*7c478bd9Sstevel@tonic-gate 			goto error;
486*7c478bd9Sstevel@tonic-gate 		}
487*7c478bd9Sstevel@tonic-gate 
488*7c478bd9Sstevel@tonic-gate 		(void) sprintf(filename, "%s/%c/%s", def_terminfo, tm[0], tm);
489*7c478bd9Sstevel@tonic-gate 
490*7c478bd9Sstevel@tonic-gate 		if (__m_read_terminfo(filename, cur_term) < 0) {
491*7c478bd9Sstevel@tonic-gate 			err_msg = e_unknown;
492*7c478bd9Sstevel@tonic-gate 			err_code = 0;
493*7c478bd9Sstevel@tonic-gate 			goto error;
494*7c478bd9Sstevel@tonic-gate 		}
495*7c478bd9Sstevel@tonic-gate 	}
496*7c478bd9Sstevel@tonic-gate 
497*7c478bd9Sstevel@tonic-gate 	if (use_environment) {
498*7c478bd9Sstevel@tonic-gate 		char	*env;
499*7c478bd9Sstevel@tonic-gate #ifdef TIOCGWINSZ
500*7c478bd9Sstevel@tonic-gate 		/*
501*7c478bd9Sstevel@tonic-gate 		 * Use ioctl(TIOCGWINSZ) to get row and column values.  These
502*7c478bd9Sstevel@tonic-gate 		 * values may override the default terminfo settings.
503*7c478bd9Sstevel@tonic-gate 		 */
504*7c478bd9Sstevel@tonic-gate 		{
505*7c478bd9Sstevel@tonic-gate 			struct winsize	wininfo;
506*7c478bd9Sstevel@tonic-gate 			if (ioctl(fd, TIOCGWINSZ, &wininfo) != -1) {
507*7c478bd9Sstevel@tonic-gate 				if (0 < wininfo.ws_col)
508*7c478bd9Sstevel@tonic-gate 					columns = wininfo.ws_col;
509*7c478bd9Sstevel@tonic-gate 				if (0 < wininfo.ws_row)
510*7c478bd9Sstevel@tonic-gate 					lines = wininfo.ws_row;
511*7c478bd9Sstevel@tonic-gate 			}
512*7c478bd9Sstevel@tonic-gate 		}
513*7c478bd9Sstevel@tonic-gate #endif /* TIOCGWINSZ */
514*7c478bd9Sstevel@tonic-gate 
515*7c478bd9Sstevel@tonic-gate 		/* Check to see is the user wants a particular size terminal. */
516*7c478bd9Sstevel@tonic-gate 		if ((env = getenv("LINES")) != NULL) {
517*7c478bd9Sstevel@tonic-gate 			int	nlines = (int) strtol(env, (char **) 0, 10);
518*7c478bd9Sstevel@tonic-gate 			if (0 < nlines)
519*7c478bd9Sstevel@tonic-gate 				lines = nlines;
520*7c478bd9Sstevel@tonic-gate 		}
521*7c478bd9Sstevel@tonic-gate 		if ((env = getenv("COLUMNS")) != NULL) {
522*7c478bd9Sstevel@tonic-gate 			int ncolumns = (int) strtol(env, (char **) 0, 10);
523*7c478bd9Sstevel@tonic-gate 			if (0 < ncolumns)
524*7c478bd9Sstevel@tonic-gate 				columns = ncolumns;
525*7c478bd9Sstevel@tonic-gate 		}
526*7c478bd9Sstevel@tonic-gate 	}
527*7c478bd9Sstevel@tonic-gate 
528*7c478bd9Sstevel@tonic-gate 	if (command_character != NULL && getenv("CC") != NULL)
529*7c478bd9Sstevel@tonic-gate 		do_prototype();
530*7c478bd9Sstevel@tonic-gate 
531*7c478bd9Sstevel@tonic-gate 	/*
532*7c478bd9Sstevel@tonic-gate 	 * If no_color_video is disabled, then assign it a value that
533*7c478bd9Sstevel@tonic-gate 	 * permits all attributes in combination with colour.
534*7c478bd9Sstevel@tonic-gate 	 */
535*7c478bd9Sstevel@tonic-gate 	if (no_color_video == -1)
536*7c478bd9Sstevel@tonic-gate 		no_color_video = 0;
537*7c478bd9Sstevel@tonic-gate 
538*7c478bd9Sstevel@tonic-gate 	__m_mvcur_cost();
539*7c478bd9Sstevel@tonic-gate error:
540*7c478bd9Sstevel@tonic-gate 	if (filename != NULL)
541*7c478bd9Sstevel@tonic-gate 		free(filename);
542*7c478bd9Sstevel@tonic-gate 
543*7c478bd9Sstevel@tonic-gate 	if (terminfo != def_terminfo)
544*7c478bd9Sstevel@tonic-gate 		free((void *) terminfo);
545*7c478bd9Sstevel@tonic-gate 
546*7c478bd9Sstevel@tonic-gate 	if (err_return != NULL) {
547*7c478bd9Sstevel@tonic-gate 		*err_return = err_code;
548*7c478bd9Sstevel@tonic-gate 
549*7c478bd9Sstevel@tonic-gate 		if (err_code == 1) {
550*7c478bd9Sstevel@tonic-gate 			err_code = OK;
551*7c478bd9Sstevel@tonic-gate 		} else {
552*7c478bd9Sstevel@tonic-gate 			err_code = ERR;
553*7c478bd9Sstevel@tonic-gate 			cur_term->_term = old_term;
554*7c478bd9Sstevel@tonic-gate 			cur_term->_names = old_names;
555*7c478bd9Sstevel@tonic-gate 			cur_term->_str_table = old_strings;
556*7c478bd9Sstevel@tonic-gate 		}
557*7c478bd9Sstevel@tonic-gate 	} else if (err_code != 1) {
558*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, err_msg, tm);
559*7c478bd9Sstevel@tonic-gate 		exit(1);
560*7c478bd9Sstevel@tonic-gate 	}
561*7c478bd9Sstevel@tonic-gate 
562*7c478bd9Sstevel@tonic-gate 	if (err_code == OK) {
563*7c478bd9Sstevel@tonic-gate 		if (old_names != NULL)
564*7c478bd9Sstevel@tonic-gate 			free(old_names);
565*7c478bd9Sstevel@tonic-gate 		if (old_strings != NULL)
566*7c478bd9Sstevel@tonic-gate 			free(old_strings);
567*7c478bd9Sstevel@tonic-gate 		if (old_term != NULL)
568*7c478bd9Sstevel@tonic-gate 			free(old_term);
569*7c478bd9Sstevel@tonic-gate 	}
570*7c478bd9Sstevel@tonic-gate 
571*7c478bd9Sstevel@tonic-gate 	return (err_code);
572*7c478bd9Sstevel@tonic-gate }
573*7c478bd9Sstevel@tonic-gate 
574*7c478bd9Sstevel@tonic-gate /*
575*7c478bd9Sstevel@tonic-gate  * Get the termios setting for the terminal.  Check the input
576*7c478bd9Sstevel@tonic-gate  * file descriptor first, else the output file descriptor.  If
577*7c478bd9Sstevel@tonic-gate  * both input and output are both terminals, it is assumed that
578*7c478bd9Sstevel@tonic-gate  * they refer to the same terminal.
579*7c478bd9Sstevel@tonic-gate  */
580*7c478bd9Sstevel@tonic-gate int
__m_tty_get(struct termios * tp)581*7c478bd9Sstevel@tonic-gate __m_tty_get(struct termios *tp)
582*7c478bd9Sstevel@tonic-gate {
583*7c478bd9Sstevel@tonic-gate 	if (tcgetattr(cur_term->_ifd, tp) != 0) {
584*7c478bd9Sstevel@tonic-gate 		/*
585*7c478bd9Sstevel@tonic-gate 		 * Input was not a terminal, possibly redirected.
586*7c478bd9Sstevel@tonic-gate 		 * Check output instead.
587*7c478bd9Sstevel@tonic-gate 		 */
588*7c478bd9Sstevel@tonic-gate 		if (tcgetattr(cur_term->_ofd, tp) != 0)
589*7c478bd9Sstevel@tonic-gate 			return (ERR);
590*7c478bd9Sstevel@tonic-gate 	}
591*7c478bd9Sstevel@tonic-gate 
592*7c478bd9Sstevel@tonic-gate 	return (OK);
593*7c478bd9Sstevel@tonic-gate }
594*7c478bd9Sstevel@tonic-gate 
595*7c478bd9Sstevel@tonic-gate int
__m_tty_set_prog_mode(void)596*7c478bd9Sstevel@tonic-gate __m_tty_set_prog_mode(void)
597*7c478bd9Sstevel@tonic-gate {
598*7c478bd9Sstevel@tonic-gate 	return (__m_tty_set(PTERMIOS(_prog)));
599*7c478bd9Sstevel@tonic-gate }
600*7c478bd9Sstevel@tonic-gate 
601*7c478bd9Sstevel@tonic-gate /*
602*7c478bd9Sstevel@tonic-gate  * Restore the termios settings.
603*7c478bd9Sstevel@tonic-gate  */
604*7c478bd9Sstevel@tonic-gate int
__m_tty_set(struct termios * tp)605*7c478bd9Sstevel@tonic-gate __m_tty_set(struct termios *tp)
606*7c478bd9Sstevel@tonic-gate {
607*7c478bd9Sstevel@tonic-gate 	int	fd;
608*7c478bd9Sstevel@tonic-gate 	int	rval;
609*7c478bd9Sstevel@tonic-gate 
610*7c478bd9Sstevel@tonic-gate 	if (cur_term->_flags & __TERM_ISATTY_OUT) {
611*7c478bd9Sstevel@tonic-gate 		fd = cur_term->_ofd;
612*7c478bd9Sstevel@tonic-gate 	} else if (cur_term->_flags & __TERM_ISATTY_IN) {
613*7c478bd9Sstevel@tonic-gate 		fd = cur_term->_ifd;
614*7c478bd9Sstevel@tonic-gate 	} else {
615*7c478bd9Sstevel@tonic-gate 		return (OK);
616*7c478bd9Sstevel@tonic-gate 	}
617*7c478bd9Sstevel@tonic-gate 	if (memcmp(tp, &cur_term->_actual, sizeof (struct termios)) == 0)
618*7c478bd9Sstevel@tonic-gate 		return (OK);
619*7c478bd9Sstevel@tonic-gate 
620*7c478bd9Sstevel@tonic-gate 	*PTERMIOS(_actual) = *tp;
621*7c478bd9Sstevel@tonic-gate 
622*7c478bd9Sstevel@tonic-gate 	rval = tcsetattr(fd, TCSADRAIN, tp) == 0 ? OK : ERR;
623*7c478bd9Sstevel@tonic-gate 
624*7c478bd9Sstevel@tonic-gate 	return (rval);
625*7c478bd9Sstevel@tonic-gate }
626*7c478bd9Sstevel@tonic-gate 
627*7c478bd9Sstevel@tonic-gate int
def_shell_mode(void)628*7c478bd9Sstevel@tonic-gate def_shell_mode(void)
629*7c478bd9Sstevel@tonic-gate {
630*7c478bd9Sstevel@tonic-gate 	return (__m_tty_get(PTERMIOS(_shell)));
631*7c478bd9Sstevel@tonic-gate }
632*7c478bd9Sstevel@tonic-gate 
633*7c478bd9Sstevel@tonic-gate int
def_prog_mode(void)634*7c478bd9Sstevel@tonic-gate def_prog_mode(void)
635*7c478bd9Sstevel@tonic-gate {
636*7c478bd9Sstevel@tonic-gate 	return (__m_tty_get(PTERMIOS(_prog)));
637*7c478bd9Sstevel@tonic-gate }
638*7c478bd9Sstevel@tonic-gate 
639*7c478bd9Sstevel@tonic-gate int
reset_shell_mode(void)640*7c478bd9Sstevel@tonic-gate reset_shell_mode(void)
641*7c478bd9Sstevel@tonic-gate {
642*7c478bd9Sstevel@tonic-gate 	return (__m_tty_set(PTERMIOS(_shell)));
643*7c478bd9Sstevel@tonic-gate }
644*7c478bd9Sstevel@tonic-gate 
645*7c478bd9Sstevel@tonic-gate int
reset_prog_mode(void)646*7c478bd9Sstevel@tonic-gate reset_prog_mode(void)
647*7c478bd9Sstevel@tonic-gate {
648*7c478bd9Sstevel@tonic-gate 	return (__m_tty_set_prog_mode());
649*7c478bd9Sstevel@tonic-gate }
650