xref: /minix3/lib/libedit/tty.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: tty.c,v 1.47 2015/05/14 10:44:15 christos Exp $	*/
23e1db26aSLionel Sambuc 
33e1db26aSLionel Sambuc /*-
43e1db26aSLionel Sambuc  * Copyright (c) 1992, 1993
53e1db26aSLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
63e1db26aSLionel Sambuc  *
73e1db26aSLionel Sambuc  * This code is derived from software contributed to Berkeley by
83e1db26aSLionel Sambuc  * Christos Zoulas of Cornell University.
93e1db26aSLionel Sambuc  *
103e1db26aSLionel Sambuc  * Redistribution and use in source and binary forms, with or without
113e1db26aSLionel Sambuc  * modification, are permitted provided that the following conditions
123e1db26aSLionel Sambuc  * are met:
133e1db26aSLionel Sambuc  * 1. Redistributions of source code must retain the above copyright
143e1db26aSLionel Sambuc  *    notice, this list of conditions and the following disclaimer.
153e1db26aSLionel Sambuc  * 2. Redistributions in binary form must reproduce the above copyright
163e1db26aSLionel Sambuc  *    notice, this list of conditions and the following disclaimer in the
173e1db26aSLionel Sambuc  *    documentation and/or other materials provided with the distribution.
183e1db26aSLionel Sambuc  * 3. Neither the name of the University nor the names of its contributors
193e1db26aSLionel Sambuc  *    may be used to endorse or promote products derived from this software
203e1db26aSLionel Sambuc  *    without specific prior written permission.
213e1db26aSLionel Sambuc  *
223e1db26aSLionel Sambuc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
233e1db26aSLionel Sambuc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
243e1db26aSLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
253e1db26aSLionel Sambuc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
263e1db26aSLionel Sambuc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
273e1db26aSLionel Sambuc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
283e1db26aSLionel Sambuc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
293e1db26aSLionel Sambuc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
303e1db26aSLionel Sambuc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
313e1db26aSLionel Sambuc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
323e1db26aSLionel Sambuc  * SUCH DAMAGE.
333e1db26aSLionel Sambuc  */
343e1db26aSLionel Sambuc 
353e1db26aSLionel Sambuc #include "config.h"
363e1db26aSLionel Sambuc #if !defined(lint) && !defined(SCCSID)
373e1db26aSLionel Sambuc #if 0
383e1db26aSLionel Sambuc static char sccsid[] = "@(#)tty.c	8.1 (Berkeley) 6/4/93";
393e1db26aSLionel Sambuc #else
40*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: tty.c,v 1.47 2015/05/14 10:44:15 christos Exp $");
413e1db26aSLionel Sambuc #endif
423e1db26aSLionel Sambuc #endif /* not lint && not SCCSID */
433e1db26aSLionel Sambuc 
443e1db26aSLionel Sambuc /*
453e1db26aSLionel Sambuc  * tty.c: tty interface stuff
463e1db26aSLionel Sambuc  */
473e1db26aSLionel Sambuc #include <assert.h>
483e1db26aSLionel Sambuc #include <errno.h>
493e1db26aSLionel Sambuc #include <unistd.h>	/* for isatty */
503e1db26aSLionel Sambuc #include <strings.h>	/* for ffs */
51*0a6a1f1dSLionel Sambuc #include <stdlib.h>	/* for abort */
523e1db26aSLionel Sambuc #include "el.h"
533e1db26aSLionel Sambuc #include "tty.h"
543e1db26aSLionel Sambuc 
553e1db26aSLionel Sambuc typedef struct ttymodes_t {
563e1db26aSLionel Sambuc 	const char *m_name;
573e1db26aSLionel Sambuc 	unsigned int m_value;
583e1db26aSLionel Sambuc 	int m_type;
593e1db26aSLionel Sambuc }          ttymodes_t;
603e1db26aSLionel Sambuc 
613e1db26aSLionel Sambuc typedef struct ttymap_t {
623e1db26aSLionel Sambuc 	Int nch, och;		/* Internal and termio rep of chars */
633e1db26aSLionel Sambuc 	el_action_t bind[3];	/* emacs, vi, and vi-cmd */
643e1db26aSLionel Sambuc } ttymap_t;
653e1db26aSLionel Sambuc 
663e1db26aSLionel Sambuc 
673e1db26aSLionel Sambuc private const ttyperm_t ttyperm = {
683e1db26aSLionel Sambuc 	{
693e1db26aSLionel Sambuc 		{"iflag:", ICRNL, (INLCR | IGNCR)},
703e1db26aSLionel Sambuc 		{"oflag:", (OPOST | ONLCR), ONLRET},
713e1db26aSLionel Sambuc 		{"cflag:", 0, 0},
723e1db26aSLionel Sambuc 		{"lflag:", (ISIG | ICANON | ECHO | ECHOE | ECHOCTL | IEXTEN),
733e1db26aSLionel Sambuc 		(NOFLSH | ECHONL | EXTPROC | FLUSHO)},
743e1db26aSLionel Sambuc 		{"chars:", 0, 0},
753e1db26aSLionel Sambuc 	},
763e1db26aSLionel Sambuc 	{
773e1db26aSLionel Sambuc 		{"iflag:", (INLCR | ICRNL), IGNCR},
783e1db26aSLionel Sambuc 		{"oflag:", (OPOST | ONLCR), ONLRET},
793e1db26aSLionel Sambuc 		{"cflag:", 0, 0},
803e1db26aSLionel Sambuc 		{"lflag:", ISIG,
813e1db26aSLionel Sambuc 		(NOFLSH | ICANON | ECHO | ECHOK | ECHONL | EXTPROC | IEXTEN | FLUSHO)},
823e1db26aSLionel Sambuc 		{"chars:", (C_SH(C_MIN) | C_SH(C_TIME) | C_SH(C_SWTCH) | C_SH(C_DSWTCH) |
833e1db26aSLionel Sambuc 			    C_SH(C_SUSP) | C_SH(C_DSUSP) | C_SH(C_EOL) | C_SH(C_DISCARD) |
843e1db26aSLionel Sambuc 		    C_SH(C_PGOFF) | C_SH(C_PAGE) | C_SH(C_STATUS)), 0}
853e1db26aSLionel Sambuc 	},
863e1db26aSLionel Sambuc 	{
873e1db26aSLionel Sambuc 		{"iflag:", 0, IXON | IXOFF | INLCR | ICRNL},
883e1db26aSLionel Sambuc 		{"oflag:", 0, 0},
893e1db26aSLionel Sambuc 		{"cflag:", 0, 0},
903e1db26aSLionel Sambuc 		{"lflag:", 0, ISIG | IEXTEN},
913e1db26aSLionel Sambuc 		{"chars:", 0, 0},
923e1db26aSLionel Sambuc 	}
933e1db26aSLionel Sambuc };
943e1db26aSLionel Sambuc 
953e1db26aSLionel Sambuc private const ttychar_t ttychar = {
963e1db26aSLionel Sambuc 	{
973e1db26aSLionel Sambuc 		CINTR, CQUIT, CERASE, CKILL,
983e1db26aSLionel Sambuc 		CEOF, CEOL, CEOL2, CSWTCH,
993e1db26aSLionel Sambuc 		CDSWTCH, CERASE2, CSTART, CSTOP,
1003e1db26aSLionel Sambuc 		CWERASE, CSUSP, CDSUSP, CREPRINT,
1013e1db26aSLionel Sambuc 		CDISCARD, CLNEXT, CSTATUS, CPAGE,
1023e1db26aSLionel Sambuc 		CPGOFF, CKILL2, CBRK, CMIN,
1033e1db26aSLionel Sambuc 		CTIME
1043e1db26aSLionel Sambuc 	},
1053e1db26aSLionel Sambuc 	{
1063e1db26aSLionel Sambuc 		CINTR, CQUIT, CERASE, CKILL,
1073e1db26aSLionel Sambuc 		_POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
1083e1db26aSLionel Sambuc 		_POSIX_VDISABLE, CERASE2, CSTART, CSTOP,
1093e1db26aSLionel Sambuc 		_POSIX_VDISABLE, CSUSP, _POSIX_VDISABLE, _POSIX_VDISABLE,
1103e1db26aSLionel Sambuc 		CDISCARD, _POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE,
1113e1db26aSLionel Sambuc 		_POSIX_VDISABLE, _POSIX_VDISABLE, _POSIX_VDISABLE, 1,
1123e1db26aSLionel Sambuc 		0
1133e1db26aSLionel Sambuc 	},
1143e1db26aSLionel Sambuc 	{
1153e1db26aSLionel Sambuc 		0, 0, 0, 0,
1163e1db26aSLionel Sambuc 		0, 0, 0, 0,
1173e1db26aSLionel Sambuc 		0, 0, 0, 0,
1183e1db26aSLionel Sambuc 		0, 0, 0, 0,
1193e1db26aSLionel Sambuc 		0, 0, 0, 0,
1203e1db26aSLionel Sambuc 		0, 0, 0, 0,
1213e1db26aSLionel Sambuc 		0
1223e1db26aSLionel Sambuc 	}
1233e1db26aSLionel Sambuc };
1243e1db26aSLionel Sambuc 
1253e1db26aSLionel Sambuc private const ttymap_t tty_map[] = {
1263e1db26aSLionel Sambuc #ifdef VERASE
1273e1db26aSLionel Sambuc 	{C_ERASE, VERASE,
1283e1db26aSLionel Sambuc 	{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
1293e1db26aSLionel Sambuc #endif /* VERASE */
1303e1db26aSLionel Sambuc #ifdef VERASE2
1313e1db26aSLionel Sambuc 	{C_ERASE2, VERASE2,
1323e1db26aSLionel Sambuc 	{EM_DELETE_PREV_CHAR, VI_DELETE_PREV_CHAR, ED_PREV_CHAR}},
1333e1db26aSLionel Sambuc #endif /* VERASE2 */
1343e1db26aSLionel Sambuc #ifdef VKILL
1353e1db26aSLionel Sambuc 	{C_KILL, VKILL,
1363e1db26aSLionel Sambuc 	{EM_KILL_LINE, VI_KILL_LINE_PREV, ED_UNASSIGNED}},
1373e1db26aSLionel Sambuc #endif /* VKILL */
1383e1db26aSLionel Sambuc #ifdef VKILL2
1393e1db26aSLionel Sambuc 	{C_KILL2, VKILL2,
1403e1db26aSLionel Sambuc 	{EM_KILL_LINE, VI_KILL_LINE_PREV, ED_UNASSIGNED}},
1413e1db26aSLionel Sambuc #endif /* VKILL2 */
1423e1db26aSLionel Sambuc #ifdef VEOF
1433e1db26aSLionel Sambuc 	{C_EOF, VEOF,
1443e1db26aSLionel Sambuc 	{EM_DELETE_OR_LIST, VI_LIST_OR_EOF, ED_UNASSIGNED}},
1453e1db26aSLionel Sambuc #endif /* VEOF */
1463e1db26aSLionel Sambuc #ifdef VWERASE
1473e1db26aSLionel Sambuc 	{C_WERASE, VWERASE,
1483e1db26aSLionel Sambuc 	{ED_DELETE_PREV_WORD, ED_DELETE_PREV_WORD, ED_PREV_WORD}},
1493e1db26aSLionel Sambuc #endif /* VWERASE */
1503e1db26aSLionel Sambuc #ifdef VREPRINT
1513e1db26aSLionel Sambuc 	{C_REPRINT, VREPRINT,
1523e1db26aSLionel Sambuc 	{ED_REDISPLAY, ED_INSERT, ED_REDISPLAY}},
1533e1db26aSLionel Sambuc #endif /* VREPRINT */
1543e1db26aSLionel Sambuc #ifdef VLNEXT
1553e1db26aSLionel Sambuc 	{C_LNEXT, VLNEXT,
1563e1db26aSLionel Sambuc 	{ED_QUOTED_INSERT, ED_QUOTED_INSERT, ED_UNASSIGNED}},
1573e1db26aSLionel Sambuc #endif /* VLNEXT */
1583e1db26aSLionel Sambuc 	{(Int)-1, (Int)-1,
1593e1db26aSLionel Sambuc 	{ED_UNASSIGNED, ED_UNASSIGNED, ED_UNASSIGNED}}
1603e1db26aSLionel Sambuc };
1613e1db26aSLionel Sambuc 
1623e1db26aSLionel Sambuc private const ttymodes_t ttymodes[] = {
1633e1db26aSLionel Sambuc #ifdef	IGNBRK
1643e1db26aSLionel Sambuc 	{"ignbrk", IGNBRK, MD_INP},
1653e1db26aSLionel Sambuc #endif /* IGNBRK */
1663e1db26aSLionel Sambuc #ifdef	BRKINT
1673e1db26aSLionel Sambuc 	{"brkint", BRKINT, MD_INP},
1683e1db26aSLionel Sambuc #endif /* BRKINT */
1693e1db26aSLionel Sambuc #ifdef	IGNPAR
1703e1db26aSLionel Sambuc 	{"ignpar", IGNPAR, MD_INP},
1713e1db26aSLionel Sambuc #endif /* IGNPAR */
1723e1db26aSLionel Sambuc #ifdef	PARMRK
1733e1db26aSLionel Sambuc 	{"parmrk", PARMRK, MD_INP},
1743e1db26aSLionel Sambuc #endif /* PARMRK */
1753e1db26aSLionel Sambuc #ifdef	INPCK
1763e1db26aSLionel Sambuc 	{"inpck", INPCK, MD_INP},
1773e1db26aSLionel Sambuc #endif /* INPCK */
1783e1db26aSLionel Sambuc #ifdef	ISTRIP
1793e1db26aSLionel Sambuc 	{"istrip", ISTRIP, MD_INP},
1803e1db26aSLionel Sambuc #endif /* ISTRIP */
1813e1db26aSLionel Sambuc #ifdef	INLCR
1823e1db26aSLionel Sambuc 	{"inlcr", INLCR, MD_INP},
1833e1db26aSLionel Sambuc #endif /* INLCR */
1843e1db26aSLionel Sambuc #ifdef	IGNCR
1853e1db26aSLionel Sambuc 	{"igncr", IGNCR, MD_INP},
1863e1db26aSLionel Sambuc #endif /* IGNCR */
1873e1db26aSLionel Sambuc #ifdef	ICRNL
1883e1db26aSLionel Sambuc 	{"icrnl", ICRNL, MD_INP},
1893e1db26aSLionel Sambuc #endif /* ICRNL */
1903e1db26aSLionel Sambuc #ifdef	IUCLC
1913e1db26aSLionel Sambuc 	{"iuclc", IUCLC, MD_INP},
1923e1db26aSLionel Sambuc #endif /* IUCLC */
1933e1db26aSLionel Sambuc #ifdef	IXON
1943e1db26aSLionel Sambuc 	{"ixon", IXON, MD_INP},
1953e1db26aSLionel Sambuc #endif /* IXON */
1963e1db26aSLionel Sambuc #ifdef	IXANY
1973e1db26aSLionel Sambuc 	{"ixany", IXANY, MD_INP},
1983e1db26aSLionel Sambuc #endif /* IXANY */
1993e1db26aSLionel Sambuc #ifdef	IXOFF
2003e1db26aSLionel Sambuc 	{"ixoff", IXOFF, MD_INP},
2013e1db26aSLionel Sambuc #endif /* IXOFF */
2023e1db26aSLionel Sambuc #ifdef  IMAXBEL
2033e1db26aSLionel Sambuc 	{"imaxbel", IMAXBEL, MD_INP},
2043e1db26aSLionel Sambuc #endif /* IMAXBEL */
2053e1db26aSLionel Sambuc 
2063e1db26aSLionel Sambuc #ifdef	OPOST
2073e1db26aSLionel Sambuc 	{"opost", OPOST, MD_OUT},
2083e1db26aSLionel Sambuc #endif /* OPOST */
2093e1db26aSLionel Sambuc #ifdef	OLCUC
2103e1db26aSLionel Sambuc 	{"olcuc", OLCUC, MD_OUT},
2113e1db26aSLionel Sambuc #endif /* OLCUC */
2123e1db26aSLionel Sambuc #ifdef	ONLCR
2133e1db26aSLionel Sambuc 	{"onlcr", ONLCR, MD_OUT},
2143e1db26aSLionel Sambuc #endif /* ONLCR */
2153e1db26aSLionel Sambuc #ifdef	OCRNL
2163e1db26aSLionel Sambuc 	{"ocrnl", OCRNL, MD_OUT},
2173e1db26aSLionel Sambuc #endif /* OCRNL */
2183e1db26aSLionel Sambuc #ifdef	ONOCR
2193e1db26aSLionel Sambuc 	{"onocr", ONOCR, MD_OUT},
2203e1db26aSLionel Sambuc #endif /* ONOCR */
2213e1db26aSLionel Sambuc #ifdef ONOEOT
2223e1db26aSLionel Sambuc 	{"onoeot", ONOEOT, MD_OUT},
2233e1db26aSLionel Sambuc #endif /* ONOEOT */
2243e1db26aSLionel Sambuc #ifdef	ONLRET
2253e1db26aSLionel Sambuc 	{"onlret", ONLRET, MD_OUT},
2263e1db26aSLionel Sambuc #endif /* ONLRET */
2273e1db26aSLionel Sambuc #ifdef	OFILL
2283e1db26aSLionel Sambuc 	{"ofill", OFILL, MD_OUT},
2293e1db26aSLionel Sambuc #endif /* OFILL */
2303e1db26aSLionel Sambuc #ifdef	OFDEL
2313e1db26aSLionel Sambuc 	{"ofdel", OFDEL, MD_OUT},
2323e1db26aSLionel Sambuc #endif /* OFDEL */
2333e1db26aSLionel Sambuc #ifdef	NLDLY
2343e1db26aSLionel Sambuc 	{"nldly", NLDLY, MD_OUT},
2353e1db26aSLionel Sambuc #endif /* NLDLY */
2363e1db26aSLionel Sambuc #ifdef	CRDLY
2373e1db26aSLionel Sambuc 	{"crdly", CRDLY, MD_OUT},
2383e1db26aSLionel Sambuc #endif /* CRDLY */
2393e1db26aSLionel Sambuc #ifdef	TABDLY
2403e1db26aSLionel Sambuc 	{"tabdly", TABDLY, MD_OUT},
2413e1db26aSLionel Sambuc #endif /* TABDLY */
2423e1db26aSLionel Sambuc #ifdef	XTABS
2433e1db26aSLionel Sambuc 	{"xtabs", XTABS, MD_OUT},
2443e1db26aSLionel Sambuc #endif /* XTABS */
2453e1db26aSLionel Sambuc #ifdef	BSDLY
2463e1db26aSLionel Sambuc 	{"bsdly", BSDLY, MD_OUT},
2473e1db26aSLionel Sambuc #endif /* BSDLY */
2483e1db26aSLionel Sambuc #ifdef	VTDLY
2493e1db26aSLionel Sambuc 	{"vtdly", VTDLY, MD_OUT},
2503e1db26aSLionel Sambuc #endif /* VTDLY */
2513e1db26aSLionel Sambuc #ifdef	FFDLY
2523e1db26aSLionel Sambuc 	{"ffdly", FFDLY, MD_OUT},
2533e1db26aSLionel Sambuc #endif /* FFDLY */
2543e1db26aSLionel Sambuc #ifdef	PAGEOUT
2553e1db26aSLionel Sambuc 	{"pageout", PAGEOUT, MD_OUT},
2563e1db26aSLionel Sambuc #endif /* PAGEOUT */
2573e1db26aSLionel Sambuc #ifdef	WRAP
2583e1db26aSLionel Sambuc 	{"wrap", WRAP, MD_OUT},
2593e1db26aSLionel Sambuc #endif /* WRAP */
2603e1db26aSLionel Sambuc 
2613e1db26aSLionel Sambuc #ifdef	CIGNORE
2623e1db26aSLionel Sambuc 	{"cignore", CIGNORE, MD_CTL},
2633e1db26aSLionel Sambuc #endif /* CBAUD */
2643e1db26aSLionel Sambuc #ifdef	CBAUD
2653e1db26aSLionel Sambuc 	{"cbaud", CBAUD, MD_CTL},
2663e1db26aSLionel Sambuc #endif /* CBAUD */
2673e1db26aSLionel Sambuc #ifdef	CSTOPB
2683e1db26aSLionel Sambuc 	{"cstopb", CSTOPB, MD_CTL},
2693e1db26aSLionel Sambuc #endif /* CSTOPB */
2703e1db26aSLionel Sambuc #ifdef	CREAD
2713e1db26aSLionel Sambuc 	{"cread", CREAD, MD_CTL},
2723e1db26aSLionel Sambuc #endif /* CREAD */
2733e1db26aSLionel Sambuc #ifdef	PARENB
2743e1db26aSLionel Sambuc 	{"parenb", PARENB, MD_CTL},
2753e1db26aSLionel Sambuc #endif /* PARENB */
2763e1db26aSLionel Sambuc #ifdef	PARODD
2773e1db26aSLionel Sambuc 	{"parodd", PARODD, MD_CTL},
2783e1db26aSLionel Sambuc #endif /* PARODD */
2793e1db26aSLionel Sambuc #ifdef	HUPCL
2803e1db26aSLionel Sambuc 	{"hupcl", HUPCL, MD_CTL},
2813e1db26aSLionel Sambuc #endif /* HUPCL */
2823e1db26aSLionel Sambuc #ifdef	CLOCAL
2833e1db26aSLionel Sambuc 	{"clocal", CLOCAL, MD_CTL},
2843e1db26aSLionel Sambuc #endif /* CLOCAL */
2853e1db26aSLionel Sambuc #ifdef	LOBLK
2863e1db26aSLionel Sambuc 	{"loblk", LOBLK, MD_CTL},
2873e1db26aSLionel Sambuc #endif /* LOBLK */
2883e1db26aSLionel Sambuc #ifdef	CIBAUD
2893e1db26aSLionel Sambuc 	{"cibaud", CIBAUD, MD_CTL},
2903e1db26aSLionel Sambuc #endif /* CIBAUD */
2913e1db26aSLionel Sambuc #ifdef CRTSCTS
2923e1db26aSLionel Sambuc #ifdef CCTS_OFLOW
2933e1db26aSLionel Sambuc 	{"ccts_oflow", CCTS_OFLOW, MD_CTL},
2943e1db26aSLionel Sambuc #else
2953e1db26aSLionel Sambuc 	{"crtscts", CRTSCTS, MD_CTL},
2963e1db26aSLionel Sambuc #endif /* CCTS_OFLOW */
2973e1db26aSLionel Sambuc #endif /* CRTSCTS */
2983e1db26aSLionel Sambuc #ifdef CRTS_IFLOW
2993e1db26aSLionel Sambuc 	{"crts_iflow", CRTS_IFLOW, MD_CTL},
3003e1db26aSLionel Sambuc #endif /* CRTS_IFLOW */
3013e1db26aSLionel Sambuc #ifdef CDTRCTS
3023e1db26aSLionel Sambuc 	{"cdtrcts", CDTRCTS, MD_CTL},
3033e1db26aSLionel Sambuc #endif /* CDTRCTS */
3043e1db26aSLionel Sambuc #ifdef MDMBUF
3053e1db26aSLionel Sambuc 	{"mdmbuf", MDMBUF, MD_CTL},
3063e1db26aSLionel Sambuc #endif /* MDMBUF */
3073e1db26aSLionel Sambuc #ifdef RCV1EN
3083e1db26aSLionel Sambuc 	{"rcv1en", RCV1EN, MD_CTL},
3093e1db26aSLionel Sambuc #endif /* RCV1EN */
3103e1db26aSLionel Sambuc #ifdef XMT1EN
3113e1db26aSLionel Sambuc 	{"xmt1en", XMT1EN, MD_CTL},
3123e1db26aSLionel Sambuc #endif /* XMT1EN */
3133e1db26aSLionel Sambuc 
3143e1db26aSLionel Sambuc #ifdef	ISIG
3153e1db26aSLionel Sambuc 	{"isig", ISIG, MD_LIN},
3163e1db26aSLionel Sambuc #endif /* ISIG */
3173e1db26aSLionel Sambuc #ifdef	ICANON
3183e1db26aSLionel Sambuc 	{"icanon", ICANON, MD_LIN},
3193e1db26aSLionel Sambuc #endif /* ICANON */
3203e1db26aSLionel Sambuc #ifdef	XCASE
3213e1db26aSLionel Sambuc 	{"xcase", XCASE, MD_LIN},
3223e1db26aSLionel Sambuc #endif /* XCASE */
3233e1db26aSLionel Sambuc #ifdef	ECHO
3243e1db26aSLionel Sambuc 	{"echo", ECHO, MD_LIN},
3253e1db26aSLionel Sambuc #endif /* ECHO */
3263e1db26aSLionel Sambuc #ifdef	ECHOE
3273e1db26aSLionel Sambuc 	{"echoe", ECHOE, MD_LIN},
3283e1db26aSLionel Sambuc #endif /* ECHOE */
3293e1db26aSLionel Sambuc #ifdef	ECHOK
3303e1db26aSLionel Sambuc 	{"echok", ECHOK, MD_LIN},
3313e1db26aSLionel Sambuc #endif /* ECHOK */
3323e1db26aSLionel Sambuc #ifdef	ECHONL
3333e1db26aSLionel Sambuc 	{"echonl", ECHONL, MD_LIN},
3343e1db26aSLionel Sambuc #endif /* ECHONL */
3353e1db26aSLionel Sambuc #ifdef	NOFLSH
3363e1db26aSLionel Sambuc 	{"noflsh", NOFLSH, MD_LIN},
3373e1db26aSLionel Sambuc #endif /* NOFLSH */
3383e1db26aSLionel Sambuc #ifdef	TOSTOP
3393e1db26aSLionel Sambuc 	{"tostop", TOSTOP, MD_LIN},
3403e1db26aSLionel Sambuc #endif /* TOSTOP */
3413e1db26aSLionel Sambuc #ifdef	ECHOCTL
3423e1db26aSLionel Sambuc 	{"echoctl", ECHOCTL, MD_LIN},
3433e1db26aSLionel Sambuc #endif /* ECHOCTL */
3443e1db26aSLionel Sambuc #ifdef	ECHOPRT
3453e1db26aSLionel Sambuc 	{"echoprt", ECHOPRT, MD_LIN},
3463e1db26aSLionel Sambuc #endif /* ECHOPRT */
3473e1db26aSLionel Sambuc #ifdef	ECHOKE
3483e1db26aSLionel Sambuc 	{"echoke", ECHOKE, MD_LIN},
3493e1db26aSLionel Sambuc #endif /* ECHOKE */
3503e1db26aSLionel Sambuc #ifdef	DEFECHO
3513e1db26aSLionel Sambuc 	{"defecho", DEFECHO, MD_LIN},
3523e1db26aSLionel Sambuc #endif /* DEFECHO */
3533e1db26aSLionel Sambuc #ifdef	FLUSHO
3543e1db26aSLionel Sambuc 	{"flusho", FLUSHO, MD_LIN},
3553e1db26aSLionel Sambuc #endif /* FLUSHO */
3563e1db26aSLionel Sambuc #ifdef	PENDIN
3573e1db26aSLionel Sambuc 	{"pendin", PENDIN, MD_LIN},
3583e1db26aSLionel Sambuc #endif /* PENDIN */
3593e1db26aSLionel Sambuc #ifdef	IEXTEN
3603e1db26aSLionel Sambuc 	{"iexten", IEXTEN, MD_LIN},
3613e1db26aSLionel Sambuc #endif /* IEXTEN */
3623e1db26aSLionel Sambuc #ifdef	NOKERNINFO
3633e1db26aSLionel Sambuc 	{"nokerninfo", NOKERNINFO, MD_LIN},
3643e1db26aSLionel Sambuc #endif /* NOKERNINFO */
3653e1db26aSLionel Sambuc #ifdef	ALTWERASE
3663e1db26aSLionel Sambuc 	{"altwerase", ALTWERASE, MD_LIN},
3673e1db26aSLionel Sambuc #endif /* ALTWERASE */
3683e1db26aSLionel Sambuc #ifdef	EXTPROC
3693e1db26aSLionel Sambuc 	{"extproc", EXTPROC, MD_LIN},
3703e1db26aSLionel Sambuc #endif /* EXTPROC */
3713e1db26aSLionel Sambuc 
3723e1db26aSLionel Sambuc #if defined(VINTR)
3733e1db26aSLionel Sambuc 	{"intr", C_SH(C_INTR), MD_CHAR},
3743e1db26aSLionel Sambuc #endif /* VINTR */
3753e1db26aSLionel Sambuc #if defined(VQUIT)
3763e1db26aSLionel Sambuc 	{"quit", C_SH(C_QUIT), MD_CHAR},
3773e1db26aSLionel Sambuc #endif /* VQUIT */
3783e1db26aSLionel Sambuc #if defined(VERASE)
3793e1db26aSLionel Sambuc 	{"erase", C_SH(C_ERASE), MD_CHAR},
3803e1db26aSLionel Sambuc #endif /* VERASE */
3813e1db26aSLionel Sambuc #if defined(VKILL)
3823e1db26aSLionel Sambuc 	{"kill", C_SH(C_KILL), MD_CHAR},
3833e1db26aSLionel Sambuc #endif /* VKILL */
3843e1db26aSLionel Sambuc #if defined(VEOF)
3853e1db26aSLionel Sambuc 	{"eof", C_SH(C_EOF), MD_CHAR},
3863e1db26aSLionel Sambuc #endif /* VEOF */
3873e1db26aSLionel Sambuc #if defined(VEOL)
3883e1db26aSLionel Sambuc 	{"eol", C_SH(C_EOL), MD_CHAR},
3893e1db26aSLionel Sambuc #endif /* VEOL */
3903e1db26aSLionel Sambuc #if defined(VEOL2)
3913e1db26aSLionel Sambuc 	{"eol2", C_SH(C_EOL2), MD_CHAR},
3923e1db26aSLionel Sambuc #endif /* VEOL2 */
3933e1db26aSLionel Sambuc #if defined(VSWTCH)
3943e1db26aSLionel Sambuc 	{"swtch", C_SH(C_SWTCH), MD_CHAR},
3953e1db26aSLionel Sambuc #endif /* VSWTCH */
3963e1db26aSLionel Sambuc #if defined(VDSWTCH)
3973e1db26aSLionel Sambuc 	{"dswtch", C_SH(C_DSWTCH), MD_CHAR},
3983e1db26aSLionel Sambuc #endif /* VDSWTCH */
3993e1db26aSLionel Sambuc #if defined(VERASE2)
4003e1db26aSLionel Sambuc 	{"erase2", C_SH(C_ERASE2), MD_CHAR},
4013e1db26aSLionel Sambuc #endif /* VERASE2 */
4023e1db26aSLionel Sambuc #if defined(VSTART)
4033e1db26aSLionel Sambuc 	{"start", C_SH(C_START), MD_CHAR},
4043e1db26aSLionel Sambuc #endif /* VSTART */
4053e1db26aSLionel Sambuc #if defined(VSTOP)
4063e1db26aSLionel Sambuc 	{"stop", C_SH(C_STOP), MD_CHAR},
4073e1db26aSLionel Sambuc #endif /* VSTOP */
4083e1db26aSLionel Sambuc #if defined(VWERASE)
4093e1db26aSLionel Sambuc 	{"werase", C_SH(C_WERASE), MD_CHAR},
4103e1db26aSLionel Sambuc #endif /* VWERASE */
4113e1db26aSLionel Sambuc #if defined(VSUSP)
4123e1db26aSLionel Sambuc 	{"susp", C_SH(C_SUSP), MD_CHAR},
4133e1db26aSLionel Sambuc #endif /* VSUSP */
4143e1db26aSLionel Sambuc #if defined(VDSUSP)
4153e1db26aSLionel Sambuc 	{"dsusp", C_SH(C_DSUSP), MD_CHAR},
4163e1db26aSLionel Sambuc #endif /* VDSUSP */
4173e1db26aSLionel Sambuc #if defined(VREPRINT)
4183e1db26aSLionel Sambuc 	{"reprint", C_SH(C_REPRINT), MD_CHAR},
4193e1db26aSLionel Sambuc #endif /* VREPRINT */
4203e1db26aSLionel Sambuc #if defined(VDISCARD)
4213e1db26aSLionel Sambuc 	{"discard", C_SH(C_DISCARD), MD_CHAR},
4223e1db26aSLionel Sambuc #endif /* VDISCARD */
4233e1db26aSLionel Sambuc #if defined(VLNEXT)
4243e1db26aSLionel Sambuc 	{"lnext", C_SH(C_LNEXT), MD_CHAR},
4253e1db26aSLionel Sambuc #endif /* VLNEXT */
4263e1db26aSLionel Sambuc #if defined(VSTATUS)
4273e1db26aSLionel Sambuc 	{"status", C_SH(C_STATUS), MD_CHAR},
4283e1db26aSLionel Sambuc #endif /* VSTATUS */
4293e1db26aSLionel Sambuc #if defined(VPAGE)
4303e1db26aSLionel Sambuc 	{"page", C_SH(C_PAGE), MD_CHAR},
4313e1db26aSLionel Sambuc #endif /* VPAGE */
4323e1db26aSLionel Sambuc #if defined(VPGOFF)
4333e1db26aSLionel Sambuc 	{"pgoff", C_SH(C_PGOFF), MD_CHAR},
4343e1db26aSLionel Sambuc #endif /* VPGOFF */
4353e1db26aSLionel Sambuc #if defined(VKILL2)
4363e1db26aSLionel Sambuc 	{"kill2", C_SH(C_KILL2), MD_CHAR},
4373e1db26aSLionel Sambuc #endif /* VKILL2 */
4383e1db26aSLionel Sambuc #if defined(VBRK)
4393e1db26aSLionel Sambuc 	{"brk", C_SH(C_BRK), MD_CHAR},
4403e1db26aSLionel Sambuc #endif /* VBRK */
4413e1db26aSLionel Sambuc #if defined(VMIN)
4423e1db26aSLionel Sambuc 	{"min", C_SH(C_MIN), MD_CHAR},
4433e1db26aSLionel Sambuc #endif /* VMIN */
4443e1db26aSLionel Sambuc #if defined(VTIME)
4453e1db26aSLionel Sambuc 	{"time", C_SH(C_TIME), MD_CHAR},
4463e1db26aSLionel Sambuc #endif /* VTIME */
4473e1db26aSLionel Sambuc 	{NULL, 0, -1},
4483e1db26aSLionel Sambuc };
4493e1db26aSLionel Sambuc 
4503e1db26aSLionel Sambuc 
4513e1db26aSLionel Sambuc 
4523e1db26aSLionel Sambuc #define	tty__gettabs(td)	((((td)->c_oflag & TAB3) == TAB3) ? 0 : 1)
4533e1db26aSLionel Sambuc #define	tty__geteightbit(td)	(((td)->c_cflag & CSIZE) == CS8)
4543e1db26aSLionel Sambuc #define	tty__cooked_mode(td)	((td)->c_lflag & ICANON)
4553e1db26aSLionel Sambuc 
4563e1db26aSLionel Sambuc private int	tty_getty(EditLine *, struct termios *);
4573e1db26aSLionel Sambuc private int	tty_setty(EditLine *, int, const struct termios *);
4583e1db26aSLionel Sambuc private int	tty__getcharindex(int);
4593e1db26aSLionel Sambuc private void	tty__getchar(struct termios *, unsigned char *);
4603e1db26aSLionel Sambuc private void	tty__setchar(struct termios *, unsigned char *);
4613e1db26aSLionel Sambuc private speed_t	tty__getspeed(struct termios *);
4623e1db26aSLionel Sambuc private int	tty_setup(EditLine *);
463*0a6a1f1dSLionel Sambuc private void	tty_setup_flags(EditLine *, struct termios *, int);
4643e1db26aSLionel Sambuc 
4653e1db26aSLionel Sambuc #define	t_qu	t_ts
4663e1db26aSLionel Sambuc 
4673e1db26aSLionel Sambuc /* tty_getty():
4683e1db26aSLionel Sambuc  *	Wrapper for tcgetattr to handle EINTR
4693e1db26aSLionel Sambuc  */
4703e1db26aSLionel Sambuc private int
tty_getty(EditLine * el,struct termios * t)4713e1db26aSLionel Sambuc tty_getty(EditLine *el, struct termios *t)
4723e1db26aSLionel Sambuc {
4733e1db26aSLionel Sambuc 	int rv;
4743e1db26aSLionel Sambuc 	while ((rv = tcgetattr(el->el_infd, t)) == -1 && errno == EINTR)
4753e1db26aSLionel Sambuc 		continue;
4763e1db26aSLionel Sambuc 	return rv;
4773e1db26aSLionel Sambuc }
4783e1db26aSLionel Sambuc 
4793e1db26aSLionel Sambuc /* tty_setty():
4803e1db26aSLionel Sambuc  *	Wrapper for tcsetattr to handle EINTR
4813e1db26aSLionel Sambuc  */
4823e1db26aSLionel Sambuc private int
tty_setty(EditLine * el,int action,const struct termios * t)4833e1db26aSLionel Sambuc tty_setty(EditLine *el, int action, const struct termios *t)
4843e1db26aSLionel Sambuc {
4853e1db26aSLionel Sambuc 	int rv;
4863e1db26aSLionel Sambuc 	while ((rv = tcsetattr(el->el_infd, action, t)) == -1 && errno == EINTR)
4873e1db26aSLionel Sambuc 		continue;
4883e1db26aSLionel Sambuc 	return rv;
4893e1db26aSLionel Sambuc }
4903e1db26aSLionel Sambuc 
4913e1db26aSLionel Sambuc /* tty_setup():
4923e1db26aSLionel Sambuc  *	Get the tty parameters and initialize the editing state
4933e1db26aSLionel Sambuc  */
4943e1db26aSLionel Sambuc private int
tty_setup(EditLine * el)4953e1db26aSLionel Sambuc tty_setup(EditLine *el)
4963e1db26aSLionel Sambuc {
4973e1db26aSLionel Sambuc 	int rst = 1;
4983e1db26aSLionel Sambuc 
4993e1db26aSLionel Sambuc 	if (el->el_flags & EDIT_DISABLED)
5003e1db26aSLionel Sambuc 		return 0;
5013e1db26aSLionel Sambuc 
5023e1db26aSLionel Sambuc 	if (!isatty(el->el_outfd)) {
5033e1db26aSLionel Sambuc #ifdef DEBUG_TTY
5043e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: isatty: %s\n", __func__,
5053e1db26aSLionel Sambuc 		    strerror(errno));
5063e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
5073e1db26aSLionel Sambuc 		return -1;
5083e1db26aSLionel Sambuc 	}
5093e1db26aSLionel Sambuc 	if (tty_getty(el, &el->el_tty.t_or) == -1) {
5103e1db26aSLionel Sambuc #ifdef DEBUG_TTY
5113e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
5123e1db26aSLionel Sambuc 		    strerror(errno));
5133e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
5143e1db26aSLionel Sambuc 		return -1;
5153e1db26aSLionel Sambuc 	}
5163e1db26aSLionel Sambuc 	el->el_tty.t_ts = el->el_tty.t_ex = el->el_tty.t_ed = el->el_tty.t_or;
5173e1db26aSLionel Sambuc 
5183e1db26aSLionel Sambuc 	el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ex);
5193e1db26aSLionel Sambuc 	el->el_tty.t_tabs = tty__gettabs(&el->el_tty.t_ex);
5203e1db26aSLionel Sambuc 	el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ex);
5213e1db26aSLionel Sambuc 
522*0a6a1f1dSLionel Sambuc 	tty_setup_flags(el, &el->el_tty.t_ex, EX_IO);
5233e1db26aSLionel Sambuc 
5243e1db26aSLionel Sambuc 	/*
5253e1db26aSLionel Sambuc          * Reset the tty chars to reasonable defaults
5263e1db26aSLionel Sambuc          * If they are disabled, then enable them.
5273e1db26aSLionel Sambuc          */
5283e1db26aSLionel Sambuc 	if (rst) {
5293e1db26aSLionel Sambuc 		if (tty__cooked_mode(&el->el_tty.t_ts)) {
5303e1db26aSLionel Sambuc 			tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
5313e1db26aSLionel Sambuc 			/*
5323e1db26aSLionel Sambuc 	                 * Don't affect CMIN and CTIME for the editor mode
5333e1db26aSLionel Sambuc 	                 */
5343e1db26aSLionel Sambuc 			for (rst = 0; rst < C_NCC - 2; rst++)
5353e1db26aSLionel Sambuc 				if (el->el_tty.t_c[TS_IO][rst] !=
5363e1db26aSLionel Sambuc 				      el->el_tty.t_vdisable
5373e1db26aSLionel Sambuc 				    && el->el_tty.t_c[ED_IO][rst] !=
5383e1db26aSLionel Sambuc 				      el->el_tty.t_vdisable)
5393e1db26aSLionel Sambuc 					el->el_tty.t_c[ED_IO][rst] =
5403e1db26aSLionel Sambuc 					    el->el_tty.t_c[TS_IO][rst];
5413e1db26aSLionel Sambuc 			for (rst = 0; rst < C_NCC; rst++)
5423e1db26aSLionel Sambuc 				if (el->el_tty.t_c[TS_IO][rst] !=
5433e1db26aSLionel Sambuc 				    el->el_tty.t_vdisable)
5443e1db26aSLionel Sambuc 					el->el_tty.t_c[EX_IO][rst] =
5453e1db26aSLionel Sambuc 					    el->el_tty.t_c[TS_IO][rst];
5463e1db26aSLionel Sambuc 		}
5473e1db26aSLionel Sambuc 		tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
5483e1db26aSLionel Sambuc 		if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
5493e1db26aSLionel Sambuc #ifdef DEBUG_TTY
5503e1db26aSLionel Sambuc 			(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
5513e1db26aSLionel Sambuc 			    __func__, strerror(errno));
5523e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
5533e1db26aSLionel Sambuc 			return -1;
5543e1db26aSLionel Sambuc 		}
5553e1db26aSLionel Sambuc 	}
5563e1db26aSLionel Sambuc 
557*0a6a1f1dSLionel Sambuc 	tty_setup_flags(el, &el->el_tty.t_ed, ED_IO);
5583e1db26aSLionel Sambuc 
5593e1db26aSLionel Sambuc 	tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
5603e1db26aSLionel Sambuc 	tty_bind_char(el, 1);
5613e1db26aSLionel Sambuc 	return 0;
5623e1db26aSLionel Sambuc }
5633e1db26aSLionel Sambuc 
5643e1db26aSLionel Sambuc protected int
tty_init(EditLine * el)5653e1db26aSLionel Sambuc tty_init(EditLine *el)
5663e1db26aSLionel Sambuc {
5673e1db26aSLionel Sambuc 
5683e1db26aSLionel Sambuc 	el->el_tty.t_mode = EX_IO;
5693e1db26aSLionel Sambuc 	el->el_tty.t_vdisable = _POSIX_VDISABLE;
5703e1db26aSLionel Sambuc 	(void) memcpy(el->el_tty.t_t, ttyperm, sizeof(ttyperm_t));
5713e1db26aSLionel Sambuc 	(void) memcpy(el->el_tty.t_c, ttychar, sizeof(ttychar_t));
5723e1db26aSLionel Sambuc 	return tty_setup(el);
5733e1db26aSLionel Sambuc }
5743e1db26aSLionel Sambuc 
5753e1db26aSLionel Sambuc 
5763e1db26aSLionel Sambuc /* tty_end():
5773e1db26aSLionel Sambuc  *	Restore the tty to its original settings
5783e1db26aSLionel Sambuc  */
5793e1db26aSLionel Sambuc protected void
5803e1db26aSLionel Sambuc /*ARGSUSED*/
tty_end(EditLine * el)5813e1db26aSLionel Sambuc tty_end(EditLine *el)
5823e1db26aSLionel Sambuc {
5833e1db26aSLionel Sambuc 	if (tty_setty(el, TCSAFLUSH, &el->el_tty.t_or) == -1) {
5843e1db26aSLionel Sambuc #ifdef DEBUG_TTY
5853e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile,
5863e1db26aSLionel Sambuc 		    "%s: tty_setty: %s\n", __func__, strerror(errno));
5873e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
5883e1db26aSLionel Sambuc 	}
5893e1db26aSLionel Sambuc }
5903e1db26aSLionel Sambuc 
5913e1db26aSLionel Sambuc 
5923e1db26aSLionel Sambuc /* tty__getspeed():
5933e1db26aSLionel Sambuc  *	Get the tty speed
5943e1db26aSLionel Sambuc  */
5953e1db26aSLionel Sambuc private speed_t
tty__getspeed(struct termios * td)5963e1db26aSLionel Sambuc tty__getspeed(struct termios *td)
5973e1db26aSLionel Sambuc {
5983e1db26aSLionel Sambuc 	speed_t spd;
5993e1db26aSLionel Sambuc 
6003e1db26aSLionel Sambuc 	if ((spd = cfgetispeed(td)) == 0)
6013e1db26aSLionel Sambuc 		spd = cfgetospeed(td);
6023e1db26aSLionel Sambuc 	return spd;
6033e1db26aSLionel Sambuc }
6043e1db26aSLionel Sambuc 
6053e1db26aSLionel Sambuc /* tty__getspeed():
6063e1db26aSLionel Sambuc  *	Return the index of the asked char in the c_cc array
6073e1db26aSLionel Sambuc  */
6083e1db26aSLionel Sambuc private int
tty__getcharindex(int i)6093e1db26aSLionel Sambuc tty__getcharindex(int i)
6103e1db26aSLionel Sambuc {
6113e1db26aSLionel Sambuc 	switch (i) {
6123e1db26aSLionel Sambuc #ifdef VINTR
6133e1db26aSLionel Sambuc 	case C_INTR:
6143e1db26aSLionel Sambuc 		return VINTR;
6153e1db26aSLionel Sambuc #endif /* VINTR */
6163e1db26aSLionel Sambuc #ifdef VQUIT
6173e1db26aSLionel Sambuc 	case C_QUIT:
6183e1db26aSLionel Sambuc 		return VQUIT;
6193e1db26aSLionel Sambuc #endif /* VQUIT */
6203e1db26aSLionel Sambuc #ifdef VERASE
6213e1db26aSLionel Sambuc 	case C_ERASE:
6223e1db26aSLionel Sambuc 		return VERASE;
6233e1db26aSLionel Sambuc #endif /* VERASE */
6243e1db26aSLionel Sambuc #ifdef VKILL
6253e1db26aSLionel Sambuc 	case C_KILL:
6263e1db26aSLionel Sambuc 		return VKILL;
6273e1db26aSLionel Sambuc #endif /* VKILL */
6283e1db26aSLionel Sambuc #ifdef VEOF
6293e1db26aSLionel Sambuc 	case C_EOF:
6303e1db26aSLionel Sambuc 		return VEOF;
6313e1db26aSLionel Sambuc #endif /* VEOF */
6323e1db26aSLionel Sambuc #ifdef VEOL
6333e1db26aSLionel Sambuc 	case C_EOL:
6343e1db26aSLionel Sambuc 		return VEOL;
6353e1db26aSLionel Sambuc #endif /* VEOL */
6363e1db26aSLionel Sambuc #ifdef VEOL2
6373e1db26aSLionel Sambuc 	case C_EOL2:
6383e1db26aSLionel Sambuc 		return VEOL2;
6393e1db26aSLionel Sambuc #endif /* VEOL2 */
6403e1db26aSLionel Sambuc #ifdef VSWTCH
6413e1db26aSLionel Sambuc 	case C_SWTCH:
6423e1db26aSLionel Sambuc 		return VSWTCH;
6433e1db26aSLionel Sambuc #endif /* VSWTCH */
6443e1db26aSLionel Sambuc #ifdef VDSWTCH
6453e1db26aSLionel Sambuc 	case C_DSWTCH:
6463e1db26aSLionel Sambuc 		return VDSWTCH;
6473e1db26aSLionel Sambuc #endif /* VDSWTCH */
6483e1db26aSLionel Sambuc #ifdef VERASE2
6493e1db26aSLionel Sambuc 	case C_ERASE2:
6503e1db26aSLionel Sambuc 		return VERASE2;
6513e1db26aSLionel Sambuc #endif /* VERASE2 */
6523e1db26aSLionel Sambuc #ifdef VSTART
6533e1db26aSLionel Sambuc 	case C_START:
6543e1db26aSLionel Sambuc 		return VSTART;
6553e1db26aSLionel Sambuc #endif /* VSTART */
6563e1db26aSLionel Sambuc #ifdef VSTOP
6573e1db26aSLionel Sambuc 	case C_STOP:
6583e1db26aSLionel Sambuc 		return VSTOP;
6593e1db26aSLionel Sambuc #endif /* VSTOP */
6603e1db26aSLionel Sambuc #ifdef VWERASE
6613e1db26aSLionel Sambuc 	case C_WERASE:
6623e1db26aSLionel Sambuc 		return VWERASE;
6633e1db26aSLionel Sambuc #endif /* VWERASE */
6643e1db26aSLionel Sambuc #ifdef VSUSP
6653e1db26aSLionel Sambuc 	case C_SUSP:
6663e1db26aSLionel Sambuc 		return VSUSP;
6673e1db26aSLionel Sambuc #endif /* VSUSP */
6683e1db26aSLionel Sambuc #ifdef VDSUSP
6693e1db26aSLionel Sambuc 	case C_DSUSP:
6703e1db26aSLionel Sambuc 		return VDSUSP;
6713e1db26aSLionel Sambuc #endif /* VDSUSP */
6723e1db26aSLionel Sambuc #ifdef VREPRINT
6733e1db26aSLionel Sambuc 	case C_REPRINT:
6743e1db26aSLionel Sambuc 		return VREPRINT;
6753e1db26aSLionel Sambuc #endif /* VREPRINT */
6763e1db26aSLionel Sambuc #ifdef VDISCARD
6773e1db26aSLionel Sambuc 	case C_DISCARD:
6783e1db26aSLionel Sambuc 		return VDISCARD;
6793e1db26aSLionel Sambuc #endif /* VDISCARD */
6803e1db26aSLionel Sambuc #ifdef VLNEXT
6813e1db26aSLionel Sambuc 	case C_LNEXT:
6823e1db26aSLionel Sambuc 		return VLNEXT;
6833e1db26aSLionel Sambuc #endif /* VLNEXT */
6843e1db26aSLionel Sambuc #ifdef VSTATUS
6853e1db26aSLionel Sambuc 	case C_STATUS:
6863e1db26aSLionel Sambuc 		return VSTATUS;
6873e1db26aSLionel Sambuc #endif /* VSTATUS */
6883e1db26aSLionel Sambuc #ifdef VPAGE
6893e1db26aSLionel Sambuc 	case C_PAGE:
6903e1db26aSLionel Sambuc 		return VPAGE;
6913e1db26aSLionel Sambuc #endif /* VPAGE */
6923e1db26aSLionel Sambuc #ifdef VPGOFF
6933e1db26aSLionel Sambuc 	case C_PGOFF:
6943e1db26aSLionel Sambuc 		return VPGOFF;
6953e1db26aSLionel Sambuc #endif /* VPGOFF */
6963e1db26aSLionel Sambuc #ifdef VKILL2
6973e1db26aSLionel Sambuc 	case C_KILL2:
6983e1db26aSLionel Sambuc 		return VKILL2;
6993e1db26aSLionel Sambuc #endif /* KILL2 */
7003e1db26aSLionel Sambuc #ifdef VMIN
7013e1db26aSLionel Sambuc 	case C_MIN:
7023e1db26aSLionel Sambuc 		return VMIN;
7033e1db26aSLionel Sambuc #endif /* VMIN */
7043e1db26aSLionel Sambuc #ifdef VTIME
7053e1db26aSLionel Sambuc 	case C_TIME:
7063e1db26aSLionel Sambuc 		return VTIME;
7073e1db26aSLionel Sambuc #endif /* VTIME */
7083e1db26aSLionel Sambuc 	default:
7093e1db26aSLionel Sambuc 		return -1;
7103e1db26aSLionel Sambuc 	}
7113e1db26aSLionel Sambuc }
7123e1db26aSLionel Sambuc 
7133e1db26aSLionel Sambuc /* tty__getchar():
7143e1db26aSLionel Sambuc  *	Get the tty characters
7153e1db26aSLionel Sambuc  */
7163e1db26aSLionel Sambuc private void
tty__getchar(struct termios * td,unsigned char * s)7173e1db26aSLionel Sambuc tty__getchar(struct termios *td, unsigned char *s)
7183e1db26aSLionel Sambuc {
7193e1db26aSLionel Sambuc 
7203e1db26aSLionel Sambuc #ifdef VINTR
7213e1db26aSLionel Sambuc 	s[C_INTR] = td->c_cc[VINTR];
7223e1db26aSLionel Sambuc #endif /* VINTR */
7233e1db26aSLionel Sambuc #ifdef VQUIT
7243e1db26aSLionel Sambuc 	s[C_QUIT] = td->c_cc[VQUIT];
7253e1db26aSLionel Sambuc #endif /* VQUIT */
7263e1db26aSLionel Sambuc #ifdef VERASE
7273e1db26aSLionel Sambuc 	s[C_ERASE] = td->c_cc[VERASE];
7283e1db26aSLionel Sambuc #endif /* VERASE */
7293e1db26aSLionel Sambuc #ifdef VKILL
7303e1db26aSLionel Sambuc 	s[C_KILL] = td->c_cc[VKILL];
7313e1db26aSLionel Sambuc #endif /* VKILL */
7323e1db26aSLionel Sambuc #ifdef VEOF
7333e1db26aSLionel Sambuc 	s[C_EOF] = td->c_cc[VEOF];
7343e1db26aSLionel Sambuc #endif /* VEOF */
7353e1db26aSLionel Sambuc #ifdef VEOL
7363e1db26aSLionel Sambuc 	s[C_EOL] = td->c_cc[VEOL];
7373e1db26aSLionel Sambuc #endif /* VEOL */
7383e1db26aSLionel Sambuc #ifdef VEOL2
7393e1db26aSLionel Sambuc 	s[C_EOL2] = td->c_cc[VEOL2];
7403e1db26aSLionel Sambuc #endif /* VEOL2 */
7413e1db26aSLionel Sambuc #ifdef VSWTCH
7423e1db26aSLionel Sambuc 	s[C_SWTCH] = td->c_cc[VSWTCH];
7433e1db26aSLionel Sambuc #endif /* VSWTCH */
7443e1db26aSLionel Sambuc #ifdef VDSWTCH
7453e1db26aSLionel Sambuc 	s[C_DSWTCH] = td->c_cc[VDSWTCH];
7463e1db26aSLionel Sambuc #endif /* VDSWTCH */
7473e1db26aSLionel Sambuc #ifdef VERASE2
7483e1db26aSLionel Sambuc 	s[C_ERASE2] = td->c_cc[VERASE2];
7493e1db26aSLionel Sambuc #endif /* VERASE2 */
7503e1db26aSLionel Sambuc #ifdef VSTART
7513e1db26aSLionel Sambuc 	s[C_START] = td->c_cc[VSTART];
7523e1db26aSLionel Sambuc #endif /* VSTART */
7533e1db26aSLionel Sambuc #ifdef VSTOP
7543e1db26aSLionel Sambuc 	s[C_STOP] = td->c_cc[VSTOP];
7553e1db26aSLionel Sambuc #endif /* VSTOP */
7563e1db26aSLionel Sambuc #ifdef VWERASE
7573e1db26aSLionel Sambuc 	s[C_WERASE] = td->c_cc[VWERASE];
7583e1db26aSLionel Sambuc #endif /* VWERASE */
7593e1db26aSLionel Sambuc #ifdef VSUSP
7603e1db26aSLionel Sambuc 	s[C_SUSP] = td->c_cc[VSUSP];
7613e1db26aSLionel Sambuc #endif /* VSUSP */
7623e1db26aSLionel Sambuc #ifdef VDSUSP
7633e1db26aSLionel Sambuc 	s[C_DSUSP] = td->c_cc[VDSUSP];
7643e1db26aSLionel Sambuc #endif /* VDSUSP */
7653e1db26aSLionel Sambuc #ifdef VREPRINT
7663e1db26aSLionel Sambuc 	s[C_REPRINT] = td->c_cc[VREPRINT];
7673e1db26aSLionel Sambuc #endif /* VREPRINT */
7683e1db26aSLionel Sambuc #ifdef VDISCARD
7693e1db26aSLionel Sambuc 	s[C_DISCARD] = td->c_cc[VDISCARD];
7703e1db26aSLionel Sambuc #endif /* VDISCARD */
7713e1db26aSLionel Sambuc #ifdef VLNEXT
7723e1db26aSLionel Sambuc 	s[C_LNEXT] = td->c_cc[VLNEXT];
7733e1db26aSLionel Sambuc #endif /* VLNEXT */
7743e1db26aSLionel Sambuc #ifdef VSTATUS
7753e1db26aSLionel Sambuc 	s[C_STATUS] = td->c_cc[VSTATUS];
7763e1db26aSLionel Sambuc #endif /* VSTATUS */
7773e1db26aSLionel Sambuc #ifdef VPAGE
7783e1db26aSLionel Sambuc 	s[C_PAGE] = td->c_cc[VPAGE];
7793e1db26aSLionel Sambuc #endif /* VPAGE */
7803e1db26aSLionel Sambuc #ifdef VPGOFF
7813e1db26aSLionel Sambuc 	s[C_PGOFF] = td->c_cc[VPGOFF];
7823e1db26aSLionel Sambuc #endif /* VPGOFF */
7833e1db26aSLionel Sambuc #ifdef VKILL2
7843e1db26aSLionel Sambuc 	s[C_KILL2] = td->c_cc[VKILL2];
7853e1db26aSLionel Sambuc #endif /* KILL2 */
7863e1db26aSLionel Sambuc #ifdef VMIN
7873e1db26aSLionel Sambuc 	s[C_MIN] = td->c_cc[VMIN];
7883e1db26aSLionel Sambuc #endif /* VMIN */
7893e1db26aSLionel Sambuc #ifdef VTIME
7903e1db26aSLionel Sambuc 	s[C_TIME] = td->c_cc[VTIME];
7913e1db26aSLionel Sambuc #endif /* VTIME */
7923e1db26aSLionel Sambuc }				/* tty__getchar */
7933e1db26aSLionel Sambuc 
7943e1db26aSLionel Sambuc 
7953e1db26aSLionel Sambuc /* tty__setchar():
7963e1db26aSLionel Sambuc  *	Set the tty characters
7973e1db26aSLionel Sambuc  */
7983e1db26aSLionel Sambuc private void
tty__setchar(struct termios * td,unsigned char * s)7993e1db26aSLionel Sambuc tty__setchar(struct termios *td, unsigned char *s)
8003e1db26aSLionel Sambuc {
8013e1db26aSLionel Sambuc 
8023e1db26aSLionel Sambuc #ifdef VINTR
8033e1db26aSLionel Sambuc 	td->c_cc[VINTR] = s[C_INTR];
8043e1db26aSLionel Sambuc #endif /* VINTR */
8053e1db26aSLionel Sambuc #ifdef VQUIT
8063e1db26aSLionel Sambuc 	td->c_cc[VQUIT] = s[C_QUIT];
8073e1db26aSLionel Sambuc #endif /* VQUIT */
8083e1db26aSLionel Sambuc #ifdef VERASE
8093e1db26aSLionel Sambuc 	td->c_cc[VERASE] = s[C_ERASE];
8103e1db26aSLionel Sambuc #endif /* VERASE */
8113e1db26aSLionel Sambuc #ifdef VKILL
8123e1db26aSLionel Sambuc 	td->c_cc[VKILL] = s[C_KILL];
8133e1db26aSLionel Sambuc #endif /* VKILL */
8143e1db26aSLionel Sambuc #ifdef VEOF
8153e1db26aSLionel Sambuc 	td->c_cc[VEOF] = s[C_EOF];
8163e1db26aSLionel Sambuc #endif /* VEOF */
8173e1db26aSLionel Sambuc #ifdef VEOL
8183e1db26aSLionel Sambuc 	td->c_cc[VEOL] = s[C_EOL];
8193e1db26aSLionel Sambuc #endif /* VEOL */
8203e1db26aSLionel Sambuc #ifdef VEOL2
8213e1db26aSLionel Sambuc 	td->c_cc[VEOL2] = s[C_EOL2];
8223e1db26aSLionel Sambuc #endif /* VEOL2 */
8233e1db26aSLionel Sambuc #ifdef VSWTCH
8243e1db26aSLionel Sambuc 	td->c_cc[VSWTCH] = s[C_SWTCH];
8253e1db26aSLionel Sambuc #endif /* VSWTCH */
8263e1db26aSLionel Sambuc #ifdef VDSWTCH
8273e1db26aSLionel Sambuc 	td->c_cc[VDSWTCH] = s[C_DSWTCH];
8283e1db26aSLionel Sambuc #endif /* VDSWTCH */
8293e1db26aSLionel Sambuc #ifdef VERASE2
8303e1db26aSLionel Sambuc 	td->c_cc[VERASE2] = s[C_ERASE2];
8313e1db26aSLionel Sambuc #endif /* VERASE2 */
8323e1db26aSLionel Sambuc #ifdef VSTART
8333e1db26aSLionel Sambuc 	td->c_cc[VSTART] = s[C_START];
8343e1db26aSLionel Sambuc #endif /* VSTART */
8353e1db26aSLionel Sambuc #ifdef VSTOP
8363e1db26aSLionel Sambuc 	td->c_cc[VSTOP] = s[C_STOP];
8373e1db26aSLionel Sambuc #endif /* VSTOP */
8383e1db26aSLionel Sambuc #ifdef VWERASE
8393e1db26aSLionel Sambuc 	td->c_cc[VWERASE] = s[C_WERASE];
8403e1db26aSLionel Sambuc #endif /* VWERASE */
8413e1db26aSLionel Sambuc #ifdef VSUSP
8423e1db26aSLionel Sambuc 	td->c_cc[VSUSP] = s[C_SUSP];
8433e1db26aSLionel Sambuc #endif /* VSUSP */
8443e1db26aSLionel Sambuc #ifdef VDSUSP
8453e1db26aSLionel Sambuc 	td->c_cc[VDSUSP] = s[C_DSUSP];
8463e1db26aSLionel Sambuc #endif /* VDSUSP */
8473e1db26aSLionel Sambuc #ifdef VREPRINT
8483e1db26aSLionel Sambuc 	td->c_cc[VREPRINT] = s[C_REPRINT];
8493e1db26aSLionel Sambuc #endif /* VREPRINT */
8503e1db26aSLionel Sambuc #ifdef VDISCARD
8513e1db26aSLionel Sambuc 	td->c_cc[VDISCARD] = s[C_DISCARD];
8523e1db26aSLionel Sambuc #endif /* VDISCARD */
8533e1db26aSLionel Sambuc #ifdef VLNEXT
8543e1db26aSLionel Sambuc 	td->c_cc[VLNEXT] = s[C_LNEXT];
8553e1db26aSLionel Sambuc #endif /* VLNEXT */
8563e1db26aSLionel Sambuc #ifdef VSTATUS
8573e1db26aSLionel Sambuc 	td->c_cc[VSTATUS] = s[C_STATUS];
8583e1db26aSLionel Sambuc #endif /* VSTATUS */
8593e1db26aSLionel Sambuc #ifdef VPAGE
8603e1db26aSLionel Sambuc 	td->c_cc[VPAGE] = s[C_PAGE];
8613e1db26aSLionel Sambuc #endif /* VPAGE */
8623e1db26aSLionel Sambuc #ifdef VPGOFF
8633e1db26aSLionel Sambuc 	td->c_cc[VPGOFF] = s[C_PGOFF];
8643e1db26aSLionel Sambuc #endif /* VPGOFF */
8653e1db26aSLionel Sambuc #ifdef VKILL2
8663e1db26aSLionel Sambuc 	td->c_cc[VKILL2] = s[C_KILL2];
8673e1db26aSLionel Sambuc #endif /* VKILL2 */
8683e1db26aSLionel Sambuc #ifdef VMIN
8693e1db26aSLionel Sambuc 	td->c_cc[VMIN] = s[C_MIN];
8703e1db26aSLionel Sambuc #endif /* VMIN */
8713e1db26aSLionel Sambuc #ifdef VTIME
8723e1db26aSLionel Sambuc 	td->c_cc[VTIME] = s[C_TIME];
8733e1db26aSLionel Sambuc #endif /* VTIME */
8743e1db26aSLionel Sambuc }				/* tty__setchar */
8753e1db26aSLionel Sambuc 
8763e1db26aSLionel Sambuc 
8773e1db26aSLionel Sambuc /* tty_bind_char():
8783e1db26aSLionel Sambuc  *	Rebind the editline functions
8793e1db26aSLionel Sambuc  */
8803e1db26aSLionel Sambuc protected void
tty_bind_char(EditLine * el,int force)8813e1db26aSLionel Sambuc tty_bind_char(EditLine *el, int force)
8823e1db26aSLionel Sambuc {
8833e1db26aSLionel Sambuc 
8843e1db26aSLionel Sambuc 	unsigned char *t_n = el->el_tty.t_c[ED_IO];
8853e1db26aSLionel Sambuc 	unsigned char *t_o = el->el_tty.t_ed.c_cc;
8863e1db26aSLionel Sambuc 	Char new[2], old[2];
8873e1db26aSLionel Sambuc 	const ttymap_t *tp;
8883e1db26aSLionel Sambuc 	el_action_t *map, *alt;
8893e1db26aSLionel Sambuc 	const el_action_t *dmap, *dalt;
8903e1db26aSLionel Sambuc 	new[1] = old[1] = '\0';
8913e1db26aSLionel Sambuc 
8923e1db26aSLionel Sambuc 	map = el->el_map.key;
8933e1db26aSLionel Sambuc 	alt = el->el_map.alt;
8943e1db26aSLionel Sambuc 	if (el->el_map.type == MAP_VI) {
8953e1db26aSLionel Sambuc 		dmap = el->el_map.vii;
8963e1db26aSLionel Sambuc 		dalt = el->el_map.vic;
8973e1db26aSLionel Sambuc 	} else {
8983e1db26aSLionel Sambuc 		dmap = el->el_map.emacs;
8993e1db26aSLionel Sambuc 		dalt = NULL;
9003e1db26aSLionel Sambuc 	}
9013e1db26aSLionel Sambuc 
9023e1db26aSLionel Sambuc 	for (tp = tty_map; tp->nch != (Int)-1; tp++) {
9033e1db26aSLionel Sambuc 		new[0] = t_n[tp->nch];
9043e1db26aSLionel Sambuc 		old[0] = t_o[tp->och];
9053e1db26aSLionel Sambuc 		if (new[0] == old[0] && !force)
9063e1db26aSLionel Sambuc 			continue;
9073e1db26aSLionel Sambuc 		/* Put the old default binding back, and set the new binding */
9083e1db26aSLionel Sambuc 		keymacro_clear(el, map, old);
9093e1db26aSLionel Sambuc 		map[UC(old[0])] = dmap[UC(old[0])];
9103e1db26aSLionel Sambuc 		keymacro_clear(el, map, new);
9113e1db26aSLionel Sambuc 		/* MAP_VI == 1, MAP_EMACS == 0... */
9123e1db26aSLionel Sambuc 		map[UC(new[0])] = tp->bind[el->el_map.type];
9133e1db26aSLionel Sambuc 		if (dalt) {
9143e1db26aSLionel Sambuc 			keymacro_clear(el, alt, old);
9153e1db26aSLionel Sambuc 			alt[UC(old[0])] = dalt[UC(old[0])];
9163e1db26aSLionel Sambuc 			keymacro_clear(el, alt, new);
9173e1db26aSLionel Sambuc 			alt[UC(new[0])] = tp->bind[el->el_map.type + 1];
9183e1db26aSLionel Sambuc 		}
9193e1db26aSLionel Sambuc 	}
9203e1db26aSLionel Sambuc }
9213e1db26aSLionel Sambuc 
9223e1db26aSLionel Sambuc 
923*0a6a1f1dSLionel Sambuc private tcflag_t *
tty__get_flag(struct termios * t,int kind)924*0a6a1f1dSLionel Sambuc tty__get_flag(struct termios *t, int kind) {
925*0a6a1f1dSLionel Sambuc 	switch (kind) {
926*0a6a1f1dSLionel Sambuc 	case MD_INP:
927*0a6a1f1dSLionel Sambuc 		return &t->c_iflag;
928*0a6a1f1dSLionel Sambuc 	case MD_OUT:
929*0a6a1f1dSLionel Sambuc 		return &t->c_oflag;
930*0a6a1f1dSLionel Sambuc 	case MD_CTL:
931*0a6a1f1dSLionel Sambuc 		return &t->c_cflag;
932*0a6a1f1dSLionel Sambuc 	case MD_LIN:
933*0a6a1f1dSLionel Sambuc 		return &t->c_lflag;
934*0a6a1f1dSLionel Sambuc 	default:
935*0a6a1f1dSLionel Sambuc 		abort();
936*0a6a1f1dSLionel Sambuc 		/*NOTREACHED*/
937*0a6a1f1dSLionel Sambuc 	}
938*0a6a1f1dSLionel Sambuc }
939*0a6a1f1dSLionel Sambuc 
940*0a6a1f1dSLionel Sambuc 
941*0a6a1f1dSLionel Sambuc private tcflag_t
tty_update_flag(EditLine * el,tcflag_t f,int mode,int kind)942*0a6a1f1dSLionel Sambuc tty_update_flag(EditLine *el, tcflag_t f, int mode, int kind)
943*0a6a1f1dSLionel Sambuc {
944*0a6a1f1dSLionel Sambuc 	f &= ~el->el_tty.t_t[mode][kind].t_clrmask;
945*0a6a1f1dSLionel Sambuc 	f |= el->el_tty.t_t[mode][kind].t_setmask;
946*0a6a1f1dSLionel Sambuc 	return f;
947*0a6a1f1dSLionel Sambuc }
948*0a6a1f1dSLionel Sambuc 
949*0a6a1f1dSLionel Sambuc 
950*0a6a1f1dSLionel Sambuc private void
tty_update_flags(EditLine * el,int kind)951*0a6a1f1dSLionel Sambuc tty_update_flags(EditLine *el, int kind)
952*0a6a1f1dSLionel Sambuc {
953*0a6a1f1dSLionel Sambuc 	tcflag_t *tt, *ed, *ex;
954*0a6a1f1dSLionel Sambuc 	tt = tty__get_flag(&el->el_tty.t_ts, kind);
955*0a6a1f1dSLionel Sambuc 	ed = tty__get_flag(&el->el_tty.t_ed, kind);
956*0a6a1f1dSLionel Sambuc 	ex = tty__get_flag(&el->el_tty.t_ex, kind);
957*0a6a1f1dSLionel Sambuc 
958*0a6a1f1dSLionel Sambuc 	if (*tt != *ex && (kind != MD_CTL || *tt != *ed)) {
959*0a6a1f1dSLionel Sambuc 		*ed = tty_update_flag(el, *tt, ED_IO, kind);
960*0a6a1f1dSLionel Sambuc 		*ex = tty_update_flag(el, *tt, EX_IO, kind);
961*0a6a1f1dSLionel Sambuc 	}
962*0a6a1f1dSLionel Sambuc }
963*0a6a1f1dSLionel Sambuc 
964*0a6a1f1dSLionel Sambuc 
965*0a6a1f1dSLionel Sambuc private void
tty_update_char(EditLine * el,int mode,int c)966*0a6a1f1dSLionel Sambuc tty_update_char(EditLine *el, int mode, int c) {
967*0a6a1f1dSLionel Sambuc 	if (!((el->el_tty.t_t[mode][MD_CHAR].t_setmask & C_SH(c)))
968*0a6a1f1dSLionel Sambuc 	    && (el->el_tty.t_c[TS_IO][c] != el->el_tty.t_c[EX_IO][c]))
969*0a6a1f1dSLionel Sambuc 		el->el_tty.t_c[mode][c] = el->el_tty.t_c[TS_IO][c];
970*0a6a1f1dSLionel Sambuc 	if (el->el_tty.t_t[mode][MD_CHAR].t_clrmask & C_SH(c))
971*0a6a1f1dSLionel Sambuc 		el->el_tty.t_c[mode][c] = el->el_tty.t_vdisable;
972*0a6a1f1dSLionel Sambuc }
973*0a6a1f1dSLionel Sambuc 
974*0a6a1f1dSLionel Sambuc 
9753e1db26aSLionel Sambuc /* tty_rawmode():
9763e1db26aSLionel Sambuc  * 	Set terminal into 1 character at a time mode.
9773e1db26aSLionel Sambuc  */
9783e1db26aSLionel Sambuc protected int
tty_rawmode(EditLine * el)9793e1db26aSLionel Sambuc tty_rawmode(EditLine *el)
9803e1db26aSLionel Sambuc {
9813e1db26aSLionel Sambuc 
9823e1db26aSLionel Sambuc 	if (el->el_tty.t_mode == ED_IO || el->el_tty.t_mode == QU_IO)
9833e1db26aSLionel Sambuc 		return 0;
9843e1db26aSLionel Sambuc 
9853e1db26aSLionel Sambuc 	if (el->el_flags & EDIT_DISABLED)
9863e1db26aSLionel Sambuc 		return 0;
9873e1db26aSLionel Sambuc 
9883e1db26aSLionel Sambuc 	if (tty_getty(el, &el->el_tty.t_ts) == -1) {
9893e1db26aSLionel Sambuc #ifdef DEBUG_TTY
9903e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: tty_getty: %s\n", __func__,
9913e1db26aSLionel Sambuc 		    strerror(errno));
9923e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
9933e1db26aSLionel Sambuc 		return -1;
9943e1db26aSLionel Sambuc 	}
9953e1db26aSLionel Sambuc 	/*
9963e1db26aSLionel Sambuc          * We always keep up with the eight bit setting and the speed of the
9973e1db26aSLionel Sambuc          * tty. But we only believe changes that are made to cooked mode!
9983e1db26aSLionel Sambuc          */
9993e1db26aSLionel Sambuc 	el->el_tty.t_eight = tty__geteightbit(&el->el_tty.t_ts);
10003e1db26aSLionel Sambuc 	el->el_tty.t_speed = tty__getspeed(&el->el_tty.t_ts);
10013e1db26aSLionel Sambuc 
10023e1db26aSLionel Sambuc 	if (tty__getspeed(&el->el_tty.t_ex) != el->el_tty.t_speed ||
10033e1db26aSLionel Sambuc 	    tty__getspeed(&el->el_tty.t_ed) != el->el_tty.t_speed) {
10043e1db26aSLionel Sambuc 		(void) cfsetispeed(&el->el_tty.t_ex, el->el_tty.t_speed);
10053e1db26aSLionel Sambuc 		(void) cfsetospeed(&el->el_tty.t_ex, el->el_tty.t_speed);
10063e1db26aSLionel Sambuc 		(void) cfsetispeed(&el->el_tty.t_ed, el->el_tty.t_speed);
10073e1db26aSLionel Sambuc 		(void) cfsetospeed(&el->el_tty.t_ed, el->el_tty.t_speed);
10083e1db26aSLionel Sambuc 	}
10093e1db26aSLionel Sambuc 	if (tty__cooked_mode(&el->el_tty.t_ts)) {
1010*0a6a1f1dSLionel Sambuc 		int i;
10113e1db26aSLionel Sambuc 
1012*0a6a1f1dSLionel Sambuc 		for (i = MD_INP; i <= MD_LIN; i++)
1013*0a6a1f1dSLionel Sambuc 			tty_update_flags(el, i);
10143e1db26aSLionel Sambuc 
10153e1db26aSLionel Sambuc 		if (tty__gettabs(&el->el_tty.t_ex) == 0)
10163e1db26aSLionel Sambuc 			el->el_tty.t_tabs = 0;
10173e1db26aSLionel Sambuc 		else
10183e1db26aSLionel Sambuc 			el->el_tty.t_tabs = EL_CAN_TAB ? 1 : 0;
10193e1db26aSLionel Sambuc 
10203e1db26aSLionel Sambuc 		tty__getchar(&el->el_tty.t_ts, el->el_tty.t_c[TS_IO]);
10213e1db26aSLionel Sambuc 		/*
10223e1db26aSLionel Sambuc 		 * Check if the user made any changes.
10233e1db26aSLionel Sambuc 		 * If he did, then propagate the changes to the
10243e1db26aSLionel Sambuc 		 * edit and execute data structures.
10253e1db26aSLionel Sambuc 		 */
10263e1db26aSLionel Sambuc 		for (i = 0; i < C_NCC; i++)
10273e1db26aSLionel Sambuc 			if (el->el_tty.t_c[TS_IO][i] !=
10283e1db26aSLionel Sambuc 			    el->el_tty.t_c[EX_IO][i])
10293e1db26aSLionel Sambuc 				break;
10303e1db26aSLionel Sambuc 
10313e1db26aSLionel Sambuc 		if (i != C_NCC) {
10323e1db26aSLionel Sambuc 			/*
10333e1db26aSLionel Sambuc 			 * Propagate changes only to the unprotected
10343e1db26aSLionel Sambuc 			 * chars that have been modified just now.
10353e1db26aSLionel Sambuc 			 */
1036*0a6a1f1dSLionel Sambuc 			for (i = 0; i < C_NCC; i++)
1037*0a6a1f1dSLionel Sambuc 				tty_update_char(el, ED_IO, i);
1038*0a6a1f1dSLionel Sambuc 
10393e1db26aSLionel Sambuc 			tty_bind_char(el, 0);
10403e1db26aSLionel Sambuc 			tty__setchar(&el->el_tty.t_ed, el->el_tty.t_c[ED_IO]);
10413e1db26aSLionel Sambuc 
1042*0a6a1f1dSLionel Sambuc 			for (i = 0; i < C_NCC; i++)
1043*0a6a1f1dSLionel Sambuc 				tty_update_char(el, EX_IO, i);
1044*0a6a1f1dSLionel Sambuc 
10453e1db26aSLionel Sambuc 			tty__setchar(&el->el_tty.t_ex, el->el_tty.t_c[EX_IO]);
10463e1db26aSLionel Sambuc 		}
10473e1db26aSLionel Sambuc 	}
10483e1db26aSLionel Sambuc 	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
10493e1db26aSLionel Sambuc #ifdef DEBUG_TTY
10503e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
10513e1db26aSLionel Sambuc 		    strerror(errno));
10523e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
10533e1db26aSLionel Sambuc 		return -1;
10543e1db26aSLionel Sambuc 	}
10553e1db26aSLionel Sambuc 	el->el_tty.t_mode = ED_IO;
10563e1db26aSLionel Sambuc 	return 0;
10573e1db26aSLionel Sambuc }
10583e1db26aSLionel Sambuc 
10593e1db26aSLionel Sambuc 
10603e1db26aSLionel Sambuc /* tty_cookedmode():
10613e1db26aSLionel Sambuc  *	Set the tty back to normal mode
10623e1db26aSLionel Sambuc  */
10633e1db26aSLionel Sambuc protected int
tty_cookedmode(EditLine * el)10643e1db26aSLionel Sambuc tty_cookedmode(EditLine *el)
10653e1db26aSLionel Sambuc {				/* set tty in normal setup */
10663e1db26aSLionel Sambuc 
10673e1db26aSLionel Sambuc 	if (el->el_tty.t_mode == EX_IO)
10683e1db26aSLionel Sambuc 		return 0;
10693e1db26aSLionel Sambuc 
10703e1db26aSLionel Sambuc 	if (el->el_flags & EDIT_DISABLED)
10713e1db26aSLionel Sambuc 		return 0;
10723e1db26aSLionel Sambuc 
10733e1db26aSLionel Sambuc 	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ex) == -1) {
10743e1db26aSLionel Sambuc #ifdef DEBUG_TTY
10753e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
10763e1db26aSLionel Sambuc 		    strerror(errno));
10773e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
10783e1db26aSLionel Sambuc 		return -1;
10793e1db26aSLionel Sambuc 	}
10803e1db26aSLionel Sambuc 	el->el_tty.t_mode = EX_IO;
10813e1db26aSLionel Sambuc 	return 0;
10823e1db26aSLionel Sambuc }
10833e1db26aSLionel Sambuc 
10843e1db26aSLionel Sambuc 
10853e1db26aSLionel Sambuc /* tty_quotemode():
10863e1db26aSLionel Sambuc  *	Turn on quote mode
10873e1db26aSLionel Sambuc  */
10883e1db26aSLionel Sambuc protected int
tty_quotemode(EditLine * el)10893e1db26aSLionel Sambuc tty_quotemode(EditLine *el)
10903e1db26aSLionel Sambuc {
10913e1db26aSLionel Sambuc 	if (el->el_tty.t_mode == QU_IO)
10923e1db26aSLionel Sambuc 		return 0;
10933e1db26aSLionel Sambuc 
10943e1db26aSLionel Sambuc 	el->el_tty.t_qu = el->el_tty.t_ed;
10953e1db26aSLionel Sambuc 
1096*0a6a1f1dSLionel Sambuc 	tty_setup_flags(el, &el->el_tty.t_qu, QU_IO);
10973e1db26aSLionel Sambuc 
10983e1db26aSLionel Sambuc 	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_qu) == -1) {
10993e1db26aSLionel Sambuc #ifdef DEBUG_TTY
11003e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
11013e1db26aSLionel Sambuc 		    strerror(errno));
11023e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
11033e1db26aSLionel Sambuc 		return -1;
11043e1db26aSLionel Sambuc 	}
11053e1db26aSLionel Sambuc 	el->el_tty.t_mode = QU_IO;
11063e1db26aSLionel Sambuc 	return 0;
11073e1db26aSLionel Sambuc }
11083e1db26aSLionel Sambuc 
11093e1db26aSLionel Sambuc 
11103e1db26aSLionel Sambuc /* tty_noquotemode():
11113e1db26aSLionel Sambuc  *	Turn off quote mode
11123e1db26aSLionel Sambuc  */
11133e1db26aSLionel Sambuc protected int
tty_noquotemode(EditLine * el)11143e1db26aSLionel Sambuc tty_noquotemode(EditLine *el)
11153e1db26aSLionel Sambuc {
11163e1db26aSLionel Sambuc 
11173e1db26aSLionel Sambuc 	if (el->el_tty.t_mode != QU_IO)
11183e1db26aSLionel Sambuc 		return 0;
11193e1db26aSLionel Sambuc 	if (tty_setty(el, TCSADRAIN, &el->el_tty.t_ed) == -1) {
11203e1db26aSLionel Sambuc #ifdef DEBUG_TTY
11213e1db26aSLionel Sambuc 		(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n", __func__,
11223e1db26aSLionel Sambuc 		    strerror(errno));
11233e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
11243e1db26aSLionel Sambuc 		return -1;
11253e1db26aSLionel Sambuc 	}
11263e1db26aSLionel Sambuc 	el->el_tty.t_mode = ED_IO;
11273e1db26aSLionel Sambuc 	return 0;
11283e1db26aSLionel Sambuc }
11293e1db26aSLionel Sambuc 
11303e1db26aSLionel Sambuc 
11313e1db26aSLionel Sambuc /* tty_stty():
11323e1db26aSLionel Sambuc  *	Stty builtin
11333e1db26aSLionel Sambuc  */
11343e1db26aSLionel Sambuc protected int
11353e1db26aSLionel Sambuc /*ARGSUSED*/
tty_stty(EditLine * el,int argc,const Char ** argv)11363e1db26aSLionel Sambuc tty_stty(EditLine *el, int argc __attribute__((__unused__)), const Char **argv)
11373e1db26aSLionel Sambuc {
11383e1db26aSLionel Sambuc 	const ttymodes_t *m;
11393e1db26aSLionel Sambuc 	char x;
11403e1db26aSLionel Sambuc 	int aflag = 0;
11413e1db26aSLionel Sambuc 	const Char *s, *d;
11423e1db26aSLionel Sambuc         char name[EL_BUFSIZ];
11433e1db26aSLionel Sambuc 	struct termios *tios = &el->el_tty.t_ex;
11443e1db26aSLionel Sambuc 	int z = EX_IO;
11453e1db26aSLionel Sambuc 
11463e1db26aSLionel Sambuc 	if (argv == NULL)
11473e1db26aSLionel Sambuc 		return -1;
11483e1db26aSLionel Sambuc 	strncpy(name, ct_encode_string(*argv++, &el->el_scratch), sizeof(name));
11493e1db26aSLionel Sambuc         name[sizeof(name) - 1] = '\0';
11503e1db26aSLionel Sambuc 
11513e1db26aSLionel Sambuc 	while (argv && *argv && argv[0][0] == '-' && argv[0][2] == '\0')
11523e1db26aSLionel Sambuc 		switch (argv[0][1]) {
11533e1db26aSLionel Sambuc 		case 'a':
11543e1db26aSLionel Sambuc 			aflag++;
11553e1db26aSLionel Sambuc 			argv++;
11563e1db26aSLionel Sambuc 			break;
11573e1db26aSLionel Sambuc 		case 'd':
11583e1db26aSLionel Sambuc 			argv++;
11593e1db26aSLionel Sambuc 			tios = &el->el_tty.t_ed;
11603e1db26aSLionel Sambuc 			z = ED_IO;
11613e1db26aSLionel Sambuc 			break;
11623e1db26aSLionel Sambuc 		case 'x':
11633e1db26aSLionel Sambuc 			argv++;
11643e1db26aSLionel Sambuc 			tios = &el->el_tty.t_ex;
11653e1db26aSLionel Sambuc 			z = EX_IO;
11663e1db26aSLionel Sambuc 			break;
11673e1db26aSLionel Sambuc 		case 'q':
11683e1db26aSLionel Sambuc 			argv++;
11693e1db26aSLionel Sambuc 			tios = &el->el_tty.t_ts;
11703e1db26aSLionel Sambuc 			z = QU_IO;
11713e1db26aSLionel Sambuc 			break;
11723e1db26aSLionel Sambuc 		default:
11733e1db26aSLionel Sambuc 			(void) fprintf(el->el_errfile,
1174*0a6a1f1dSLionel Sambuc 			    "%s: Unknown switch `" FCHAR "'.\n",
1175*0a6a1f1dSLionel Sambuc 			    name, (Int)argv[0][1]);
11763e1db26aSLionel Sambuc 			return -1;
11773e1db26aSLionel Sambuc 		}
11783e1db26aSLionel Sambuc 
11793e1db26aSLionel Sambuc 	if (!argv || !*argv) {
11803e1db26aSLionel Sambuc 		int i = -1;
11813e1db26aSLionel Sambuc 		size_t len = 0, st = 0, cu;
11823e1db26aSLionel Sambuc 		for (m = ttymodes; m->m_name; m++) {
11833e1db26aSLionel Sambuc 			if (m->m_type != i) {
11843e1db26aSLionel Sambuc 				(void) fprintf(el->el_outfile, "%s%s",
11853e1db26aSLionel Sambuc 				    i != -1 ? "\n" : "",
11863e1db26aSLionel Sambuc 				    el->el_tty.t_t[z][m->m_type].t_name);
11873e1db26aSLionel Sambuc 				i = m->m_type;
11883e1db26aSLionel Sambuc 				st = len =
11893e1db26aSLionel Sambuc 				    strlen(el->el_tty.t_t[z][m->m_type].t_name);
11903e1db26aSLionel Sambuc 			}
11913e1db26aSLionel Sambuc 			if (i != -1) {
11923e1db26aSLionel Sambuc 			    x = (el->el_tty.t_t[z][i].t_setmask & m->m_value)
11933e1db26aSLionel Sambuc 				?  '+' : '\0';
11943e1db26aSLionel Sambuc 
11953e1db26aSLionel Sambuc 			    if (el->el_tty.t_t[z][i].t_clrmask & m->m_value)
11963e1db26aSLionel Sambuc 				x = '-';
11973e1db26aSLionel Sambuc 			} else {
11983e1db26aSLionel Sambuc 			    x = '\0';
11993e1db26aSLionel Sambuc 			}
12003e1db26aSLionel Sambuc 
12013e1db26aSLionel Sambuc 			if (x != '\0' || aflag) {
12023e1db26aSLionel Sambuc 
12033e1db26aSLionel Sambuc 				cu = strlen(m->m_name) + (x != '\0') + 1;
12043e1db26aSLionel Sambuc 
12053e1db26aSLionel Sambuc 				if (len + cu >=
12063e1db26aSLionel Sambuc 				    (size_t)el->el_terminal.t_size.h) {
12073e1db26aSLionel Sambuc 					(void) fprintf(el->el_outfile, "\n%*s",
12083e1db26aSLionel Sambuc 					    (int)st, "");
12093e1db26aSLionel Sambuc 					len = st + cu;
12103e1db26aSLionel Sambuc 				} else
12113e1db26aSLionel Sambuc 					len += cu;
12123e1db26aSLionel Sambuc 
12133e1db26aSLionel Sambuc 				if (x != '\0')
12143e1db26aSLionel Sambuc 					(void) fprintf(el->el_outfile, "%c%s ",
12153e1db26aSLionel Sambuc 					    x, m->m_name);
12163e1db26aSLionel Sambuc 				else
12173e1db26aSLionel Sambuc 					(void) fprintf(el->el_outfile, "%s ",
12183e1db26aSLionel Sambuc 					    m->m_name);
12193e1db26aSLionel Sambuc 			}
12203e1db26aSLionel Sambuc 		}
12213e1db26aSLionel Sambuc 		(void) fprintf(el->el_outfile, "\n");
12223e1db26aSLionel Sambuc 		return 0;
12233e1db26aSLionel Sambuc 	}
12243e1db26aSLionel Sambuc 	while (argv && (s = *argv++)) {
12253e1db26aSLionel Sambuc 		const Char *p;
12263e1db26aSLionel Sambuc 		switch (*s) {
12273e1db26aSLionel Sambuc 		case '+':
12283e1db26aSLionel Sambuc 		case '-':
12293e1db26aSLionel Sambuc 			x = (char)*s++;
12303e1db26aSLionel Sambuc 			break;
12313e1db26aSLionel Sambuc 		default:
12323e1db26aSLionel Sambuc 			x = '\0';
12333e1db26aSLionel Sambuc 			break;
12343e1db26aSLionel Sambuc 		}
12353e1db26aSLionel Sambuc 		d = s;
12363e1db26aSLionel Sambuc 		p = Strchr(s, '=');
12373e1db26aSLionel Sambuc 		for (m = ttymodes; m->m_name; m++)
12383e1db26aSLionel Sambuc 			if ((p ? strncmp(m->m_name, ct_encode_string(d,
12393e1db26aSLionel Sambuc 			    &el->el_scratch), (size_t)(p - d)) :
12403e1db26aSLionel Sambuc 			    strcmp(m->m_name, ct_encode_string(d,
12413e1db26aSLionel Sambuc 			    &el->el_scratch))) == 0 &&
12423e1db26aSLionel Sambuc 			    (p == NULL || m->m_type == MD_CHAR))
12433e1db26aSLionel Sambuc 				break;
12443e1db26aSLionel Sambuc 
12453e1db26aSLionel Sambuc 		if (!m->m_name) {
12463e1db26aSLionel Sambuc 			(void) fprintf(el->el_errfile,
12473e1db26aSLionel Sambuc 			    "%s: Invalid argument `" FSTR "'.\n", name, d);
12483e1db26aSLionel Sambuc 			return -1;
12493e1db26aSLionel Sambuc 		}
12503e1db26aSLionel Sambuc 		if (p) {
12513e1db26aSLionel Sambuc 			int c = ffs((int)m->m_value);
12523e1db26aSLionel Sambuc 			int v = *++p ? parse__escape(&p) :
12533e1db26aSLionel Sambuc 			    el->el_tty.t_vdisable;
12543e1db26aSLionel Sambuc 			assert(c != 0);
12553e1db26aSLionel Sambuc 			c--;
12563e1db26aSLionel Sambuc 			c = tty__getcharindex(c);
12573e1db26aSLionel Sambuc 			assert(c != -1);
12583e1db26aSLionel Sambuc 			tios->c_cc[c] = (cc_t)v;
12593e1db26aSLionel Sambuc 			continue;
12603e1db26aSLionel Sambuc 		}
12613e1db26aSLionel Sambuc 		switch (x) {
12623e1db26aSLionel Sambuc 		case '+':
12633e1db26aSLionel Sambuc 			el->el_tty.t_t[z][m->m_type].t_setmask |= m->m_value;
12643e1db26aSLionel Sambuc 			el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
12653e1db26aSLionel Sambuc 			break;
12663e1db26aSLionel Sambuc 		case '-':
12673e1db26aSLionel Sambuc 			el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
12683e1db26aSLionel Sambuc 			el->el_tty.t_t[z][m->m_type].t_clrmask |= m->m_value;
12693e1db26aSLionel Sambuc 			break;
12703e1db26aSLionel Sambuc 		default:
12713e1db26aSLionel Sambuc 			el->el_tty.t_t[z][m->m_type].t_setmask &= ~m->m_value;
12723e1db26aSLionel Sambuc 			el->el_tty.t_t[z][m->m_type].t_clrmask &= ~m->m_value;
12733e1db26aSLionel Sambuc 			break;
12743e1db26aSLionel Sambuc 		}
12753e1db26aSLionel Sambuc 	}
12763e1db26aSLionel Sambuc 
1277*0a6a1f1dSLionel Sambuc 	tty_setup_flags(el, tios, z);
12783e1db26aSLionel Sambuc 	if (el->el_tty.t_mode == z) {
12793e1db26aSLionel Sambuc 		if (tty_setty(el, TCSADRAIN, tios) == -1) {
12803e1db26aSLionel Sambuc #ifdef DEBUG_TTY
12813e1db26aSLionel Sambuc 			(void) fprintf(el->el_errfile, "%s: tty_setty: %s\n",
12823e1db26aSLionel Sambuc 			    __func__, strerror(errno));
12833e1db26aSLionel Sambuc #endif /* DEBUG_TTY */
12843e1db26aSLionel Sambuc 			return -1;
12853e1db26aSLionel Sambuc 		}
12863e1db26aSLionel Sambuc 	}
12873e1db26aSLionel Sambuc 
12883e1db26aSLionel Sambuc 	return 0;
12893e1db26aSLionel Sambuc }
12903e1db26aSLionel Sambuc 
12913e1db26aSLionel Sambuc 
12923e1db26aSLionel Sambuc #ifdef notyet
12933e1db26aSLionel Sambuc /* tty_printchar():
12943e1db26aSLionel Sambuc  *	DEbugging routine to print the tty characters
12953e1db26aSLionel Sambuc  */
12963e1db26aSLionel Sambuc private void
tty_printchar(EditLine * el,unsigned char * s)12973e1db26aSLionel Sambuc tty_printchar(EditLine *el, unsigned char *s)
12983e1db26aSLionel Sambuc {
12993e1db26aSLionel Sambuc 	ttyperm_t *m;
13003e1db26aSLionel Sambuc 	int i;
13013e1db26aSLionel Sambuc 
13023e1db26aSLionel Sambuc 	for (i = 0; i < C_NCC; i++) {
13033e1db26aSLionel Sambuc 		for (m = el->el_tty.t_t; m->m_name; m++)
13043e1db26aSLionel Sambuc 			if (m->m_type == MD_CHAR && C_SH(i) == m->m_value)
13053e1db26aSLionel Sambuc 				break;
13063e1db26aSLionel Sambuc 		if (m->m_name)
13073e1db26aSLionel Sambuc 			(void) fprintf(el->el_errfile, "%s ^%c ",
13083e1db26aSLionel Sambuc 			    m->m_name, s[i] + 'A' - 1);
13093e1db26aSLionel Sambuc 		if (i % 5 == 0)
13103e1db26aSLionel Sambuc 			(void) fprintf(el->el_errfile, "\n");
13113e1db26aSLionel Sambuc 	}
13123e1db26aSLionel Sambuc 	(void) fprintf(el->el_errfile, "\n");
13133e1db26aSLionel Sambuc }
13143e1db26aSLionel Sambuc #endif /* notyet */
1315*0a6a1f1dSLionel Sambuc 
1316*0a6a1f1dSLionel Sambuc 
1317*0a6a1f1dSLionel Sambuc private void
tty_setup_flags(EditLine * el,struct termios * tios,int mode)1318*0a6a1f1dSLionel Sambuc tty_setup_flags(EditLine *el, struct termios *tios, int mode)
1319*0a6a1f1dSLionel Sambuc {
1320*0a6a1f1dSLionel Sambuc 	int kind;
1321*0a6a1f1dSLionel Sambuc 	for (kind = MD_INP; kind <= MD_LIN; kind++) {
1322*0a6a1f1dSLionel Sambuc 		tcflag_t *f = tty__get_flag(tios, kind);
1323*0a6a1f1dSLionel Sambuc 		*f = tty_update_flag(el, *f, mode, kind);
1324*0a6a1f1dSLionel Sambuc 	}
1325*0a6a1f1dSLionel Sambuc }
1326