2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
9 static char sccsid
[] = "$Id: ex_cmd.c,v 8.34 1993/12/22 18:38:40 bostic Exp $ (Berkeley) $Date: 1993/12/22 18:38:40 $";
12 #include <sys/types.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
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:
31 * 1 -- flags: [+-]*[pl#][+-]*
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)
38 * S -- string with file name expansion
41 * w[N#][or] -- word (a number or N, optional or required)
43 EXCMDLIST
const cmds
[] = {
45 {"!", ex_bang
, E_ADDR2_NONE
|E_NORC
,
47 "[line [,line]] ! command",
48 "filter lines through commands or run commands"},
50 {"#", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
52 "[line [,line]] # [count] [l]",
53 "display numbered lines"},
55 {"&", ex_subagain
, E_ADDR2
|E_NORC
,
57 "[line [,line]] & [cgr] [count] [#lp]",
58 "repeat the last subsitution"},
65 {"<", ex_shiftl
, E_ADDR2
|E_NORC
,
67 "[line [,line]] <[<...] [count] [flags]",
70 {"=", ex_equal
, E_ADDR1
|E_NORC
,
73 "display line number"},
75 {">", ex_shiftr
, E_ADDR2
|E_NORC
,
77 "[line [,line]] >[>...] [count] [flags]",
85 {"append", ex_append
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
88 "append input to a line"},
90 {"abbreviate", ex_abbr
, E_NOGLOBAL
,
92 "ab[brev] word replace",
93 "specify an input abbreviation"},
95 {"args", ex_args
, E_NOGLOBAL
|E_NORC
,
98 "display file argument list"},
100 {"bg", ex_bg
, E_NOGLOBAL
|E_NORC
,
103 "background the current screen"},
105 {"change", ex_change
, E_ADDR2
|E_NORC
|E_ZERODEF
,
107 "[line [,line]] c[hange][!] [count]",
108 "change lines to input"},
110 {"cd", ex_cd
, E_NOGLOBAL
,
113 "change the current directory"},
115 {"chdir", ex_cd
, E_NOGLOBAL
,
117 "chd[ir][!] [directory]",
118 "change the current directory"},
120 {"copy", ex_copy
, E_ADDR2
|E_NORC
,
122 "[line [,line]] co[py] line [flags]",
123 "copy lines elsewhere in the file"},
125 {"delete", ex_delete
, E_ADDR2
|E_NORC
,
127 "[line [,line]] d[elete] [buffer] [count] [flags]",
128 "delete lines from the file"},
130 {"display", ex_display
, E_NOGLOBAL
|E_NORC
,
132 "display b[uffers] | s[creens] | t[ags]",
133 "display buffers, screens or tags"},
135 {"digraph", ex_digraph
, E_NOGLOBAL
|E_NOPERM
|E_NORC
,
138 "specify digraphs (not implemented)"},
140 {"edit", ex_edit
, E_NOGLOBAL
|E_NORC
,
142 "e[dit][!] [+cmd] [file]",
143 "begin editing another file"},
145 {"ex", ex_edit
, E_NOGLOBAL
|E_NORC
,
147 "ex[!] [+cmd] [file]",
148 "begin editing another file"},
150 {"exusage", ex_usage
, E_NOGLOBAL
|E_NORC
,
152 "[exu]sage [command]",
153 "display ex command usage statement"},
155 {"file", ex_file
, E_NOGLOBAL
|E_NORC
,
158 "display (and optionally set) file name"},
160 {"fg", ex_fg
, E_NOGLOBAL
|E_NORC
,
163 "switch the current screen and a backgrounded screen"},
165 {"global", ex_global
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
167 "[line [,line]] g[lobal][!] [;/]pattern[;/] [commands]",
168 "execute a global command on lines matching a pattern"},
170 {"help", ex_help
, E_NOGLOBAL
|E_NORC
,
173 "display help statement"},
175 {"insert", ex_insert
, E_ADDR1
|E_NORC
,
177 "[line] i[nsert][!]",
178 "insert input before a line"},
180 {"join", ex_join
, E_ADDR2
|E_NORC
,
182 "[line [,line]] j[oin][!] [count] [flags]",
183 "join lines into a single line"},
185 {"k", ex_mark
, E_ADDR1
|E_NORC
,
188 "mark a line position"},
190 {"list", ex_list
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
192 "[line [,line]] l[ist] [count] [#]",
193 "display lines in an unambiguous form"},
195 {"move", ex_move
, E_ADDR2
|E_NORC
,
197 "[line [,line]] m[ove] line",
198 "move lines elsewhere in the file"},
200 {"mark", ex_mark
, E_ADDR1
|E_NORC
,
203 "mark a line position"},
207 "map[!] [keys replace]",
208 "map input or commands to one or more keys"},
210 {"mkexrc", ex_mkexrc
, E_NOGLOBAL
|E_NORC
,
213 "write a .exrc file"},
215 {"next", ex_next
, E_NOGLOBAL
|E_NORC
,
217 "n[ext][!] [file ...]",
218 "edit (and optionally specify) the next file"},
220 {"number", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
222 "[line [,line]] nu[mber] [count] [l]",
223 "change display to number lines"},
225 {"open", ex_open
, E_ADDR1
,
227 "[line] o[pen] [/pattern/] [flags]",
228 "enter \"open\" mode (not implemented)"},
230 {"print", ex_pr
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
232 "[line [,line]] p[rint] [count] [#l]",
235 {"preserve", ex_preserve
, E_NOGLOBAL
|E_NORC
,
238 "preserve an edit session for recovery"},
240 {"previous", ex_prev
, E_NOGLOBAL
|E_NORC
,
243 "edit the previous file in the file argument list"},
245 {"put", ex_put
, E_ADDR1
|E_NORC
|E_ZERO
,
247 "[line] pu[t] [buffer]",
248 "append a cut buffer to the line"},
250 {"quit", ex_quit
, E_NOGLOBAL
,
255 {"read", ex_read
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
257 "[line] r[ead] [!cmd | [file]]",
258 "append input from a command or file to the line"},
260 {"resize", ex_resize
, E_NOGLOBAL
|E_NORC
,
263 "grow or shrink the current screen"},
265 {"rewind", ex_rew
, E_NOGLOBAL
|E_NORC
,
268 "re-edit all the files in the file argument list"},
270 {"substitute", ex_substitute
, E_ADDR2
|E_NORC
,
272 "[line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]",
273 "substitute on lines matching a pattern"},
275 {"script", ex_script
, E_NOGLOBAL
|E_NORC
,
277 "sc[ript][!] [file]",
278 "run a shell in a screen"},
280 {"set", ex_set
, E_NOGLOBAL
,
282 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
283 "set options (use \":set all\" to see all options)"},
285 {"shell", ex_shell
, E_NOGLOBAL
|E_NORC
,
288 "suspend editing and run a shell"},
290 {"source", ex_source
, E_NOGLOBAL
,
293 "read a file of ex commands"},
295 {"split", ex_split
, E_NOGLOBAL
|E_NORC
,
297 "s[plit] [file ...]",
298 "split the current screen into two screens"},
300 {"stop", ex_stop
, E_NOGLOBAL
|E_NORC
,
303 "suspend the edit session"},
305 {"suspend", ex_stop
, E_NOGLOBAL
|E_NORC
,
308 "suspend the edit session"},
310 {"t", ex_copy
, E_ADDR2
|E_NORC
,
312 "[line [,line]] t line [flags]",
313 "move lines elsewhere in the file"},
315 {"tag", ex_tagpush
, E_NOGLOBAL
,
318 "edit the file containing the tag"},
320 {"tagpop", ex_tagpop
, E_NOGLOBAL
|E_NORC
,
322 "tagp[op][!] [number | file]",
323 "return to a previous tag"},
325 {"tagtop", ex_tagtop
, E_NOGLOBAL
|E_NORC
,
328 "return to the first tag"},
330 {"Undo", ex_undol
, E_NOGLOBAL
|E_NORC
,
333 "undo all the changes to this line"},
335 {"undo", ex_undo
, E_NOGLOBAL
|E_NORC
,
338 "undo the most recent change"},
340 {"unabbreviate",ex_unabbr
, E_NOGLOBAL
,
343 "delete an abbreviation"},
345 {"unmap", ex_unmap
, E_NOGLOBAL
,
348 "delete an input or command map"},
350 {"vglobal", ex_vglobal
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
352 "[line [,line]] v[global] [;/]pattern[;/] [commands]",
353 "execute a global command on lines NOT matching a pattern"},
355 {"version", ex_version
, E_NOGLOBAL
|E_NORC
,
358 "display the program version information"},
360 {"visual", ex_visual
, E_ADDR1
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
362 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
363 "enter visual (vi) mode from ex mode"},
365 {"visual", ex_edit
, E_NOGLOBAL
|E_NORC
,
367 "vi[sual][!] [+cmd] [file]",
368 "edit another file (from vi mode only)"},
370 {"viusage", ex_viusage
, E_NOGLOBAL
|E_NORC
,
373 "display vi key usage statement"},
375 {"write", ex_write
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
377 "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
380 {"wq", ex_wq
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
382 "[line [,line]] wq[!] [>>] [file]",
383 "write the file and exit"},
385 {"xit", ex_xit
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
387 "[line [,line]] x[it][!] [file]",
390 {"yank", ex_yank
, E_ADDR2
|E_NORC
,
392 "[line [,line]] ya[nk] [buffer] [count]",
393 "copy lines to a cut buffer"},
395 {"z", ex_z
, E_ADDR1
|E_NOGLOBAL
|E_NORC
,
397 "[line] z [-|.|+|^|=] [count] [flags]",
398 "display different screens of the file"},
400 {"~", ex_subtilde
, E_ADDR2
|E_NORC
,
402 "[line [,line]] ~ [cgr] [count] [#lp]",
403 "replace previous RE with previous replacement string,"},