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