Commit | Line | Data |
---|---|---|
ad787160 C |
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 | * @(#)excmd.h.stub 8.1 (Berkeley) 6/9/93 | |
34 | */ | |
35 | ||
36 | struct _excmdarg; | |
37 | ||
38 | /* Ex command structure. */ | |
39 | typedef struct _excmdlist { | |
40 | char *name; /* Command name. */ | |
41 | /* Underlying function. */ | |
42 | int (*fn) __P((SCR *, EXF *, struct _excmdarg *)); | |
43 | ||
44 | #define E_ADDR1 0x00001 /* One address. */ | |
45 | #define E_ADDR2 0x00002 /* Two address. */ | |
46 | #define E_ADDR2_ALL 0x00004 /* Zero/two addresses; zero == all. */ | |
47 | #define E_ADDR2_NONE 0x00008 /* Zero/two addresses; zero == none. */ | |
48 | #define E_FORCE 0x00010 /* ! */ | |
49 | ||
50 | #define E_F_CARAT 0x00020 /* ^ flag. */ | |
51 | #define E_F_DASH 0x00040 /* - flag. */ | |
52 | #define E_F_DOT 0x00080 /* . flag. */ | |
53 | #define E_F_HASH 0x00100 /* # flag. */ | |
54 | #define E_F_LIST 0x00200 /* l flag. */ | |
55 | #define E_F_PLUS 0x00400 /* + flag. */ | |
56 | #define E_F_PRINT 0x00800 /* p flag. */ | |
57 | #define E_F_MASK 0x00fe0 /* Flag mask. */ | |
58 | #define E_F_PRCLEAR 0x01000 /* Clear the print (#, l, p) flags. */ | |
59 | ||
60 | #define E_NOGLOBAL 0x02000 /* Not in a global. */ | |
61 | #define E_NOPERM 0x04000 /* Permission denied for now. */ | |
62 | #define E_NORC 0x08000 /* Not from a .exrc or EXINIT. */ | |
63 | #define E_SETLAST 0x10000 /* Reset last command. */ | |
64 | #define E_ZERO 0x20000 /* 0 is a legal addr1. */ | |
65 | #define E_ZERODEF 0x40000 /* 0 is default addr1 of empty files. */ | |
66 | u_int flags; | |
67 | char *syntax; /* Syntax script. */ | |
68 | char *usage; /* Usage line. */ | |
69 | } EXCMDLIST; | |
70 | extern EXCMDLIST cmds[]; /* List of ex commands. */ | |
71 | ||
72 | /* Structure passed around to functions implementing ex commands. */ | |
73 | typedef struct _excmdarg { | |
74 | EXCMDLIST *cmd; /* Command entry in command table. */ | |
75 | int addrcnt; /* Number of addresses (0, 1 or 2). */ | |
76 | MARK addr1; /* 1st address. */ | |
77 | MARK addr2; /* 2nd address. */ | |
78 | recno_t lineno; /* Line number. */ | |
79 | u_int flags; /* Selected flags from EXCMDLIST. */ | |
80 | int argc; /* Count of file/word arguments. */ | |
81 | char **argv; /* List of file/word arguments. */ | |
82 | char *command; /* Command line, if parse locally. */ | |
83 | char *plus; /* '+' command word. */ | |
84 | char *string; /* String. */ | |
85 | int buffer; /* Named buffer. */ | |
86 | } EXCMDARG; | |
87 | ||
88 | extern char *defcmdarg[2]; /* Default array. */ | |
89 | ||
90 | /* Macro to set up the structure. */ | |
91 | #define SETCMDARG(s, _cmd, _addrcnt, _lno1, _lno2, _force, _arg) { \ | |
92 | memset(&s, 0, sizeof(EXCMDARG)); \ | |
93 | s.cmd = &cmds[_cmd]; \ | |
94 | s.addrcnt = (_addrcnt); \ | |
95 | s.addr1.lno = (_lno1); \ | |
96 | s.addr2.lno = (_lno2); \ | |
97 | s.addr1.cno = s.addr2.cno = 1; \ | |
98 | if (_force) \ | |
99 | s.flags |= E_FORCE; \ | |
100 | s.argc = _arg ? 1 : 0; \ | |
101 | s.argv = defcmdarg; \ | |
102 | s.string = ""; \ | |
103 | defcmdarg[0] = _arg; \ | |
104 | } | |
105 | ||
106 | /* Control character. */ | |
107 | #define ctrl(ch) ((ch) & 0x1f) | |
108 | ||
109 | #define AUTOWRITE(sp, ep) { \ | |
110 | if (F_ISSET((ep), F_MODIFIED) && O_ISSET((sp), O_AUTOWRITE) && \ | |
111 | file_write((sp), (ep), NULL, NULL, NULL, FS_ALL)) \ | |
112 | return (1); \ | |
113 | } | |
114 | ||
115 | #define MODIFY_CHECK(sp, ep, force) { \ | |
116 | if (F_ISSET((ep), F_MODIFIED)) \ | |
117 | if (O_ISSET((sp), O_AUTOWRITE)) { \ | |
118 | if (file_write((sp), (ep), NULL, NULL, NULL, \ | |
119 | FS_ALL | force?FS_FORCE:0 | FS_POSSIBLE)) \ | |
120 | return (1); \ | |
121 | } else if (ep->refcnt <= 1 && !(force)) { \ | |
122 | msgq(sp, M_ERR, \ | |
123 | "Modified since last write; write or use ! to override."); \ | |
124 | return (1); \ | |
125 | } \ | |
126 | } | |
127 | ||
128 | #define MODIFY_WARN(sp, ep) { \ | |
129 | if (F_ISSET(ep, F_MODIFIED) && O_ISSET(sp, O_WARN)) \ | |
130 | (void)fprintf(sp->stdfp, \ | |
131 | "Modified since last write.\n"); \ | |
132 | } | |
133 | ||
134 | /* Ex function prototypes. */ | |
135 | int buildargv __P((SCR *, EXF *, char *, int, int *, char ***)); | |
136 | int esystem __P((SCR *, const u_char *, const u_char *)); | |
137 | int ex_run_process __P((SCR *, char *, size_t *, char *, size_t)); | |
138 | void set_altfname __P((SCR *, char *)); | |
139 | ||
140 | int ex __P((SCR *, EXF *)); | |
141 | int ex_cfile __P((SCR *, EXF *, char *, int)); | |
142 | int ex_cmd __P((SCR *, EXF *, char *)); | |
143 | int ex_cstring __P((SCR *, EXF *, char *, int)); | |
144 | int ex_end __P((SCR *)); | |
145 | int ex_gb __P((SCR *, EXF *, HDR *, int, u_int)); | |
146 | int ex_getline __P((SCR *, FILE *, size_t *)); | |
147 | int ex_init __P((SCR *, EXF *)); | |
148 | int ex_print __P((SCR *, EXF *, MARK *, MARK *, int)); | |
149 | int ex_readfp __P((SCR *, EXF *, char *, FILE *, MARK *, recno_t *)); | |
150 | int ex_suspend __P((SCR *)); | |
151 | int ex_writefp __P((SCR *, EXF *, char *, FILE *, MARK *, MARK *, int)); | |
152 | void ex_refresh __P((SCR *, EXF *)); | |
153 | ||
154 | #define EXPROTO(type, name) \ | |
155 | type name __P((SCR *, EXF *, EXCMDARG *)); | |
156 | ||
157 | EXPROTO(int, ex_abbr); | |
158 | EXPROTO(int, ex_append); | |
159 | EXPROTO(int, ex_args); | |
160 | EXPROTO(int, ex_at); | |
161 | EXPROTO(int, ex_bang); | |
162 | EXPROTO(int, ex_bdisplay); | |
163 | EXPROTO(int, ex_cc); | |
164 | EXPROTO(int, ex_cd); | |
165 | EXPROTO(int, ex_change); | |
166 | EXPROTO(int, ex_color); | |
167 | EXPROTO(int, ex_copy); | |
168 | EXPROTO(int, ex_debug); | |
169 | EXPROTO(int, ex_delete); | |
170 | EXPROTO(int, ex_digraph); | |
171 | EXPROTO(int, ex_edit); | |
172 | EXPROTO(int, ex_equal); | |
173 | EXPROTO(int, ex_errlist); | |
174 | EXPROTO(int, ex_file); | |
175 | EXPROTO(int, ex_global); | |
176 | EXPROTO(int, ex_join); | |
177 | EXPROTO(int, ex_list); | |
178 | EXPROTO(int, ex_make); | |
179 | EXPROTO(int, ex_map); | |
180 | EXPROTO(int, ex_mark); | |
181 | EXPROTO(int, ex_mkexrc); | |
182 | EXPROTO(int, ex_move); | |
183 | EXPROTO(int, ex_next); | |
184 | EXPROTO(int, ex_number); | |
185 | EXPROTO(int, ex_pr); | |
186 | EXPROTO(int, ex_preserve); | |
187 | EXPROTO(int, ex_prev); | |
188 | EXPROTO(int, ex_put); | |
189 | EXPROTO(int, ex_quit); | |
190 | EXPROTO(int, ex_read); | |
191 | EXPROTO(int, ex_rew); | |
192 | EXPROTO(int, ex_set); | |
193 | EXPROTO(int, ex_shell); | |
194 | EXPROTO(int, ex_shiftl); | |
195 | EXPROTO(int, ex_shiftr); | |
196 | EXPROTO(int, ex_source); | |
197 | EXPROTO(int, ex_split); | |
198 | EXPROTO(int, ex_stop); | |
199 | EXPROTO(int, ex_subagain); | |
200 | EXPROTO(int, ex_substitute); | |
201 | EXPROTO(int, ex_tagpop); | |
202 | EXPROTO(int, ex_tagpush); | |
203 | EXPROTO(int, ex_tagtop); | |
204 | EXPROTO(int, ex_unabbr); | |
205 | EXPROTO(int, ex_undo); | |
206 | EXPROTO(int, ex_undol); | |
207 | EXPROTO(int, ex_unmap); | |
208 | EXPROTO(int, ex_usage); | |
209 | EXPROTO(int, ex_validate); | |
210 | EXPROTO(int, ex_version); | |
211 | EXPROTO(int, ex_vglobal); | |
212 | EXPROTO(int, ex_visual); | |
213 | EXPROTO(int, ex_viusage); | |
214 | EXPROTO(int, ex_wq); | |
215 | EXPROTO(int, ex_write); | |
216 | EXPROTO(int, ex_xit); | |
217 | EXPROTO(int, ex_yank); |