minor char * -> CHAR_T *
[nvi.git] / ex / ex.h
blob2d6a7a3ff0bb1b5b2bbafe7004ae35ea32b8f876
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.40 1993/12/19 12:59:47 bostic Exp $ (Berkeley) $Date: 1993/12/19 12:59:47 $
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_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. */
42 u_long flags;
43 char *syntax; /* Syntax script. */
44 char *usage; /* Usage line. */
45 char *help; /* Help line. */
46 } EXCMDLIST;
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. */
51 struct _excmdarg {
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. */
83 } EX_PRIVATE;
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) { \
88 ARGS *__ap[2], __a; \
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; \
95 if (force) \
96 s.flags |= E_FORCE; \
97 if ((__a.bp = arg) == NULL) { \
98 s.argc = 0; \
99 __a.len = 0; \
100 } else { \
101 s.argc = 1; \
102 __a.len = strlen(arg); \
104 __ap[0] = &__a; \
105 __ap[1] = NULL; \
106 s.argv = __ap; \
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)) { \
116 if (!(force) && \
117 file_write((sp), (ep), NULL, NULL, NULL, \
118 FS_ALL | FS_POSSIBLE)) \
119 return (1); \
120 } else if (ep->refcnt <= 1 && !(force)) { \
121 msgq(sp, M_ERR, \
122 "Modified since last write; write or use ! to override."); \
123 return (1); \
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"); \
144 rval = 1; \
145 goto err; \
147 if (tcsetattr(STDIN_FILENO, TCSANOW | TCSASOFT, \
148 &sp->gp->original_termios)) { \
149 msgq(sp, M_SYSERR, "tcsetattr"); \
150 rval = 1; \
151 goto err; \
154 /* \
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. \
159 */ \
160 sb.st_mtime = 1; \
161 osb.st_mtime = 0; \
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"); \
169 rval = 1; \
171 if (tcsetattr(STDIN_FILENO, \
172 TCSANOW | TCSASOFT, &(term))) { \
173 msgq(sp, M_SYSERR, "tcsetattr"); \
174 rval = 1; \
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); \
184 * Filter actions:
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_optchange __P((SCR *, int));
213 int ex_print __P((SCR *, EXF *, MARK *, MARK *, int));
214 int ex_readfp __P((SCR *, EXF *, char *, FILE *, MARK *, recno_t *, int));
215 void ex_refresh __P((SCR *, EXF *));
216 int ex_screen_copy __P((SCR *, SCR *));
217 int ex_screen_end __P((SCR *));
218 int ex_sdisplay __P((SCR *, EXF *));
219 int ex_suspend __P((SCR *));
220 int ex_tdisplay __P((SCR *, EXF *));
221 int ex_writefp __P((SCR *, EXF *,
222 char *, FILE *, MARK *, MARK *, u_long *, u_long *));
223 int proc_wait __P((SCR *, long, const char *, int));
224 int sscr_end __P((SCR *));
225 int sscr_exec __P((SCR *, EXF *, recno_t));
226 int sscr_input __P((SCR *));
228 #define EXPROTO(type, name) \
229 type name __P((SCR *, EXF *, EXCMDARG *))
231 EXPROTO(int, ex_abbr);
232 EXPROTO(int, ex_append);
233 EXPROTO(int, ex_args);
234 EXPROTO(int, ex_at);
235 EXPROTO(int, ex_bang);
236 EXPROTO(int, ex_bg);
237 EXPROTO(int, ex_cd);
238 EXPROTO(int, ex_change);
239 EXPROTO(int, ex_color);
240 EXPROTO(int, ex_copy);
241 EXPROTO(int, ex_debug);
242 EXPROTO(int, ex_delete);
243 EXPROTO(int, ex_digraph);
244 EXPROTO(int, ex_display);
245 EXPROTO(int, ex_edit);
246 EXPROTO(int, ex_equal);
247 EXPROTO(int, ex_fg);
248 EXPROTO(int, ex_file);
249 EXPROTO(int, ex_global);
250 EXPROTO(int, ex_help);
251 EXPROTO(int, ex_insert);
252 EXPROTO(int, ex_join);
253 EXPROTO(int, ex_list);
254 EXPROTO(int, ex_map);
255 EXPROTO(int, ex_mark);
256 EXPROTO(int, ex_mkexrc);
257 EXPROTO(int, ex_move);
258 EXPROTO(int, ex_next);
259 EXPROTO(int, ex_number);
260 EXPROTO(int, ex_open);
261 EXPROTO(int, ex_pr);
262 EXPROTO(int, ex_preserve);
263 EXPROTO(int, ex_prev);
264 EXPROTO(int, ex_put);
265 EXPROTO(int, ex_quit);
266 EXPROTO(int, ex_read);
267 EXPROTO(int, ex_resize);
268 EXPROTO(int, ex_rew);
269 EXPROTO(int, ex_script);
270 EXPROTO(int, ex_set);
271 EXPROTO(int, ex_shell);
272 EXPROTO(int, ex_shiftl);
273 EXPROTO(int, ex_shiftr);
274 EXPROTO(int, ex_source);
275 EXPROTO(int, ex_split);
276 EXPROTO(int, ex_stop);
277 EXPROTO(int, ex_subagain);
278 EXPROTO(int, ex_substitute);
279 EXPROTO(int, ex_subtilde);
280 EXPROTO(int, ex_tagpop);
281 EXPROTO(int, ex_tagpush);
282 EXPROTO(int, ex_tagtop);
283 EXPROTO(int, ex_unabbr);
284 EXPROTO(int, ex_undo);
285 EXPROTO(int, ex_undol);
286 EXPROTO(int, ex_unmap);
287 EXPROTO(int, ex_usage);
288 EXPROTO(int, ex_validate);
289 EXPROTO(int, ex_version);
290 EXPROTO(int, ex_vglobal);
291 EXPROTO(int, ex_visual);
292 EXPROTO(int, ex_viusage);
293 EXPROTO(int, ex_wq);
294 EXPROTO(int, ex_write);
295 EXPROTO(int, ex_xit);
296 EXPROTO(int, ex_yank);
297 EXPROTO(int, ex_z);