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