xref: /freebsd/contrib/nvi/common/screen.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1 /*-
2  * Copyright (c) 1992, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  * Copyright (c) 1992, 1993, 1994, 1995, 1996
5  *	Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  *
9  *	$Id: screen.h,v 10.26 2011/12/12 22:31:36 zy Exp $
10  */
11 
12 /*
13  * There are minimum values that vi has to have to display a screen.  The row
14  * minimum is fixed at 1 (the svi code can share a line between the text line
15  * and the colon command/message line).  Column calculation is a lot trickier.
16  * For example, you have to have enough columns to display the line number,
17  * not to mention guaranteeing that tabstop and shiftwidth values are smaller
18  * than the current column value.  It's simpler to have a fixed value and not
19  * worry about it.
20  *
21  * XXX
22  * MINIMUM_SCREEN_COLS is almost certainly wrong.
23  */
24 #define	MINIMUM_SCREEN_ROWS	 1
25 #define	MINIMUM_SCREEN_COLS	20
26 
27 /*
28  * SCR --
29  *	The screen structure.  To the extent possible, all screen information
30  *	is stored in the various private areas.  The only information here
31  *	is used by global routines or is shared by too many screens.
32  */
33 struct _scr {
34 /* INITIALIZED AT SCREEN CREATE. */
35 	TAILQ_ENTRY(_scr) q;		/* Screens. */
36 
37 	int	 id;			/* Screen id #. */
38 	int	 refcnt;		/* Reference count. */
39 
40 	GS	*gp;			/* Pointer to global area. */
41 	SCR	*nextdisp;		/* Next display screen. */
42 	SCR	*ccl_parent;		/* Colon command-line parent screen. */
43 	EXF	*ep;			/* Screen's current EXF structure. */
44 
45 	FREF	*frp;			/* FREF being edited. */
46 	char	**argv;			/* NULL terminated file name array. */
47 	char	**cargv;		/* Current file name. */
48 
49 	u_long	 ccnt;			/* Command count. */
50 	u_long	 q_ccnt;		/* Quit or ZZ command count. */
51 
52 					/* Screen's: */
53 	size_t	 rows;			/* 1-N: number of rows. */
54 	size_t	 cols;			/* 1-N: number of columns. */
55 	size_t	 t_rows;		/* 1-N: cur number of text rows. */
56 	size_t	 t_maxrows;		/* 1-N: max number of text rows. */
57 	size_t	 t_minrows;		/* 1-N: min number of text rows. */
58 	size_t	 coff;			/* 0-N: screen col offset in display. */
59 	size_t	 roff;			/* 0-N: screen row offset in display. */
60 
61 					/* Cursor's: */
62 	recno_t	 lno;			/* 1-N: file line. */
63 	size_t	 cno;			/* 0-N: file character in line. */
64 
65 	size_t	 rcm;			/* Vi: 0-N: Most attractive column. */
66 
67 #define	L_ADDED		0		/* Added lines. */
68 #define	L_CHANGED	1		/* Changed lines. */
69 #define	L_DELETED	2		/* Deleted lines. */
70 #define	L_JOINED	3		/* Joined lines. */
71 #define	L_MOVED		4		/* Moved lines. */
72 #define	L_SHIFT		5		/* Shift lines. */
73 #define	L_YANKED	6		/* Yanked lines. */
74 	recno_t	 rptlchange;		/* Ex/vi: last L_CHANGED lno. */
75 	recno_t	 rptlines[L_YANKED + 1];/* Ex/vi: lines changed by last op. */
76 
77 	TEXTH	 tiq[1];		/* Ex/vi: text input queue. */
78 
79 	SCRIPT	*script;		/* Vi: script mode information .*/
80 
81 	recno_t	 defscroll;		/* Vi: ^D, ^U scroll information. */
82 
83 					/* Display character. */
84 	char	 cname[MAX_CHARACTER_COLUMNS + 1];
85 	size_t	 clen;			/* Length of display character. */
86 	ARG_CHAR_T lastc;		/* The last display character. */
87 
88 	enum {				/* Vi editor mode. */
89 	    SM_APPEND = 0, SM_CHANGE, SM_COMMAND, SM_INSERT,
90 	    SM_REPLACE } showmode;
91 
92 	void	*ex_private;		/* Ex private area. */
93 	void	*vi_private;		/* Vi private area. */
94 	void	*cl_private;		/* Curses private area. */
95 
96 	CONV	 conv;			/* Conversion functions. */
97 	CONVWIN	 cw;			/* Conversion buffer. */
98 
99 /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
100 	char	*alt_name;		/* Ex/vi: alternate file name. */
101 
102 	CHAR_T	 at_lbuf;		/* Ex/vi: Last executed at buffer. */
103 
104 					/* Ex/vi: re_compile flags. */
105 #define	RE_C_CSCOPE	0x0001		/* Compile cscope pattern. */
106 #define	RE_C_SEARCH	0x0002		/* Compile search replacement. */
107 #define	RE_C_SILENT	0x0004		/* No error messages. */
108 #define	RE_C_SUBST	0x0008		/* Compile substitute replacement. */
109 #define	RE_C_TAG	0x0010		/* Compile ctag pattern. */
110 
111 #define	RE_WSTART	L("[[:<:]]")	/* Ex/vi: not-in-word search pattern. */
112 #define	RE_WSTOP	L("[[:>:]]")
113 #define RE_WSTART_LEN	(SIZE(RE_WSTART) - 1)
114 #define RE_WSTOP_LEN	(SIZE(RE_WSTOP) - 1)
115 					/* Ex/vi: flags to search routines. */
116 #define	SEARCH_CSCOPE	0x0001		/* Search for a cscope pattern. */
117 #define	SEARCH_EOL	0x0002		/* Offset past EOL is okay. */
118 #define	SEARCH_FILE	0x0004		/* Search the entire file. */
119 #define	SEARCH_INCR	0x0008		/* Search incrementally. */
120 #define	SEARCH_MSG	0x0010		/* Display search messages. */
121 #define	SEARCH_PARSE	0x0020		/* Parse the search pattern. */
122 #define	SEARCH_SET	0x0040		/* Set search direction. */
123 #define	SEARCH_TAG	0x0080		/* Search for a tag pattern. */
124 #define	SEARCH_WMSG	0x0100		/* Display search-wrapped messages. */
125 
126 					/* Ex/vi: RE information. */
127 	dir_t	 searchdir;		/* Last file search direction. */
128 	regex_t	 re_c;			/* Search RE: compiled form. */
129 	CHAR_T	*re;			/* Search RE: uncompiled form. */
130 	size_t	 re_len;		/* Search RE: uncompiled length. */
131 	regex_t	 subre_c;		/* Substitute RE: compiled form. */
132 	CHAR_T	*subre;			/* Substitute RE: uncompiled form. */
133 	size_t	 subre_len;		/* Substitute RE: uncompiled length). */
134 	CHAR_T	*repl;			/* Substitute replacement. */
135 	size_t	 repl_len;		/* Substitute replacement length.*/
136 	size_t	*newl;			/* Newline offset array. */
137 	size_t	 newl_len;		/* Newline array size. */
138 	size_t	 newl_cnt;		/* Newlines in replacement. */
139 	u_int8_t c_suffix;		/* Edcompatible 'c' suffix value. */
140 	u_int8_t g_suffix;		/* Edcompatible 'g' suffix value. */
141 
142 	OPTION	 opts[O_OPTIONCOUNT];	/* Ex/vi: Options. */
143 
144 /*
145  * Screen flags.
146  *
147  * Editor screens.
148  */
149 #define	SC_EX		0x00000001	/* Ex editor. */
150 #define	SC_VI		0x00000002	/* Vi editor. */
151 
152 /*
153  * Screen formatting flags, first major, then minor.
154  *
155  * SC_SCR_EX
156  *	Ex screen, i.e. cooked mode.
157  * SC_SCR_VI
158  *	Vi screen, i.e. raw mode.
159  * SC_SCR_EXWROTE
160  *	The editor had to write on the screen behind curses' back, and we can't
161  *	let curses change anything until the user agrees, e.g. entering the
162  *	commands :!utility followed by :set.  We have to switch back into the
163  *	vi "editor" to read the user's command input, but we can't touch the
164  *	rest of the screen because it's known to be wrong.
165  * SC_SCR_REFORMAT
166  *	The expected presentation of the lines on the screen have changed,
167  *	requiring that the intended screen lines be recalculated.  Implies
168  *	SC_SCR_REDRAW.
169  * SC_SCR_REDRAW
170  *	The screen doesn't correctly represent the file; repaint it.  Note,
171  *	setting SC_SCR_REDRAW in the current window causes *all* windows to
172  *	be repainted.
173  * SC_SCR_CENTER
174  *	If the current line isn't already on the screen, center it.
175  * SC_SCR_TOP
176  *	If the current line isn't already on the screen, put it at the to@.
177  */
178 #define	SC_SCR_EX	0x00000004	/* Screen is in ex mode. */
179 #define	SC_SCR_VI	0x00000008	/* Screen is in vi mode. */
180 #define	SC_SCR_EXWROTE	0x00000010	/* Ex overwrite: see comment above. */
181 #define	SC_SCR_REFORMAT	0x00000020	/* Reformat (refresh). */
182 #define	SC_SCR_REDRAW	0x00000040	/* Refresh. */
183 
184 #define	SC_SCR_CENTER	0x00000080	/* Center the line if not visible. */
185 #define	SC_SCR_TOP	0x00000100	/* Top the line if not visible. */
186 
187 /* Screen/file changes. */
188 #define	SC_EXIT		0x00000200	/* Exiting (not forced). */
189 #define	SC_EXIT_FORCE	0x00000400	/* Exiting (forced). */
190 #define	SC_FSWITCH	0x00000800	/* Switch underlying files. */
191 #define	SC_SSWITCH	0x00001000	/* Switch screens. */
192 
193 #define	SC_ARGNOFREE	0x00002000	/* Argument list wasn't allocated. */
194 #define	SC_ARGRECOVER	0x00004000	/* Argument list is recovery files. */
195 #define	SC_AT_SET	0x00008000	/* Last at buffer set. */
196 #define	SC_COMEDIT	0x00010000	/* Colon command-line edit window. */
197 #define	SC_EX_GLOBAL	0x00020000	/* Ex: executing a global command. */
198 #define	SC_EX_SILENT	0x00040000	/* Ex: batch script. */
199 #define	SC_EX_WAIT_NO	0x00080000	/* Ex: don't wait for the user. */
200 #define	SC_EX_WAIT_YES	0x00100000	/* Ex:    do wait for the user. */
201 #define	SC_READONLY	0x00200000	/* Persistent readonly state. */
202 #define	SC_RE_SEARCH	0x00400000	/* Search RE has been compiled. */
203 #define	SC_RE_SUBST	0x00800000	/* Substitute RE has been compiled. */
204 #define	SC_SCRIPT	0x01000000	/* Shell script window. */
205 #define	SC_STATUS	0x02000000	/* Welcome message. */
206 #define	SC_STATUS_CNT	0x04000000	/* Welcome message plus file count. */
207 #define	SC_TINPUT	0x08000000	/* Doing text input. */
208 #define	SC_TINPUT_INFO	0x10000000	/* Doing text input on info line. */
209 #define SC_CONV_ERROR	0x20000000	/* Met with a conversion error. */
210 	u_int32_t flags;
211 };
212