Must distinguish between "ambiguous" and "unknown" commands.
[unix-history] / usr / src / usr.bin / ex / ex_vis.h
CommitLineData
edf71f48
DF
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 *
5a6c967e 6 * @(#)ex_vis.h 7.5 (Berkeley) %G%
edf71f48
DF
7 */
8
36f0c78e 9/*
d266c416 10 * Ex version 3
36f0c78e
MH
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
3c7b865a
MH
26var short bastate;
27var short state;
36f0c78e
MH
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 */
3c7b865a
MH
47var short basWTOP;
48var short basWLINES;
49var short WTOP;
50var short WBOT;
51var short WLINES;
52var short WCOLS;
53var short WECHO;
36f0c78e
MH
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 */
3c7b865a 60var bool splitw;
36f0c78e
MH
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 */
70struct vlinfo {
299f2784
MH
71 short vliny; /* Y coordinate */ /* mjm: was char */
72 short vdepth; /* Depth of displayed line */ /*mjm: was char */
36f0c78e 73 short vflags; /* Is line potentially dirty ? */
299f2784 74};
3c7b865a 75var struct vlinfo vlinfo[TUBELINES + 2];
36f0c78e
MH
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 */
3c7b865a
MH
102var short vcline;
103var short vcnt;
36f0c78e
MH
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 */
3c7b865a
MH
113var char *vtube[TUBELINES];
114var char *vtube0;
36f0c78e
MH
115
116/*
117 * The current cursor position within the current line is kept in
118 * cursor. The current line is kept in linebuf. During insertions
119 * we use the auxiliary array genbuf as scratch area.
120 * The cursor wcursor and wdot are used in operations within/spanning
121 * lines to mark the other end of the affected area, or the target
122 * for a motion.
123 */
3c7b865a
MH
124var char *cursor;
125var char *wcursor;
126var line *wdot;
36f0c78e
MH
127
128/*
129 * Undo information is saved in a LBSIZE buffer at "vutmp" for changes
130 * within the current line, or as for command mode for multi-line changes
131 * or changes on lines no longer the current line.
132 * The change kind "VCAPU" is used immediately after a U undo to prevent
133 * two successive U undo's from destroying the previous state.
134 */
135#define VNONE 0
136#define VCHNG 1
137#define VMANY 2
138#define VCAPU 3
139#define VMCHNG 4
140#define VMANYINS 5
141
3c7b865a
MH
142var short vundkind; /* Which kind of undo - from above */
143var char *vutmp; /* Prev line image when "VCHNG" */
36f0c78e 144
d266c416
MH
145/*
146 * State information for undoing of macros. The basic idea is that
147 * if the macro does only 1 change or even none, we don't treat it
148 * specially. If it does 2 or more changes we want to be able to
149 * undo it as a unit. We remember how many changes have been made
150 * within the current macro. (Remember macros can be nested.)
151 */
152#define VC_NOTINMAC 0 /* Not in a macro */
153#define VC_NOCHANGE 1 /* In a macro, no changes so far */
8c05092e 154#define VC_ONECHANGE 2 /* In a macro, one change so far */
d266c416
MH
155#define VC_MANYCHANGE 3 /* In a macro, at least 2 changes so far */
156
3c7b865a 157var short vch_mac; /* Change state - one of the above */
d266c416 158
36f0c78e
MH
159/*
160 * For U undo's the line is grabbed by "vmove" after it first appears
161 * on that line. The "vUNDdot" which specifies which line has been
162 * saved is selectively cleared when changes involving other lines
163 * are made, i.e. after a 'J' join. This is because a 'JU' would
164 * lose completely the text of the line just joined on.
165 */
3c7b865a
MH
166var char *vUNDcurs; /* Cursor just before 'U' */
167var line *vUNDdot; /* The line address of line saved in vUNDsav */
168var line vUNDsav; /* Grabbed initial "*dot" */
36f0c78e
MH
169
170#define killU() vUNDdot = NOLINE
171
172/*
173 * There are a number of cases where special behaviour is needed
174 * from deeply nested routines. This is accomplished by setting
175 * the bits of hold, which acts to change the state of the general
176 * visual editing behaviour in specific ways.
177 *
178 * HOLDAT prevents the clreol (clear to end of line) routines from
179 * putting out @'s or ~'s on empty lines.
180 *
181 * HOLDDOL prevents the reopen routine from putting a '$' at the
182 * end of a reopened line in list mode (for hardcopy mode, e.g.).
183 *
184 * HOLDROL prevents spurious blank lines when scrolling in hardcopy
185 * open mode.
186 *
187 * HOLDQIK prevents the fake insert mode during repeated commands.
188 *
189 * HOLDPUPD prevents updating of the physical screen image when
190 * mucking around while in insert mode.
191 *
192 * HOLDECH prevents clearing of the echo area while rolling the screen
193 * backwards (e.g.) in deference to the clearing of the area at the
194 * end of the scroll (1 time instead of n times). The fact that this
195 * is actually needed is recorded in heldech, which says that a clear
196 * of the echo area was actually held off.
197 */
3c7b865a
MH
198var short hold;
199var short holdupd; /* Hold off update when echo line is too long */
36f0c78e
MH
200
201#define HOLDAT 1
202#define HOLDDOL 2
203#define HOLDROL 4
204#define HOLDQIK 8
205#define HOLDPUPD 16
206#define HOLDECH 32
207#define HOLDWIG 64
208
209/*
210 * Miscellaneous variables
211 */
3c7b865a
MH
212var short CDCNT; /* Count of ^D's in insert on this line */
213var char DEL[VBSIZE]; /* Last deleted text */
214var bool HADUP; /* This insert line started with ^ then ^D */
215var bool HADZERO; /* This insert line started with 0 then ^D */
216var char INS[VBSIZE]; /* Last inserted text */
217var int Vlines; /* Number of file lines "before" vi command */
218var int Xcnt; /* External variable holding last cmd's count */
219var bool Xhadcnt; /* Last command had explicit count? */
5a6c967e 220var short ex_ZERO;
3c7b865a
MH
221var short dir; /* Direction for search (+1 or -1) */
222var short doomed; /* Disply chars right of cursor to be killed */
223var bool gobblebl; /* Wrapmargin space generated nl, eat a space */
224var bool hadcnt; /* (Almost) internal to vmain() */
225var bool heldech; /* We owe a clear of echo area */
226var bool insmode; /* Are in character insert mode */
227var char lastcmd[5]; /* Chars in last command */
228var int lastcnt; /* Count for last command */
229var char *lastcp; /* Save current command here to repeat */
230var bool lasthad; /* Last command had a count? */
231var short lastvgk; /* Previous input key, if not from keyboard */
232var short lastreg; /* Register with last command */
233var char *ncols['z'-'a'+2]; /* Cursor positions of marks */
234var char *notenam; /* Name to be noted with change count */
235var char *notesgn; /* Change count from last command */
236var char op; /* Operation of current command */
5a6c967e 237var short Peek_key; /* Peek ahead key */
3c7b865a 238var bool rubble; /* Line is filthy (in hardcopy open), redraw! */
5a6c967e 239var int ex_vSCROLL; /* Number lines to scroll on ^D/^U */
3c7b865a
MH
240var char *vglobp; /* Untyped input (e.g. repeat insert text) */
241var char vmacbuf[VBSIZE]; /* Text of visual macro, hence nonnestable */
242var char *vmacp; /* Like vglobp but for visual macros */
243var char *vmcurs; /* Cursor for restore after undo d), e.g. */
244var short vmovcol; /* Column to try to keep on arrow keys */
245var bool vmoving; /* Are trying to keep vmovcol */
246var short vreg; /* Reg for this command */ /* mjm: was char */
247var short wdkind; /* Liberal/conservative words? */
248var char workcmd[5]; /* Temporary for lastcmd */
36f0c78e
MH
249
250
251/*
252 * Macros
253 */
254#define INF 30000
255#define LASTLINE LINE(vcnt)
256#define OVERBUF QUOTE
257#define beep obeep
258#define cindent() ((outline - vlinfo[vcline].vliny) * WCOLS + outcol)
259#define vputp(cp, cnt) tputs(cp, cnt, vputch)
260#define vputc(c) putch(c)
261
262/*
263 * Function types
264 */
265int beep();
266int qcount();
267int vchange();
268int vdelete();
269int vgrabit();
270int vinschar();
271int vmove();
272int vputchar();
273int vshift();
274int vyankit();