1 /* $NetBSD: ex_cmd.c,v 1.2 2013/11/22 15:52:05 christos Exp $ */
3 * Copyright (c) 1992, 1993, 1994
4 * The Regents of the University of California. All rights reserved.
5 * Copyright (c) 1992, 1993, 1994, 1995, 1996
6 * Keith Bostic. All rights reserved.
8 * See the LICENSE file for redistribution information.
14 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 ";
17 #include <sys/types.h>
18 #include <sys/queue.h>
20 #include <bitstring.h>
24 #include "../common/common.h"
27 * This array maps ex command names to command functions.
29 * The order in which command names are listed below is important --
30 * ambiguous abbreviations are resolved to be the first possible match,
31 * e.g. "r" means "read", not "rewind", because "read" is listed before
34 * The syntax of the ex commands is unbelievably irregular, and a special
35 * case from beginning to end. Each command has an associated "syntax
36 * script" which describes the "arguments" that are possible. The script
37 * syntax is as follows:
40 * 1 -- flags: [+-]*[pl#][+-]*
44 * c[01+a] -- count (0-N, 1-N, signed 1-N, address offset)
45 * f[N#][or] -- file (a number or N, optional or required)
47 * S -- string with file name expansion
50 * w[N#][or] -- word (a number or N, optional or required)
52 EXCMDLIST
const cmds
[] = {
54 {L("\004"), ex_pr
, E_ADDR2
,
59 {L("!"), ex_bang
, E_ADDR2_NONE
|E_SECURE
,
61 "[line [,line]] ! command",
62 "filter lines through commands or run commands"},
64 {L("#"), ex_number
, E_ADDR2
|E_CLRFLAG
,
66 "[line [,line]] # [count] [l]",
67 "display numbered lines"},
69 {L("&"), ex_subagain
, E_ADDR2
|E_ADDR_ZERO
,
71 "[line [,line]] & [cgr] [count] [#lp]",
72 "repeat the last subsitution"},
79 {L("<"), ex_shiftl
, E_ADDR2
|E_AUTOPRINT
,
81 "[line [,line]] <[<...] [count] [flags]",
84 {L("="), ex_equal
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
87 "display line number"},
89 {L(">"), ex_shiftr
, E_ADDR2
|E_AUTOPRINT
,
91 "[line [,line]] >[>...] [count] [flags]",
94 {L("@"), ex_at
, E_ADDR2
,
99 {L("append"), ex_append
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
101 "[line] a[ppend][!]",
102 "append input to a line"},
104 {L("abbreviate"), ex_abbr
, 0,
106 "ab[brev] [word replace]",
107 "specify an input abbreviation"},
109 {L("args"), ex_args
, 0,
112 "display file argument list"},
114 {L("bg"), ex_bg
, E_VIONLY
,
117 "put a foreground screen into the background"},
119 {L("change"), ex_change
, E_ADDR2
|E_ADDR_ZERODEF
,
121 "[line [,line]] c[hange][!] [count]",
122 "change lines to input"},
127 "change the current directory"},
129 {L("chdir"), ex_cd
, 0,
131 "chd[ir][!] [directory]",
132 "change the current directory"},
134 {L("copy"), ex_copy
, E_ADDR2
|E_AUTOPRINT
,
136 "[line [,line]] co[py] line [flags]",
137 "copy lines elsewhere in the file"},
139 {L("cscope"), ex_cscope
, 0,
141 "cs[cope] command [args]",
142 "create a set of tags using a cscope command"},
145 * Adding new commands starting with 'd' may break the delete command code
146 * in ex_cmd() (the ex parser). Read through the comments there, first.
149 {L("delete"), ex_delete
, E_ADDR2
|E_AUTOPRINT
,
151 "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
152 "delete lines from the file"},
154 {L("display"), ex_display
, 0,
156 "display b[uffers] | c[onnections] | s[creens] | t[ags]",
157 "display buffers, connections, screens or tags"},
159 {L("edit"), ex_edit
, E_NEWSCREEN
,
161 "[Ee][dit][!] [+cmd] [file]",
162 "begin editing another file"},
164 {L("ex"), ex_edit
, E_NEWSCREEN
,
166 "[Ee]x[!] [+cmd] [file]",
167 "begin editing another file"},
169 {L("exusage"), ex_usage
, 0,
171 "[exu]sage [command]",
172 "display ex command usage statement"},
174 {L("file"), ex_file
, 0,
177 "display (and optionally set) file name"},
179 {L("fg"), ex_fg
, E_NEWSCREEN
|E_VIONLY
,
182 "bring a backgrounded screen into the foreground"},
184 {L("global"), ex_global
, E_ADDR2_ALL
,
186 "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
187 "execute a global command on lines matching an RE"},
189 {L("help"), ex_help
, 0,
192 "display help statement"},
194 {L("insert"), ex_insert
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
196 "[line] i[nsert][!]",
197 "insert input before a line"},
199 {L("join"), ex_join
, E_ADDR2
|E_AUTOPRINT
,
201 "[line [,line]] j[oin][!] [count] [flags]",
202 "join lines into a single line"},
204 {L("k"), ex_mark
, E_ADDR1
,
207 "mark a line position"},
209 {L("list"), ex_list
, E_ADDR2
|E_CLRFLAG
,
211 "[line [,line]] l[ist] [count] [#]",
212 "display lines in an unambiguous form"},
214 {L("move"), ex_move
, E_ADDR2
|E_AUTOPRINT
,
216 "[line [,line]] m[ove] line",
217 "move lines elsewhere in the file"},
219 {L("mark"), ex_mark
, E_ADDR1
,
222 "mark a line position"},
224 {L("map"), ex_map
, 0,
226 "map[!] [keys replace]",
227 "map input or commands to one or more keys"},
229 {L("mkexrc"), ex_mkexrc
, 0,
232 "write a .exrc file"},
234 {L("next"), ex_next
, E_NEWSCREEN
,
236 "[Nn][ext][!] [+cmd] [file ...]",
237 "edit (and optionally specify) the next file"},
239 {L("number"), ex_number
, E_ADDR2
|E_CLRFLAG
,
241 "[line [,line]] nu[mber] [count] [l]",
242 "change display to number lines"},
244 {L("open"), ex_open
, E_ADDR1
,
246 "[line] o[pen] [/RE/] [flags]",
247 "enter \"open\" mode (not implemented)"},
249 {L("print"), ex_pr
, E_ADDR2
|E_CLRFLAG
,
251 "[line [,line]] p[rint] [count] [#l]",
254 {L("perl"), ex_perl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
255 E_ADDR_ZERODEF
|E_SECURE
,
258 "run the perl interpreter with the command"},
260 {L("perldo"), ex_perl
, E_ADDR2
|E_ADDR_ZERO
|
261 E_ADDR_ZERODEF
|E_SECURE
,
264 "run the perl interpreter with the command, on each line"},
266 {L("preserve"), ex_preserve
, 0,
269 "preserve an edit session for recovery"},
271 {L("previous"), ex_prev
, E_NEWSCREEN
,
274 "edit the previous file in the file argument list"},
277 E_ADDR1
|E_AUTOPRINT
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
279 "[line] pu[t] [buffer]",
280 "append a cut buffer to the line"},
282 {L("quit"), ex_quit
, 0,
287 {L("read"), ex_read
, E_ADDR1
|E_ADDR_ZERO
|E_ADDR_ZERODEF
,
289 "[line] r[ead] [!cmd | [file]]",
290 "append input from a command or file to the line"},
292 {L("recover"), ex_recover
, 0,
295 "recover a saved file"},
297 {L("resize"), ex_resize
, E_VIONLY
,
300 "grow or shrink the current screen"},
302 {L("rewind"), ex_rew
, 0,
305 "re-edit all the files in the file argument list"},
308 {L("rtag"), ex_rtag_push
, E_NEWSCREEN
,
310 "rta[g][!] [string]",
311 "edit the file containing the tag"},
315 * Adding new commands starting with 's' may break the substitute command code
316 * in ex_cmd() (the ex parser). Read through the comments there, first.
319 {L("s"), ex_s
, E_ADDR2
|E_ADDR_ZERO
,
321 "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]",
322 "substitute on lines matching an RE"},
324 {L("script"), ex_script
, E_SECURE
,
326 "sc[ript][!] [file]",
327 "run a shell in a screen"},
329 {L("set"), ex_set
, 0,
331 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
332 "set options (use \":set all\" to see all options)"},
334 {L("shell"), ex_shell
, E_SECURE
,
337 "suspend editing and run a shell"},
339 {L("source"), ex_source
, 0,
342 "read a file of ex commands"},
344 {L("stop"), ex_stop
, E_SECURE
,
347 "suspend the edit session"},
349 {L("suspend"), ex_stop
, E_SECURE
,
352 "suspend the edit session"},
354 {L("t"), ex_copy
, E_ADDR2
|E_AUTOPRINT
,
356 "[line [,line]] t line [flags]",
357 "copy lines elsewhere in the file"},
359 {L("tag"), ex_tag_push
, E_NEWSCREEN
,
361 "[Tt]a[g][!] [string]",
362 "edit the file containing the tag"},
364 {L("tagnext"), ex_tag_next
, 0,
367 "move to the next tag"},
369 {L("tagpop"), ex_tag_pop
, 0,
371 "tagp[op][!] [number | file]",
372 "return to the previous group of tags"},
374 {L("tagprev"), ex_tag_prev
, 0,
377 "move to the previous tag"},
379 {L("tagtop"), ex_tag_top
, 0,
384 {L("tcl"), ex_tcl
, E_ADDR2_ALL
|E_ADDR_ZERO
|
385 E_ADDR_ZERODEF
|E_SECURE
,
388 "run the tcl interpreter with the command"},
390 {L("undo"), ex_undo
, E_AUTOPRINT
,
393 "undo the most recent change"},
395 {L("unabbreviate"),ex_unabbr
, 0,
398 "delete an abbreviation"},
400 {L("unmap"), ex_unmap
, 0,
403 "delete an input or command map"},
405 {L("v"), ex_v
, E_ADDR2_ALL
,
407 "[line [,line]] v [;/]RE[;/] [commands]",
408 "execute a global command on lines NOT matching an RE"},
410 {L("version"), ex_version
, 0,
413 "display the program version information"},
415 {L("visual"), ex_visual
, E_ADDR1
|E_ADDR_ZERODEF
,
417 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
418 "enter visual (vi) mode from ex mode"},
420 {L("visual"), ex_edit
, E_NEWSCREEN
,
422 "[Vv]i[sual][!] [+cmd] [file]",
423 "edit another file (from vi mode only)"},
425 {L("viusage"), ex_viusage
, 0,
428 "display vi key usage statement"},
430 {L("vsplit"), ex_edit
, E_VIONLY
,
432 "vs[plit] [+cmd] [file]",
433 "split the current screen vertically"},
435 {L("write"), ex_write
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
437 "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]",
440 {L("wn"), ex_wn
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
442 "[line [,line]] wn[!] [>>] [file]",
443 "write the file and switch to the next file"},
445 {L("wq"), ex_wq
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
447 "[line [,line]] wq[!] [>>] [file]",
448 "write the file and exit"},
450 {L("xit"), ex_xit
, E_ADDR2_ALL
|E_ADDR_ZERODEF
,
452 "[line [,line]] x[it][!] [file]",
455 {L("yank"), ex_yank
, E_ADDR2
,
457 "[line [,line]] ya[nk] [buffer] [count]",
458 "copy lines to a cut buffer"},
460 {L("z"), ex_z
, E_ADDR1
,
462 "[line] z [-|.|+|^|=] [count] [flags]",
463 "display different screens of the file"},
465 {L("~"), ex_subtilde
, E_ADDR2
|E_ADDR_ZERO
,
467 "[line [,line]] ~ [cgr] [count] [#lp]",
468 "replace previous RE with previous replacement string,"},