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.41 1993/12/22 16:59:03 bostic Exp $ (Berkeley) $Date: 1993/12/22 16:59:03 $
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_BUFFER 0x0000020 /* Buffer name supplied. */
22 #define E_COUNT 0x0000040 /* Count supplied. */
23 #define E_FORCE 0x0000080 /* ! */
25 #define E_F_CARAT 0x0000100 /* ^ flag. */
26 #define E_F_DASH 0x0000200 /* - flag. */
27 #define E_F_DOT 0x0000400 /* . flag. */
28 #define E_F_EQUAL 0x0000800 /* = flag. */
29 #define E_F_HASH 0x0001000 /* # flag. */
30 #define E_F_LIST 0x0002000 /* l flag. */
31 #define E_F_PLUS 0x0004000 /* + flag. */
32 #define E_F_PRINT 0x0008000 /* p flag. */
34 #define E_F_PRCLEAR 0x0010000 /* Clear the print (#, l, p) flags. */
35 #define E_MODIFY 0x0020000 /* File name expansion modified arg. */
36 #define E_NOGLOBAL 0x0040000 /* Not in a global. */
37 #define E_NOPERM 0x0080000 /* Permission denied for now. */
38 #define E_NORC 0x0100000 /* Not from a .exrc or EXINIT. */
39 #define E_SETLAST 0x0200000 /* Reset last command. */
40 #define E_ZERO 0x0400000 /* 0 is a legal addr1. */
41 #define E_ZERODEF 0x0800000 /* 0 is default addr1 of empty files. */
43 char *syntax
; /* Syntax script. */
44 char *usage
; /* Usage line. */
45 char *help
; /* Help line. */
47 #define MAXCMDNAMELEN 12 /* Longest command name. */
48 extern EXCMDLIST
const cmds
[]; /* List of ex commands. */
50 /* Structure passed around to functions implementing ex commands. */
52 EXCMDLIST
const *cmd
; /* Command entry in command table. */
53 CHAR_T buffer
; /* Named buffer. */
54 recno_t lineno
; /* Line number. */
55 long count
; /* Signed, specified count. */
56 int addrcnt
; /* Number of addresses (0, 1 or 2). */
57 MARK addr1
; /* 1st address. */
58 MARK addr2
; /* 2nd address. */
59 ARGS
**argv
; /* Array of arguments. */
60 int argc
; /* Count of arguments. */
61 u_int flags
; /* Selected flags from EXCMDLIST. */
64 /* Ex private, per-screen memory. */
65 typedef struct _ex_private
{
66 ARGS
**args
; /* Arguments. */
67 int argscnt
; /* Argument count. */
68 int argsoff
; /* Offset into arguments. */
70 CHAR_T at_lbuf
; /* Last executed at buffer's name. */
71 int at_lbuf_set
; /* If at_lbuf is set. */
73 char *ibp
; /* Line input buffer. */
74 size_t ibp_len
; /* Line input buffer length. */
76 EXCMDLIST
const *lastcmd
; /* Last command. */
78 CHAR_T
*lastbcomm
; /* Last bang command. */
80 TAILQ_HEAD(_tagh
, _tag
) tagq
; /* Tag stack. */
81 TAILQ_HEAD(_tagfh
, _tagf
) tagfq
;/* Tag stack. */
82 char *tlast
; /* Saved last tag. */
84 #define EXP(sp) ((EX_PRIVATE *)((sp)->ex_private))
86 /* Macro to set up a command structure. */
87 #define SETCMDARG(s, cmd_id, naddr, lno1, lno2, force, arg) { \
89 memset(&s, 0, sizeof(EXCMDARG)); \
90 s.cmd = &cmds[cmd_id]; \
91 s.addrcnt = (naddr); \
92 s.addr1.lno = (lno1); \
93 s.addr2.lno = (lno2); \
94 s.addr1.cno = s.addr2.cno = 1; \
97 if ((__a.bp = arg) == NULL) { \
102 __a.len = strlen(arg); \
110 * :next, :prev, :rewind, :tag, :tagpush, :tagpop modifications check.
111 * If force is set, the autowrite is skipped.
113 #define MODIFY_CHECK(sp, ep, force) { \
114 if (F_ISSET((ep), F_MODIFIED)) \
115 if (O_ISSET((sp), O_AUTOWRITE)) { \
117 file_write((sp), (ep), NULL, NULL, NULL, \
118 FS_ALL | FS_POSSIBLE)) \
120 } else if (ep->refcnt <= 1 && !(force)) { \
122 "Modified since last write; write or use ! to override."); \
128 * Macros to set and restore the terminal values, and note if the screen
129 * was modified. Specific to their uses in ex/filter.c and ex/ex_shell.c.
131 * The old terminal values almost certainly turn on VINTR, VQUIT and VSUSP.
132 * We don't want to interrupt the parent(s), so we ignore VINTR. VQUIT is
133 * ignored by main() because nvi never wants to catch it. A VSUSP handler
134 * have been installed by the screen code.
136 #define EX_LEAVE(sp, isig, act, oact, sb, osb, term) \
137 if (F_ISSET(sp->gp, G_ISFROMTTY)) { \
138 (act).sa_handler = SIG_IGN; \
139 sigemptyset(&(act).sa_mask); \
140 (act).sa_flags = 0; \
141 if ((isig) = !sigaction(SIGINT, &(act), &(oact))) { \
142 if (tcgetattr(STDIN_FILENO, &(term))) { \
143 msgq(sp, M_SYSERR, "tcgetattr"); \
147 if (tcsetattr(STDIN_FILENO, TCSANOW | TCSASOFT, \
148 &sp->gp->original_termios)) { \
149 msgq(sp, M_SYSERR, "tcsetattr"); \
155 * The process may write to the terminal. Save the \
156 * access time (read) and modification time (write) \
157 * of the tty; if they have changed when we restore \
158 * the modes, will have to refresh the screen. \
162 (void)fstat(STDIN_FILENO, &osb); \
165 #define EX_RETURN(sp, isig, act, oact, sb, osb, term) \
166 if (F_ISSET(sp->gp, G_ISFROMTTY) && (isig)) { \
167 if (sigaction(SIGINT, &(oact), NULL)) { \
168 msgq(sp, M_SYSERR, "signal"); \
171 if (tcsetattr(STDIN_FILENO, \
172 TCSANOW | TCSASOFT, &(term))) { \
173 msgq(sp, M_SYSERR, "tcsetattr"); \
176 /* If the terminal was used, refresh the screen. */ \
177 (void)fstat(STDIN_FILENO, &(sb)); \
178 if ((sb).st_mtime != (osb).st_mtime || \
179 (sb).st_atime != (osb).st_atime) \
180 F_SET(sp, S_REFRESH); \
186 * FILTER Filter text through the utility.
187 * FILTER_READ Read from the utility into the file.
188 * FILTER_WRITE Write to the utility, display its output.
190 enum filtertype
{ FILTER
, FILTER_READ
, FILTER_WRITE
};
191 int filtercmd
__P((SCR
*, EXF
*,
192 MARK
*, MARK
*, MARK
*, char *, enum filtertype
));
194 /* Argument expansion routines. */
195 int argv_init
__P((SCR
*, EXF
*, EXCMDARG
*));
196 int argv_exp0
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t));
197 int argv_exp1
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t, int));
198 int argv_exp2
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t, int));
199 int argv_exp3
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t));
200 int argv_free
__P((SCR
*));
202 /* Ex function prototypes. */
203 int ex
__P((SCR
*, EXF
*));
204 int ex_cfile
__P((SCR
*, EXF
*, char *));
205 int ex_cmd
__P((SCR
*, EXF
*, char *, size_t));
206 int ex_end
__P((SCR
*));
207 int ex_exec_proc
__P((SCR
*, char *, char *, char *));
208 int ex_gb
__P((SCR
*, EXF
*, TEXTH
*, int, u_int
));
209 int ex_getline
__P((SCR
*, FILE *, size_t *));
210 int ex_icmd
__P((SCR
*, EXF
*, char *, size_t));
211 int ex_init
__P((SCR
*, EXF
*));
212 int ex_is_abbrev
__P((char *, size_t));
213 int ex_optchange
__P((SCR
*, int));
214 int ex_print
__P((SCR
*, EXF
*, MARK
*, MARK
*, int));
215 int ex_readfp
__P((SCR
*, EXF
*, char *, FILE *, MARK
*, recno_t
*, int));
216 void ex_refresh
__P((SCR
*, EXF
*));
217 int ex_screen_copy
__P((SCR
*, SCR
*));
218 int ex_screen_end
__P((SCR
*));
219 int ex_sdisplay
__P((SCR
*, EXF
*));
220 int ex_suspend
__P((SCR
*));
221 int ex_tdisplay
__P((SCR
*, EXF
*));
222 int ex_writefp
__P((SCR
*, EXF
*,
223 char *, FILE *, MARK
*, MARK
*, u_long
*, u_long
*));
224 int proc_wait
__P((SCR
*, long, const char *, int));
225 int sscr_end
__P((SCR
*));
226 int sscr_exec
__P((SCR
*, EXF
*, recno_t
));
227 int sscr_input
__P((SCR
*));
229 #define EXPROTO(type, name) \
230 type name __P((SCR *, EXF *, EXCMDARG *))
232 EXPROTO(int, ex_abbr
);
233 EXPROTO(int, ex_append
);
234 EXPROTO(int, ex_args
);
236 EXPROTO(int, ex_bang
);
239 EXPROTO(int, ex_change
);
240 EXPROTO(int, ex_color
);
241 EXPROTO(int, ex_copy
);
242 EXPROTO(int, ex_debug
);
243 EXPROTO(int, ex_delete
);
244 EXPROTO(int, ex_digraph
);
245 EXPROTO(int, ex_display
);
246 EXPROTO(int, ex_edit
);
247 EXPROTO(int, ex_equal
);
249 EXPROTO(int, ex_file
);
250 EXPROTO(int, ex_global
);
251 EXPROTO(int, ex_help
);
252 EXPROTO(int, ex_insert
);
253 EXPROTO(int, ex_join
);
254 EXPROTO(int, ex_list
);
255 EXPROTO(int, ex_map
);
256 EXPROTO(int, ex_mark
);
257 EXPROTO(int, ex_mkexrc
);
258 EXPROTO(int, ex_move
);
259 EXPROTO(int, ex_next
);
260 EXPROTO(int, ex_number
);
261 EXPROTO(int, ex_open
);
263 EXPROTO(int, ex_preserve
);
264 EXPROTO(int, ex_prev
);
265 EXPROTO(int, ex_put
);
266 EXPROTO(int, ex_quit
);
267 EXPROTO(int, ex_read
);
268 EXPROTO(int, ex_resize
);
269 EXPROTO(int, ex_rew
);
270 EXPROTO(int, ex_script
);
271 EXPROTO(int, ex_set
);
272 EXPROTO(int, ex_shell
);
273 EXPROTO(int, ex_shiftl
);
274 EXPROTO(int, ex_shiftr
);
275 EXPROTO(int, ex_source
);
276 EXPROTO(int, ex_split
);
277 EXPROTO(int, ex_stop
);
278 EXPROTO(int, ex_subagain
);
279 EXPROTO(int, ex_substitute
);
280 EXPROTO(int, ex_subtilde
);
281 EXPROTO(int, ex_tagpop
);
282 EXPROTO(int, ex_tagpush
);
283 EXPROTO(int, ex_tagtop
);
284 EXPROTO(int, ex_unabbr
);
285 EXPROTO(int, ex_undo
);
286 EXPROTO(int, ex_undol
);
287 EXPROTO(int, ex_unmap
);
288 EXPROTO(int, ex_usage
);
289 EXPROTO(int, ex_validate
);
290 EXPROTO(int, ex_version
);
291 EXPROTO(int, ex_vglobal
);
292 EXPROTO(int, ex_visual
);
293 EXPROTO(int, ex_viusage
);
295 EXPROTO(int, ex_write
);
296 EXPROTO(int, ex_xit
);
297 EXPROTO(int, ex_yank
);