rework SEQ's to sort on more than the first character of the input
[nvi.git] / ex / ex_cmd.c
blobb51f4fcbf77ec321446bd38a5708a4fb4cd4e1af
1 /*-
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
5 * %sccs.include.redist.c%
6 */
8 #ifndef lint
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 $";
10 #endif /* not lint */
12 #include <sys/types.h>
14 #include "vi.h"
15 #include "excmd.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
23 * "rewind".
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:
30 * ! -- ! flag
31 * + -- +cmd
32 * 1 -- flags: [+-]*[pl#][+-]*
33 * 2 -- flags: [-.+^]
34 * 3 -- flags: [-.+^=]
35 * b -- buffer
36 * C -- count
37 * c -- count as an address offset
38 * f[N#][or] -- file (a number or N, optional or required)
39 * l -- line
40 * n -- signed count
41 * S -- string with file name expansion
42 * s -- string
43 * W -- word string
44 * w[N#][or] -- word (a number or N, optional or required)
46 EXCMDLIST const cmds[] = {
47 /* C_BANG */
48 {"!", ex_bang, E_ADDR2_NONE|E_NORC,
49 "S",
50 "[line [,line]] ! command",
51 "filter lines through commands or run commands"},
52 /* C_HASH */
53 {"#", ex_number, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
54 "c1",
55 "[line [,line]] # [count] [l]",
56 "display numbered lines"},
57 /* C_SUBAGAIN */
58 {"&", ex_subagain, E_ADDR2|E_NORC,
59 "s",
60 "[line [,line]] & [cgr] [count] [#lp]",
61 "repeat the last subsitution"},
62 /* C_STAR */
63 {"*", ex_at, 0,
64 "b",
65 "* [buffer]",
66 "execute a buffer"},
67 /* C_SHIFTL */
68 {"<", ex_shiftl, E_ADDR2|E_NORC,
69 "c1",
70 "[line [,line]] <[<...] [count] [flags]",
71 "shift lines left"},
72 /* C_EQUAL */
73 {"=", ex_equal, E_ADDR1|E_NORC,
74 "1",
75 "[line] = [flags]",
76 "display line number"},
77 /* C_SHIFTR */
78 {">", ex_shiftr, E_ADDR2|E_NORC,
79 "c1",
80 "[line [,line]] >[>...] [count] [flags]",
81 "shift lines right"},
82 /* C_AT */
83 {"@", ex_at, 0,
84 "b",
85 "@ [buffer]",
86 "execute a buffer"},
87 /* C_SUBTILDE */
88 {"~", ex_subtilde, E_ADDR2|E_NORC,
89 "s",
90 "[line [,line]] ~ [cgr] [count] [#lp]",
91 "replace previous RE with previous replacement string,"},
92 /* C_APPEND */
93 {"append", ex_append, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
94 "!",
95 "[line] a[ppend][!]",
96 "append input to a line"},
97 /* C_ABBR */
98 {"abbreviate", ex_abbr, E_NOGLOBAL,
99 "W",
100 "ab[brev] word replace",
101 "specify an input abbreviation"},
102 /* C_ARGS */
103 {"args", ex_args, E_NOGLOBAL|E_NORC,
104 "",
105 "ar[gs]",
106 "display file argument list"},
107 /* C_BG */
108 {"bg", ex_bg, E_NOGLOBAL|E_NORC,
110 "bg",
111 "background the current screen"},
112 /* C_CHANGE */
113 {"change", ex_change, E_ADDR2|E_NORC|E_ZERODEF,
114 "!c",
115 "[line [,line]] c[hange][!] [count]",
116 "change lines to input"},
117 /* C_CD */
118 {"cd", ex_cd, E_NOGLOBAL,
119 "!f1o",
120 "cd[!] [directory]",
121 "change the current directory"},
122 /* C_CHDIR */
123 {"chdir", ex_cd, E_NOGLOBAL,
124 "!f1o",
125 "chd[ir][!] [directory]",
126 "change the current directory"},
127 /* C_COPY */
128 {"copy", ex_copy, E_ADDR2|E_NORC,
129 "l1",
130 "[line [,line]] co[py] line [flags]",
131 "copy lines elsewhere in the file"},
132 /* C_DELETE */
133 {"delete", ex_delete, E_ADDR2|E_NORC,
134 "bc1",
135 "[line [,line]] d[elete] [buffer] [count] [flags]",
136 "delete lines from the file"},
137 /* C_DISPLAY */
138 {"display", ex_display, E_NOGLOBAL|E_NORC,
139 "w1r",
140 "display b[uffers] | s[creens] | t[ags]",
141 "display buffers, screens or tags"},
142 /* C_DIGRAPH */
143 {"digraph", ex_digraph, E_NOGLOBAL|E_NOPERM|E_NORC,
144 "",
145 "digraph",
146 "specify digraphs (not implemented)"},
147 /* C_EDIT */
148 {"edit", ex_edit, E_NOGLOBAL|E_NORC,
149 "!+f1o",
150 "e[dit][!] [+cmd] [file]",
151 "begin editing another file"},
152 /* C_EX */
153 {"ex", ex_edit, E_NOGLOBAL|E_NORC,
154 "!+f1o",
155 "ex[!] [+cmd] [file]",
156 "begin editing another file"},
157 /* C_EXUSAGE */
158 {"exusage", ex_usage, E_NOGLOBAL|E_NORC,
159 "w1o",
160 "[exu]sage [command]",
161 "display ex command usage statement"},
162 /* C_FILE */
163 {"file", ex_file, E_NOGLOBAL|E_NORC,
164 "f1o",
165 "f[ile] [name]",
166 "display (and optionally set) file name"},
167 /* C_FG */
168 {"fg", ex_fg, E_NOGLOBAL|E_NORC,
169 "f1o",
170 "fg [file]",
171 "switch the current screen and a backgrounded screen"},
172 /* C_GLOBAL */
173 {"global", ex_global, E_ADDR2_ALL|E_NOGLOBAL|E_NORC,
174 "!s",
175 "[line [,line]] g[lobal][!] [;/]pattern[;/] [commands]",
176 "execute a global command on lines matching a pattern"},
177 /* C_HELP */
178 {"help", ex_help, E_NOGLOBAL|E_NORC,
180 "he[lp]",
181 "display help statement"},
182 /* C_INSERT */
183 {"insert", ex_insert, E_ADDR1|E_NORC,
184 "!",
185 "[line] i[nsert][!]",
186 "insert input before a line"},
187 /* C_JOIN */
188 {"join", ex_join, E_ADDR2|E_NORC,
189 "!c1",
190 "[line [,line]] j[oin][!] [count] [flags]",
191 "join lines into a single line"},
192 /* C_K */
193 {"k", ex_mark, E_ADDR1|E_NORC,
194 "w1r",
195 "[line] k key",
196 "mark a line position"},
197 /* C_LIST */
198 {"list", ex_list, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
199 "c1",
200 "[line [,line]] l[ist] [count] [#]",
201 "display lines in an unambiguous form"},
202 /* C_MOVE */
203 {"move", ex_move, E_ADDR2|E_NORC,
204 "l",
205 "[line [,line]] m[ove] line",
206 "move lines elsewhere in the file"},
207 /* C_MARK */
208 {"mark", ex_mark, E_ADDR1|E_NORC,
209 "w1r",
210 "[line] ma[rk] key",
211 "mark a line position"},
212 /* C_MAP */
213 {"map", ex_map, 0,
214 "!W",
215 "map[!] [keys replace]",
216 "map input or commands to one or more keys"},
217 /* C_MKEXRC */
218 {"mkexrc", ex_mkexrc, E_NOGLOBAL|E_NORC,
219 "!f1r",
220 "mkexrc[!] file",
221 "write a .exrc file"},
222 /* C_NEXT */
223 {"next", ex_next, E_NOGLOBAL|E_NORC,
224 "!fN",
225 "n[ext][!] [file ...]",
226 "edit (and optionally specify) the next file"},
227 /* C_NUMBER */
228 {"number", ex_number, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
229 "c1",
230 "[line [,line]] nu[mber] [count] [l]",
231 "change display to number lines"},
232 /* C_OPEN */
233 {"open", ex_open, E_ADDR1,
234 "s",
235 "[line] o[pen] [/pattern/] [flags]",
236 "enter \"open\" mode (not implemented)"},
237 /* C_PRINT */
238 {"print", ex_pr, E_ADDR2|E_F_PRCLEAR|E_NORC|E_SETLAST,
239 "c1",
240 "[line [,line]] p[rint] [count] [#l]",
241 "display lines"},
242 /* C_PRESERVE */
243 {"preserve", ex_preserve, E_NOGLOBAL|E_NORC,
244 "",
245 "pre[serve]",
246 "preserve an edit session for recovery"},
247 /* C_PREVIOUS */
248 {"previous", ex_prev, E_NOGLOBAL|E_NORC,
249 "!",
250 "prev[ious][!]",
251 "edit the previous file in the file argument list"},
252 /* C_PUT */
253 {"put", ex_put, E_ADDR1|E_NORC|E_ZERO,
254 "b",
255 "[line] pu[t] [buffer]",
256 "append a cut buffer to the line"},
257 /* C_QUIT */
258 {"quit", ex_quit, E_NOGLOBAL,
259 "!",
260 "q[uit][!]",
261 "exit ex/vi"},
262 /* C_READ */
263 {"read", ex_read, E_ADDR1|E_NORC|E_ZERO|E_ZERODEF,
264 "!s",
265 "[line] r[ead] [!cmd | [file]]",
266 "append input from a command or file to the line"},
267 /* C_RESIZE */
268 {"resize", ex_resize, E_NOGLOBAL|E_NORC,
269 "n",
270 "resize [change]",
271 "grow or shrink the current screen"},
272 /* C_REWIND */
273 {"rewind", ex_rew, E_NOGLOBAL|E_NORC,
274 "!",
275 "rew[ind][!]",
276 "re-edit all the files in the file argument list"},
277 /* C_SUBSTITUTE */
278 {"substitute", ex_substitute, E_ADDR2|E_NORC,
279 "s",
280 "[line [,line]] s[ubstitute] [[/;]pat[/;]/repl[/;] [cgr] [count] [#lp]]",
281 "substitute on lines matching a pattern"},
282 /* C_SCRIPT */
283 {"script", ex_script, E_NOGLOBAL|E_NORC,
284 "!f1o",
285 "sc[ript][!] [file]",
286 "run a shell in a screen"},
287 /* C_SET */
288 {"set", ex_set, E_NOGLOBAL,
289 "wN",
290 "se[t] [option[=[value]]...] [nooption ...] [option? ...] [all]",
291 "set options (use \":set all\" to see all options)"},
292 /* C_SHELL */
293 {"shell", ex_shell, E_NOGLOBAL|E_NORC,
294 "",
295 "sh[ell]",
296 "suspend editing and run a shell"},
297 /* C_SOURCE */
298 {"source", ex_source, E_NOGLOBAL,
299 "f1r",
300 "so[urce] file",
301 "read a file of ex commands"},
302 /* C_SPLIT */
303 {"split", ex_split, E_NOGLOBAL|E_NORC,
304 "fNo",
305 "s[plit] [file ...]",
306 "split the current screen into two screens"},
307 /* C_STOP */
308 {"stop", ex_stop, E_NOGLOBAL|E_NORC,
309 "!",
310 "st[op][!]",
311 "suspend the edit session"},
312 /* C_SUSPEND */
313 {"suspend", ex_stop, E_NOGLOBAL|E_NORC,
314 "!",
315 "su[spend][!]",
316 "suspend the edit session"},
317 /* C_T */
318 {"t", ex_copy, E_ADDR2|E_NORC,
319 "l1",
320 "[line [,line]] t line [flags]",
321 "move lines elsewhere in the file"},
322 /* C_TAG */
323 {"tag", ex_tagpush, E_NOGLOBAL,
324 "!w1o",
325 "ta[g][!] [string]",
326 "edit the file containing the tag"},
327 /* C_TAGPOP */
328 {"tagpop", ex_tagpop, E_NOGLOBAL|E_NORC,
329 "!w1o",
330 "tagp[op][!] [number | file]",
331 "return to a previous tag"},
332 /* C_TAGTOP */
333 {"tagtop", ex_tagtop, E_NOGLOBAL|E_NORC,
334 "!",
335 "tagt[op][!]",
336 "return to the first tag"},
337 /* C_UNDOL */
338 {"Undo", ex_undol, E_NOGLOBAL|E_NORC,
339 "",
340 "U[ndo]",
341 "undo all the changes to this line"},
342 /* C_UNDO */
343 {"undo", ex_undo, E_NOGLOBAL|E_NORC,
344 "",
345 "u[ndo]",
346 "undo the most recent change"},
347 /* C_UNABBREVIATE */
348 {"unabbreviate",ex_unabbr, E_NOGLOBAL,
349 "w1r",
350 "una[bbrev] word",
351 "delete an abbreviation"},
352 /* C_UNMAP */
353 {"unmap", ex_unmap, E_NOGLOBAL,
354 "!w1r",
355 "unm[ap][!] word",
356 "delete an input or command map"},
357 /* C_VGLOBAL */
358 {"vglobal", ex_vglobal, E_ADDR2_ALL|E_NOGLOBAL|E_NORC,
359 "s",
360 "[line [,line]] v[global] [;/]pattern[;/] [commands]",
361 "execute a global command on lines NOT matching a pattern"},
362 /* C_VERSION */
363 {"version", ex_version, E_NOGLOBAL|E_NORC,
364 "",
365 "version",
366 "display the program version information"},
367 /* C_VISUAL_EX */
368 {"visual", ex_visual, E_ADDR1|E_NOGLOBAL|E_NORC|E_ZERODEF,
369 "2C1",
370 "[line] vi[sual] [-|.|+|^] [window_size] [flags]",
371 "enter visual (vi) mode"},
372 /* C_VISUAL_VI */
373 {"visual", ex_edit, E_NOGLOBAL|E_NORC,
374 "!+f1o",
375 "vi[sual][!] [+cmd] [file]",
376 "enter visual (vi) mode"},
377 /* C_VIUSAGE */
378 {"viusage", ex_viusage, E_NOGLOBAL|E_NORC,
379 "w1o",
380 "[viu]sage [key]",
381 "display vi key usage statement"},
382 /* C_WRITE */
383 {"write", ex_write, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
384 "!s",
385 "[line [,line]] w[rite][!] [!cmd | [>>] [file]]",
386 "write the file"},
387 /* C_WQ */
388 {"wq", ex_wq, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
389 "!s",
390 "[line [,line]] wq[!] [>>] [file]",
391 "write the file and exit"},
392 /* C_XIT */
393 {"xit", ex_xit, E_ADDR2_ALL|E_NOGLOBAL|E_NORC|E_ZERODEF,
394 "!f1o",
395 "[line [,line]] x[it][!] [file]",
396 "exit"},
397 /* C_YANK */
398 {"yank", ex_yank, E_ADDR2|E_NORC,
399 "bc",
400 "[line [,line]] ya[nk] [buffer] [count]",
401 "copy lines to a cut buffer"},
402 /* C_Z */
403 {"z", ex_z, E_ADDR1|E_NOGLOBAL|E_NORC,
404 "3C1",
405 "[line] z [-|.|+|^|=] [count] [flags]",
406 "display different screens of the file"},
407 {NULL},