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