add checks for .exrc files -- don't source the startup files unless
[nvi.git] / ex / ex_cmd.c
blob641f21c30cbc89db472462ee1fe63b1a45900af3
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
9 static char sccsid[] = "$Id: ex_cmd.c,v 8.32 1993/12/17 13:45:08 bostic Exp $ (Berkeley) $Date: 1993/12/17 13:45:08 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "excmd.h"
18 * This array maps ex command names to command functions.
20 * The order in which command names are listed below is important --
21 * ambiguous abbreviations are resolved to be the first possible match,
22 * e.g. "r" means "read", not "rewind", because "read" is listed before
23 * "rewind".
25 * The syntax of the ex commands is unbelievably irregular, and a special
26 * case from beginning to end. Each command has an associated "syntax
27 * script" which describes the "arguments" that are possible. The script
28 * syntax is as follows:
30 * ! -- ! flag
31 * 1 -- flags: [+-]*[pl#][+-]*
32 * 2 -- flags: [-.+^]
33 * 3 -- flags: [-.+^=]
34 * b -- buffer
35 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
36 * f[N#][or] -- file (a number or N, optional or required)
37 * l -- line
38 * S -- string with file name expansion
39 * s -- string
40 * W -- word string
41 * w[N#][or] -- word (a number or N, optional or required)
43 EXCMDLIST const cmds[] = {
44 /* C_BANG */
45 {"!", ex_bang, E_ADDR2_NONE|E_NORC,
46 "S",
47 "[line [,line]] ! command",
48 "filter lines through commands or run commands"},
49 /* C_HASH */
50 {"#", ex_number, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
51 "ca1",
52 "[line [,line]] # [count] [l]",
53 "display numbered lines"},
54 /* C_SUBAGAIN */
55 {"&", ex_subagain, E_ADDR2|E_NORC,
56 "s",
57 "[line [,line]] & [cgr] [count] [#lp]",
58 "repeat the last subsitution"},
59 /* C_STAR */
60 {"*", ex_at, 0,
61 "b",
62 "* [buffer]",
63 "execute a buffer"},
64 /* C_SHIFTL */
65 {"<", ex_shiftl, E_ADDR2|E_NORC,
66 "ca1",
67 "[line [,line]] <[<...] [count] [flags]",
68 "shift lines left"},
69 /* C_EQUAL */
70 {"=", ex_equal, E_ADDR1|E_NORC,
71 "1",
72 "[line] = [flags]",
73 "display line number"},
74 /* C_SHIFTR */
75 {">", ex_shiftr, E_ADDR2|E_NORC,
76 "ca1",
77 "[line [,line]] >[>...] [count] [flags]",
78 "shift lines right"},
79 /* C_AT */
80 {"@", ex_at, 0,
81 "b",
82 "@ [buffer]",
83 "execute a buffer"},
84 /* C_SUBTILDE */
85 {"~", ex_subtilde, E_ADDR2|E_NORC,
86 "s",
87 "[line [,line]] ~ [cgr] [count] [#lp]",
88 "replace previous RE with previous replacement string,"},
89 /* C_APPEND */
90 {"append", ex_append, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
91 "!",
92 "[line] a[ppend][!]",
93 "append input to a line"},
94 /* C_ABBR */
95 {"abbreviate", ex_abbr, E_NOGLOBAL,
96 "W",
97 "ab[brev] word replace",
98 "specify an input abbreviation"},
99 /* C_ARGS */
100 {"args", ex_args, E_NOGLOBAL|E_NORC,
101 "",
102 "ar[gs]",
103 "display file argument list"},
104 /* C_BG */
105 {"bg", ex_bg, E_NOGLOBAL|E_NORC,
107 "bg",
108 "background the current screen"},
109 /* C_CHANGE */
110 {"change", ex_change, E_ADDR2|E_NORC|E_ZERODEF,
111 "!ca",
112 "[line [,line]] c[hange][!] [count]",
113 "change lines to input"},
114 /* C_CD */
115 {"cd", ex_cd, E_NOGLOBAL,
116 "!f1o",
117 "cd[!] [directory]",
118 "change the current directory"},
119 /* C_CHDIR */
120 {"chdir", ex_cd, E_NOGLOBAL,
121 "!f1o",
122 "chd[ir][!] [directory]",
123 "change the current directory"},
124 /* C_COPY */
125 {"copy", ex_copy, E_ADDR2|E_NORC,
126 "l1",
127 "[line [,line]] co[py] line [flags]",
128 "copy lines elsewhere in the file"},
129 /* C_DELETE */
130 {"delete", ex_delete, E_ADDR2|E_NORC,
131 "bca1",
132 "[line [,line]] d[elete] [buffer] [count] [flags]",
133 "delete lines from the file"},
134 /* C_DISPLAY */
135 {"display", ex_display, E_NOGLOBAL|E_NORC,
136 "w1r",
137 "display b[uffers] | s[creens] | t[ags]",
138 "display buffers, screens or tags"},
139 /* C_DIGRAPH */
140 {"digraph", ex_digraph, E_NOGLOBAL|E_NOPERM|E_NORC,
141 "",
142 "digraph",
143 "specify digraphs (not implemented)"},
144 /* C_EDIT */
145 {"edit", ex_edit, E_NOGLOBAL|E_NORC,
146 "!f1o",
147 "e[dit][!] [+cmd] [file]",
148 "begin editing another file"},
149 /* C_EX */
150 {"ex", ex_edit, E_NOGLOBAL|E_NORC,
151 "!f1o",
152 "ex[!] [+cmd] [file]",
153 "begin editing another file"},
154 /* C_EXUSAGE */
155 {"exusage", ex_usage, E_NOGLOBAL|E_NORC,
156 "w1o",
157 "[exu]sage [command]",
158 "display ex command usage statement"},
159 /* C_FILE */
160 {"file", ex_file, E_NOGLOBAL|E_NORC,
161 "f1o",
162 "f[ile] [name]",
163 "display (and optionally set) file name"},
164 /* C_FG */
165 {"fg", ex_fg, E_NOGLOBAL|E_NORC,
166 "f1o",
167 "fg [file]",
168 "switch the current screen and a backgrounded screen"},
169 /* C_GLOBAL */
170 {"global", ex_global, E_ADDR2_ALL|E_NOGLOBAL|E_NORC,
171 "!s",
172 "[line [,line]] g[lobal][!] [;/]pattern[;/] [commands]",
173 "execute a global command on lines matching a pattern"},
174 /* C_HELP */
175 {"help", ex_help, E_NOGLOBAL|E_NORC,
177 "he[lp]",
178 "display help statement"},
179 /* C_INSERT */
180 {"insert", ex_insert, E_ADDR1|E_NORC,
181 "!",
182 "[line] i[nsert][!]",
183 "insert input before a line"},
184 /* C_JOIN */
185 {"join", ex_join, E_ADDR2|E_NORC,
186 "!ca1",
187 "[line [,line]] j[oin][!] [count] [flags]",
188 "join lines into a single line"},
189 /* C_K */
190 {"k", ex_mark, E_ADDR1|E_NORC,
191 "w1r",
192 "[line] k key",
193 "mark a line position"},
194 /* C_LIST */
195 {"list", ex_list, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
196 "ca1",
197 "[line [,line]] l[ist] [count] [#]",
198 "display lines in an unambiguous form"},
199 /* C_MOVE */
200 {"move", ex_move, E_ADDR2|E_NORC,
201 "l",
202 "[line [,line]] m[ove] line",
203 "move lines elsewhere in the file"},
204 /* C_MARK */
205 {"mark", ex_mark, E_ADDR1|E_NORC,
206 "w1r",
207 "[line] ma[rk] key",
208 "mark a line position"},
209 /* C_MAP */
210 {"map", ex_map, 0,
211 "!W",
212 "map[!] [keys replace]",
213 "map input or commands to one or more keys"},
214 /* C_MKEXRC */
215 {"mkexrc", ex_mkexrc, E_NOGLOBAL|E_NORC,
216 "!f1r",
217 "mkexrc[!] file",
218 "write a .exrc file"},
219 /* C_NEXT */
220 {"next", ex_next, E_NOGLOBAL|E_NORC,
221 "!fN",
222 "n[ext][!] [file ...]",
223 "edit (and optionally specify) the next file"},
224 /* C_NUMBER */
225 {"number", ex_number, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
226 "ca1",
227 "[line [,line]] nu[mber] [count] [l]",
228 "change display to number lines"},
229 /* C_OPEN */
230 {"open", ex_open, E_ADDR1,
231 "s",
232 "[line] o[pen] [/pattern/] [flags]",
233 "enter \"open\" mode (not implemented)"},
234 /* C_PRINT */
235 {"print", ex_pr, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
236 "ca1",
237 "[line [,line]] p[rint] [count] [#l]",
238 "display lines"},
239 /* C_PRESERVE */
240 {"preserve", ex_preserve, E_NOGLOBAL|E_NORC,
241 "",
242 "pre[serve]",
243 "preserve an edit session for recovery"},
244 /* C_PREVIOUS */
245 {"previous", ex_prev, E_NOGLOBAL|E_NORC,
246 "!",
247 "prev[ious][!]",
248 "edit the previous file in the file argument list"},
249 /* C_PUT */
250 {"put", ex_put, E_ADDR1|E_NORC|E_ZERO,
251 "b",
252 "[line] pu[t] [buffer]",
253 "append a cut buffer to the line"},
254 /* C_QUIT */
255 {"quit", ex_quit, E_NOGLOBAL,
256 "!",
257 "q[uit][!]",
258 "exit ex/vi"},
259 /* C_READ */
260 {"read", ex_read, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
261 "!s",
262 "[line] r[ead] [!cmd | [file]]",
263 "append input from a command or file to the line"},
264 /* C_RESIZE */
265 {"resize", ex_resize, E_NOGLOBAL|E_NORC,
266 "c+",
267 "resize [change]",
268 "grow or shrink the current screen"},
269 /* C_REWIND */
270 {"rewind", ex_rew, E_NOGLOBAL|E_NORC,
271 "!",
272 "rew[ind][!]",
273 "re-edit all the files in the file argument list"},
274 /* C_SUBSTITUTE */
275 {"substitute", ex_substitute, E_ADDR2|E_NORC,
276 "s",
277 "[line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]",
278 "substitute on lines matching a pattern"},
279 /* C_SCRIPT */
280 {"script", ex_script, E_NOGLOBAL|E_NORC,
281 "!f1o",
282 "sc[ript][!] [file]",
283 "run a shell in a screen"},
284 /* C_SET */
285 {"set", ex_set, E_NOGLOBAL,
286 "wN",
287 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
288 "set options (use \":set all\" to see all options)"},
289 /* C_SHELL */
290 {"shell", ex_shell, E_NOGLOBAL|E_NORC,
291 "",
292 "sh[ell]",
293 "suspend editing and run a shell"},
294 /* C_SOURCE */
295 {"source", ex_source, E_NOGLOBAL,
296 "f1r",
297 "so[urce] file",
298 "read a file of ex commands"},
299 /* C_SPLIT */
300 {"split", ex_split, E_NOGLOBAL|E_NORC,
301 "fNo",
302 "s[plit] [file ...]",
303 "split the current screen into two screens"},
304 /* C_STOP */
305 {"stop", ex_stop, E_NOGLOBAL|E_NORC,
306 "!",
307 "st[op][!]",
308 "suspend the edit session"},
309 /* C_SUSPEND */
310 {"suspend", ex_stop, E_NOGLOBAL|E_NORC,
311 "!",
312 "su[spend][!]",
313 "suspend the edit session"},
314 /* C_T */
315 {"t", ex_copy, E_ADDR2|E_NORC,
316 "l1",
317 "[line [,line]] t line [flags]",
318 "move lines elsewhere in the file"},
319 /* C_TAG */
320 {"tag", ex_tagpush, E_NOGLOBAL,
321 "!w1o",
322 "ta[g][!] [string]",
323 "edit the file containing the tag"},
324 /* C_TAGPOP */
325 {"tagpop", ex_tagpop, E_NOGLOBAL|E_NORC,
326 "!w1o",
327 "tagp[op][!] [number | file]",
328 "return to a previous tag"},
329 /* C_TAGTOP */
330 {"tagtop", ex_tagtop, E_NOGLOBAL|E_NORC,
331 "!",
332 "tagt[op][!]",
333 "return to the first tag"},
334 /* C_UNDOL */
335 {"Undo", ex_undol, E_NOGLOBAL|E_NORC,
336 "",
337 "U[ndo]",
338 "undo all the changes to this line"},
339 /* C_UNDO */
340 {"undo", ex_undo, E_NOGLOBAL|E_NORC,
341 "",
342 "u[ndo]",
343 "undo the most recent change"},
344 /* C_UNABBREVIATE */
345 {"unabbreviate",ex_unabbr, E_NOGLOBAL,
346 "w1r",
347 "una[bbrev] word",
348 "delete an abbreviation"},
349 /* C_UNMAP */
350 {"unmap", ex_unmap, E_NOGLOBAL,
351 "!w1r",
352 "unm[ap][!] word",
353 "delete an input or command map"},
354 /* C_VGLOBAL */
355 {"vglobal", ex_vglobal, E_ADDR2_ALL|E_NOGLOBAL|E_NORC,
356 "s",
357 "[line [,line]] v[global] [;/]pattern[;/] [commands]",
358 "execute a global command on lines NOT matching a pattern"},
359 /* C_VERSION */
360 {"version", ex_version, E_NOGLOBAL|E_NORC,
361 "",
362 "version",
363 "display the program version information"},
364 /* C_VISUAL_EX */
365 {"visual", ex_visual, E_ADDR1|E_NOGLOBAL|E_NORC|E_ZERODEF,
366 "2c11",
367 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
368 "enter visual (vi) mode from ex mode"},
369 /* C_VISUAL_VI */
370 {"visual", ex_edit, E_NOGLOBAL|E_NORC,
371 "!f1o",
372 "vi[sual][!] [+cmd] [file]",
373 "edit another file (from vi mode only)"},
374 /* C_VIUSAGE */
375 {"viusage", ex_viusage, E_NOGLOBAL|E_NORC,
376 "w1o",
377 "[viu]sage [key]",
378 "display vi key usage statement"},
379 /* C_WRITE */
380 {"write", ex_write, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
381 "!s",
382 "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
383 "write the file"},
384 /* C_WQ */
385 {"wq", ex_wq, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
386 "!s",
387 "[line [,line]] wq[!] [>>] [file]",
388 "write the file and exit"},
389 /* C_XIT */
390 {"xit", ex_xit, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
391 "!f1o",
392 "[line [,line]] x[it][!] [file]",
393 "exit"},
394 /* C_YANK */
395 {"yank", ex_yank, E_ADDR2|E_NORC,
396 "bca",
397 "[line [,line]] ya[nk] [buffer] [count]",
398 "copy lines to a cut buffer"},
399 /* C_Z */
400 {"z", ex_z, E_ADDR1|E_NOGLOBAL|E_NORC,
401 "3c01",
402 "[line] z [-|.|+|^|=] [count] [flags]",
403 "display different screens of the file"},
404 {NULL},