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.32 1993/12/17 13:45:08 bostic Exp $ (Berkeley) $Date: 1993/12/17 13:45:08 $";
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 {"~", ex_subtilde
, E_ADDR2
|E_NORC
,
87 "[line [,line]] ~ [cgr] [count] [#lp]",
88 "replace previous RE with previous replacement string,"},
90 {"append", ex_append
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
93 "append input to a line"},
95 {"abbreviate", ex_abbr
, E_NOGLOBAL
,
97 "ab[brev] word replace",
98 "specify an input abbreviation"},
100 {"args", ex_args
, E_NOGLOBAL
|E_NORC
,
103 "display file argument list"},
105 {"bg", ex_bg
, E_NOGLOBAL
|E_NORC
,
108 "background the current screen"},
110 {"change", ex_change
, E_ADDR2
|E_NORC
|E_ZERODEF
,
112 "[line [,line]] c[hange][!] [count]",
113 "change lines to input"},
115 {"cd", ex_cd
, E_NOGLOBAL
,
118 "change the current directory"},
120 {"chdir", ex_cd
, E_NOGLOBAL
,
122 "chd[ir][!] [directory]",
123 "change the current directory"},
125 {"copy", ex_copy
, E_ADDR2
|E_NORC
,
127 "[line [,line]] co[py] line [flags]",
128 "copy lines elsewhere in the file"},
130 {"delete", ex_delete
, E_ADDR2
|E_NORC
,
132 "[line [,line]] d[elete] [buffer] [count] [flags]",
133 "delete lines from the file"},
135 {"display", ex_display
, E_NOGLOBAL
|E_NORC
,
137 "display b[uffers] | s[creens] | t[ags]",
138 "display buffers, screens or tags"},
140 {"digraph", ex_digraph
, E_NOGLOBAL
|E_NOPERM
|E_NORC
,
143 "specify digraphs (not implemented)"},
145 {"edit", ex_edit
, E_NOGLOBAL
|E_NORC
,
147 "e[dit][!] [+cmd] [file]",
148 "begin editing another file"},
150 {"ex", ex_edit
, E_NOGLOBAL
|E_NORC
,
152 "ex[!] [+cmd] [file]",
153 "begin editing another file"},
155 {"exusage", ex_usage
, E_NOGLOBAL
|E_NORC
,
157 "[exu]sage [command]",
158 "display ex command usage statement"},
160 {"file", ex_file
, E_NOGLOBAL
|E_NORC
,
163 "display (and optionally set) file name"},
165 {"fg", ex_fg
, E_NOGLOBAL
|E_NORC
,
168 "switch the current screen and a backgrounded screen"},
170 {"global", ex_global
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
172 "[line [,line]] g[lobal][!] [;/]pattern[;/] [commands]",
173 "execute a global command on lines matching a pattern"},
175 {"help", ex_help
, E_NOGLOBAL
|E_NORC
,
178 "display help statement"},
180 {"insert", ex_insert
, E_ADDR1
|E_NORC
,
182 "[line] i[nsert][!]",
183 "insert input before a line"},
185 {"join", ex_join
, E_ADDR2
|E_NORC
,
187 "[line [,line]] j[oin][!] [count] [flags]",
188 "join lines into a single line"},
190 {"k", ex_mark
, E_ADDR1
|E_NORC
,
193 "mark a line position"},
195 {"list", ex_list
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
197 "[line [,line]] l[ist] [count] [#]",
198 "display lines in an unambiguous form"},
200 {"move", ex_move
, E_ADDR2
|E_NORC
,
202 "[line [,line]] m[ove] line",
203 "move lines elsewhere in the file"},
205 {"mark", ex_mark
, E_ADDR1
|E_NORC
,
208 "mark a line position"},
212 "map[!] [keys replace]",
213 "map input or commands to one or more keys"},
215 {"mkexrc", ex_mkexrc
, E_NOGLOBAL
|E_NORC
,
218 "write a .exrc file"},
220 {"next", ex_next
, E_NOGLOBAL
|E_NORC
,
222 "n[ext][!] [file ...]",
223 "edit (and optionally specify) the next file"},
225 {"number", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
227 "[line [,line]] nu[mber] [count] [l]",
228 "change display to number lines"},
230 {"open", ex_open
, E_ADDR1
,
232 "[line] o[pen] [/pattern/] [flags]",
233 "enter \"open\" mode (not implemented)"},
235 {"print", ex_pr
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
237 "[line [,line]] p[rint] [count] [#l]",
240 {"preserve", ex_preserve
, E_NOGLOBAL
|E_NORC
,
243 "preserve an edit session for recovery"},
245 {"previous", ex_prev
, E_NOGLOBAL
|E_NORC
,
248 "edit the previous file in the file argument list"},
250 {"put", ex_put
, E_ADDR1
|E_NORC
|E_ZERO
,
252 "[line] pu[t] [buffer]",
253 "append a cut buffer to the line"},
255 {"quit", ex_quit
, E_NOGLOBAL
,
260 {"read", ex_read
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
262 "[line] r[ead] [!cmd | [file]]",
263 "append input from a command or file to the line"},
265 {"resize", ex_resize
, E_NOGLOBAL
|E_NORC
,
268 "grow or shrink the current screen"},
270 {"rewind", ex_rew
, E_NOGLOBAL
|E_NORC
,
273 "re-edit all the files in the file argument list"},
275 {"substitute", ex_substitute
, E_ADDR2
|E_NORC
,
277 "[line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]",
278 "substitute on lines matching a pattern"},
280 {"script", ex_script
, E_NOGLOBAL
|E_NORC
,
282 "sc[ript][!] [file]",
283 "run a shell in a screen"},
285 {"set", ex_set
, E_NOGLOBAL
,
287 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
288 "set options (use \":set all\" to see all options)"},
290 {"shell", ex_shell
, E_NOGLOBAL
|E_NORC
,
293 "suspend editing and run a shell"},
295 {"source", ex_source
, E_NOGLOBAL
,
298 "read a file of ex commands"},
300 {"split", ex_split
, E_NOGLOBAL
|E_NORC
,
302 "s[plit] [file ...]",
303 "split the current screen into two screens"},
305 {"stop", ex_stop
, E_NOGLOBAL
|E_NORC
,
308 "suspend the edit session"},
310 {"suspend", ex_stop
, E_NOGLOBAL
|E_NORC
,
313 "suspend the edit session"},
315 {"t", ex_copy
, E_ADDR2
|E_NORC
,
317 "[line [,line]] t line [flags]",
318 "move lines elsewhere in the file"},
320 {"tag", ex_tagpush
, E_NOGLOBAL
,
323 "edit the file containing the tag"},
325 {"tagpop", ex_tagpop
, E_NOGLOBAL
|E_NORC
,
327 "tagp[op][!] [number | file]",
328 "return to a previous tag"},
330 {"tagtop", ex_tagtop
, E_NOGLOBAL
|E_NORC
,
333 "return to the first tag"},
335 {"Undo", ex_undol
, E_NOGLOBAL
|E_NORC
,
338 "undo all the changes to this line"},
340 {"undo", ex_undo
, E_NOGLOBAL
|E_NORC
,
343 "undo the most recent change"},
345 {"unabbreviate",ex_unabbr
, E_NOGLOBAL
,
348 "delete an abbreviation"},
350 {"unmap", ex_unmap
, E_NOGLOBAL
,
353 "delete an input or command map"},
355 {"vglobal", ex_vglobal
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
357 "[line [,line]] v[global] [;/]pattern[;/] [commands]",
358 "execute a global command on lines NOT matching a pattern"},
360 {"version", ex_version
, E_NOGLOBAL
|E_NORC
,
363 "display the program version information"},
365 {"visual", ex_visual
, E_ADDR1
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
367 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
368 "enter visual (vi) mode from ex mode"},
370 {"visual", ex_edit
, E_NOGLOBAL
|E_NORC
,
372 "vi[sual][!] [+cmd] [file]",
373 "edit another file (from vi mode only)"},
375 {"viusage", ex_viusage
, E_NOGLOBAL
|E_NORC
,
378 "display vi key usage statement"},
380 {"write", ex_write
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
382 "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
385 {"wq", ex_wq
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
387 "[line [,line]] wq[!] [>>] [file]",
388 "write the file and exit"},
390 {"xit", ex_xit
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
392 "[line [,line]] x[it][!] [file]",
395 {"yank", ex_yank
, E_ADDR2
|E_NORC
,
397 "[line [,line]] ya[nk] [buffer] [count]",
398 "copy lines to a cut buffer"},
400 {"z", ex_z
, E_ADDR1
|E_NOGLOBAL
|E_NORC
,
402 "[line] z [-|.|+|^|=] [count] [flags]",
403 "display different screens of the file"},