xref: /titanic_52/usr/src/cmd/vi/port/ex_tty.h (revision 67e3a03ed4a2813074d36330f062ed6e593a4937)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 /* Copyright (c) 1981 Regents of the University of California */
32 
33 #ifndef _EX_TTY_H
34 #define	_EX_TTY_H
35 
36 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Capabilities from termcap
44  *
45  * The description of terminals is a difficult business, and we only
46  * attempt to summarize the capabilities here;  for a full description
47  * see the paper describing termcap.
48  *
49  * Capabilities from termcap are of three kinds - string valued options,
50  * numeric valued options, and boolean options.  The string valued options
51  * are the most complicated, since they may include padding information,
52  * which we describe now.
53  *
54  * Intelligent terminals often require padding on intelligent operations
55  * at high (and sometimes even low) speed.  This is specified by
56  * a number before the string in the capability, and has meaning for the
57  * capabilities which have a P at the front of their comment.
58  * This normally is a number of milliseconds to pad the operation.
59  * In the current system which has no true programmable delays, we
60  * do this by sending a sequence of pad characters (normally nulls, but
61  * specifiable as "pc").  In some cases, the pad is better computed
62  * as some number of milliseconds times the number of affected lines
63  * (to bottom of screen usually, except when terminals have insert modes
64  * which will shift several lines.)  This is specified as '12*' e.g.
65  * before the capability to say 12 milliseconds per affected whatever
66  * (currently always line).  Capabilities where this makes sense say P*.
67  */
68 
69 /*
70  * From the tty modes...
71  */
72 var	bool	NONL;		/* Terminal can't hack linefeeds doing a CR */
73 var	bool	UPPERCASE;
74 var	short	OCOLUMNS;	/* Save columns for a hack in open mode */
75 
76 var	short	outcol;		/* Where the cursor is */
77 var	short	outline;
78 
79 var	short	destcol;	/* Where the cursor should be */
80 var	short	destline;
81 
82 /*
83  * There are several kinds of tty drivers to contend with.  These include:
84  * (1)	V6:		no CBREAK, no ioctl.  (Include PWB V1 here).
85  *			[NO LONGER SUPPORTED]
86  * (2)	V7 research:	has CBREAK, has ioctl, and has the tchars (TIOCSETC)
87  *			business to change start, stop, etc. chars.
88  * (3)	USG V2:		Basically like V6 but RAW mode is like V7 RAW.
89  *			[NO LONGER SUPPORTED]
90  * (4)	USG V3:		equivalent to V7 but totally incompatible.
91  * (5)  Berkeley 4BSD:	has ltchars in addition to all of V7.
92  *
93  * The following attempts to decide what we are on, and declare
94  * some variables in the appropriate format.  The wierd looking one (ttymode)
95  * is the thing we pass to sTTY and family to turn "RAW" mode on or off
96  * when we go into or out of visual mode.  In V7/4BSD it's just the flags word
97  * to stty.  In USG V3 it's the whole tty structure.
98  */
99 #ifdef	USG			/* USG V3 */
100   var	struct	termios tty;	/* Use this one structure to change modes */
101   typedef	struct termios ttymode;	/* Mode to contain tty flags */
102 
103 #else				/* All others */
104   var	struct	sgttyb tty;	/* Always stty/gtty using this one structure */
105   typedef	int ttymode;	/* Mode to contain tty flags */
106 #ifdef 	TIOCSETC		/* V7 */
107    var	struct	tchars ottyc, nttyc;	/* For V7 character masking */
108 #endif
109 #ifdef		TIOCLGET	/* Berkeley 4BSD */
110    var	struct	ltchars olttyc, nlttyc;	/* More of tchars style stuff */
111 #endif
112 
113 #endif
114 
115 var	ttymode	normf;		/* Restore tty flags to this (someday) */
116 var	bool	normtty;	/* Have to restore normal mode from normf */
117 
118 ttymode ostart(), setty(), unixex();
119 void putpad(unsigned char *cp);
120 void pstart(void);
121 void pstop(void);
122 void tostart(void);
123 void ttcharoff(void);
124 void tostop(void);
125 void normal(ttymode);
126 void sTTY(int);
127 
128 var	short	costCM;	/* # chars to output a typical cursor_address, with padding etc. */
129 var	short	costSR;	/* likewise for scroll reverse */
130 var	short	costAL;	/* likewise for insert line */
131 var	short	costDP;	/* likewise for parm_down_cursor */
132 var	short	costLP;	/* likewise for parm_left_cursor */
133 var	short	costRP;	/* likewise for parm_right_cursor */
134 var	short	costCE;	/* likewise for clear to end of line */
135 var	short	costCD;	/* likewise for clear to end of display */
136 
137 #ifdef VMUNIX
138 #define MAXNOMACS	128	/* max number of macros of each kind */
139 #define MAXCHARMACS	2048	/* max # of chars total in macros */
140 #else
141 #define MAXNOMACS	32	/* max number of macros of each kind */
142 #define MAXCHARMACS	512	/* max # of chars total in macros */
143 #endif
144 struct maps {
145 	unsigned char *cap;	/* pressing button that sends this.. */
146 	unsigned char *mapto;	/* .. maps to this string */
147 	unsigned char *descr;	/* legible description of key */
148 };
149 void kpadd(struct maps *, unsigned char *, unsigned char *, unsigned char *);
150 var	struct maps arrows[MAXNOMACS];	/* macro defs - 1st 5 built in */
151 var	struct maps immacs[MAXNOMACS];	/* for while in insert mode */
152 var	struct maps abbrevs[MAXNOMACS];	/* for word abbreviations */
153 var	int 	abbrepcnt;		/* Repeating an abbreviation */
154 var	int	ldisc;			/* line discipline for ucb tty driver */
155 var	unsigned char	mapspace[MAXCHARMACS];
156 var	unsigned char	*msnext;	/* next free location in mapspace */
157 var	int	maphopcnt;	/* check for infinite mapping loops */
158 var	bool	anyabbrs;	/* true if abbr or unabbr has been done */
159 var	unsigned char	ttynbuf[20];	/* result of ttyname() */
160 var	int	ttymesg;	/* original mode of users tty */
161 
162 #ifdef XPG4
163 /*
164  * For POSIX.2, we need to make $LINES and $COLUMNS override whatever the
165  * system thinks are the appropriate real values.  The points of support
166  * for this feature lie scattered about in the fossil record, so we
167  * expose them to the World.
168  */
169 
170 var int envlines;
171 var int envcolumns;
172 var int oldlines;
173 var int oldcolumns;
174 #endif /* XPG4 */
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif /* _EX_TTY_H */
181