1 /*
2  * This code contains changes by
3  *      Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
4  *
5  * Conditions 1, 2, and 4 and the no-warranty notice below apply
6  * to these changes.
7  *
8  *
9  * Copyright (c) 1980, 1993
10  * 	The Regents of the University of California.  All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  * 	This product includes software developed by the University of
23  * 	California, Berkeley and its contributors.
24  * 4. Neither the name of the University nor the names of its contributors
25  *    may be used to endorse or promote products derived from this software
26  *    without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38  * SUCH DAMAGE.
39  *
40  *
41  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
42  *
43  * Redistribution and use in source and binary forms, with or without
44  * modification, are permitted provided that the following conditions
45  * are met:
46  *   Redistributions of source code and documentation must retain the
47  *    above copyright notice, this list of conditions and the following
48  *    disclaimer.
49  *   Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  *   All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *      This product includes software developed or owned by Caldera
55  *      International, Inc.
56  *   Neither the name of Caldera International, Inc. nor the names of
57  *    other contributors may be used to endorse or promote products
58  *    derived from this software without specific prior written permission.
59  *
60  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
61  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
62  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
63  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64  * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
65  * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
66  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
67  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
68  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
69  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
70  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
71  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72  *
73  *	from ex_tty.h	7.5.1 (2.11BSD GTE) 12/9/94
74  *
75  *	@(#)ex_tty.h	1.13 (gritter) 12/1/04
76  */
77 #include "libterm/libterm.h"
78 
79 /*
80  * Capabilities from termcap
81  *
82  * The description of terminals is a difficult business, and we only
83  * attempt to summarize the capabilities here;  for a full description
84  * see the paper describing termcap.
85  *
86  * Capabilities from termcap are of three kinds - string valued options,
87  * numeric valued options, and boolean options.  The string valued options
88  * are the most complicated, since they may include padding information,
89  * which we describe now.
90  *
91  * Intelligent terminals often require padding on intelligent operations
92  * at high (and sometimes even low) speed.  This is specified by
93  * a number before the string in the capability, and has meaning for the
94  * capabilities which have a P at the front of their comment.
95  * This normally is a number of milliseconds to pad the operation.
96  * In the current system which has no true programmible delays, we
97  * do this by sending a sequence of pad characters (normally nulls, but
98  * specifiable as "pc").  In some cases, the pad is better computed
99  * as some number of milliseconds times the number of affected lines
100  * (to bottom of screen usually, except when terminals have insert modes
101  * which will shift several lines.)  This is specified as '12*' e.g.
102  * before the capability to say 12 milliseconds per affected whatever
103  * (currently always line).  Capabilities where this makes sense say P*.
104  */
105 #ifndef	VMUNIX
106 var	char	tspace[256];	/* Space for capability strings */
107 #else
108 var	char	tspace[1024];	/* Space for capability strings */
109 #endif
110 var	char	*aoftspace;	/* Address of tspace for relocation */
111 
112 var	char	*AL;		/* P* Add new blank line */
113 var	char	*AL_PARM;	/* P* Add n new blank lines */
114 extern	char	*BC;		/*    Back cursor */
115 var	char	*BT;		/* P  Back tab */
116 var	char	*CD;		/* P* Clear to end of display */
117 var	char	*CE;		/* P  Clear to end of line */
118 var	char	*CL;		/* P* Clear screen */
119 var	char	*CM;		/* PG Cursor motion */
120 var	char	*xCS;		/* PG Change scrolling region (vt100) */
121 var	char	*xCR;		/* P  Carriage return */
122 var	char	*DC;		/* P* Delete character */
123 var	char	*DL;		/* P* Delete line sequence */
124 var	char	*DL_PARM;	/* P* Delete n lines */
125 var	char	*DM;		/*    Delete mode (enter)  */
126 var	char	*DO;		/*    Down line sequence */
127 var	char	*DOWN_PARM;	/*    Down n lines */
128 var	char	*ED;		/*    End delete mode */
129 var	char	*EI;		/*    End insert mode */
130 var	char	*F0,*F1,*F2,*F3,*F4,*F5,*F6,*F7,*F8,*F9;
131 				/*    Strings sent by various function keys */
132 var	char	*HO;		/*    Home cursor */
133 var	char	*IC;		/* P  Insert character */
134 var	char	*IM;		/*    Insert mode (give as ':im=:' if 'ic' */
135 var	char	*IP;		/* P* Insert pad after char ins'd using IM+IE */
136 var	char	*KD;		/*    Keypad down arrow */
137 var	char	*KE;		/*    Keypad don't xmit */
138 var	char	*KH;		/*    Keypad home key */
139 var	char	*KL;		/*    Keypad left arrow */
140 var	char	*KR;		/*    Keypad right arrow */
141 var	char	*KS;		/*    Keypad start xmitting */
142 var	char	*KU;		/*    Keypad up arrow */
143 var	char	*LEFT_PARM;	/*    Left n chars */
144 var	char	*LL;		/*    Quick to last line, column 0 */
145 var	char	*ND;		/*    Non-destructive space */
146 var	char	*RIGHT_PARM;	/*    Right n spaces */
147 var	char	*xNL;		/*    Line feed (new line) */
148 extern	char	PC;		/*    Pad character */
149 var	char	*RC;		/*    Restore cursor from last SC */
150 var	char	*SC;		/*    Save cursor */
151 var	char	*SE;		/*    Standout end (may leave space) */
152 var	char	*SF;		/* P  Scroll forwards */
153 var	char	*SO;		/*    Stand out begin (may leave space) */
154 var	char	*SR;		/* P  Scroll backwards */
155 var	char	*TA;		/* P  Tab (other than ^I or with padding) */
156 var	char	*TE;		/*    Terminal end sequence */
157 var	char	*TI;		/*    Terminal initial sequence */
158 extern	char	*UP;		/*    Upline */
159 var	char	*UP_PARM;	/*    Up n lines */
160 var	char	*VB;		/*    Visible bell */
161 var	char	*VE;		/*    Visual end sequence */
162 var	char	*VS;		/*    Visual start sequence */
163 var	bool	AM;		/* Automatic margins */
164 var	bool	BS;		/* Backspace works */
165 var	bool	CA;		/* Cursor addressible */
166 var	bool	DA;		/* Display may be retained above */
167 var	bool	DB;		/* Display may be retained below */
168 var	bool	EO;		/* Can erase overstrikes with ' ' */
169 var	bool	GT;		/* Gtty indicates tabs */
170 var	bool	HC;		/* Hard copy terminal */
171 #ifdef	UCVISUAL
172 var	bool	xHZ;		/* Hazeltine ~ braindamage */
173 #endif
174 var	bool	IN;		/* Insert-null blessing */
175 var	bool	MI;		/* can move in insert mode */
176 var	bool	NC;		/* No Cr - \r snds \r\n then eats \n (dm2500) */
177 var	bool	NS;		/* No scroll - linefeed at bottom won't scroll */
178 var	bool	OS;		/* Overstrike works */
179 var	bool	UL;		/* Underlining works even though !os */
180 var	bool	XB;		/* Beehive (no escape key, simulate with f1) */
181 var	bool	XN;		/* A newline gets eaten after wrap (concept) */
182 var	bool	XT;		/* Tabs are destructive */
183 var	bool	XX;		/* Tektronix 4025 insert line */
184 	/* X? is reserved for severely nauseous glitches */
185 	/* If there are enough of these we may need bit masks! */
186 
187 /*
188  * From the tty modes...
189  */
190 var	bool	NONL;		/* Terminal can't hack linefeeds doing a CR */
191 #ifdef	UCVISUAL
192 var	bool	UPPERCASE;	/* Ick! */
193 #endif
194 extern	short	TLINES;		/* Number of lines on screen */
195 extern	short	TCOLUMNS;
196 var	short	OCOLUMNS;	/* Save TCOLUMNS for a hack in open mode */
197 #ifdef	TIOCGWINSZ
198 var	struct winsize winsz;	/* Save window size for stopping comparisons */
199 #endif
200 
201 var	short	outcol;		/* Where the cursor is */
202 var	short	outline;
203 
204 var	short	destcol;	/* Where the cursor should be */
205 var	short	destline;
206 
207 var	struct	termios tty;	/* Use this one structure to change modes */
208 
209 var	struct termios	normf;		/* Restore tty flags to this (someday) */
210 var	bool	normtty;	/* Have to restore normal mode from normf */
211 
212 var	short	costCM;	/* # chars to output a typical CM, with padding etc. */
213 var	short	costSR;	/* likewise for scroll reverse */
214 var	short	costAL;	/* likewise for insert line */
215 var	short	costDP;	/* likewise for DOWN_PARM */
216 var	short	costLP;	/* likewise for LEFT_PARM */
217 var	short	costRP;	/* likewise for RIGHT_PARM */
218 
219 #ifdef VMUNIX
220 # define MAXNOMACS	128	/* max number of macros of each kind */
221 # define MAXCHARMACS	2048	/* max # of chars total in macros */
222 #else
223 # define MAXNOMACS	48	/* max number of macros of each kind */
224 # define MAXCHARMACS	1536	/* max # of chars total in macros */
225 #endif
226 struct maps {
227 	char *cap;	/* pressing button that sends this.. */
228 	int  *icap;	/* same as int */
229 	char *mapto;	/* .. maps to this string */
230 	char *descr;	/* legible description of key */
231 	bool hadthis;	/* did this mapping already (avoid recursion) */
232 };
233 var	struct maps arrows[MAXNOMACS];	/* macro defs - 1st 5 built in */
234 var	struct maps immacs[MAXNOMACS];	/* for while in insert mode */
235 var	struct maps abbrevs[MAXNOMACS];	/* for word abbreviations */
236 var	int	ldisc;			/* line discipline for ucb tty driver */
237 var	char	mapspace[MAXCHARMACS];
238 var	int	imapspace[MAXCHARMACS];
239 var	char	*msnext;	/* next free location in mapspace */
240 var	int	*imsnext;	/* next free location in imapspace */
241 var	int	maphopcnt;	/* check for infinite mapping loops */
242 var	bool	anyabbrs;	/* true if abbr or unabbr has been done */
243 var	char	ttynbuf[255];	/* result of ttyname() */
244 var	int	ttymesg;	/* original mode of users tty */
245 
246 extern int map(register int, register struct maps *);
247 extern void addmac1(register char *, register char *, register char *,
248 		register struct maps *, int);
249 #define	addmac(a, b, c, d)	addmac1(a, b, c, d, 0)
250