xref: /minix/external/bsd/nvi/dist/common/screen.h (revision 84d9c625)
1*84d9c625SLionel Sambuc /*	$NetBSD: screen.h,v 1.3 2013/11/25 22:43:46 christos Exp $ */
2*84d9c625SLionel Sambuc /*-
3*84d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994
4*84d9c625SLionel Sambuc  *	The Regents of the University of California.  All rights reserved.
5*84d9c625SLionel Sambuc  * Copyright (c) 1992, 1993, 1994, 1995, 1996
6*84d9c625SLionel Sambuc  *	Keith Bostic.  All rights reserved.
7*84d9c625SLionel Sambuc  *
8*84d9c625SLionel Sambuc  * See the LICENSE file for redistribution information.
9*84d9c625SLionel Sambuc  *
10*84d9c625SLionel Sambuc  *	Id: screen.h,v 10.49 2002/03/02 23:47:02 skimo Exp  (Berkeley) Date: 2002/03/02 23:47:02
11*84d9c625SLionel Sambuc  */
12*84d9c625SLionel Sambuc 
13*84d9c625SLionel Sambuc /*
14*84d9c625SLionel Sambuc  * There are minimum values that vi has to have to display a screen.  The row
15*84d9c625SLionel Sambuc  * minimum is fixed at 1 (the svi code can share a line between the text line
16*84d9c625SLionel Sambuc  * and the colon command/message line).  Column calculation is a lot trickier.
17*84d9c625SLionel Sambuc  * For example, you have to have enough columns to display the line number,
18*84d9c625SLionel Sambuc  * not to mention guaranteeing that tabstop and shiftwidth values are smaller
19*84d9c625SLionel Sambuc  * than the current column value.  It's simpler to have a fixed value and not
20*84d9c625SLionel Sambuc  * worry about it.
21*84d9c625SLionel Sambuc  *
22*84d9c625SLionel Sambuc  * XXX
23*84d9c625SLionel Sambuc  * MINIMUM_SCREEN_COLS is almost certainly wrong.
24*84d9c625SLionel Sambuc  */
25*84d9c625SLionel Sambuc #define	MINIMUM_SCREEN_ROWS	 1
26*84d9c625SLionel Sambuc #define	MINIMUM_SCREEN_COLS	20
27*84d9c625SLionel Sambuc 
28*84d9c625SLionel Sambuc /*
29*84d9c625SLionel Sambuc  * WIN --
30*84d9c625SLionel Sambuc  *	A list of screens that are displayed as a whole.
31*84d9c625SLionel Sambuc  */
32*84d9c625SLionel Sambuc struct _win {
33*84d9c625SLionel Sambuc 	TAILQ_ENTRY(_win)	    q;	    /* Windows. */
34*84d9c625SLionel Sambuc 
35*84d9c625SLionel Sambuc 	TAILQ_HEAD(_scrh, _scr)   scrq;   /* Screens */
36*84d9c625SLionel Sambuc 
37*84d9c625SLionel Sambuc 	GS	*gp;			/* Pointer to global area. */
38*84d9c625SLionel Sambuc 
39*84d9c625SLionel Sambuc 	SCR	*ccl_sp;		/* Colon command-line screen. */
40*84d9c625SLionel Sambuc 
41*84d9c625SLionel Sambuc 	void	*perl_private;		/* Perl interpreter. */
42*84d9c625SLionel Sambuc 
43*84d9c625SLionel Sambuc 	void	*ip_private;		/* IP support private area. */
44*84d9c625SLionel Sambuc 
45*84d9c625SLionel Sambuc 	void	*th_private;		/* Threading support private area. */
46*84d9c625SLionel Sambuc 
47*84d9c625SLionel Sambuc 	/*
48*84d9c625SLionel Sambuc 	 * Ex command structures (EXCMD).  Defined here because ex commands
49*84d9c625SLionel Sambuc 	 * exist outside of any particular screen or file.
50*84d9c625SLionel Sambuc 	 */
51*84d9c625SLionel Sambuc #define	EXCMD_RUNNING(wp)	((wp)->ecq.lh_first->clen != 0)
52*84d9c625SLionel Sambuc 	LIST_HEAD(_excmdh, _excmd) ecq;	/* Ex command linked list. */
53*84d9c625SLionel Sambuc 	EXCMD	 	excmd;		/* Default ex command structure. */
54*84d9c625SLionel Sambuc 	char	       *if_name;	/* Current associated file. */
55*84d9c625SLionel Sambuc 	db_recno_t	if_lno;		/* Current associated line number. */
56*84d9c625SLionel Sambuc 
57*84d9c625SLionel Sambuc 	EVENT	*i_event;		/* Array of input events. */
58*84d9c625SLionel Sambuc 	size_t	 i_nelem;		/* Number of array elements. */
59*84d9c625SLionel Sambuc 	size_t	 i_cnt;			/* Count of events. */
60*84d9c625SLionel Sambuc 	size_t	 i_next;		/* Offset of next event. */
61*84d9c625SLionel Sambuc 
62*84d9c625SLionel Sambuc 	CB	*dcbp;			/* Default cut buffer pointer. */
63*84d9c625SLionel Sambuc 	CB	 dcb_store;		/* Default cut buffer storage. */
64*84d9c625SLionel Sambuc 	LIST_HEAD(_cuth, _cb) cutq;	/* Linked list of cut buffers. */
65*84d9c625SLionel Sambuc 
66*84d9c625SLionel Sambuc 	/* For now, can be either char or CHAR_T buffer */
67*84d9c625SLionel Sambuc 	char	*tmp_bp;		/* Temporary buffer. */
68*84d9c625SLionel Sambuc 	size_t	 tmp_blen;		/* Temporary buffer size. */
69*84d9c625SLionel Sambuc 
70*84d9c625SLionel Sambuc 	char	*l_lp;			/* Log buffer. */
71*84d9c625SLionel Sambuc 	size_t	 l_len;			/* Log buffer length. */
72*84d9c625SLionel Sambuc 
73*84d9c625SLionel Sambuc 	CONVWIN	 cw;
74*84d9c625SLionel Sambuc 
75*84d9c625SLionel Sambuc /* Flags. */
76*84d9c625SLionel Sambuc #define	W_TMP_INUSE	0x0001		/* Temporary buffer in use. */
77*84d9c625SLionel Sambuc 	u_int32_t flags;
78*84d9c625SLionel Sambuc 
79*84d9c625SLionel Sambuc 					/* Message or ex output. */
80*84d9c625SLionel Sambuc 	void	(*scr_msg) __P((SCR *, mtype_t, char *, size_t));
81*84d9c625SLionel Sambuc };
82*84d9c625SLionel Sambuc 
83*84d9c625SLionel Sambuc /*
84*84d9c625SLionel Sambuc  * SCR --
85*84d9c625SLionel Sambuc  *	The screen structure.  To the extent possible, all screen information
86*84d9c625SLionel Sambuc  *	is stored in the various private areas.  The only information here
87*84d9c625SLionel Sambuc  *	is used by global routines or is shared by too many screens.
88*84d9c625SLionel Sambuc  */
89*84d9c625SLionel Sambuc struct _scr {
90*84d9c625SLionel Sambuc /* INITIALIZED AT SCREEN CREATE. */
91*84d9c625SLionel Sambuc 	TAILQ_ENTRY(_scr) q;		/* Screens. */
92*84d9c625SLionel Sambuc 	TAILQ_ENTRY(_scr) eq;         /* Screens. */
93*84d9c625SLionel Sambuc 
94*84d9c625SLionel Sambuc 	int	 id;			/* Screen id #. */
95*84d9c625SLionel Sambuc 	int	 refcnt;		/* Reference count. */
96*84d9c625SLionel Sambuc 
97*84d9c625SLionel Sambuc 	WIN	*wp;			/* Pointer to window. */
98*84d9c625SLionel Sambuc 	GS	*gp;			/* Pointer to global area. */
99*84d9c625SLionel Sambuc 	SCR	*nextdisp;		/* Next display screen. */
100*84d9c625SLionel Sambuc 	SCR	*ccl_parent;		/* Colon command-line parent screen. */
101*84d9c625SLionel Sambuc 	EXF	*ep;			/* Screen's current EXF structure. */
102*84d9c625SLionel Sambuc 
103*84d9c625SLionel Sambuc 	CHAR_T	*c_lp;			/* Cached line. */
104*84d9c625SLionel Sambuc 	size_t	 c_len;			/* Cached line length. */
105*84d9c625SLionel Sambuc 	/* May move out again once we use DB
106*84d9c625SLionel Sambuc 	 * to cache internal representation
107*84d9c625SLionel Sambuc 	 */
108*84d9c625SLionel Sambuc 	size_t	 c_blen;		/* Cached line buffer length. */
109*84d9c625SLionel Sambuc 	db_recno_t	 c_lno;		/* Cached line number. */
110*84d9c625SLionel Sambuc 
111*84d9c625SLionel Sambuc 	FREF	*frp;			/* FREF being edited. */
112*84d9c625SLionel Sambuc 	char	**argv;			/* NULL terminated file name array. */
113*84d9c625SLionel Sambuc 	char	**cargv;		/* Current file name. */
114*84d9c625SLionel Sambuc 
115*84d9c625SLionel Sambuc 	u_long	 ccnt;			/* Command count. */
116*84d9c625SLionel Sambuc 	u_long	 q_ccnt;		/* Quit or ZZ command count. */
117*84d9c625SLionel Sambuc 
118*84d9c625SLionel Sambuc 					/* Screen's: */
119*84d9c625SLionel Sambuc 	size_t	 rows;			/* 1-N: number of rows. */
120*84d9c625SLionel Sambuc 	size_t	 cols;			/* 1-N: number of columns. */
121*84d9c625SLionel Sambuc 	size_t	 t_rows;		/* 1-N: cur number of text rows. */
122*84d9c625SLionel Sambuc 	size_t	 t_maxrows;		/* 1-N: max number of text rows. */
123*84d9c625SLionel Sambuc 	size_t	 t_minrows;		/* 1-N: min number of text rows. */
124*84d9c625SLionel Sambuc 	size_t	 coff;			/* 0-N: screen col offset in display. */
125*84d9c625SLionel Sambuc 	size_t	 roff;			/* 0-N: screen row offset in display. */
126*84d9c625SLionel Sambuc 
127*84d9c625SLionel Sambuc 					/* Cursor's: */
128*84d9c625SLionel Sambuc 	db_recno_t	 lno;			/* 1-N: file line. */
129*84d9c625SLionel Sambuc 	size_t	 cno;			/* 0-N: file character in line. */
130*84d9c625SLionel Sambuc 
131*84d9c625SLionel Sambuc 	size_t	 rcm;			/* Vi: 0-N: Most attractive column. */
132*84d9c625SLionel Sambuc 
133*84d9c625SLionel Sambuc #define	L_ADDED		0		/* Added lines. */
134*84d9c625SLionel Sambuc #define	L_CHANGED	1		/* Changed lines. */
135*84d9c625SLionel Sambuc #define	L_DELETED	2		/* Deleted lines. */
136*84d9c625SLionel Sambuc #define	L_JOINED	3		/* Joined lines. */
137*84d9c625SLionel Sambuc #define	L_MOVED		4		/* Moved lines. */
138*84d9c625SLionel Sambuc #define	L_SHIFT		5		/* Shift lines. */
139*84d9c625SLionel Sambuc #define	L_YANKED	6		/* Yanked lines. */
140*84d9c625SLionel Sambuc 	db_recno_t	 rptlchange;		/* Ex/vi: last L_CHANGED lno. */
141*84d9c625SLionel Sambuc 	db_recno_t	 rptlines[L_YANKED + 1];/* Ex/vi: lines changed by last op. */
142*84d9c625SLionel Sambuc 
143*84d9c625SLionel Sambuc 	TEXTH	 tiq;			/* Ex/vi: text input queue. */
144*84d9c625SLionel Sambuc 
145*84d9c625SLionel Sambuc 	SCRIPT	*script;		/* Vi: script mode information .*/
146*84d9c625SLionel Sambuc 
147*84d9c625SLionel Sambuc 	db_recno_t	 defscroll;	/* Vi: ^D, ^U scroll information. */
148*84d9c625SLionel Sambuc 
149*84d9c625SLionel Sambuc 					/* Display character. */
150*84d9c625SLionel Sambuc 	u_char	 cname[MAX_CHARACTER_COLUMNS + 1];
151*84d9c625SLionel Sambuc 	size_t	 clen;			/* Length of display character. */
152*84d9c625SLionel Sambuc 
153*84d9c625SLionel Sambuc 	enum {				/* Vi editor mode. */
154*84d9c625SLionel Sambuc 	    SM_APPEND = 0, SM_CHANGE, SM_COMMAND, SM_INSERT,
155*84d9c625SLionel Sambuc 	    SM_REPLACE } showmode;
156*84d9c625SLionel Sambuc 
157*84d9c625SLionel Sambuc 	void	*ex_private;		/* Ex private area. */
158*84d9c625SLionel Sambuc 	void	*vi_private;		/* Vi private area. */
159*84d9c625SLionel Sambuc 	void	*perl_private;		/* Perl private area. */
160*84d9c625SLionel Sambuc 	void	*cl_private;		/* Curses private area. */
161*84d9c625SLionel Sambuc 
162*84d9c625SLionel Sambuc 	CONV	conv;
163*84d9c625SLionel Sambuc 
164*84d9c625SLionel Sambuc 	struct _log_state  state;	/* State during log traversal. */
165*84d9c625SLionel Sambuc 
166*84d9c625SLionel Sambuc /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
167*84d9c625SLionel Sambuc 	char	*alt_name;		/* Ex/vi: alternate file name. */
168*84d9c625SLionel Sambuc 
169*84d9c625SLionel Sambuc 	ARG_CHAR_T	 at_lbuf;	/* Ex/vi: Last executed at buffer. */
170*84d9c625SLionel Sambuc 
171*84d9c625SLionel Sambuc 					/* Ex/vi: re_compile flags. */
172*84d9c625SLionel Sambuc #define	RE_WSTART	L("[[:<:]]")	/* Ex/vi: not-in-word search pattern. */
173*84d9c625SLionel Sambuc #define	RE_WSTOP	L("[[:>:]]")
174*84d9c625SLionel Sambuc #define RE_WSTART_LEN	(sizeof(RE_WSTART)/sizeof(CHAR_T)-1)
175*84d9c625SLionel Sambuc #define RE_WSTOP_LEN	(sizeof(RE_WSTOP)/sizeof(CHAR_T)-1)
176*84d9c625SLionel Sambuc 					/* Ex/vi: flags to search routines. */
177*84d9c625SLionel Sambuc #define	SEARCH_CSCOPE	0x000001	/* Search for a cscope pattern. */
178*84d9c625SLionel Sambuc #define	SEARCH_CSEARCH	0x000002	/* Compile search replacement. */
179*84d9c625SLionel Sambuc #define	SEARCH_CSUBST	0x000004	/* Compile substitute replacement. */
180*84d9c625SLionel Sambuc #define	SEARCH_EOL	0x000008	/* Offset past EOL is okay. */
181*84d9c625SLionel Sambuc #define	SEARCH_EXTEND	0x000010	/* Extended RE. */
182*84d9c625SLionel Sambuc #define	SEARCH_FIRST	0x000020	/* Search from the first line. */
183*84d9c625SLionel Sambuc #define	SEARCH_IC	0x000040	/* Ignore case. */
184*84d9c625SLionel Sambuc #define	SEARCH_ICL	0x000080	/* Ignore case. */
185*84d9c625SLionel Sambuc #define	SEARCH_INCR	0x000100	/* Search incrementally. */
186*84d9c625SLionel Sambuc #define	SEARCH_LITERAL	0x000200	/* Literal string. */
187*84d9c625SLionel Sambuc #define	SEARCH_MSG	0x000400	/* Display search messages. */
188*84d9c625SLionel Sambuc #define	SEARCH_NOOPT	0x000800	/* Ignore edit options. */
189*84d9c625SLionel Sambuc #define	SEARCH_PARSE	0x001000	/* Parse the search pattern. */
190*84d9c625SLionel Sambuc #define	SEARCH_SET	0x002000	/* Set search direction. */
191*84d9c625SLionel Sambuc #define	SEARCH_TAG	0x004000	/* Search for a tag pattern. */
192*84d9c625SLionel Sambuc #define	SEARCH_WMSG	0x008000	/* Display search-wrapped messages. */
193*84d9c625SLionel Sambuc #define	SEARCH_WRAP	0x010000	/* Wrap past sof/eof. */
194*84d9c625SLionel Sambuc 
195*84d9c625SLionel Sambuc 					/* Ex/vi: RE information. */
196*84d9c625SLionel Sambuc 	dir_t	 searchdir;		/* Last file search direction. */
197*84d9c625SLionel Sambuc 	regex_t	 re_c;			/* Search RE: compiled form. */
198*84d9c625SLionel Sambuc 	CHAR_T	*re;			/* Search RE: uncompiled form. */
199*84d9c625SLionel Sambuc 	size_t	 re_len;		/* Search RE: uncompiled length. */
200*84d9c625SLionel Sambuc 	regex_t	 subre_c;		/* Substitute RE: compiled form. */
201*84d9c625SLionel Sambuc 	CHAR_T	*subre;			/* Substitute RE: uncompiled form. */
202*84d9c625SLionel Sambuc 	size_t	 subre_len;		/* Substitute RE: uncompiled length). */
203*84d9c625SLionel Sambuc 	CHAR_T	*repl;			/* Substitute replacement. */
204*84d9c625SLionel Sambuc 	size_t	 repl_len;		/* Substitute replacement length.*/
205*84d9c625SLionel Sambuc 	size_t	*newl;			/* Newline offset array. */
206*84d9c625SLionel Sambuc 	size_t	 newl_len;		/* Newline array size. */
207*84d9c625SLionel Sambuc 	size_t	 newl_cnt;		/* Newlines in replacement. */
208*84d9c625SLionel Sambuc 	u_int8_t c_suffix;		/* Edcompatible 'c' suffix value. */
209*84d9c625SLionel Sambuc 	u_int8_t g_suffix;		/* Edcompatible 'g' suffix value. */
210*84d9c625SLionel Sambuc 
211*84d9c625SLionel Sambuc 	OPTION	 opts[O_OPTIONCOUNT];	/* Ex/vi: Options. */
212*84d9c625SLionel Sambuc 
213*84d9c625SLionel Sambuc /*
214*84d9c625SLionel Sambuc  * Screen flags.
215*84d9c625SLionel Sambuc  *
216*84d9c625SLionel Sambuc  * Editor screens.
217*84d9c625SLionel Sambuc  */
218*84d9c625SLionel Sambuc #define	SC_EX		0x00000001	/* Ex editor. */
219*84d9c625SLionel Sambuc #define	SC_VI		0x00000002	/* Vi editor. */
220*84d9c625SLionel Sambuc 
221*84d9c625SLionel Sambuc /*
222*84d9c625SLionel Sambuc  * Screen formatting flags, first major, then minor.
223*84d9c625SLionel Sambuc  *
224*84d9c625SLionel Sambuc  * SC_SCR_EX
225*84d9c625SLionel Sambuc  *	Ex screen, i.e. cooked mode.
226*84d9c625SLionel Sambuc  * SC_SCR_VI
227*84d9c625SLionel Sambuc  *	Vi screen, i.e. raw mode.
228*84d9c625SLionel Sambuc  * SC_SCR_EXWROTE
229*84d9c625SLionel Sambuc  *	The editor had to write on the screen behind curses' back, and we can't
230*84d9c625SLionel Sambuc  *	let curses change anything until the user agrees, e.g. entering the
231*84d9c625SLionel Sambuc  *	commands :!utility followed by :set.  We have to switch back into the
232*84d9c625SLionel Sambuc  *	vi "editor" to read the user's command input, but we can't touch the
233*84d9c625SLionel Sambuc  *	rest of the screen because it's known to be wrong.
234*84d9c625SLionel Sambuc  * SC_SCR_REFORMAT
235*84d9c625SLionel Sambuc  *	The expected presentation of the lines on the screen have changed,
236*84d9c625SLionel Sambuc  *	requiring that the intended screen lines be recalculated.  Implies
237*84d9c625SLionel Sambuc  *	SC_SCR_REDRAW.
238*84d9c625SLionel Sambuc  * SC_SCR_REDRAW
239*84d9c625SLionel Sambuc  *	The screen doesn't correctly represent the file; repaint it.  Note,
240*84d9c625SLionel Sambuc  *	setting SC_SCR_REDRAW in the current window causes *all* windows to
241*84d9c625SLionel Sambuc  *	be repainted.
242*84d9c625SLionel Sambuc  * SC_SCR_CENTER
243*84d9c625SLionel Sambuc  *	If the current line isn't already on the screen, center it.
244*84d9c625SLionel Sambuc  * SC_SCR_TOP
245*84d9c625SLionel Sambuc  *	If the current line isn't already on the screen, put it at the to@.
246*84d9c625SLionel Sambuc  */
247*84d9c625SLionel Sambuc #define	SC_SCR_EX	0x00000004	/* Screen is in ex mode. */
248*84d9c625SLionel Sambuc #define	SC_SCR_VI	0x00000008	/* Screen is in vi mode. */
249*84d9c625SLionel Sambuc #define	SC_SCR_EXWROTE	0x00000010	/* Ex overwrite: see comment above. */
250*84d9c625SLionel Sambuc #define	SC_SCR_REFORMAT	0x00000020	/* Reformat (refresh). */
251*84d9c625SLionel Sambuc #define	SC_SCR_REDRAW	0x00000040	/* Refresh. */
252*84d9c625SLionel Sambuc 
253*84d9c625SLionel Sambuc #define	SC_SCR_CENTER	0x00000080	/* Center the line if not visible. */
254*84d9c625SLionel Sambuc #define	SC_SCR_TOP	0x00000100	/* Top the line if not visible. */
255*84d9c625SLionel Sambuc 
256*84d9c625SLionel Sambuc /* Screen/file changes. */
257*84d9c625SLionel Sambuc #define	SC_EXIT		0x00000200	/* Exiting (not forced). */
258*84d9c625SLionel Sambuc #define	SC_EXIT_FORCE	0x00000400	/* Exiting (forced). */
259*84d9c625SLionel Sambuc #define	SC_FSWITCH	0x00000800	/* Switch underlying files. */
260*84d9c625SLionel Sambuc #define	SC_SSWITCH	0x00001000	/* Switch screens. */
261*84d9c625SLionel Sambuc 
262*84d9c625SLionel Sambuc #define	SC_ARGNOFREE	0x00002000	/* Argument list wasn't allocated. */
263*84d9c625SLionel Sambuc #define	SC_ARGRECOVER	0x00004000	/* Argument list is recovery files. */
264*84d9c625SLionel Sambuc #define	SC_AT_SET	0x00008000	/* Last at buffer set. */
265*84d9c625SLionel Sambuc #define	SC_COMEDIT	0x00010000	/* Colon command-line edit window. */
266*84d9c625SLionel Sambuc #define	SC_EX_GLOBAL	0x00020000	/* Ex: executing a global command. */
267*84d9c625SLionel Sambuc #define	SC_EX_SILENT	0x00040000	/* Ex: batch script. */
268*84d9c625SLionel Sambuc #define	SC_EX_WAIT_NO	0x00080000	/* Ex: don't wait for the user. */
269*84d9c625SLionel Sambuc #define	SC_EX_WAIT_YES	0x00100000	/* Ex:    do wait for the user. */
270*84d9c625SLionel Sambuc #define	SC_READONLY	0x00200000	/* Persistent readonly state. */
271*84d9c625SLionel Sambuc #define	SC_RE_SEARCH	0x00400000	/* Search RE has been compiled. */
272*84d9c625SLionel Sambuc #define	SC_RE_SUBST	0x00800000	/* Substitute RE has been compiled. */
273*84d9c625SLionel Sambuc #define	SC_SCRIPT	0x01000000	/* Shell script window. */
274*84d9c625SLionel Sambuc #define	SC_STATUS	0x02000000	/* Welcome message. */
275*84d9c625SLionel Sambuc #define	SC_STATUS_CNT	0x04000000	/* Welcome message plus file count. */
276*84d9c625SLionel Sambuc #define	SC_TINPUT	0x08000000	/* Doing text input. */
277*84d9c625SLionel Sambuc #define	SC_TINPUT_INFO	0x10000000	/* Doing text input on info line. */
278*84d9c625SLionel Sambuc #define SC_CONV_ERROR	0x20000000	/* Met with a conversion error. */
279*84d9c625SLionel Sambuc 	u_int32_t flags;
280*84d9c625SLionel Sambuc 
281*84d9c625SLionel Sambuc 	int	    db_error;		/* Return code from db function. */
282*84d9c625SLionel Sambuc };
283