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