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