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