xref: /titanic_52/usr/src/cmd/vi/port/ex_vis.h (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
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 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 /* Copyright (c) 1981 Regents of the University of California */
27 /*
28  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
29  * Use is subject to license terms.
30  */
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.10	*/
32 /*
33  * Ex version 3
34  *
35  * Open and visual mode definitions.
36  *
37  * There are actually 4 major states in open/visual modes.  These
38  * are visual, crt open (where the cursor can move about the screen and
39  * the screen can scroll and be erased), one line open (on dumb glass-crt's
40  * like the adm3), and hardcopy open (for everything else).
41  *
42  * The basic state is given by bastate, and the current state by state,
43  * since we can be in pseudo-hardcopy mode if we are on an adm3 and the
44  * line is longer than 80.
45  */
46 
47 var	short	bastate;
48 var	short	state;
49 
50 #define	VISUAL		0
51 #define	CRTOPEN		1
52 #define	ONEOPEN		2
53 #define	HARDOPEN	3
54 
55 /*
56  * The screen in visual and crtopen is of varying size; the basic
57  * window has top basWTOP and basWLINES lines are thereby implied.
58  * The current window (which may have grown from the basic size)
59  * has top WTOP and WLINES lines.  The top line of the window is WTOP,
60  * and the bottom line WBOT.  The line WECHO is used for messages,
61  * search strings and the like.  If WBOT==WECHO then we are in ONEOPEN
62  * or HARDOPEN and there is no way back to the line we were on if we
63  * go to WECHO (i.e. we will have to scroll before we go there, and
64  * we can't get back).  There are WCOLS columns per line.
65  * If WBOT!=WECHO then WECHO will be the last line on the screen
66  * and WBOT is the line before it.
67  */
68 var	short	basWTOP;
69 var	short	basWLINES;
70 var	short	WTOP;
71 var	short	WBOT;
72 var	short	WLINES;
73 var	short	WCOLS;
74 var	short	WECHO;
75 
76 /*
77  * When we are dealing with the echo area we consider the window
78  * to be "split" and set the variable splitw.  Otherwise, moving
79  * off the bottom of the screen into WECHO causes a screen rollup.
80  */
81 var	bool	splitw;
82 
83 /*
84  * Information about each line currently on the screen includes
85  * the y coordinate associated with the line, the printing depth
86  * of the line (0 indicates unknown), and a mask which indicates
87  * whether the line is "unclean", i.e. whether we should check
88  * to make sure the line is displayed correctly at the next
89  * appropriate juncture.
90  */
91 struct vlinfo {
92 	short	vliny;		/* Y coordinate */	/* was char */
93 	short	vdepth;		/* Depth of displayed line */ /* was char */
94 	short	vflags;		/* Is line potentially dirty ? */
95 };
96 var	struct vlinfo  vlinfo[TUBELINES + 2];
97 
98 #define	DEPTH(c)	(vlinfo[c].vdepth)
99 #define	LINE(c)		(vlinfo[c].vliny)
100 #define	FLAGS(c)	(vlinfo[c].vflags)
101 
102 #define	VDIRT	1
103 
104 /*
105  * Hacks to copy vlinfo structures around
106  */
107 #ifdef	V6
108 	/* Kludge to make up for no structure assignment */
109 	struct {
110 		long	longi;
111 	};
112 #define	vlcopy(i, j)	i.longi = j.longi
113 #else
114 #define	vlcopy(i, j)	i = j;
115 #endif
116 
117 /*
118  * The current line on the screen is represented by vcline.
119  * There are vcnt lines on the screen, the last being "vcnt - 1".
120  * Vcline is intimately tied to the current value of dot,
121  * and when command mode is used as a subroutine fancy footwork occurs.
122  */
123 var	short	vcline;
124 var	short	vcnt;
125 
126 /*
127  * To allow many optimizations on output, an exact image of the terminal
128  * screen is maintained in the space addressed by vtube0.  The vtube
129  * array indexes this space as lines, and is shuffled on scrolls, insert+delete
130  * lines and the like rather than (more expensively) shuffling the screen
131  * data itself.  It is also rearranged during insert mode across line
132  * boundaries to make incore work easier.
133  */
134 var	wchar_t	*vtube[TUBELINES];
135 var	wchar_t	*vtube0;
136 
137 /*
138  * The current cursor position within the current line is kept in
139  * cursor.  The current line is kept in linebuf.  During insertions
140  * we use the auxiliary array genbuf as scratch area.
141  * The cursor wcursor and wdot are used in operations within/spanning
142  * lines to mark the other end of the affected area, or the target
143  * for a motion.
144  */
145 var	unsigned char	*cursor;
146 var	unsigned char	*wcursor;
147 var	line	*wdot;
148 
149 /*
150  * Undo information is saved in a LBSIZE buffer at "vutmp" for changes
151  * within the current line, or as for command mode for multi-line changes
152  * or changes on lines no longer the current line.
153  * The change kind "VCAPU" is used immediately after a U undo to prevent
154  * two successive U undo's from destroying the previous state.
155  */
156 #define	VNONE	0
157 #define	VCHNG	1
158 #define	VMANY	2
159 #define	VCAPU	3
160 #define	VMCHNG	4
161 #define	VMANYINS 5
162 
163 var	short	vundkind;	/* Which kind of undo - from above */
164 var	unsigned char	*vutmp;		/* Prev line image when "VCHNG" */
165 
166 /*
167  * State information for undoing of macros.  The basic idea is that
168  * if the macro does only 1 change or even none, we don't treat it
169  * specially.  If it does 2 or more changes we want to be able to
170  * undo it as a unit.  We remember how many changes have been made
171  * within the current macro.  (Remember macros can be nested.)
172  */
173 #define VC_NOTINMAC	0	/* Not in a macro */
174 #define VC_NOCHANGE	1	/* In a macro, no changes so far */
175 #define VC_ONECHANGE	2	/* In a macro, one change so far */
176 #define VC_MANYCHANGE	3	/* In a macro, at least 2 changes so far */
177 
178 var	short	vch_mac;	/* Change state - one of the above */
179 
180 /*
181  * For U undo's the line is grabbed by "vmove" after it first appears
182  * on that line.  The "vUNDdot" which specifies which line has been
183  * saved is selectively cleared when changes involving other lines
184  * are made, i.e. after a 'J' join.  This is because a 'JU' would
185  * lose completely the text of the line just joined on.
186  */
187 var	unsigned char	*vUNDcurs;	/* Cursor just before 'U' */
188 var	line	*vUNDdot;	/* The line address of line saved in vUNDsav */
189 var	line	vUNDsav;	/* Grabbed initial "*dot" */
190 
191 #define	killU()		vUNDdot = NOLINE
192 
193 /*
194  * There are a number of cases where special behaviour is needed
195  * from deeply nested routines.  This is accomplished by setting
196  * the bits of hold, which acts to change the state of the general
197  * visual editing behaviour in specific ways.
198  *
199  * HOLDAT prevents the clreol (clear to end of line) routines from
200  * putting out @'s or ~'s on empty lines.
201  *
202  * HOLDDOL prevents the reopen routine from putting a '$' at the
203  * end of a reopened line in list mode (for hardcopy mode, e.g.).
204  *
205  * HOLDROL prevents spurious blank lines when scrolling in hardcopy
206  * open mode.
207  *
208  * HOLDQIK prevents the fake insert mode during repeated commands.
209  *
210  * HOLDPUPD prevents updating of the physical screen image when
211  * mucking around while in insert mode.
212  *
213  * HOLDECH prevents clearing of the echo area while rolling the screen
214  * backwards (e.g.) in deference to the clearing of the area at the
215  * end of the scroll (1 time instead of n times).  The fact that this
216  * is actually needed is recorded in heldech, which says that a clear
217  * of the echo area was actually held off.
218  */
219 var	short	hold;
220 var	short	holdupd;	/* Hold off update when echo line is too long */
221 
222 #define	HOLDAT		1
223 #define	HOLDDOL		2
224 #define	HOLDROL		4
225 #define	HOLDQIK		8
226 #define	HOLDPUPD	16
227 #define	HOLDECH		32
228 #define HOLDWIG		64
229 
230 /*
231  * Miscellaneous variables
232  */
233 var	short	CDCNT;		/* Count of ^D's in insert on this line */
234 var	unsigned char	DEL[VBSIZE+1];	/* Last deleted text */
235 var	bool	HADUP;		/* This insert line started with ^ then ^D */
236 var	bool	HADZERO;	/* This insert line started with 0 then ^D */
237 var	unsigned char	INS[VBSIZE+1];	/* Last inserted text */
238 var	int	Vlines;		/* Number of file lines "before" vi command */
239 var	int	Xcnt;		/* External variable holding last cmd's count */
240 var	bool	Xhadcnt;	/* Last command had explicit count? */
241 var	short	ZERO;
242 var	short	dir;		/* Direction for search (+1 or -1) */
243 var	short	doomed;		/* Disply chars right of cursor to be killed */
244 var	bool	gobblebl;	/* Wrapmargin space generated nl, eat a space */
245 var	bool	hadcnt;		/* (Almost) internal to vmain() */
246 var	bool	heldech;	/* We owe a clear of echo area */
247 var	bool	insmode;	/* Are in character insert mode */
248 var	unsigned char	lastcmd[5];	/* Chars in last command */
249 var	int	lastcnt;	/* Count for last command */
250 var	unsigned char	*lastcp;	/* Save current command here to repeat */
251 var	bool	lasthad;	/* Last command had a count? */
252 var	short	lastvgk;	/* Previous input key, if not from keyboard */
253 var	short	lastreg;	/* Register with last command */
254 var	unsigned char	*ncols['z'-'a'+2];	/* Cursor positions of marks */
255 var	unsigned char	*notenam;	/* Name to be noted with change count */
256 var	unsigned char	*notesgn;	/* Change count from last command */
257 var	unsigned char	op;		/* Operation of current command */
258 var	int	Peekkey;	/* Peek ahead key */
259 var	bool	rubble;		/* Line is filthy (in hardcopy open), redraw! */
260 var	int	vSCROLL;	/* Number lines to scroll on ^D/^U */
261 var	unsigned char	*vglobp;	/* Untyped input (e.g. repeat insert text) */
262 var	unsigned char	vmacbuf[VBSIZE];   /* Text of visual macro, hence nonnestable */
263 var	unsigned char	*vmacp;		/* Like vglobp but for visual macros */
264 var	unsigned char	*vmcurs;	/* Cursor for restore after undo d), e.g. */
265 var	short	vmovcol;	/* Column to try to keep on arrow keys */
266 var	bool	vmoving;	/* Are trying to keep vmovcol */
267 var	short	vreg;		/* Reg for this command */   /* mjm: was char */
268 var	short	wdkind;		/* Liberal/conservative words? */
269 var	unsigned char	workcmd[5];	/* Temporary for lastcmd */
270 var	bool rewrite;
271 #ifdef XPG4
272 var	int	P_cursor_offset;	/* cursor adjust for Put */
273 #endif
274 #ifndef PRESUNEUC
275 var	unsigned char	wcharfiller;	/* Right margin filler for wide char */
276 #endif /* PRESUNEUC */
277 
278 
279 /*
280  * Macros
281  */
282 #define	INF		30000
283 #define	LASTLINE	LINE(vcnt)
284 #define	beep		obeep
285 #define	cindent()	((outline - vlinfo[vcline].vliny) * WCOLS + outcol)
286 #define	vputp(cp, cnt)	tputs(cp, cnt, vputch)
287 #define	vputc(c)	putch(c)
288 #define	_ON	1
289 #define	_OFF	0
290 /*
291  * Function types
292  */
293 int	beep();
294 int	qcount();
295 int	vchange();
296 int	vdelete();
297 int	vgrabit();
298 int	vinschar();
299 int	vmove();
300 int	vputchar();
301 int	vshift();
302 int	vyankit();
303 
304 #define FILLER 0177 /* fill positions for multibyte characters */
305