Sync usage with man page.
[netbsd-mini2440.git] / dist / nvi / ex / ex_cmd.c
blob0e16ed2968e34de68ab116f74f0b6b8f3f69ca97
1 /* $NetBSD: ex_cmd.c,v 1.2 2008/10/29 17:50:49 christos Exp $ */
3 /*-
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.
12 #include "config.h"
14 #ifndef lint
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";
16 #endif /* not lint */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <bitstring.h>
22 #include <limits.h>
23 #include <stdio.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
33 * "rewind".
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:
40 * ! -- ! flag
41 * 1 -- flags: [+-]*[pl#][+-]*
42 * 2 -- flags: [-.+^]
43 * 3 -- flags: [-.+^=]
44 * b -- buffer
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)
47 * l -- line
48 * S -- string with file name expansion
49 * s -- string
50 * W -- word string
51 * w[N#][or] -- word (a number or N, optional or required)
53 EXCMDLIST const cmds[] = {
54 /* C_SCROLL */
55 {L("\004"), ex_pr, E_ADDR2,
56 "",
57 "^D",
58 "scroll lines"},
59 /* C_BANG */
60 {L("!"), ex_bang, E_ADDR2_NONE|E_SECURE,
61 "S",
62 "[line [,line]] ! command",
63 "filter lines through commands or run commands"},
64 /* C_HASH */
65 {L("#"), ex_number, E_ADDR2|E_CLRFLAG,
66 "ca1",
67 "[line [,line]] # [count] [l]",
68 "display numbered lines"},
69 /* C_SUBAGAIN */
70 {L("&"), ex_subagain, E_ADDR2|E_ADDR_ZERO,
71 "s",
72 "[line [,line]] & [cgr] [count] [#lp]",
73 "repeat the last subsitution"},
74 /* C_STAR */
75 {L("*"), ex_at, 0,
76 "b",
77 "* [buffer]",
78 "execute a buffer"},
79 /* C_SHIFTL */
80 {L("<"), ex_shiftl, E_ADDR2|E_AUTOPRINT,
81 "ca1",
82 "[line [,line]] <[<...] [count] [flags]",
83 "shift lines left"},
84 /* C_EQUAL */
85 {L("="), ex_equal, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
86 "1",
87 "[line] = [flags]",
88 "display line number"},
89 /* C_SHIFTR */
90 {L(">"), ex_shiftr, E_ADDR2|E_AUTOPRINT,
91 "ca1",
92 "[line [,line]] >[>...] [count] [flags]",
93 "shift lines right"},
94 /* C_AT */
95 {L("@"), ex_at, E_ADDR2,
96 "b",
97 "@ [buffer]",
98 "execute a buffer"},
99 /* C_APPEND */
100 {L("append"), ex_append, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
101 "!",
102 "[line] a[ppend][!]",
103 "append input to a line"},
104 /* C_ABBR */
105 {L("abbreviate"), ex_abbr, 0,
106 "W",
107 "ab[brev] [word replace]",
108 "specify an input abbreviation"},
109 /* C_ARGS */
110 {L("args"), ex_args, 0,
112 "ar[gs]",
113 "display file argument list"},
114 /* C_BG */
115 {L("bg"), ex_bg, E_VIONLY,
117 "bg",
118 "put a foreground screen into the background"},
119 /* C_CHANGE */
120 {L("change"), ex_change, E_ADDR2|E_ADDR_ZERODEF,
121 "!ca",
122 "[line [,line]] c[hange][!] [count]",
123 "change lines to input"},
124 /* C_CD */
125 {L("cd"), ex_cd, 0,
126 "!f1o",
127 "cd[!] [directory]",
128 "change the current directory"},
129 /* C_CHDIR */
130 {L("chdir"), ex_cd, 0,
131 "!f1o",
132 "chd[ir][!] [directory]",
133 "change the current directory"},
134 /* C_COPY */
135 {L("copy"), ex_copy, E_ADDR2|E_AUTOPRINT,
136 "l1",
137 "[line [,line]] co[py] line [flags]",
138 "copy lines elsewhere in the file"},
139 /* C_CSCOPE */
140 {L("cscope"), ex_cscope, 0,
141 "!s",
142 "cs[cope] command [args]",
143 "create a set of tags using a cscope command"},
145 * !!!
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.
149 /* C_DELETE */
150 {L("delete"), ex_delete, E_ADDR2|E_AUTOPRINT,
151 "bca1",
152 "[line [,line]] d[elete][flags] [buffer] [count] [flags]",
153 "delete lines from the file"},
154 /* C_DISPLAY */
155 {L("display"), ex_display, 0,
156 "w1r",
157 "display b[uffers] | c[onnections] | s[creens] | t[ags]",
158 "display buffers, connections, screens or tags"},
159 /* C_EDIT */
160 {L("edit"), ex_edit, E_NEWSCREEN,
161 "f1o",
162 "[Ee][dit][!] [+cmd] [file]",
163 "begin editing another file"},
164 /* C_EX */
165 {L("ex"), ex_edit, E_NEWSCREEN,
166 "f1o",
167 "[Ee]x[!] [+cmd] [file]",
168 "begin editing another file"},
169 /* C_EXUSAGE */
170 {L("exusage"), ex_usage, 0,
171 "w1o",
172 "[exu]sage [command]",
173 "display ex command usage statement"},
174 /* C_FILE */
175 {L("file"), ex_file, 0,
176 "f1o",
177 "f[ile] [name]",
178 "display (and optionally set) file name"},
179 /* C_FG */
180 {L("fg"), ex_fg, E_NEWSCREEN|E_VIONLY,
181 "f1o",
182 "[Ff]g [file]",
183 "bring a backgrounded screen into the foreground"},
184 /* C_GLOBAL */
185 {L("global"), ex_global, E_ADDR2_ALL,
186 "!s",
187 "[line [,line]] g[lobal][!] [;/]RE[;/] [commands]",
188 "execute a global command on lines matching an RE"},
189 /* C_HELP */
190 {L("help"), ex_help, 0,
192 "he[lp]",
193 "display help statement"},
194 /* C_INSERT */
195 {L("insert"), ex_insert, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
196 "!",
197 "[line] i[nsert][!]",
198 "insert input before a line"},
199 /* C_JOIN */
200 {L("join"), ex_join, E_ADDR2|E_AUTOPRINT,
201 "!ca1",
202 "[line [,line]] j[oin][!] [count] [flags]",
203 "join lines into a single line"},
204 /* C_K */
205 {L("k"), ex_mark, E_ADDR1,
206 "w1r",
207 "[line] k key",
208 "mark a line position"},
209 /* C_LIST */
210 {L("list"), ex_list, E_ADDR2|E_CLRFLAG,
211 "ca1",
212 "[line [,line]] l[ist] [count] [#]",
213 "display lines in an unambiguous form"},
214 /* C_MOVE */
215 {L("move"), ex_move, E_ADDR2|E_AUTOPRINT,
216 "l",
217 "[line [,line]] m[ove] line",
218 "move lines elsewhere in the file"},
219 /* C_MARK */
220 {L("mark"), ex_mark, E_ADDR1,
221 "w1r",
222 "[line] ma[rk] key",
223 "mark a line position"},
224 /* C_MAP */
225 {L("map"), ex_map, 0,
226 "!W",
227 "map[!] [keys replace]",
228 "map input or commands to one or more keys"},
229 /* C_MKEXRC */
230 {L("mkexrc"), ex_mkexrc, 0,
231 "!f1r",
232 "mkexrc[!] file",
233 "write a .exrc file"},
234 /* C_NEXT */
235 {L("next"), ex_next, E_NEWSCREEN,
236 "!fN",
237 "[Nn][ext][!] [+cmd] [file ...]",
238 "edit (and optionally specify) the next file"},
239 /* C_NUMBER */
240 {L("number"), ex_number, E_ADDR2|E_CLRFLAG,
241 "ca1",
242 "[line [,line]] nu[mber] [count] [l]",
243 "change display to number lines"},
244 /* C_OPEN */
245 {L("open"), ex_open, E_ADDR1,
246 "s",
247 "[line] o[pen] [/RE/] [flags]",
248 "enter \"open\" mode (not implemented)"},
249 /* C_PRINT */
250 {L("print"), ex_pr, E_ADDR2|E_CLRFLAG,
251 "ca1",
252 "[line [,line]] p[rint] [count] [#l]",
253 "display lines"},
254 /* C_PERLCMD */
255 {L("perl"), ex_perl, E_ADDR2_ALL|E_ADDR_ZERO|
256 E_ADDR_ZERODEF|E_SECURE,
257 "s",
258 "pe[rl] cmd",
259 "run the perl interpreter with the command"},
260 /* C_PERLDOCMD */
261 {L("perldo"), ex_perl, E_ADDR2|E_ADDR_ZERO|
262 E_ADDR_ZERODEF|E_SECURE,
263 "s",
264 "perld[o] cmd",
265 "run the perl interpreter with the command, on each line"},
266 /* C_PRESERVE */
267 {L("preserve"), ex_preserve, 0,
269 "pre[serve]",
270 "preserve an edit session for recovery"},
271 /* C_PREVIOUS */
272 {L("previous"), ex_prev, E_NEWSCREEN,
273 "!",
274 "[Pp]rev[ious][!]",
275 "edit the previous file in the file argument list"},
276 /* C_PUT */
277 {L("put"), ex_put,
278 E_ADDR1|E_AUTOPRINT|E_ADDR_ZERO|E_ADDR_ZERODEF,
279 "b",
280 "[line] pu[t] [buffer]",
281 "append a cut buffer to the line"},
282 /* C_QUIT */
283 {L("quit"), ex_quit, 0,
284 "!",
285 "q[uit][!]",
286 "exit ex/vi"},
287 /* C_READ */
288 {L("read"), ex_read, E_ADDR1|E_ADDR_ZERO|E_ADDR_ZERODEF,
289 "s",
290 "[line] r[ead] [!cmd | [file]]",
291 "append input from a command or file to the line"},
292 /* C_RECOVER */
293 {L("recover"), ex_recover, 0,
294 "!f1r",
295 "recover[!] file",
296 "recover a saved file"},
297 /* C_RESIZE */
298 {L("resize"), ex_resize, E_VIONLY,
299 "c+",
300 "resize [+-]rows",
301 "grow or shrink the current screen"},
302 /* C_REWIND */
303 {L("rewind"), ex_rew, 0,
304 "!",
305 "rew[ind][!]",
306 "re-edit all the files in the file argument list"},
307 #ifdef GTAGS
308 /* C_RTAG */
309 {L("rtag"), ex_rtag_push, E_NEWSCREEN,
310 "!w1o",
311 "rta[g][!] [string]",
312 "edit the file containing the tag"},
313 #endif
315 * !!!
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.
319 /* C_SUBSTITUTE */
320 {L("s"), ex_s, E_ADDR2|E_ADDR_ZERO,
321 "s",
322 "[line [,line]] s [[/;]RE[/;]repl[/;] [cgr] [count] [#lp]]",
323 "substitute on lines matching an RE"},
324 /* C_SCRIPT */
325 {L("script"), ex_script, E_SECURE,
326 "!f1o",
327 "sc[ript][!] [file]",
328 "run a shell in a screen"},
329 /* C_SET */
330 {L("set"), ex_set, 0,
331 "wN",
332 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
333 "set options (use \":set all\" to see all options)"},
334 /* C_SHELL */
335 {L("shell"), ex_shell, E_SECURE,
337 "sh[ell]",
338 "suspend editing and run a shell"},
339 /* C_SOURCE */
340 {L("source"), ex_source, 0,
341 "f1r",
342 "so[urce] file",
343 "read a file of ex commands"},
344 /* C_STOP */
345 {L("stop"), ex_stop, E_SECURE,
346 "!",
347 "st[op][!]",
348 "suspend the edit session"},
349 /* C_SUSPEND */
350 {L("suspend"), ex_stop, E_SECURE,
351 "!",
352 "su[spend][!]",
353 "suspend the edit session"},
354 /* C_T */
355 {L("t"), ex_copy, E_ADDR2|E_AUTOPRINT,
356 "l1",
357 "[line [,line]] t line [flags]",
358 "copy lines elsewhere in the file"},
359 /* C_TAG */
360 {L("tag"), ex_tag_push, E_NEWSCREEN,
361 "!w1o",
362 "[Tt]a[g][!] [string]",
363 "edit the file containing the tag"},
364 /* C_TAGNEXT */
365 {L("tagnext"), ex_tag_next, 0,
366 "!",
367 "tagn[ext][!]",
368 "move to the next tag"},
369 /* C_TAGPOP */
370 {L("tagpop"), ex_tag_pop, 0,
371 "!w1o",
372 "tagp[op][!] [number | file]",
373 "return to the previous group of tags"},
374 /* C_TAGPREV */
375 {L("tagprev"), ex_tag_prev, 0,
376 "!",
377 "tagpr[ev][!]",
378 "move to the previous tag"},
379 /* C_TAGTOP */
380 {L("tagtop"), ex_tag_top, 0,
381 "!",
382 "tagt[op][!]",
383 "discard all tags"},
384 /* C_TCLCMD */
385 {L("tcl"), ex_tcl, E_ADDR2_ALL|E_ADDR_ZERO|
386 E_ADDR_ZERODEF|E_SECURE,
387 "s",
388 "tc[l] cmd",
389 "run the tcl interpreter with the command"},
390 /* C_UNDO */
391 {L("undo"), ex_undo, E_AUTOPRINT,
393 "u[ndo]",
394 "undo the most recent change"},
395 /* C_UNABBREVIATE */
396 {L("unabbreviate"),ex_unabbr, 0,
397 "w1r",
398 "una[bbrev] word",
399 "delete an abbreviation"},
400 /* C_UNMAP */
401 {L("unmap"), ex_unmap, 0,
402 "!w1r",
403 "unm[ap][!] word",
404 "delete an input or command map"},
405 /* C_V */
406 {L("v"), ex_v, E_ADDR2_ALL,
407 "s",
408 "[line [,line]] v [;/]RE[;/] [commands]",
409 "execute a global command on lines NOT matching an RE"},
410 /* C_VERSION */
411 {L("version"), ex_version, 0,
413 "version",
414 "display the program version information"},
415 /* C_VISUAL_EX */
416 {L("visual"), ex_visual, E_ADDR1|E_ADDR_ZERODEF,
417 "2c11",
418 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
419 "enter visual (vi) mode from ex mode"},
420 /* C_VISUAL_VI */
421 {L("visual"), ex_edit, E_NEWSCREEN,
422 "f1o",
423 "[Vv]i[sual][!] [+cmd] [file]",
424 "edit another file (from vi mode only)"},
425 /* C_VIUSAGE */
426 {L("viusage"), ex_viusage, 0,
427 "w1o",
428 "[viu]sage [key]",
429 "display vi key usage statement"},
430 /* C_VSPLIT */
431 {L("vsplit"), ex_edit, E_VIONLY,
432 "f1o",
433 "vs[plit] [+cmd] [file]",
434 "split the current screen vertically"},
435 /* C_WRITE */
436 {L("write"), ex_write, E_ADDR2_ALL|E_ADDR_ZERODEF,
437 "!s",
438 "[line [,line]] w[rite][!] [ !cmd | [>>] [file]]",
439 "write the file"},
440 /* C_WN */
441 {L("wn"), ex_wn, E_ADDR2_ALL|E_ADDR_ZERODEF,
442 "!s",
443 "[line [,line]] wn[!] [>>] [file]",
444 "write the file and switch to the next file"},
445 /* C_WQ */
446 {L("wq"), ex_wq, E_ADDR2_ALL|E_ADDR_ZERODEF,
447 "!s",
448 "[line [,line]] wq[!] [>>] [file]",
449 "write the file and exit"},
450 /* C_XIT */
451 {L("xit"), ex_xit, E_ADDR2_ALL|E_ADDR_ZERODEF,
452 "!f1o",
453 "[line [,line]] x[it][!] [file]",
454 "exit"},
455 /* C_YANK */
456 {L("yank"), ex_yank, E_ADDR2,
457 "bca",
458 "[line [,line]] ya[nk] [buffer] [count]",
459 "copy lines to a cut buffer"},
460 /* C_Z */
461 {L("z"), ex_z, E_ADDR1,
462 "3c01",
463 "[line] z [-|.|+|^|=] [count] [flags]",
464 "display different screens of the file"},
465 /* C_SUBTILDE */
466 {L("~"), ex_subtilde, E_ADDR2|E_ADDR_ZERO,
467 "s",
468 "[line [,line]] ~ [cgr] [count] [#lp]",
469 "replace previous RE with previous replacement string,"},
470 {NULL, NULL, 0,
471 NULL,
472 NULL,
473 NULL,},