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