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