Subversion Repositories planix.SVN

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 7u83 1
/*
2
 * This code contains changes by
3
 *      Gunnar Ritter, Freiburg i. Br., Germany, 2002. All rights reserved.
4
 *
5
 * Conditions 1, 2, and 4 and the no-warranty notice below apply
6
 * to these changes.
7
 *
8
 *
9
 * Copyright (c) 1980, 1993
10
 * 	The Regents of the University of California.  All rights reserved.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 * 1. Redistributions of source code must retain the above copyright
16
 *    notice, this list of conditions and the following disclaimer.
17
 * 2. Redistributions in binary form must reproduce the above copyright
18
 *    notice, this list of conditions and the following disclaimer in the
19
 *    documentation and/or other materials provided with the distribution.
20
 * 3. All advertising materials mentioning features or use of this software
21
 *    must display the following acknowledgement:
22
 * 	This product includes software developed by the University of
23
 * 	California, Berkeley and its contributors.
24
 * 4. Neither the name of the University nor the names of its contributors
25
 *    may be used to endorse or promote products derived from this software
26
 *    without specific prior written permission.
27
 *
28
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38
 * SUCH DAMAGE.
39
 *
40
 *
41
 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
42
 *
43
 * Redistribution and use in source and binary forms, with or without
44
 * modification, are permitted provided that the following conditions
45
 * are met:
46
 *   Redistributions of source code and documentation must retain the
47
 *    above copyright notice, this list of conditions and the following
48
 *    disclaimer.
49
 *   Redistributions in binary form must reproduce the above copyright
50
 *    notice, this list of conditions and the following disclaimer in the
51
 *    documentation and/or other materials provided with the distribution.
52
 *   All advertising materials mentioning features or use of this software
53
 *    must display the following acknowledgement:
54
 *      This product includes software developed or owned by Caldera
55
 *      International, Inc.
56
 *   Neither the name of Caldera International, Inc. nor the names of
57
 *    other contributors may be used to endorse or promote products
58
 *    derived from this software without specific prior written permission.
59
 *
60
 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
61
 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
62
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
63
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
64
 * ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
65
 * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
66
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
67
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
68
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
69
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
70
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
71
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72
 *
73
 *	from ex_vis.h	7.4 (Berkeley) 5/31/85
74
 *
75
 *	@(#)ex_vis.h	1.18 (gritter) 3/24/05
76
 */
77
 
78
/*
79
 * Ex version 3
80
 * Mark Horton, UCB
81
 * Bill Joy UCB
82
 *
83
 * Open and visual mode definitions.
84
 * 
85
 * There are actually 4 major states in open/visual modes.  These
86
 * are visual, crt open (where the cursor can move about the screen and
87
 * the screen can scroll and be erased), one line open (on dumb glass-crt's
88
 * like the adm3), and hardcopy open (for everything else).
89
 *
90
 * The basic state is given by bastate, and the current state by state,
91
 * since we can be in pseudo-hardcopy mode if we are on an adm3 and the
92
 * line is longer than 80.
93
 */
94
 
95
var enum {
96
	VISUAL		= 0,
97
	CRTOPEN		= 1,
98
	ONEOPEN		= 2,
99
	HARDOPEN	= 3
100
} bastate, state;
101
 
102
/*
103
 * The screen in visual and crtopen is of varying size; the basic
104
 * window has top basWTOP and basWLINES lines are thereby implied.
105
 * The current window (which may have grown from the basic size)
106
 * has top WTOP and WLINES lines.  The top line of the window is WTOP,
107
 * and the bottom line WBOT.  The line WECHO is used for messages,
108
 * search strings and the like.  If WBOT==WECHO then we are in ONEOPEN
109
 * or HARDOPEN and there is no way back to the line we were on if we
110
 * go to WECHO (i.e. we will have to scroll before we go there, and
111
 * we can't get back).  There are WCOLS columns per line.
112
 * If WBOT!=WECHO then WECHO will be the last line on the screen
113
 * and WBOT is the line before it.
114
 */
115
var	short	basWTOP;
116
var	short	basWLINES;
117
var	short	WTOP;
118
var	short	WBOT;
119
var	short	WLINES;
120
var	short	WCOLS;
121
var	short	WECHO;
122
 
123
/*
124
 * When we are dealing with the echo area we consider the window
125
 * to be "split" and set the variable splitw.  Otherwise, moving
126
 * off the bottom of the screen into WECHO causes a screen rollup.
127
 */
128
var	bool	splitw;
129
 
130
/*
131
 * Information about each line currently on the screen includes
132
 * the y coordinate associated with the line, the printing depth
133
 * of the line (0 indicates unknown), and a mask which indicates
134
 * whether the line is "unclean", i.e. whether we should check
135
 * to make sure the line is displayed correctly at the next
136
 * appropriate juncture.
137
 */
138
struct vlinfo {
139
	short	vliny;		/* Y coordinate */	/* mjm: was char */
140
	short	vdepth;		/* Depth of displayed line */ /*mjm: was char */
141
	short	vflags;		/* Is line potentially dirty ? */
142
};
143
var	struct vlinfo  vlinfo[TUBELINES + 2];
144
 
145
#define	DEPTH(c)	(vlinfo[c].vdepth)
146
#define	LINE(c)		(vlinfo[c].vliny)
147
#define	FLAGS(c)	(vlinfo[c].vflags)
148
 
149
#define	VDIRT	1
150
 
151
/*
152
 * Hacks to copy vlinfo structures around
153
 */
154
#	define	vlcopy(i, j)	i = j;
155
 
156
/*
157
 * The current line on the screen is represented by vcline.
158
 * There are vcnt lines on the screen, the last being "vcnt - 1".
159
 * Vcline is intimately tied to the current value of dot,
160
 * and when command mode is used as a subroutine fancy footwork occurs.
161
 */
162
var	short	vcline;
163
var	short	vcnt;
164
 
165
/*
166
 * To allow many optimizations on output, an exact image of the terminal
167
 * screen is maintained in the space addressed by vtube0.  The vtube
168
 * array indexes this space as lines, and is shuffled on scrolls, insert+delete
169
 * lines and the like rather than (more expensively) shuffling the screen
170
 * data itself.  It is also rearranged during insert mode across line
171
 * boundaries to make incore work easier.
172
 */
173
var	cell	*vtube[TUBELINES];
174
var	cell	*vtube0;
175
 
176
/*
177
 * The current cursor position within the current line is kept in
178
 * cursor.  The current line is kept in linebuf.  During insertions
179
 * we use the auxiliary array genbuf as scratch area.
180
 * The cursor wcursor and wdot are used in operations within/spanning
181
 * lines to mark the other end of the affected area, or the target
182
 * for a motion.
183
 */
184
var	char	*cursor;
185
var	char	*wcursor;
186
var	line	*wdot;
187
 
188
/*
189
 * Undo information is saved in a LBSIZE buffer at "vutmp" for changes
190
 * within the current line, or as for command mode for multi-line changes
191
 * or changes on lines no longer the current line.
192
 * The change kind "VCAPU" is used immediately after a U undo to prevent
193
 * two successive U undo's from destroying the previous state.
194
 */
195
#define	VNONE	0
196
#define	VCHNG	1
197
#define	VMANY	2
198
#define	VCAPU	3
199
#define	VMCHNG	4
200
#define	VMANYINS 5
201
 
202
var	short	vundkind;	/* Which kind of undo - from above */
203
var	char	*vutmp;		/* Prev line image when "VCHNG" */
204
 
205
/*
206
 * State information for undoing of macros.  The basic idea is that
207
 * if the macro does only 1 change or even none, we don't treat it
208
 * specially.  If it does 2 or more changes we want to be able to
209
 * undo it as a unit.  We remember how many changes have been made
210
 * within the current macro.  (Remember macros can be nested.)
211
 */
212
#define VC_NOTINMAC	0	/* Not in a macro */
213
#define VC_NOCHANGE	1	/* In a macro, no changes so far */
214
#define VC_ONECHANGE	2	/* In a macro, one change so far */
215
#define VC_MANYCHANGE	3	/* In a macro, at least 2 changes so far */
216
 
217
var	short	vch_mac;	/* Change state - one of the above */
218
 
219
/*
220
 * For U undo's the line is grabbed by "vmove" after it first appears
221
 * on that line.  The "vUNDdot" which specifies which line has been
222
 * saved is selectively cleared when changes involving other lines
223
 * are made, i.e. after a 'J' join.  This is because a 'JU' would
224
 * lose completely the text of the line just joined on.
225
 */
226
var	char	*vUNDcurs;	/* Cursor just before 'U' */
227
var	line	*vUNDdot;	/* The line address of line saved in vUNDsav */
228
var	line	vUNDsav;	/* Grabbed initial "*dot" */
229
 
230
#define	killU()		vUNDdot = NOLINE
231
 
232
/*
233
 * There are a number of cases where special behaviour is needed
234
 * from deeply nested routines.  This is accomplished by setting
235
 * the bits of hold, which acts to change the state of the general
236
 * visual editing behaviour in specific ways.
237
 *
238
 * HOLDAT prevents the clreol (clear to end of line) routines from
239
 * putting out @'s or ~'s on empty lines.
240
 *
241
 * HOLDDOL prevents the reopen routine from putting a '$' at the
242
 * end of a reopened line in list mode (for hardcopy mode, e.g.).
243
 *
244
 * HOLDROL prevents spurious blank lines when scrolling in hardcopy
245
 * open mode.
246
 *
247
 * HOLDQIK prevents the fake insert mode during repeated commands.
248
 *
249
 * HOLDPUPD prevents updating of the physical screen image when
250
 * mucking around while in insert mode.
251
 *
252
 * HOLDECH prevents clearing of the echo area while rolling the screen
253
 * backwards (e.g.) in deference to the clearing of the area at the
254
 * end of the scroll (1 time instead of n times).  The fact that this
255
 * is actually needed is recorded in heldech, which says that a clear
256
 * of the echo area was actually held off.
257
 */
258
var	short	hold;
259
var	short	holdupd;	/* Hold off update when echo line is too long */
260
 
261
#define	HOLDAT		1
262
#define	HOLDDOL		2
263
#define	HOLDROL		4
264
#define	HOLDQIK		8
265
#define	HOLDPUPD	16
266
#define	HOLDECH		32
267
#define HOLDWIG		64
268
 
269
/*
270
 * Miscellaneous variables
271
 */
272
var	short	CDCNT;		/* Count of ^D's in insert on this line */
273
var	cell	DEL[VBSIZE];	/* Last deleted text */
274
var	bool	HADUP;		/* This insert line started with ^ then ^D */
275
var	bool	HADZERO;	/* This insert line started with 0 then ^D */
276
var	cell	INS[VBSIZE];	/* Last inserted text */
277
var	int	Vlines;		/* Number of file lines "before" vi command */
278
var	int	Xcnt;		/* External variable holding last cmd's count */
279
var	bool	Xhadcnt;	/* Last command had explicit count? */
280
var	short	ZERO;
281
var	short	dir;		/* Direction for search (+1 or -1) */
282
var	short	doomed;		/* Disply chars right of cursor to be killed */
283
var	bool	gobblebl;	/* Wrapmargin space generated nl, eat a space */
284
var	bool	hadcnt;		/* (Almost) internal to vmain() */
285
var	bool	heldech;	/* We owe a clear of echo area */
286
var	bool	insmode;	/* Are in character insert mode */
287
var	cell	lastcmd[5];	/* Chars in last command */
288
var	int	lastcnt;	/* Count for last command */
289
var	cell	*lastcp;	/* Save current command here to repeat */
290
var	bool	lasthad;	/* Last command had a count? */
291
var	int	lastvgk;	/* Previous input key, if not from keyboard */
292
var	short	lastreg;	/* Register with last command */
293
var	char	*ncols['z'-'a'+2];	/* Cursor positions of marks */
294
var	char	*notenam;	/* Name to be noted with change count */
295
var	char	*notesgn;	/* Change count from last command */
296
var	int	op;		/* Operation of current command */
297
var	int	Peekkey;	/* Peek ahead key */
298
var	bool	rubble;		/* Line is filthy (in hardcopy open), redraw! */
299
var	int	vSCROLL;	/* Number lines to scroll on ^D/^U */
300
var	cell	*vglobp;	/* Untyped input (e.g. repeat insert text) */
301
var	char	vmacbuf[VBSIZE];   /* Text of visual macro, hence nonnestable */
302
var	char	*vmacp;		/* Like vglobp but for visual macros */
303
var	char	*vmcurs;	/* Cursor for restore after undo d), e.g. */
304
var	short	vmovcol;	/* Column to try to keep on arrow keys */
305
var	bool	vmoving;	/* Are trying to keep vmovcol */
306
var	short	vreg;		/* Reg for this command */   /* mjm: was char */
307
var	short	wdkind;		/* Liberal/conservative words? */
308
var	cell	workcmd[5];	/* Temporary for lastcmd */
309
var	char	*vcolbp;	/* first byte of current character in column */
310
 
311
 
312
/*
313
 * Macros
314
 */
315
#define	INF		30000
316
#define	LASTLINE	LINE(vcnt)
317
#define	OVERBUF		QUOTE
318
#define	beep		obeep
319
#define	cindent()	((outline - vlinfo[vcline].vliny) * WCOLS + outcol)
320
#define	vputp(cp, cnt)	tputs(cp, cnt, vputch)
321
#define	vputc(c)	putch(c)