This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / usr.bin / vi / screen.h
CommitLineData
1e64b3ba
JH
1/*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)screen.h 8.81 (Berkeley) 12/29/93
34 */
35
36/*
37 * There are minimum values that vi has to have to display a screen. The
38 * row minimum is fixed at 1 line for the text, and 1 line for any error
39 * messages. The column calculation is a lot trickier. For example, you
40 * have to have enough columns to display the line number, not to mention
41 * guaranteeing that tabstop and shiftwidth values are smaller than the
42 * current column value. It's a lot simpler to have a fixed value and not
43 * worry about it.
44 *
45 * XXX
46 * MINIMUM_SCREEN_COLS is probably wrong.
47 */
48#define MINIMUM_SCREEN_ROWS 2
49#define MINIMUM_SCREEN_COLS 20
50 /* Line operations. */
51enum operation { LINE_APPEND, LINE_DELETE, LINE_INSERT, LINE_RESET };
52 /* Position values. */
53enum position { P_BOTTOM, P_FILL, P_MIDDLE, P_TOP };
54
55/*
56 * Structure for holding file references. Each SCR structure contains a
57 * linked list of these (the user's argument list) as well as pointers to
58 * the current and previous files. The structure contains the name of the
59 * file, along with the information that follows the name. A file has up
60 * to three "names". The tname field is the path of the temporary backing
61 * file, if any. The name field is the name the user originally used to
62 * specify the file to be edited. The cname field is the changed name if
63 * the user changed the name.
64 *
65 * Note that the read-only bit follows the file name, not the file itself.
66 *
67 * XXX
68 * The mtime field should be a struct timespec, but time_t is more portable.
69 */
70struct _fref {
71 CIRCLEQ_ENTRY(_fref) q; /* Linked list of file references. */
72 char *cname; /* Changed file name. */
73 char *name; /* File name. */
74 char *tname; /* Temporary file name. */
75
76 recno_t lno; /* 1-N: file cursor line. */
77 size_t cno; /* 0-N: file cursor column. */
78 time_t mtime; /* Last modification time. */
79
80#define FR_CHANGEWRITE 0x001 /* Name changed and then written. */
81#define FR_CURSORSET 0x002 /* If lno/cno valid. */
82#define FR_EDITED 0x004 /* If the file was ever edited. */
83#define FR_IGNORE 0x008 /* File isn't part of argument list. */
84#define FR_NEWFILE 0x010 /* File doesn't really exist yet. */
85#define FR_RDONLY 0x020 /* File is read-only. */
86 u_int flags;
87};
88
89/*
90 * There's a file name hierarchy -- if the user has changed the name, we
91 * use it, otherwise, we use the original name, if there was one, othewise
92 * use the temporary name.
93 */
94#define FILENAME(frp) \
95 ((frp)->cname != NULL) ? (frp)->cname : \
96 ((frp)->name != NULL) ? (frp)->name : (frp)->tname
97
98/*
99 * SCR --
100 * The screen structure. To the extent possible, all screen information
101 * is stored in the various private areas. The only information here
102 * is used by global routines or is shared by too many screens.
103 */
104struct _scr {
105/* INITIALIZED AT SCREEN CREATE. */
106 CIRCLEQ_ENTRY(_scr) q; /* Screens. */
107
108 GS *gp; /* Pointer to global area. */
109
110 SCR *nextdisp; /* Next display screen. */
111
112 EXF *ep; /* Screen's current EXF structure. */
113
114 MSGH msgq; /* Message list. */
115 /* FREF list. */
116 CIRCLEQ_HEAD(_frefh, _fref) frefq;
117 FREF *frp; /* FREF being edited. */
118 FREF *a_frp; /* Last argument list FREF edited. */
119 FREF *p_frp; /* Last FREF edited. */
120
121 u_long ccnt; /* Command count. */
122 u_long q_ccnt; /* Quit or ZZ command count. */
123
124 /* Screen's: */
125 size_t rows; /* 1-N: number of rows. */
126 size_t cols; /* 1-N: number of columns. */
127 size_t woff; /* 0-N: row offset in screen. */
128 size_t t_rows; /* 1-N: cur number of text rows. */
129 size_t t_maxrows; /* 1-N: max number of text rows. */
130 size_t t_minrows; /* 1-N: min number of text rows. */
131
132 /* Cursor's: */
133 recno_t lno; /* 1-N: file line. */
134 size_t cno; /* 0-N: file character in line. */
135
136 size_t rcm; /* Vi: 0-N: Column suck. */
137#define RCM_FNB 0x01 /* Column suck: first non-blank. */
138#define RCM_LAST 0x02 /* Column suck: last. */
139 u_int rcmflags;
140
141#define L_ADDED 0 /* Added lines. */
142#define L_CHANGED 1 /* Changed lines. */
143#define L_COPIED 2 /* Copied lines. */
144#define L_DELETED 3 /* Deleted lines. */
145#define L_JOINED 4 /* Joined lines. */
146#define L_MOVED 5 /* Moved lines. */
147#define L_PUT 6 /* Put lines. */
148#define L_LSHIFT 7 /* Left shift lines. */
149#define L_RSHIFT 8 /* Right shift lines. */
150#define L_YANKED 9 /* Yanked lines. */
151 recno_t rptlines[L_YANKED + 1];/* Ex/vi: lines changed by last op. */
152
153 FILE *stdfp; /* Ex output file pointer. */
154
155 char *if_name; /* Ex input file name, for messages. */
156 recno_t if_lno; /* Ex input file line, for messages. */
157
158 fd_set rdfd; /* Ex/vi: read fd select mask. */
159
160 TEXTH tiq; /* Ex/vi: text input queue. */
161
162 SCRIPT *script; /* Vi: script mode information .*/
163
164 char const *time_msg; /* ITIMER_REAL message. */
165 struct itimerval time_value; /* ITIMER_REAL saved value. */
166 struct sigaction time_handler; /* ITIMER_REAL saved handler. */
167
168 void *vi_private; /* Vi private area. */
169 void *ex_private; /* Ex private area. */
170 void *svi_private; /* Vi curses screen private area. */
171 void *xaw_private; /* Vi XAW screen private area. */
172
173/* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
174 char *alt_name; /* Ex/vi: alternate file name. */
175
176 /* Ex/vi: search/substitute info. */
177 regex_t sre; /* Last search RE. */
178 regex_t subre; /* Last substitute RE. */
179 enum direction searchdir; /* File search direction. */
180 enum cdirection csearchdir; /* Character search direction. */
181 CHAR_T lastckey; /* Last search character. */
182 regmatch_t *match; /* Substitute match array. */
183 size_t matchsize; /* Substitute match array size. */
184 char *repl; /* Substitute replacement. */
185 size_t repl_len; /* Substitute replacement length.*/
186 size_t *newl; /* Newline offset array. */
187 size_t newl_len; /* Newline array size. */
188 size_t newl_cnt; /* Newlines in replacement. */
189
190 u_int saved_vi_mode; /* Saved vi display type. */
191
192 OPTION opts[O_OPTIONCOUNT]; /* Options. */
193
194/*
195 * SCREEN SUPPORT ROUTINES.
196 *
197 * A SCR * MUST be the first argument to these routines.
198 */
199 /* Ring the screen bell. */
200 void (*s_bell) __P((SCR *));
201 /* Background the screen. */
202 int (*s_bg) __P((SCR *));
203 /* Put up a busy message. */
204 int (*s_busy) __P((SCR *, char const *));
205 /* Change a screen line. */
206 int (*s_change) __P((SCR *, EXF *, recno_t, enum operation));
207 /* Return column close to specified. */
208 size_t (*s_chposition) __P((SCR *, EXF *, recno_t, size_t));
209 /* Clear the screen. */
210 int (*s_clear) __P((SCR *));
211 /* Return the logical cursor column. */
212 int (*s_column) __P((SCR *, EXF *, size_t *));
213 enum confirm /* Confirm an action with the user. */
214 (*s_confirm) __P((SCR *, EXF *, MARK *, MARK *));
215 /* Move down the screen. */
216 int (*s_down) __P((SCR *, EXF *, MARK *, recno_t, int));
217 /* Edit a file. */
218 int (*s_edit) __P((SCR *, EXF *));
219 /* End a screen. */
220 int (*s_end) __P((SCR *));
221 /* Run a single ex command. */
222 int (*s_ex_cmd) __P((SCR *, EXF *, EXCMDARG *, MARK *));
223 /* Run user's ex commands. */
224 int (*s_ex_run) __P((SCR *, EXF *, MARK *));
225 /* Screen's ex write function. */
226 int (*s_ex_write) __P((void *, const char *, int));
227 /* Foreground the screen. */
228 int (*s_fg) __P((SCR *, CHAR_T *));
229 /* Fill the screen's map. */
230 int (*s_fill) __P((SCR *, EXF *, recno_t, enum position));
231 enum input /* Get a line from the user. */
232 (*s_get) __P((SCR *, EXF *, TEXTH *, int, u_int));
233 enum input /* Get a key from the user. */
234 (*s_key_read) __P((SCR *, int *, struct timeval *));
235 /* Tell the screen an option changed. */
236 int (*s_optchange) __P((SCR *, int));
237 /* Return column at screen position. */
238 int (*s_position) __P((SCR *, EXF *,
239 MARK *, u_long, enum position));
240 /* Change the absolute screen size. */
241 int (*s_rabs) __P((SCR *, long));
242 /* Refresh the screen. */
243 int (*s_refresh) __P((SCR *, EXF *));
244 /* Return column close to last char. */
245 size_t (*s_relative) __P((SCR *, EXF *, recno_t));
246 /* Change the relative screen size. */
247 int (*s_rrel) __P((SCR *, long));
248 /* Split the screen. */
249 int (*s_split) __P((SCR *, ARGS *[]));
250 /* Suspend the screen. */
251 int (*s_suspend) __P((SCR *));
252 /* Move up the screen. */
253 int (*s_up) __P((SCR *, EXF *, MARK *, recno_t, int));
254
255/* Editor screens. */
256#define S_EX 0x0000001 /* Ex screen. */
257#define S_VI_CURSES 0x0000002 /* Vi: curses screen. */
258#define S_VI_XAW 0x0000004 /* Vi: Athena widgets screen. */
259
260#define IN_EX_MODE(sp) /* If in ex mode. */ \
261 (F_ISSET(sp, S_EX))
262#define IN_VI_MODE(sp) /* If in vi mode. */ \
263 (F_ISSET(sp, S_VI_CURSES | S_VI_XAW))
264#define S_SCREENS /* Screens. */ \
265 (S_EX | S_VI_CURSES | S_VI_XAW)
266
267/* Major screen/file changes. */
268#define S_EXIT 0x0000008 /* Exiting (not forced). */
269#define S_EXIT_FORCE 0x0000010 /* Exiting (forced). */
270#define S_FSWITCH 0x0000020 /* Switch files. */
271#define S_SSWITCH 0x0000040 /* Switch screens. */
272#define S_MAJOR_CHANGE /* Screen or file changes. */ \
273 (S_EXIT | S_EXIT_FORCE | S_FSWITCH | S_SSWITCH)
274
275#define S_BELLSCHED 0x0000080 /* Bell scheduled. */
276#define S_CONTINUE 0x0000100 /* Need to ask the user to continue. */
277#define S_EXSILENT 0x0000200 /* Ex batch script. */
278#define S_GLOBAL 0x0000400 /* Doing a global command. */
279#define S_INPUT 0x0000800 /* Doing text input. */
280#define S_INTERRUPTED 0x0001000 /* If have been interrupted. */
281#define S_INTERRUPTIBLE 0x0002000 /* If can be interrupted. */
282#define S_REDRAW 0x0004000 /* Redraw the screen. */
283#define S_REFORMAT 0x0008000 /* Reformat the screen. */
284#define S_REFRESH 0x0010000 /* Refresh the screen. */
285#define S_RENUMBER 0x0020000 /* Renumber the screen. */
286#define S_RESIZE 0x0040000 /* Resize the screen. */
287#define S_SCRIPT 0x0080000 /* Window is a shell script. */
288#define S_SRE_SET 0x0100000 /* The search RE has been set. */
289#define S_SUBRE_SET 0x0200000 /* The substitute RE has been set. */
290#define S_TIMER_SET 0x0400000 /* If a busy timer is running. */
291#define S_UPDATE_MODE 0x0800000 /* Don't repaint modeline. */
292 u_int flags;
293};
294
295/* Generic routines to start/stop a screen. */
296int screen_end __P((SCR *));
297int screen_init __P((SCR *, SCR **, u_int));
298
299/* Public interfaces to the underlying screens. */
300int ex_screen_copy __P((SCR *, SCR *));
301int ex_screen_end __P((SCR *));
302int ex_screen_init __P((SCR *));
303int sex_screen_copy __P((SCR *, SCR *));
304int sex_screen_end __P((SCR *));
305int sex_screen_init __P((SCR *));
306int svi_screen_copy __P((SCR *, SCR *));
307int svi_screen_end __P((SCR *));
308int svi_screen_init __P((SCR *));
309int v_screen_copy __P((SCR *, SCR *));
310int v_screen_end __P((SCR *));
311int v_screen_init __P((SCR *));
312int xaw_screen_copy __P((SCR *, SCR *));
313int xaw_screen_end __P((SCR *));
314int xaw_screen_init __P((SCR *));