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