go to 0.81
[nvi.git] / common / screen.h
blob9db702ae54c961b0d4d842caedde960573a44c1d
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
7 * $Id: screen.h,v 8.51 1993/11/04 16:16:10 bostic Exp $ (Berkeley) $Date: 1993/11/04 16:16:10 $
8 */
11 * There are minimum values that vi has to have to display a screen. The
12 * row minimum is fixed at 1 line for the text, and 1 line for any error
13 * messages. The column calculation is a lot trickier. For example, you
14 * have to have enough columns to display the line number, not to mention
15 * guaranteeing that tabstop and shiftwidth values are smaller than the
16 * current column value. It's a lot simpler to have a fixed value and not
17 * worry about it.
19 * XXX
20 * MINIMUM_SCREEN_COLS is probably wrong.
22 #define MINIMUM_SCREEN_ROWS 2
23 #define MINIMUM_SCREEN_COLS 20
24 /* Line operations. */
25 enum operation { LINE_APPEND, LINE_DELETE, LINE_INSERT, LINE_RESET };
26 /* Standard continue message. */
27 enum position { P_BOTTOM, P_FILL, P_MIDDLE, P_TOP };
30 * Structure for holding file references. This structure contains the
31 * "name" of a file, including the state of the name and if it's backed
32 * by a temporary file. Each SCR structure contains a linked list of
33 * these (the user's argument list) as well as pointers for the current,
34 * previous and next files.
36 * Note that the read-only bit follows the file name, not the file itself.
38 * XXX
39 * The mtime field should be a struct timespec, but time_t is more portable.
41 typedef struct _fref {
42 struct queue_entry q; /* Linked list of file references. */
43 char *tname; /* Temporary file name. */
44 char *fname; /* File name. */
45 size_t nlen; /* File name length. */
46 recno_t lno; /* 1-N: file cursor line. */
47 size_t cno; /* 0-N: file cursor column. */
48 time_t mtime; /* Last modification time. */
50 #define FR_CURSORSET 0x001 /* If lno/cno valid. */
51 #define FR_EDITED 0x002 /* If the file was ever edited. */
52 #define FR_FREE_TNAME 0x004 /* Free the tname field. */
53 #define FR_IGNORE 0x008 /* File isn't part of argument list. */
54 #define FR_NAMECHANGED 0x010 /* File name was changed. */
55 #define FR_NEWFILE 0x020 /* File doesn't really exist yet. */
56 #define FR_NONAME 0x040 /* File has no name. */
57 #define FR_RDONLY 0x080 /* File is read-only. */
58 #define FR_UNLINK_TFILE 0x100 /* Unlink the temporary file. */
59 u_int flags;
60 } FREF;
63 * scr --
64 * The screen structure.
66 * Most of the traditional ex/vi options and values follow the screen, and
67 * are kept here. For those of you that didn't follow that sentence, read
68 * "dumping ground". Each new screen added to the editor will probably have
69 * to keep its own stuff in here as well.
71 typedef struct _scr {
72 /* INITIALIZED AT SCREEN CREATE. */
73 struct queue_entry screenq; /* Linked list of screens. */
75 struct _scr *child; /* split screen: child screen. */
76 struct _scr *parent; /* split screen: parent screen. */
77 struct _scr *snext; /* split screen: next display screen. */
79 struct _exf *ep; /* Screen's current file. */
81 /* File name oriented state. */
82 struct queue_entry frefq; /* Linked list of FREF structures. */
83 FREF *frp; /* Current FREF. */
84 FREF *p_frp; /* Previous FREF. */
86 void *vi_private; /* Vi information. */
87 void *svi_private; /* Vi curses screen information. */
88 void *xaw_private; /* Vi XAW screen information. */
90 recno_t lno; /* 1-N: cursor file line. */
91 recno_t olno; /* 1-N: old cursor file line. */
92 size_t cno; /* 0-N: file cursor column. */
93 size_t ocno; /* 0-N: old file cursor column. */
94 size_t sc_col; /* 0-N: logical screen cursor column. */
96 size_t rows; /* 1-N: rows per screen. */
97 size_t cols; /* 1-N: columns per screen. */
98 size_t t_rows; /* 1-N: text rows per screen. */
99 size_t t_maxrows; /* 1-N: max text rows per screen. */
100 size_t t_minrows; /* 1-N: min text rows per screen. */
101 size_t w_rows; /* 1-N: rows per window. */
102 size_t s_off; /* 0-N: row offset in window. */
104 size_t rcm; /* Vi: 0-N: Column suck. */
105 #define RCM_FNB 0x01 /* Column suck: first non-blank. */
106 #define RCM_LAST 0x02 /* Column suck: last. */
107 u_int rcmflags;
109 #define L_ADDED 0 /* Added lines. */
110 #define L_CHANGED 1 /* Changed lines. */
111 #define L_COPIED 2 /* Copied lines. */
112 #define L_DELETED 3 /* Deleted lines. */
113 #define L_JOINED 4 /* Joined lines. */
114 #define L_MOVED 5 /* Moved lines. */
115 #define L_PUT 6 /* Put lines. */
116 #define L_LSHIFT 7 /* Left shift lines. */
117 #define L_RSHIFT 8 /* Right shift lines. */
118 #define L_YANKED 9 /* Yanked lines. */
119 recno_t rptlines[L_YANKED + 1];/* Ex/vi: lines changed by last op. */
121 struct _msg *msgp; /* User message list. */
123 u_long ccnt; /* Command count. */
124 u_long q_ccnt; /* Quit command count. */
126 void *args; /* Ex argument buffers. */
127 char **argv; /* Arguments. */
128 char *ex_argv[3]; /* Special purpose 2 slots. */
129 int argscnt; /* Argument count. */
131 /* Ex/vi: interface between ex/vi. */
132 FILE *stdfp; /* Ex output file pointer. */
133 size_t exlinecount; /* Ex/vi overwrite count. */
134 size_t extotalcount; /* Ex/vi overwrite count. */
135 size_t exlcontinue; /* Ex/vi line continue value. */
137 /* FWOPEN_NOT_AVAILABLE */
138 int trapped_fd; /* Ex/vi trapped file descriptor. */
140 CHAR_T at_lbuf; /* Last executed at buffer's name. */
141 int at_lbuf_set; /* If at_lbuf is set. */
143 fd_set rdfd; /* Ex/vi: read fd select mask. */
145 HDR txthdr; /* Vi: text input TEXT header. */
147 char *ibp; /* Ex: line input buffer. */
148 size_t ibp_len; /* Line input buffer length. */
150 /* Ex: last command. */
151 struct _excmdlist const *lastcmd;
153 int sh_in[2]; /* Vi: script pipe. */
154 int sh_out[2]; /* Vi: script pipe. */
155 pid_t sh_pid; /* Vi: shell pid. */
156 char *sh_prompt; /* Vi: script prompt. */
157 size_t sh_prompt_len; /* Vi: script prompt length. */
159 /* PARTIALLY OR COMPLETELY COPIED FROM PREVIOUS SCREEN. */
160 struct _gs *gp; /* Pointer to global area. */
162 char *rep; /* Vi: input replay buffer. */
163 size_t rep_len; /* Vi: input replay buffer length. */
165 char *lastbcomm; /* Ex/vi: last bang command. */
167 char *alt_fname; /* Ex/vi: alternate file name. */
169 u_char inc_lastch; /* Vi: Last increment character. */
170 long inc_lastval; /* Last increment value. */
172 char *paragraph; /* Vi: paragraph search list. */
174 struct queue_entry tagq; /* Ex/vi: tag stack. */
175 struct queue_entry tagfq; /* Ex/vi: tag file queue. */
176 char *tlast; /* Ex/vi: saved last tag. */
178 /* Ex/vi: search/substitute info. */
179 regex_t sre; /* Last search RE. */
180 regex_t subre; /* Last substitute RE. */
181 enum direction searchdir; /* File search direction. */
182 enum cdirection csearchdir; /* Character search direction. */
183 u_char lastckey; /* Last search character. */
184 regmatch_t *match; /* Substitute match array. */
185 size_t matchsize; /* Substitute match array size. */
186 char *repl; /* Substitute replacement. */
187 size_t repl_len; /* Substitute replacement length.*/
188 size_t *newl; /* Newline offset array. */
189 size_t newl_len; /* Newline array size. */
190 size_t newl_cnt; /* Newlines in replacement. */
192 CHNAME const *cname; /* Display names of characters. */
193 u_char special[UCHAR_MAX]; /* Special character array. */
195 char const *time_msg; /* ITIMER_REAL message. */
196 struct itimerval time_value; /* ITIMER_REAL saved value. */
197 struct sigaction time_handler; /* ITIMER_REAL saved handler. */
199 OPTION opts[O_OPTIONCOUNT]; /* Ex/vi: options. */
202 * SCREEN SUPPORT ROUTINES.
203 * This is the set of routines that have to be written to add a screen.
205 void (*s_bell) __P((struct _scr *));
206 int (*s_busy) __P((struct _scr *, char const *));
207 int (*s_change) __P((struct _scr *,
208 struct _exf *, recno_t, enum operation));
209 size_t (*s_chposition) __P((struct _scr *,
210 struct _exf *, recno_t, size_t));
211 enum confirm
212 (*s_confirm) __P((struct _scr *,
213 struct _exf *, struct _mark *, struct _mark *));
214 int (*s_down) __P((struct _scr *,
215 struct _exf *, struct _mark *, recno_t, int));
216 int (*s_ex_cmd) __P((struct _scr *, struct _exf *,
217 struct _excmdarg *, struct _mark *));
218 int (*s_ex_run) __P((struct _scr *, struct _exf *,
219 struct _mark *));
220 int (*s_ex_write) __P((void *, const char *, int));
221 int (*s_fill) __P((struct _scr *,
222 struct _exf *, recno_t, enum position));
223 enum input
224 (*s_get) __P((struct _scr *,
225 struct _exf *, HDR *, int, u_int));
226 enum input
227 (*s_key_read) __P((struct _scr *, int *, int));
228 int (*s_key_wait) __P((struct _scr *));
229 int (*s_optchange) __P((struct _scr *, int));
230 int (*s_position) __P((struct _scr *,
231 struct _exf *, MARK *, u_long, enum position));
232 int (*s_refresh) __P((struct _scr *, struct _exf *));
233 size_t (*s_relative) __P((struct _scr *, struct _exf *, recno_t));
234 int (*s_split) __P((struct _scr *, char *[]));
235 int (*s_suspend) __P((struct _scr *));
236 int (*s_up) __P((struct _scr *,
237 struct _exf *, struct _mark *, recno_t, int));
239 /* Editor modes. */
240 #define S_MODE_EX 0x0000001 /* Ex mode. */
241 #define S_MODE_VI 0x0000002 /* Vi mode. */
243 /* Major screen/file changes. */
244 #define S_EXIT 0x0000004 /* Exiting (not forced). */
245 #define S_EXIT_FORCE 0x0000008 /* Exiting (forced). */
246 #define S_FSWITCH 0x0000010 /* Switch files. */
247 #define S_SSWITCH 0x0000020 /* Switch screens. */
248 #define S_MAJOR_CHANGE /* Screen or file changes. */ \
249 (S_EXIT | S_EXIT_FORCE | S_FSWITCH | S_SSWITCH)
251 #define S_ABBREV 0x0000040 /* If have abbreviations. */
252 #define S_AUTOPRINT 0x0000080 /* Autoprint flag. */
253 #define S_BELLSCHED 0x0000100 /* Bell scheduled. */
254 #define S_GLOBAL 0x0000200 /* Doing a global command. */
255 #define S_INPUT 0x0000400 /* Doing text input. */
256 #define S_INTERRUPTED 0x0000800 /* If have been interrupted. */
257 #define S_INTERRUPTIBLE 0x0001000 /* If can be interrupted. */
258 #define S_MSGREENTER 0x0002000 /* If msg routine reentered. */
259 #define S_REDRAW 0x0004000 /* Redraw the screen. */
260 #define S_REFORMAT 0x0008000 /* Reformat the screen. */
261 #define S_REFRESH 0x0010000 /* Refresh the screen. */
262 #define S_RESIZE 0x0020000 /* Resize the screen. */
263 #define S_SCRIPT 0x0040000 /* Window is a shell script. */
264 #define S_SRE_SET 0x0080000 /* The search RE has been set. */
265 #define S_SUBRE_SET 0x0100000 /* The substitute RE has been set. */
266 #define S_TERMSIGNAL 0x0200000 /* Termination signal received. */
267 #define S_TIMER_SET 0x0400000 /* If a busy timer is running. */
268 #define S_UPDATE_MODE 0x0800000 /* Don't repaint modeline. */
269 u_int flags;
270 } SCR;
272 /* Public interfaces to the screens. */
273 int screen_end __P((struct _scr *));
274 int screen_init __P((struct _scr *, struct _scr *));
275 int sex __P((struct _scr *, struct _exf *, struct _scr **));
276 int svi __P((struct _scr *, struct _exf *, struct _scr **));
277 int xaw __P((struct _scr *, struct _exf *, struct _scr **));