forgot to delete a TRACE call
[nvi.git] / ex / ex.h
blob7101aada515392df2b458cd0422817541b408feb
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
7 * $Id: ex.h,v 8.44 1993/12/29 09:51:01 bostic Exp $ (Berkeley) $Date: 1993/12/29 09:51:01 $
8 */
10 /* Ex command structure. */
11 typedef struct _excmdlist {
12 char *name; /* Command name. */
13 /* Underlying function. */
14 int (*fn) __P((SCR *, EXF *, EXCMDARG *));
16 #define E_ADDR1 0x0000001 /* One address. */
17 #define E_ADDR2 0x0000002 /* Two address. */
18 #define E_ADDR2_ALL 0x0000004 /* Zero/two addresses; zero == all. */
19 #define E_ADDR2_NONE 0x0000008 /* Zero/two addresses; zero == none. */
20 #define E_ADDRDEF 0x0000010 /* Default addresses used. */
21 #define E_AUTOPRINT 0x0000020 /* Command always sets autoprint. */
22 #define E_BUFFER 0x0000040 /* Buffer name supplied. */
23 #define E_COUNT 0x0000080 /* Count supplied. */
24 #define E_FORCE 0x0000100 /* ! */
26 #define E_F_CARAT 0x0000200 /* ^ flag. */
27 #define E_F_DASH 0x0000400 /* - flag. */
28 #define E_F_DOT 0x0000800 /* . flag. */
29 #define E_F_EQUAL 0x0001000 /* = flag. */
30 #define E_F_HASH 0x0002000 /* # flag. */
31 #define E_F_LIST 0x0004000 /* l flag. */
32 #define E_F_PLUS 0x0008000 /* + flag. */
33 #define E_F_PRINT 0x0010000 /* p flag. */
35 #define E_F_PRCLEAR 0x0020000 /* Clear the print (#, l, p) flags. */
36 #define E_MODIFY 0x0040000 /* File name expansion modified arg. */
37 #define E_NOGLOBAL 0x0080000 /* Not in a global. */
38 #define E_NOPERM 0x0100000 /* Permission denied for now. */
39 #define E_NORC 0x0200000 /* Not from a .exrc or EXINIT. */
40 #define E_SETLAST 0x0400000 /* Reset last command. */
41 #define E_ZERO 0x0800000 /* 0 is a legal addr1. */
42 #define E_ZERODEF 0x1000000 /* 0 is default addr1 of empty files. */
43 u_long flags;
44 char *syntax; /* Syntax script. */
45 char *usage; /* Usage line. */
46 char *help; /* Help line. */
47 } EXCMDLIST;
48 #define MAXCMDNAMELEN 12 /* Longest command name. */
49 extern EXCMDLIST const cmds[]; /* List of ex commands. */
51 /* Structure passed around to functions implementing ex commands. */
52 struct _excmdarg {
53 EXCMDLIST const *cmd; /* Command entry in command table. */
54 CHAR_T buffer; /* Named buffer. */
55 recno_t lineno; /* Line number. */
56 long count; /* Signed, specified count. */
57 int addrcnt; /* Number of addresses (0, 1 or 2). */
58 MARK addr1; /* 1st address. */
59 MARK addr2; /* 2nd address. */
60 ARGS **argv; /* Array of arguments. */
61 int argc; /* Count of arguments. */
62 u_int flags; /* Selected flags from EXCMDLIST. */
65 /* Global ranges. */
66 typedef struct _range RANGE;
67 struct _range {
68 CIRCLEQ_ENTRY(_range) q; /* Linked list of ranges. */
69 recno_t start, stop; /* Start/stop of the range. */
72 /* Ex private, per-screen memory. */
73 typedef struct _ex_private {
74 ARGS **args; /* Arguments. */
75 int argscnt; /* Argument count. */
76 int argsoff; /* Offset into arguments. */
78 CHAR_T at_lbuf; /* Last executed at buffer's name. */
79 int at_lbuf_set; /* If at_lbuf is set. */
81 char *ibp; /* Line input buffer. */
82 size_t ibp_len; /* Line input buffer length. */
84 EXCMDLIST const *lastcmd; /* Last command. */
86 CHAR_T *lastbcomm; /* Last bang command. */
88 TAILQ_HEAD(_tagh, _tag) tagq; /* Tag stack. */
89 TAILQ_HEAD(_tagfh, _tagf) tagfq;/* Tag stack. */
90 char *tlast; /* Saved last tag. */
92 /* Linked list of ranges. */
93 CIRCLEQ_HEAD(_rangeh, _range) rangeq;
94 recno_t range_lno; /* Range set line number. */
96 #define EX_AUTOPRINT 0x01 /* Autoprint flag. */
97 u_int flags;
98 } EX_PRIVATE;
99 #define EXP(sp) ((EX_PRIVATE *)((sp)->ex_private))
101 /* Macro to set up a command structure. */
102 #define SETCMDARG(s, cmd_id, naddr, lno1, lno2, force, arg) { \
103 ARGS *__ap[2], __a; \
104 memset(&s, 0, sizeof(EXCMDARG)); \
105 s.cmd = &cmds[cmd_id]; \
106 s.addrcnt = (naddr); \
107 s.addr1.lno = (lno1); \
108 s.addr2.lno = (lno2); \
109 s.addr1.cno = s.addr2.cno = 1; \
110 if (force) \
111 s.flags |= E_FORCE; \
112 if ((__a.bp = arg) == NULL) { \
113 s.argc = 0; \
114 __a.len = 0; \
115 } else { \
116 s.argc = 1; \
117 __a.len = strlen(arg); \
119 __ap[0] = &__a; \
120 __ap[1] = NULL; \
121 s.argv = __ap; \
125 * :next, :prev, :rewind, :tag, :tagpush, :tagpop modifications check.
126 * If force is set, the autowrite is skipped.
128 #define MODIFY_CHECK(sp, ep, force) { \
129 if (F_ISSET((ep), F_MODIFIED)) \
130 if (O_ISSET((sp), O_AUTOWRITE)) { \
131 if (!(force) && \
132 file_write((sp), (ep), NULL, NULL, NULL, \
133 FS_ALL | FS_POSSIBLE)) \
134 return (1); \
135 } else if (ep->refcnt <= 1 && !(force)) { \
136 msgq(sp, M_ERR, \
137 "Modified since last write; write or use ! to override."); \
138 return (1); \
143 * Macros to set and restore the terminal values, and note if the screen
144 * was modified. Specific to their uses in ex/filter.c and ex/ex_shell.c.
146 * The old terminal values almost certainly turn on VINTR, VQUIT and VSUSP.
147 * We don't want to interrupt the parent(s), so we ignore VINTR. VQUIT is
148 * ignored by main() because nvi never wants to catch it. A VSUSP handler
149 * have been installed by the screen code.
151 #define EX_LEAVE(sp, isig, act, oact, sb, osb, term) \
152 if (F_ISSET(sp->gp, G_ISFROMTTY)) { \
153 (act).sa_handler = SIG_IGN; \
154 sigemptyset(&(act).sa_mask); \
155 (act).sa_flags = 0; \
156 if ((isig) = !sigaction(SIGINT, &(act), &(oact))) { \
157 if (tcgetattr(STDIN_FILENO, &(term))) { \
158 msgq(sp, M_SYSERR, "tcgetattr"); \
159 rval = 1; \
160 goto err; \
162 if (tcsetattr(STDIN_FILENO, TCSANOW | TCSASOFT, \
163 &sp->gp->original_termios)) { \
164 msgq(sp, M_SYSERR, "tcsetattr"); \
165 rval = 1; \
166 goto err; \
169 /* \
170 * The process may write to the terminal. Save the \
171 * access time (read) and modification time (write) \
172 * of the tty; if they have changed when we restore \
173 * the modes, will have to refresh the screen. \
174 */ \
175 sb.st_mtime = 1; \
176 osb.st_mtime = 0; \
177 (void)fstat(STDIN_FILENO, &osb); \
180 #define EX_RETURN(sp, isig, act, oact, sb, osb, term) \
181 if (F_ISSET(sp->gp, G_ISFROMTTY) && (isig)) { \
182 if (sigaction(SIGINT, &(oact), NULL)) { \
183 msgq(sp, M_SYSERR, "signal"); \
184 rval = 1; \
186 if (tcsetattr(STDIN_FILENO, \
187 TCSANOW | TCSASOFT, &(term))) { \
188 msgq(sp, M_SYSERR, "tcsetattr"); \
189 rval = 1; \
191 /* If the terminal was used, refresh the screen. */ \
192 (void)fstat(STDIN_FILENO, &(sb)); \
193 if ((sb).st_mtime != (osb).st_mtime || \
194 (sb).st_atime != (osb).st_atime) \
195 F_SET(sp, S_REFRESH); \
199 * Filter actions:
201 * FILTER Filter text through the utility.
202 * FILTER_READ Read from the utility into the file.
203 * FILTER_WRITE Write to the utility, display its output.
205 enum filtertype { FILTER, FILTER_READ, FILTER_WRITE };
206 int filtercmd __P((SCR *, EXF *,
207 MARK *, MARK *, MARK *, char *, enum filtertype));
209 /* Argument expansion routines. */
210 int argv_init __P((SCR *, EXF *, EXCMDARG *));
211 int argv_exp0 __P((SCR *, EXF *, EXCMDARG *, char *, size_t));
212 int argv_exp1 __P((SCR *, EXF *, EXCMDARG *, char *, size_t, int));
213 int argv_exp2 __P((SCR *, EXF *, EXCMDARG *, char *, size_t, int));
214 int argv_exp3 __P((SCR *, EXF *, EXCMDARG *, char *, size_t));
215 int argv_free __P((SCR *));
217 /* Ex function prototypes. */
218 int ex __P((SCR *, EXF *));
219 int ex_cfile __P((SCR *, EXF *, char *));
220 int ex_cmd __P((SCR *, EXF *, char *, size_t));
221 int ex_end __P((SCR *));
222 int ex_exec_proc __P((SCR *, char *, char *, char *));
223 int ex_gb __P((SCR *, EXF *, TEXTH *, int, u_int));
224 int ex_getline __P((SCR *, FILE *, size_t *));
225 int ex_icmd __P((SCR *, EXF *, char *, size_t));
226 int ex_init __P((SCR *, EXF *));
227 int ex_is_abbrev __P((char *, size_t));
228 int ex_optchange __P((SCR *, int));
229 int ex_print __P((SCR *, EXF *, MARK *, MARK *, int));
230 int ex_readfp __P((SCR *, EXF *, char *, FILE *, MARK *, recno_t *, int));
231 void ex_refresh __P((SCR *, EXF *));
232 int ex_screen_copy __P((SCR *, SCR *));
233 int ex_screen_end __P((SCR *));
234 int ex_sdisplay __P((SCR *, EXF *));
235 int ex_suspend __P((SCR *));
236 int ex_tdisplay __P((SCR *, EXF *));
237 int ex_writefp __P((SCR *, EXF *,
238 char *, FILE *, MARK *, MARK *, u_long *, u_long *));
239 void global_insdel __P((SCR *, EXF *, enum operation, recno_t));
240 int proc_wait __P((SCR *, long, const char *, int));
241 int sscr_end __P((SCR *));
242 int sscr_exec __P((SCR *, EXF *, recno_t));
243 int sscr_input __P((SCR *));
245 #define EXPROTO(type, name) \
246 type name __P((SCR *, EXF *, EXCMDARG *))
248 EXPROTO(int, ex_abbr);
249 EXPROTO(int, ex_append);
250 EXPROTO(int, ex_args);
251 EXPROTO(int, ex_at);
252 EXPROTO(int, ex_bang);
253 EXPROTO(int, ex_bg);
254 EXPROTO(int, ex_cd);
255 EXPROTO(int, ex_change);
256 EXPROTO(int, ex_color);
257 EXPROTO(int, ex_copy);
258 EXPROTO(int, ex_debug);
259 EXPROTO(int, ex_delete);
260 EXPROTO(int, ex_digraph);
261 EXPROTO(int, ex_display);
262 EXPROTO(int, ex_edit);
263 EXPROTO(int, ex_equal);
264 EXPROTO(int, ex_fg);
265 EXPROTO(int, ex_file);
266 EXPROTO(int, ex_global);
267 EXPROTO(int, ex_help);
268 EXPROTO(int, ex_insert);
269 EXPROTO(int, ex_join);
270 EXPROTO(int, ex_list);
271 EXPROTO(int, ex_map);
272 EXPROTO(int, ex_mark);
273 EXPROTO(int, ex_mkexrc);
274 EXPROTO(int, ex_move);
275 EXPROTO(int, ex_next);
276 EXPROTO(int, ex_number);
277 EXPROTO(int, ex_open);
278 EXPROTO(int, ex_pr);
279 EXPROTO(int, ex_preserve);
280 EXPROTO(int, ex_prev);
281 EXPROTO(int, ex_put);
282 EXPROTO(int, ex_quit);
283 EXPROTO(int, ex_read);
284 EXPROTO(int, ex_resize);
285 EXPROTO(int, ex_rew);
286 EXPROTO(int, ex_script);
287 EXPROTO(int, ex_set);
288 EXPROTO(int, ex_shell);
289 EXPROTO(int, ex_shiftl);
290 EXPROTO(int, ex_shiftr);
291 EXPROTO(int, ex_source);
292 EXPROTO(int, ex_split);
293 EXPROTO(int, ex_stop);
294 EXPROTO(int, ex_subagain);
295 EXPROTO(int, ex_substitute);
296 EXPROTO(int, ex_subtilde);
297 EXPROTO(int, ex_tagpop);
298 EXPROTO(int, ex_tagpush);
299 EXPROTO(int, ex_tagtop);
300 EXPROTO(int, ex_unabbr);
301 EXPROTO(int, ex_undo);
302 EXPROTO(int, ex_undol);
303 EXPROTO(int, ex_unmap);
304 EXPROTO(int, ex_usage);
305 EXPROTO(int, ex_validate);
306 EXPROTO(int, ex_version);
307 EXPROTO(int, ex_vglobal);
308 EXPROTO(int, ex_visual);
309 EXPROTO(int, ex_viusage);
310 EXPROTO(int, ex_wq);
311 EXPROTO(int, ex_write);
312 EXPROTO(int, ex_xit);
313 EXPROTO(int, ex_yank);
314 EXPROTO(int, ex_z);