2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
13 static const char sccsid[] = "@(#)ex_cmd.c 10.20 (Berkeley) 10/10/96";
16 #include <sys/types.h>
17 #include <sys/queue.h>
19 #include <bitstring.h>
23 #include "../common/common.h"
26 * This array maps ex command names to command functions.
28 * The order in which command names are listed below is important --
29 * ambiguous abbreviations are resolved to be the first possible match,
30 * e.g. "r" means "read", not "rewind", because "read" is listed before
33 * The syntax of the ex commands is unbelievably irregular, and a special
34 * case from beginning to end. Each command has an associated "syntax
35 * script" which describes the "arguments" that are possible. The script
36 * syntax is as follows:
39 * 1 -- flags: [+-]*[pl#][+-]*
43 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
44 * f[N#][or] -- file (a number or N, optional or required)
46 * S -- string with file name expansion
49 * w[N#][or] -- word (a number or N, optional or required)
51 EXCMDLIST const cmds[] = {
53 {"\004", ex_pr, E_ADDR2,
58 {"!", ex_bang, E_ADDR2_NONE | E_SECURE,
60 "[line [,line]] ! command",
61 "filter lines through commands or run commands"},
63 {"#", ex_number, E_ADDR2|E_CLRFLAG,
65 "[line [,line]] # [count] [l]",
66 "display numbered lines"},
68 {"&", ex_subagain, E_ADDR2,
70 "[line [,line]] & [cgr] [count] [#lp]",
71 "repeat the last subsitution"},
78 {"<", ex_shiftl, E_ADDR2|E_AUTOPRINT,
80 "[line [,line]] <[<...] [count] [flags]",
83 {"=", ex_equal, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
86 "display line number"},
88 {">", ex_shiftr, E_ADDR2|E_AUTOPRINT,
90 "[line [,line]] >[>...] [count] [flags]",
98 {"append", ex_append, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
100 "[line] a[ppend][!]",
101 "append input to a line"},
103 {"abbreviate", ex_abbr, 0,
105 "ab[brev] [word replace]",
106 "specify an input abbreviation"},
111 "display file argument list"},
113 {"bg", ex_bg, E_VIONLY,
116 "put a foreground screen into the background"},
118 {"change", ex_change, E_ADDR2|E_ADDR_ZERODEF,
120 "[line [,line]] c[hange][!] [count]",
121 "change lines to input"},
126 "change the current directory"},
130 "chd[ir][!] [directory]",
131 "change the current directory"},
133 {"copy", ex_copy, E_ADDR2|E_AUTOPRINT,
135 "[line [,line]] co[py] line [flags]",
136 "copy lines elsewhere in the file"},
138 {"cscope", ex_cscope, 0,
140 "cs[cope] command [args]",
141 "create a set of tags using a cscope command"},
144 * Adding new commands starting with 'd' may break the delete command code
145 * in ex_cmd() (the ex parser). Read through the comments there, first.
148 {"delete", ex_delete, E_ADDR2|E_AUTOPRINT,
150 "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
151 "delete lines from the file"},
153 {"display", ex_display, 0,
155 "display b[uffers] | c[onnections] | s[creens] | t[ags]",
156 "display buffers, connections, screens or tags"},
158 {"edit", ex_edit, E_NEWSCREEN,
160 "[Ee][dit][!] [+cmd] [file]",
161 "begin editing another file"},
163 {"ex", ex_edit, E_NEWSCREEN,
165 "[Ee]x[!] [+cmd] [file]",
166 "begin editing another file"},
168 {"exusage", ex_usage, 0,
170 "[exu]sage [command]",
171 "display ex command usage statement"},
176 "display (and optionally set) file name"},
178 {"fg", ex_fg, E_NEWSCREEN|E_VIONLY,
181 "bring a backgrounded screen into the foreground"},
183 {"global", ex_global, E_ADDR2_ALL,
185 "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
186 "execute a global command on lines matching an RE"},
191 "display help statement"},
193 {"insert", ex_insert, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
195 "[line] i[nsert][!]",
196 "insert input before a line"},
198 {"join", ex_join, E_ADDR2|E_AUTOPRINT,
200 "[line [,line]] j[oin][!] [count] [flags]",
201 "join lines into a single line"},
203 {"k", ex_mark, E_ADDR1,
206 "mark a line position"},
208 {"list", ex_list, E_ADDR2|E_CLRFLAG,
210 "[line [,line]] l[ist] [count] [#]",
211 "display lines in an unambiguous form"},
213 {"move", ex_move, E_ADDR2|E_AUTOPRINT,
215 "[line [,line]] m[ove] line",
216 "move lines elsewhere in the file"},
218 {"mark", ex_mark, E_ADDR1,
221 "mark a line position"},
225 "map[!] [keys replace]",
226 "map input or commands to one or more keys"},
228 {"mkexrc", ex_mkexrc, 0,
231 "write a .exrc file"},
233 {"next", ex_next, E_NEWSCREEN,
235 "[Nn][ext][!] [+cmd] [file ...]",
236 "edit (and optionally specify) the next file"},
238 {"number", ex_number, E_ADDR2|E_CLRFLAG,
240 "[line [,line]] nu[mber] [count] [l]",
241 "change display to number lines"},
243 {"open", ex_open, E_ADDR1,
245 "[line] o[pen] [/RE/] [flags]",
246 "enter \"open\" mode (not implemented)"},
248 {"print", ex_pr, E_ADDR2|E_CLRFLAG,
250 "[line [,line]] p[rint] [count] [#l]",
253 {"perl", ex_perl, E_ADDR2_ALL|E_ADDR_ZERO|
254 E_ADDR_ZERODEF|E_SECURE,
257 "run the perl interpreter with the command"},
259 {"perldo", ex_perl, E_ADDR2_ALL|E_ADDR_ZERO|
260 E_ADDR_ZERODEF|E_SECURE,
263 "run the perl interpreter with the command, on each line"},
265 {"preserve", ex_preserve, 0,
268 "preserve an edit session for recovery"},
270 {"previous", ex_prev, E_NEWSCREEN,
273 "edit the previous file in the file argument list"},
276 E_ADDR1|E_AUTOPRINT|E_ADDR_ZERO|E_ADDR_ZERODEF,
278 "[line] pu[t] [buffer]",
279 "append a cut buffer to the line"},
286 {"read", ex_read, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
288 "[line] r[ead] [!cmd | [file]]",
289 "append input from a command or file to the line"},
291 {"recover", ex_recover, 0,
294 "recover a saved file"},
296 {"resize", ex_resize, E_VIONLY,
299 "grow or shrink the current screen"},
301 {"rewind", ex_rew, 0,
304 "re-edit all the files in the file argument list"},
307 {"rtag", ex_rtag_push, E_NEWSCREEN,
309 "[Rr]ta[g][!] [string]",
310 "edit the file containing the tag"},
314 * Adding new commands starting with 's' may break the substitute command code
315 * in ex_cmd() (the ex parser). Read through the comments there, first.
320 "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]",
321 "substitute on lines matching an RE"},
323 {"script", ex_script, E_SECURE,
325 "sc[ript][!] [file]",
326 "run a shell in a screen"},
330 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
331 "set options (use \":set all\" to see all options)"},
333 {"shell", ex_shell, E_SECURE,
336 "suspend editing and run a shell"},
338 {"source", ex_source, 0,
341 "read a file of ex commands"},
343 {"stop", ex_stop, E_SECURE,
346 "suspend the edit session"},
348 {"suspend", ex_stop, E_SECURE,
351 "suspend the edit session"},
353 {"t", ex_copy, E_ADDR2|E_AUTOPRINT,
355 "[line [,line]] t line [flags]",
356 "copy lines elsewhere in the file"},
358 {"tag", ex_tag_push, E_NEWSCREEN,
360 "[Tt]a[g][!] [string]",
361 "edit the file containing the tag"},
363 {"tagnext", ex_tag_next, 0,
366 "move to the next tag"},
368 {"tagpop", ex_tag_pop, 0,
370 "tagp[op][!] [number | file]",
371 "return to the previous group of tags"},
373 {"tagprev", ex_tag_prev, 0,
376 "move to the previous tag"},
378 {"tagtop", ex_tag_top, 0,
383 {"tcl", ex_tcl, E_ADDR2_ALL|E_ADDR_ZERO|
384 E_ADDR_ZERODEF|E_SECURE,
387 "run the tcl interpreter with the command"},
389 {"undo", ex_undo, E_AUTOPRINT,
392 "undo the most recent change"},
394 {"unabbreviate",ex_unabbr, 0,
397 "delete an abbreviation"},
399 {"unmap", ex_unmap, 0,
402 "delete an input or command map"},
404 {"v", ex_v, E_ADDR2_ALL,
406 "[line [,line]] v [;/]RE[;/] [commands]",
407 "execute a global command on lines NOT matching an RE"},
409 {"version", ex_version, 0,
412 "display the program version information"},
414 {"visual", ex_visual, E_ADDR1|E_ADDR_ZERODEF,
416 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
417 "enter visual (vi) mode from ex mode"},
419 {"visual", ex_edit, E_NEWSCREEN,
421 "[Vv]i[sual][!] [+cmd] [file]",
422 "edit another file (from vi mode only)"},
424 {"viusage", ex_viusage, 0,
427 "display vi key usage statement"},
429 {"write", ex_write, E_ADDR2_ALL|E_ADDR_ZERODEF,
431 "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]",
434 {"wn", ex_wn, E_ADDR2_ALL|E_ADDR_ZERODEF,
436 "[line [,line]] wn[!] [>>] [file]",
437 "write the file and switch to the next file"},
439 {"wq", ex_wq, E_ADDR2_ALL|E_ADDR_ZERODEF,
441 "[line [,line]] wq[!] [>>] [file]",
442 "write the file and exit"},
444 {"xit", ex_xit, E_ADDR2_ALL|E_ADDR_ZERODEF,
446 "[line [,line]] x[it][!] [file]",
449 {"yank", ex_yank, E_ADDR2,
451 "[line [,line]] ya[nk] [buffer] [count]",
452 "copy lines to a cut buffer"},
456 "[line] z [-|.|+|^|=] [count] [flags]",
457 "display different screens of the file"},
459 {"~", ex_subtilde, E_ADDR2,
461 "[line [,line]] ~ [cgr] [count] [#lp]",
462 "replace previous RE with previous replacement string,"},