1 /* $NetBSD: ex_cmd.c,v 1.2 2008/10/29 17:50:49 christos Exp $ */
4 * Copyright (c) 1992, 1993, 1994
5 * The Regents of the University of California. All rights reserved.
6 * Copyright (c) 1992, 1993, 1994, 1995, 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
15 static const char sccsid
[] = "Id: ex_cmd.c,v 10.25 2001/06/10 10:23:44 skimo Exp (Berkeley) Date: 2001/06/10 10:23:44";
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <bitstring.h>
25 #include "../common/common.h"
28 * This array maps ex command names to command functions.
30 * The order in which command names are listed below is important --
31 * ambiguous abbreviations are resolved to be the first possible match,
32 * e.g. "r" means "read", not "rewind", because "read" is listed before
35 * The syntax of the ex commands is unbelievably irregular, and a special
36 * case from beginning to end. Each command has an associated "syntax
37 * script" which describes the "arguments" that are possible. The script
38 * syntax is as follows:
41 * 1 -- flags: [+-]*[pl#][+-]*
45 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
46 * f[N#][or] -- file (a number or N, optional or required)
48 * S -- string with file name expansion
51 * w[N#][or] -- word (a number or N, optional or required)
53 EXCMDLIST
const cmds
[] = {
55 {L("\004"), ex_pr
, E_ADDR2
,
60 {L("!"), ex_bang
, E_ADDR2_NONE
|E_SECURE
,
62 "[line [,line]] ! command",
63 "filter lines through commands or run commands"},
65 {L("#"), ex_number
, E_ADDR2
|E_CLRFLAG
,
67 "[line [,line]] # [count] [l]",
68 "display numbered lines"},
70 {L("&"), ex_subagain
, E_ADDR2
|E_ADDR_ZERO
,
72 "[line [,line]] & [cgr] [count] [#lp]",
73 "repeat the last subsitution"},
80 {L("<"), ex_shiftl
, E_ADDR2
|E_AUTOPRINT
,
82 "[line [,line]] <[<...] [count] [flags]",
85 {L("="), ex_equal
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
88 "display line number"},
90 {L(">"), ex_shiftr
, E_ADDR2
|E_AUTOPRINT
,
92 "[line [,line]] >[>...] [count] [flags]",
95 {L("@"), ex_at
, E_ADDR2
,
100 {L("append"), ex_append
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
102 "[line] a[ppend][!]",
103 "append input to a line"},
105 {L("abbreviate"), ex_abbr
, 0,
107 "ab[brev] [word replace]",
108 "specify an input abbreviation"},
110 {L("args"), ex_args
, 0,
113 "display file argument list"},
115 {L("bg"), ex_bg
, E_VIONLY
,
118 "put a foreground screen into the background"},
120 {L("change"), ex_change
, E_ADDR2
|E_ADDR_ZERODEF
,
122 "[line [,line]] c[hange][!] [count]",
123 "change lines to input"},
128 "change the current directory"},
130 {L("chdir"), ex_cd
, 0,
132 "chd[ir][!] [directory]",
133 "change the current directory"},
135 {L("copy"), ex_copy
, E_ADDR2
|E_AUTOPRINT
,
137 "[line [,line]] co[py] line [flags]",
138 "copy lines elsewhere in the file"},
140 {L("cscope"), ex_cscope
, 0,
142 "cs[cope] command [args]",
143 "create a set of tags using a cscope command"},
146 * Adding new commands starting with 'd' may break the delete command code
147 * in ex_cmd() (the ex parser). Read through the comments there, first.
150 {L("delete"), ex_delete
, E_ADDR2
|E_AUTOPRINT
,
152 "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
153 "delete lines from the file"},
155 {L("display"), ex_display
, 0,
157 "display b[uffers] | c[onnections] | s[creens] | t[ags]",
158 "display buffers, connections, screens or tags"},
160 {L("edit"), ex_edit
, E_NEWSCREEN
,
162 "[Ee][dit][!] [+cmd] [file]",
163 "begin editing another file"},
165 {L("ex"), ex_edit
, E_NEWSCREEN
,
167 "[Ee]x[!] [+cmd] [file]",
168 "begin editing another file"},
170 {L("exusage"), ex_usage
, 0,
172 "[exu]sage [command]",
173 "display ex command usage statement"},
175 {L("file"), ex_file
, 0,
178 "display (and optionally set) file name"},
180 {L("fg"), ex_fg
, E_NEWSCREEN
|E_VIONLY
,
183 "bring a backgrounded screen into the foreground"},
185 {L("global"), ex_global
, E_ADDR2_ALL
,
187 "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
188 "execute a global command on lines matching an RE"},
190 {L("help"), ex_help
, 0,
193 "display help statement"},
195 {L("insert"), ex_insert
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
197 "[line] i[nsert][!]",
198 "insert input before a line"},
200 {L("join"), ex_join
, E_ADDR2
|E_AUTOPRINT
,
202 "[line [,line]] j[oin][!] [count] [flags]",
203 "join lines into a single line"},
205 {L("k"), ex_mark
, E_ADDR1
,
208 "mark a line position"},
210 {L("list"), ex_list
, E_ADDR2
|E_CLRFLAG
,
212 "[line [,line]] l[ist] [count] [#]",
213 "display lines in an unambiguous form"},
215 {L("move"), ex_move
, E_ADDR2
|E_AUTOPRINT
,
217 "[line [,line]] m[ove] line",
218 "move lines elsewhere in the file"},
220 {L("mark"), ex_mark
, E_ADDR1
,
223 "mark a line position"},
225 {L("map"), ex_map
, 0,
227 "map[!] [keys replace]",
228 "map input or commands to one or more keys"},
230 {L("mkexrc"), ex_mkexrc
, 0,
233 "write a .exrc file"},
235 {L("next"), ex_next
, E_NEWSCREEN
,
237 "[Nn][ext][!] [+cmd] [file ...]",
238 "edit (and optionally specify) the next file"},
240 {L("number"), ex_number
, E_ADDR2
|E_CLRFLAG
,
242 "[line [,line]] nu[mber] [count] [l]",
243 "change display to number lines"},
245 {L("open"), ex_open
, E_ADDR1
,
247 "[line] o[pen] [/RE/] [flags]",
248 "enter \"open\" mode (not implemented)"},
250 {L("print"), ex_pr
, E_ADDR2
|E_CLRFLAG
,
252 "[line [,line]] p[rint] [count] [#l]",
255 {L("perl"), ex_perl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
256 E_ADDR_ZERODEF
|E_SECURE
,
259 "run the perl interpreter with the command"},
261 {L("perldo"), ex_perl
, E_ADDR2
|E_ADDR_ZERO
|
262 E_ADDR_ZERODEF
|E_SECURE
,
265 "run the perl interpreter with the command, on each line"},
267 {L("preserve"), ex_preserve
, 0,
270 "preserve an edit session for recovery"},
272 {L("previous"), ex_prev
, E_NEWSCREEN
,
275 "edit the previous file in the file argument list"},
278 E_ADDR1
|E_AUTOPRINT
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
280 "[line] pu[t] [buffer]",
281 "append a cut buffer to the line"},
283 {L("quit"), ex_quit
, 0,
288 {L("read"), ex_read
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
290 "[line] r[ead] [!cmd | [file]]",
291 "append input from a command or file to the line"},
293 {L("recover"), ex_recover
, 0,
296 "recover a saved file"},
298 {L("resize"), ex_resize
, E_VIONLY
,
301 "grow or shrink the current screen"},
303 {L("rewind"), ex_rew
, 0,
306 "re-edit all the files in the file argument list"},
309 {L("rtag"), ex_rtag_push
, E_NEWSCREEN
,
311 "rta[g][!] [string]",
312 "edit the file containing the tag"},
316 * Adding new commands starting with 's' may break the substitute command code
317 * in ex_cmd() (the ex parser). Read through the comments there, first.
320 {L("s"), ex_s
, E_ADDR2
|E_ADDR_ZERO
,
322 "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]",
323 "substitute on lines matching an RE"},
325 {L("script"), ex_script
, E_SECURE
,
327 "sc[ript][!] [file]",
328 "run a shell in a screen"},
330 {L("set"), ex_set
, 0,
332 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
333 "set options (use \":set all\" to see all options)"},
335 {L("shell"), ex_shell
, E_SECURE
,
338 "suspend editing and run a shell"},
340 {L("source"), ex_source
, 0,
343 "read a file of ex commands"},
345 {L("stop"), ex_stop
, E_SECURE
,
348 "suspend the edit session"},
350 {L("suspend"), ex_stop
, E_SECURE
,
353 "suspend the edit session"},
355 {L("t"), ex_copy
, E_ADDR2
|E_AUTOPRINT
,
357 "[line [,line]] t line [flags]",
358 "copy lines elsewhere in the file"},
360 {L("tag"), ex_tag_push
, E_NEWSCREEN
,
362 "[Tt]a[g][!] [string]",
363 "edit the file containing the tag"},
365 {L("tagnext"), ex_tag_next
, 0,
368 "move to the next tag"},
370 {L("tagpop"), ex_tag_pop
, 0,
372 "tagp[op][!] [number | file]",
373 "return to the previous group of tags"},
375 {L("tagprev"), ex_tag_prev
, 0,
378 "move to the previous tag"},
380 {L("tagtop"), ex_tag_top
, 0,
385 {L("tcl"), ex_tcl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
386 E_ADDR_ZERODEF
|E_SECURE
,
389 "run the tcl interpreter with the command"},
391 {L("undo"), ex_undo
, E_AUTOPRINT
,
394 "undo the most recent change"},
396 {L("unabbreviate"),ex_unabbr
, 0,
399 "delete an abbreviation"},
401 {L("unmap"), ex_unmap
, 0,
404 "delete an input or command map"},
406 {L("v"), ex_v
, E_ADDR2_ALL
,
408 "[line [,line]] v [;/]RE[;/] [commands]",
409 "execute a global command on lines NOT matching an RE"},
411 {L("version"), ex_version
, 0,
414 "display the program version information"},
416 {L("visual"), ex_visual
, E_ADDR1
|E_ADDR_ZERODEF
,
418 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
419 "enter visual (vi) mode from ex mode"},
421 {L("visual"), ex_edit
, E_NEWSCREEN
,
423 "[Vv]i[sual][!] [+cmd] [file]",
424 "edit another file (from vi mode only)"},
426 {L("viusage"), ex_viusage
, 0,
429 "display vi key usage statement"},
431 {L("vsplit"), ex_edit
, E_VIONLY
,
433 "vs[plit] [+cmd] [file]",
434 "split the current screen vertically"},
436 {L("write"), ex_write
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
438 "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]",
441 {L("wn"), ex_wn
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
443 "[line [,line]] wn[!] [>>] [file]",
444 "write the file and switch to the next file"},
446 {L("wq"), ex_wq
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
448 "[line [,line]] wq[!] [>>] [file]",
449 "write the file and exit"},
451 {L("xit"), ex_xit
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
453 "[line [,line]] x[it][!] [file]",
456 {L("yank"), ex_yank
, E_ADDR2
,
458 "[line [,line]] ya[nk] [buffer] [count]",
459 "copy lines to a cut buffer"},
461 {L("z"), ex_z
, E_ADDR1
,
463 "[line] z [-|.|+|^|=] [count] [flags]",
464 "display different screens of the file"},
466 {L("~"), ex_subtilde
, E_ADDR2
|E_ADDR_ZERO
,
468 "[line [,line]] ~ [cgr] [count] [#lp]",
469 "replace previous RE with previous replacement string,"},