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.38 1993/12/03 15:21:50 bostic Exp $ (Berkeley) $Date: 1993/12/03 15:21:50 $
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."); \
130 * FILTER Filter text through the utility.
131 * FILTER_READ Read from the utility into the file.
132 * FILTER_WRITE Write to the utility, display its output.
134 enum filtertype
{ FILTER
, FILTER_READ
, FILTER_WRITE
};
135 int filtercmd
__P((SCR
*, EXF
*,
136 MARK
*, MARK
*, MARK
*, char *, enum filtertype
));
138 /* Argument expansion routines. */
139 int argv_init
__P((SCR
*, EXF
*, EXCMDARG
*));
140 int argv_exp0
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t));
141 int argv_exp1
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t, int));
142 int argv_exp2
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t, int));
143 int argv_exp3
__P((SCR
*, EXF
*, EXCMDARG
*, char *, size_t));
144 int argv_free
__P((SCR
*));
146 /* Ex function prototypes. */
147 int ex
__P((SCR
*, EXF
*));
148 int ex_cfile
__P((SCR
*, EXF
*, char *));
149 int ex_cmd
__P((SCR
*, EXF
*, char *, size_t));
150 int ex_end
__P((SCR
*));
151 int ex_exec_proc
__P((SCR
*, char *, char *, char *));
152 int ex_gb
__P((SCR
*, EXF
*, TEXTH
*, int, u_int
));
153 int ex_getline
__P((SCR
*, FILE *, size_t *));
154 int ex_icmd
__P((SCR
*, EXF
*, char *, size_t));
155 int ex_init
__P((SCR
*, EXF
*));
156 int ex_optchange
__P((SCR
*, int));
157 int ex_print
__P((SCR
*, EXF
*, MARK
*, MARK
*, int));
158 int ex_readfp
__P((SCR
*, EXF
*, char *, FILE *, MARK
*, recno_t
*, int));
159 void ex_refresh
__P((SCR
*, EXF
*));
160 int ex_screen_copy
__P((SCR
*, SCR
*));
161 int ex_screen_end
__P((SCR
*));
162 int ex_sdisplay
__P((SCR
*, EXF
*));
163 int ex_suspend
__P((SCR
*));
164 int ex_tdisplay
__P((SCR
*, EXF
*));
165 int ex_writefp
__P((SCR
*, EXF
*,
166 char *, FILE *, MARK
*, MARK
*, u_long
*, u_long
*));
167 int proc_wait
__P((SCR
*, long, const char *, int));
168 int sscr_end
__P((SCR
*));
169 int sscr_exec
__P((SCR
*, EXF
*, recno_t
));
170 int sscr_input
__P((SCR
*));
172 #define EXPROTO(type, name) \
173 type name __P((SCR *, EXF *, EXCMDARG *))
175 EXPROTO(int, ex_abbr
);
176 EXPROTO(int, ex_append
);
177 EXPROTO(int, ex_args
);
179 EXPROTO(int, ex_bang
);
182 EXPROTO(int, ex_change
);
183 EXPROTO(int, ex_color
);
184 EXPROTO(int, ex_copy
);
185 EXPROTO(int, ex_debug
);
186 EXPROTO(int, ex_delete
);
187 EXPROTO(int, ex_digraph
);
188 EXPROTO(int, ex_display
);
189 EXPROTO(int, ex_edit
);
190 EXPROTO(int, ex_equal
);
192 EXPROTO(int, ex_file
);
193 EXPROTO(int, ex_global
);
194 EXPROTO(int, ex_help
);
195 EXPROTO(int, ex_insert
);
196 EXPROTO(int, ex_join
);
197 EXPROTO(int, ex_list
);
198 EXPROTO(int, ex_map
);
199 EXPROTO(int, ex_mark
);
200 EXPROTO(int, ex_mkexrc
);
201 EXPROTO(int, ex_move
);
202 EXPROTO(int, ex_next
);
203 EXPROTO(int, ex_number
);
204 EXPROTO(int, ex_open
);
206 EXPROTO(int, ex_preserve
);
207 EXPROTO(int, ex_prev
);
208 EXPROTO(int, ex_put
);
209 EXPROTO(int, ex_quit
);
210 EXPROTO(int, ex_read
);
211 EXPROTO(int, ex_resize
);
212 EXPROTO(int, ex_rew
);
213 EXPROTO(int, ex_script
);
214 EXPROTO(int, ex_set
);
215 EXPROTO(int, ex_shell
);
216 EXPROTO(int, ex_shiftl
);
217 EXPROTO(int, ex_shiftr
);
218 EXPROTO(int, ex_source
);
219 EXPROTO(int, ex_split
);
220 EXPROTO(int, ex_stop
);
221 EXPROTO(int, ex_subagain
);
222 EXPROTO(int, ex_substitute
);
223 EXPROTO(int, ex_subtilde
);
224 EXPROTO(int, ex_tagpop
);
225 EXPROTO(int, ex_tagpush
);
226 EXPROTO(int, ex_tagtop
);
227 EXPROTO(int, ex_unabbr
);
228 EXPROTO(int, ex_undo
);
229 EXPROTO(int, ex_undol
);
230 EXPROTO(int, ex_unmap
);
231 EXPROTO(int, ex_usage
);
232 EXPROTO(int, ex_validate
);
233 EXPROTO(int, ex_version
);
234 EXPROTO(int, ex_vglobal
);
235 EXPROTO(int, ex_visual
);
236 EXPROTO(int, ex_viusage
);
238 EXPROTO(int, ex_write
);
239 EXPROTO(int, ex_xit
);
240 EXPROTO(int, ex_yank
);