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.28 1993/11/23 11:00:34 bostic Exp $ (Berkeley) $Date: 1993/11/23 11:00:34 $";
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:
32 * 1 -- flags: [+-]*[pl#][+-]*
37 * c -- count as an address offset
38 * f[N#][or] -- file (a number or N, optional or required)
41 * S -- string with file name expansion
44 * w[N#][or] -- word (a number or N, optional or required)
46 EXCMDLIST
const cmds
[] = {
48 {"!", ex_bang
, E_ADDR2_NONE
|E_NORC
,
50 "[line [,line]] ! command",
51 "filter lines through commands or run commands"},
53 {"#", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
55 "[line [,line]] # [count] [l]",
56 "display numbered lines"},
58 {"&", ex_subagain
, E_ADDR2
|E_NORC
,
60 "[line [,line]] & [cgr] [count] [#lp]",
61 "repeat the last subsitution"},
68 {"<", ex_shiftl
, E_ADDR2
|E_NORC
,
70 "[line [,line]] <[<...] [count] [flags]",
73 {"=", ex_equal
, E_ADDR1
|E_NORC
,
76 "display line number"},
78 {">", ex_shiftr
, E_ADDR2
|E_NORC
,
80 "[line [,line]] >[>...] [count] [flags]",
88 {"~", ex_subtilde
, E_ADDR2
|E_NORC
,
90 "[line [,line]] ~ [cgr] [count] [#lp]",
91 "replace previous RE with previous replacement string,"},
93 {"append", ex_append
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
96 "append input to a line"},
98 {"abbreviate", ex_abbr
, E_NOGLOBAL
,
100 "ab[brev] word replace",
101 "specify an input abbreviation"},
103 {"args", ex_args
, E_NOGLOBAL
|E_NORC
,
106 "display file argument list"},
108 {"bg", ex_bg
, E_NOGLOBAL
|E_NORC
,
111 "background the current screen"},
113 {"change", ex_change
, E_ADDR2
|E_NORC
|E_ZERODEF
,
115 "[line [,line]] c[hange][!] [count]",
116 "change lines to input"},
118 {"cd", ex_cd
, E_NOGLOBAL
,
121 "change the current directory"},
123 {"chdir", ex_cd
, E_NOGLOBAL
,
125 "chd[ir][!] [directory]",
126 "change the current directory"},
128 {"copy", ex_copy
, E_ADDR2
|E_NORC
,
130 "[line [,line]] co[py] line [flags]",
131 "copy lines elsewhere in the file"},
133 {"delete", ex_delete
, E_ADDR2
|E_NORC
,
135 "[line [,line]] d[elete] [buffer] [count] [flags]",
136 "delete lines from the file"},
138 {"display", ex_display
, E_NOGLOBAL
|E_NORC
,
140 "display b[uffers] | s[creens] | t[ags]",
141 "display buffers, screens or tags"},
143 {"digraph", ex_digraph
, E_NOGLOBAL
|E_NOPERM
|E_NORC
,
146 "specify digraphs (not implemented)"},
148 {"edit", ex_edit
, E_NOGLOBAL
|E_NORC
,
150 "e[dit][!] [+cmd] [file]",
151 "begin editing another file"},
153 {"ex", ex_edit
, E_NOGLOBAL
|E_NORC
,
155 "ex[!] [+cmd] [file]",
156 "begin editing another file"},
158 {"exusage", ex_usage
, E_NOGLOBAL
|E_NORC
,
160 "[exu]sage [command]",
161 "display ex command usage statement"},
163 {"file", ex_file
, E_NOGLOBAL
|E_NORC
,
166 "display (and optionally set) file name"},
168 {"fg", ex_fg
, E_NOGLOBAL
|E_NORC
,
171 "switch the current screen and a backgrounded screen"},
173 {"global", ex_global
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
175 "[line [,line]] g[lobal][!] [;/]pattern[;/] [commands]",
176 "execute a global command on lines matching a pattern"},
178 {"help", ex_help
, E_NOGLOBAL
|E_NORC
,
181 "display help statement"},
183 {"insert", ex_insert
, E_ADDR1
|E_NORC
,
185 "[line] i[nsert][!]",
186 "insert input before a line"},
188 {"join", ex_join
, E_ADDR2
|E_NORC
,
190 "[line [,line]] j[oin][!] [count] [flags]",
191 "join lines into a single line"},
193 {"k", ex_mark
, E_ADDR1
|E_NORC
,
196 "mark a line position"},
198 {"list", ex_list
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
200 "[line [,line]] l[ist] [count] [#]",
201 "display lines in an unambiguous form"},
203 {"move", ex_move
, E_ADDR2
|E_NORC
,
205 "[line [,line]] m[ove] line",
206 "move lines elsewhere in the file"},
208 {"mark", ex_mark
, E_ADDR1
|E_NORC
,
211 "mark a line position"},
215 "map[!] [keys replace]",
216 "map input or commands to one or more keys"},
218 {"mkexrc", ex_mkexrc
, E_NOGLOBAL
|E_NORC
,
221 "write a .exrc file"},
223 {"next", ex_next
, E_NOGLOBAL
|E_NORC
,
225 "n[ext][!] [file ...]",
226 "edit (and optionally specify) the next file"},
228 {"number", ex_number
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
230 "[line [,line]] nu[mber] [count] [l]",
231 "change display to number lines"},
233 {"open", ex_open
, E_ADDR1
,
235 "[line] o[pen] [/pattern/] [flags]",
236 "enter \"open\" mode (not implemented)"},
238 {"print", ex_pr
, E_ADDR2
|E_F_PRCLEAR
|E_NORC
|E_SETLAST
,
240 "[line [,line]] p[rint] [count] [#l]",
243 {"preserve", ex_preserve
, E_NOGLOBAL
|E_NORC
,
246 "preserve an edit session for recovery"},
248 {"previous", ex_prev
, E_NOGLOBAL
|E_NORC
,
251 "edit the previous file in the file argument list"},
253 {"put", ex_put
, E_ADDR1
|E_NORC
|E_ZERO
,
255 "[line] pu[t] [buffer]",
256 "append a cut buffer to the line"},
258 {"quit", ex_quit
, E_NOGLOBAL
,
263 {"read", ex_read
, E_ADDR1
|E_NORC
|E_ZERO
|E_ZERODEF
,
265 "[line] r[ead] [!cmd | [file]]",
266 "append input from a command or file to the line"},
268 {"resize", ex_resize
, E_NOGLOBAL
|E_NORC
,
271 "grow or shrink the current screen"},
273 {"rewind", ex_rew
, E_NOGLOBAL
|E_NORC
,
276 "re-edit all the files in the file argument list"},
278 {"substitute", ex_substitute
, E_ADDR2
|E_NORC
,
280 "[line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]",
281 "substitute on lines matching a pattern"},
283 {"script", ex_script
, E_NOGLOBAL
|E_NORC
,
285 "sc[ript][!] [file]",
286 "run a shell in a screen"},
288 {"set", ex_set
, E_NOGLOBAL
,
290 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
291 "set options (use \":set all\" to see all options)"},
293 {"shell", ex_shell
, E_NOGLOBAL
|E_NORC
,
296 "suspend editing and run a shell"},
298 {"source", ex_source
, E_NOGLOBAL
,
301 "read a file of ex commands"},
303 {"split", ex_split
, E_NOGLOBAL
|E_NORC
,
305 "s[plit] [file ...]",
306 "split the current screen into two screens"},
308 {"stop", ex_stop
, E_NOGLOBAL
|E_NORC
,
311 "suspend the edit session"},
313 {"suspend", ex_stop
, E_NOGLOBAL
|E_NORC
,
316 "suspend the edit session"},
318 {"t", ex_copy
, E_ADDR2
|E_NORC
,
320 "[line [,line]] t line [flags]",
321 "move lines elsewhere in the file"},
323 {"tag", ex_tagpush
, E_NOGLOBAL
,
326 "edit the file containing the tag"},
328 {"tagpop", ex_tagpop
, E_NOGLOBAL
|E_NORC
,
330 "tagp[op][!] [number | file]",
331 "return to a previous tag"},
333 {"tagtop", ex_tagtop
, E_NOGLOBAL
|E_NORC
,
336 "return to the first tag"},
338 {"Undo", ex_undol
, E_NOGLOBAL
|E_NORC
,
341 "undo all the changes to this line"},
343 {"undo", ex_undo
, E_NOGLOBAL
|E_NORC
,
346 "undo the most recent change"},
348 {"unabbreviate",ex_unabbr
, E_NOGLOBAL
,
351 "delete an abbreviation"},
353 {"unmap", ex_unmap
, E_NOGLOBAL
,
356 "delete an input or command map"},
358 {"vglobal", ex_vglobal
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
,
360 "[line [,line]] v[global] [;/]pattern[;/] [commands]",
361 "execute a global command on lines NOT matching a pattern"},
363 {"version", ex_version
, E_NOGLOBAL
|E_NORC
,
366 "display the program version information"},
368 {"visual", ex_visual
, E_ADDR1
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
370 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
371 "enter visual (vi) mode"},
373 {"visual", ex_edit
, E_NOGLOBAL
|E_NORC
,
375 "vi[sual][!] [+cmd] [file]",
376 "enter visual (vi) mode"},
378 {"viusage", ex_viusage
, E_NOGLOBAL
|E_NORC
,
381 "display vi key usage statement"},
383 {"write", ex_write
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
385 "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
388 {"wq", ex_wq
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
390 "[line [,line]] wq[!] [>>] [file]",
391 "write the file and exit"},
393 {"xit", ex_xit
, E_ADDR2_ALL
|E_NOGLOBAL
|E_NORC
|E_ZERODEF
,
395 "[line [,line]] x[it][!] [file]",
398 {"yank", ex_yank
, E_ADDR2
|E_NORC
,
400 "[line [,line]] ya[nk] [buffer] [count]",
401 "copy lines to a cut buffer"},
403 {"z", ex_z
, E_ADDR1
|E_NOGLOBAL
|E_NORC
,
405 "[line] z [-|.|+|^|=] [count] [flags]",
406 "display different screens of the file"},