source: commands.c @ 507d5aa

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 507d5aa was 1c6c4d3, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
Added owl_sprintf which returns the formatted string, or NULL. The caller must free this string. This will allocate enough memory and thus avoid potential some buffer overrun situations. Started fixing some potential buffer overrun situations. Simple implementation of 'zwrite -m' (doesn't yet log an outgoing message as having been sent.) The "Not logged in or subscribing to messages" error now includes the name of the recipient.
  • Property mode set to 100644
File size: 48.2 KB
RevLine 
[7d4fbcd]1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include "owl.h"
6
[1aee7d9]7static const char fileIdent[] = "$Id$";
8
[7d4fbcd]9/* fn is "char *foo(int argc, char **argv, char *buff)" */
10#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
11        { name, summary, usage, description, ctx, \
12          NULL, fn, NULL, NULL, NULL, NULL, NULL }
13
14/* fn is "void foo(void)" */
15#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
16        { name, summary, usage, description, ctx, \
17          NULL, NULL, fn, NULL, NULL, NULL, NULL }
18
19/* fn is "void foo(int)" */
20#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
21        { name, summary, usage, description, ctx, \
22          NULL, NULL, NULL, fn, NULL, NULL, NULL }
23
24#define OWLCMD_ALIAS(name, actualname) \
25        { name, OWL_CMD_ALIAS_SUMMARY_PREFIX actualname, "", "", OWL_CTX_ANY, \
26          actualname, NULL, NULL, NULL, NULL, NULL, NULL }
27
28/* fn is "char *foo(void *ctx, int argc, char **argv, char *buff)" */
29#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
30        { name, summary, usage, description, ctx, \
31          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,char**,char*))fn), NULL, NULL }
32
33/* fn is "void foo(void)" */
34#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
35        { name, summary, usage, description, ctx, \
36          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL }
37
38/* fn is "void foo(int)" */
39#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
40        { name, summary, usage, description, ctx, \
41          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn) }
42
43
44owl_cmd commands_to_init[]
45  = {
46  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
47              "send a login or logout notification",
48              "zlog in\nzlog out",
49              "zlog in will send a login notification, zlog out will send a\n"
50              "logout notification.  By default a login notification is sent\n"
51              "when owl is started and a logout notification is sent when owl\n"
52              "is exited.  This behavior can be changed with the 'startuplogin'\n"
53              "and 'shudownlogout' variables.\n"),
54
55  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
56              "exit owl",
57              "",
58              "Exit owl and run any shutdown activities."),
59  OWLCMD_ALIAS("exit", "quit"),
60  OWLCMD_ALIAS("q",    "quit"),
61 
62  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
63              "prompts the user to enter a command",
64              "start-command [initial-value]",
65              "Initializes the command field to initial-value."),
66
67  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
68              "creates a command alias",
69              "alias <new_command> <old_command>",
70              "Creates a command alias from new_command to old_command.\n"
71              "Any arguments passed to <new_command> will be appended to\n"
72              "<old_command> before it is executed.\n"),
73
74  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
75              "creates a binding in a keymap",
76              "bindkey <keymap> <keyseq> command <command>",
77              "Binds a key sequence to a command within a keymap.\n"
78              "Use 'show keymaps' to see the existing keymaps.\n"
79              "Key sequences may be things like M-C-t or NPAGE.\n"),
80
81  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
82              "send a zephyr",
[1c6c4d3]83              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
[7d4fbcd]84              "Zwrite send a zephyr to the one or more users specified.\n\n"
85              "The following options are available:\n\n"
[1c6c4d3]86              "-m    Specifies a message to send without prompting.\n"
87              "      Note that this does not yet log an outgoing message.\n"
88              "      This must be the last argument.\n\n"
[7d4fbcd]89              "-n    Do not send a ping message.\n\n"
90              "-C    If the message is sent to more than one user include a\n"
91              "      \"cc:\" line in the text\n\n"
92              "-c class\n"
93              "      Send to the specified zephyr class\n\n"
94              "-i instance\n"
95              "      Send to the specified zephyr instance\n\n"
96              "-r realm\n"
97              "      Send to a foreign realm\n"
98              "-O opcode\n"
99              "      Send to the specified opcode\n"),
100 
101  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
102              "reply to the current message",
[e75011e]103              "reply [-e] [ sender | all | zaway ]",
[7d4fbcd]104              "If -e is specified, the zwrite command line is presented to\n"
105              "allow editing.\n\n"
106              "If 'sender' is specified, reply to the sender.\n\n"
107              "If 'all' or no args are specified, reply publically to the\n"
108              "same class/instance for non-personal messages and to the\n"
[e75011e]109              "sender for personal messages.\n\n"
110              "If 'zaway' is specified, replies with a zaway message.\n\n"),
[7d4fbcd]111
112  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
113              "set a variable value",
114              "set [-q] <variable> <value>\n"
115              "set",
116              "Set the named variable to the specified value.  If no\n"
117              "arguments are used print the value of all variables.\n"
118              "If -q is specified, is silent and doesn't print a message.\n"),
119
120  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
121              "print a variable value",
122              "print <variable>\n"
123              "print",
124              "Print the value of the named variable.  If no arugments\n"
125              "are used print the value of all variables.\n"),
126
127  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
128              "print the version of the running owl", "", ""),
129
130  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
131              "subscribe to a zephyr class, instance, recipient",
132              "subscribe <class> <instance> [recipient]",
133              "Subscribe the specified class and instance.  If the recipient\n"
134              "is not listed on the command line it defaults\n"
135              "to * (the wildcard recipient).\n"),
136  OWLCMD_ALIAS("sub", "subscribe"),
137
138  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
139              "unsubscribe from a zephyr class, instance, recipient",
140              "unsubscribe <class> <instance> [recipient]",
141              "Unsubscribe from the specified class and instance.  If the\n"
142              "recipient is not listed on the command line it defaults\n"
143              "to * (the wildcard recipient).\n"),
144  OWLCMD_ALIAS("unsub", "unsubscribe"),
145
146  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
147              "unsubscribe from all zephyrs", "", ""),
148 
149  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
150              "print all current subscriptions",
151              "getsubs",
152              "getsubs retrieves the current subscriptions from the server\n"
153              "and displays them.\n"),
154
[d36f2cb]155  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
156              "creates a zpunt based on the current message",
157              "smartnarrow [-i | --instance]",
158              "Starts a zpunt command based on the current message's class\n"
159              "(and instance if -i is specified).\n"),
160
[7d4fbcd]161  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
162              "suppress a given zephyr triplet",
163              "zpunt <class> <instance> [recipient]\n"
164              "zpunt <instance>",
165              "The zpunt command will supress message to the specified\n"
166              "zephyr triplet.  In the second usage messages as supressed\n"
167              "for class MESSAGE and the named instance.\n\n"
168              "SEE ALSO:  zunpunt, show zpunts\n"),
169
170  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
171              "undo a previous zpunt",
172              "zunpunt <class> <instance> [recipient]\n"
173              "zunpunt <instance>",
174              "The zunpunt command will allow messages that were previosly\n"
175              "suppressed to be received again.\n\n"
176              "SEE ALSO:  zpunt, show zpunts\n"),
177
178  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
179              "display detailed information about the current message",
180              "", ""),
181 
182  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
183              "display help on using owl",
184              "help [command]", ""),
185 
186  OWLCMD_VOID("recv:shiftleft", owl_command_shift_left, OWL_CTX_INTERACTIVE,
187              "scrolls receive window to the left", "", ""),
188
189  OWLCMD_VOID("recv:shiftright", owl_command_shift_right, OWL_CTX_INTERACTIVE,
190              "scrolls receive window to the left", "", ""),
191
192  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
193              OWL_CTX_INTERACTIVE,
194              "scrolls down by a page", "", ""),
195
196  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
197              "scrolls up by a page", "", ""),
198
199  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
200              "scrolls current message up or down", 
201              "recv:scroll <numlines>", 
202              "Scrolls the current message up or down by <numlines>.\n"
203              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
204
[b950088]205  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
206              "move the pointer to the next message",
[7360fab]207              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
208              "          [ --smart-filter | --smart-filter-instance ]",
[b950088]209              "Moves the pointer to the next message in the current view.\n"
210              "If --filter is specified, will only consider messages in\n"
211              "the filter <name>.\n"
[7360fab]212              "If --smart-filter or --smart-filter-instance is specified,\n"
213              "goes to the next message that is similar to the current message.\n"
[b950088]214              "If --skip-deleted is specified, deleted messages will\n"
215              "be skipped.\n"
216              "If --last-if-none is specified, will stop at last message\n"
217              "in the view if no other suitable messages are found.\n"),
[7d4fbcd]218  OWLCMD_ALIAS("recv:next", "next"),
219
[b950088]220  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
221              "move the pointer to the previous message",
[7360fab]222              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
223              "          [ --smart-filter | --smart-filter-instance ]",
[b950088]224              "Moves the pointer to the next message in the current view.\n"
225              "If --filter is specified, will only consider messages in\n"
226              "the filter <name>.\n"
[7360fab]227              "If --smart-filter or --smart-filter-instance is specified,\n"
228              "goes to the previous message that is similar to the current message.\n"
[b950088]229              "If --skip-deleted is specified, deleted messages will\n"
230              "be skipped.\n"
231              "If --first-if-none is specified, will stop at first message\n"
232              "in the view if no other suitable messages are found.\n"),
[7d4fbcd]233  OWLCMD_ALIAS("recv:prev", "prev"),
234
[b950088]235  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
236  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
[7d4fbcd]237
[b950088]238  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
239  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
[7d4fbcd]240
[b950088]241  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
[7d4fbcd]242
[b950088]243  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
[7d4fbcd]244
245  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
246              "move the pointer to the first message", "", ""),
247  OWLCMD_ALIAS("recv:first", "first"),
248
249  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
250              "move the pointer to the last message", "", ""),
251  OWLCMD_ALIAS("recv:last", "last"),
252
253  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
254              "remove all messages marked for deletion", "", ""),
255
256  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
257              "resize the window to the current screen size", "", ""),
258
259  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
260              "redraw the entire window", "", ""),
261
262  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
263              "suspend owl", "", ""),
264
265  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
266              "pops up a message in popup window",
267              "echo [args .. ]\n\n", ""),
268
269  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
270              "run a command from the shell",
271              "exec [args .. ]", ""),
272
273  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
274              "run a command from the shell and display in an admin message",
275              "aexec [args .. ]", ""),
276
277  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
278              "run a command from the shell and display in a popup window",
279              "pexec [args .. ]", ""),
280
281  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
282              "run a perl expression",
283              "perl [args .. ]", ""),
284
285  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
286              "run a perl expression and display in an admin message",
287              "aperl [args .. ]", ""),
288
289  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
290              "run a perl expression and display in a popup window",
291              "pperl [args .. ]", ""),
292
293  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
294              "runs multiple ;-separated commands",
295              "multi <command1> ( ; <command2> )*\n",
296              "Runs multiple semicolon-separated commands in order.\n"
297              "Note quoting isn't supported here yet.\n"
298              "If you want to do something fancy, use perl.\n"),
299
300  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
301              "runs multiple ;-separated commands",
302              "'(' <command1> ( ; <command2> )* ')'\n",
303              "Runs multiple semicolon-separated commands in order.\n"
304              "You must have a space before the final ')'\n"
305              "Note quoting isn't supported here yet.\n"
306              "If you want to do something fancy, use perl.\n"),
307
308  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
309              "pops up a message in a window", "", ""),
310
311  OWLCMD_VOID("openurl", owl_command_openurl, OWL_CTX_INTERACTIVE,
312              "opens up a URL from the current message",
313              "", 
314              "Uses the 'webbrowser' variable to determine\n"
315              "which browser to use.  Currently, 'netscape'\n"
316              "and 'galeon' are supported.\n"),
317
318  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
319              "running a command from the shell",
320              "zaway [ on | off | toggle ]\n"
321              "zaway <message>",
322              "Turn on or off the default zaway message.  If a message is\n"
323              "specified turn on zaway with that message\n"),
324
325  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
326              "load subscriptions from a file",
327              "load-subs <file>\n", ""),
328
329  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
330              "print information about owl", "", ""),
331
332  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
333              "print status information about the running owl", "", ""),
334 
335  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
336              "locate a user",
337              "zlocate [-d] <user>", 
338              "Performs a zlocate on a user and puts the result into\n"
339              "a popwin.  If -d is specified, does not authenticate\n"
340              "the lookup request.\n"),
341 
342  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
343              "create a message filter",
344              "filter <name> [ -c color ] [ <expression> ... ]",
345              "The filter command creates a filter with the specified name,\n"
346              "or if one already exists it is replaced.  Example filter\n"
347              "syntax would be:\n\n"
348              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
349              "Valid matching fields are class, instance, recipient, sender,\n"
350              "opcode and realm. Valid operations are 'and', 'or' and 'not'.\n"
351              "Spaces must be present before and after parenthesis.  If the\n"
352              "optional color argument is used it specifies the color that\n"
353              "messages matching this filter should be displayed in.\n\n"
354
355              "SEE ALSO: view, viewclass, viewuser\n"),
356
357  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
358              "change the color on the current filter",
359              "colorview <color>",
360              "The color of messages in the current filter will be changed\n"
361              "to <color>.  Use the 'show colors' command for a list\n"
362              "of valid colors.\n\n"
363              "SEE ALSO: 'show colors'\n"),
364
365  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
366              "view messages matching a filter",
367              "view <filter>\n"
368              "view -d <expression>\n"
369              "view --home",
370              "In the first usage, The view command sets the current view to\n"
371              "the specified filter.   This causes only messages matching\n"
372              "that filter to be displayed.\n"
373              "\n"
374              "In the second usage a filter expression\n"
375              "and be specified directly\n"
376              "after -d.  Owl will build an internal filter based on this\n"
377              "filter and change the current view to use it.\n\n"
378              "If --home is specified, switches to the view specified by\n"
379              "the 'view_home' variable.\n\n"
380              "SEE ALSO: filter, viewclass, viewuser\n"),
381
382  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
383              "view only messages similar to the current message",
[7360fab]384              "smartnarrow [-i | --instance]",
[7d4fbcd]385              "If the curmsg is a personal message narrow\n"
386              "   to the converstaion with that user.\n"
387              "If the curmsg is a class message, instance foo, recip *\n"
388              "   message, narrow to the class, inst.\n"
389              "If the curmsg is a class message then narrow\n"
390              "    to the class.\n"
391              "If the curmsg is a class message and '-i' is specied\n"
392              "    then narrow to the class, instance\n"),
393
[7360fab]394  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
395              "returns the name of a filter based on the current message",
396              "smartfilter [-i | --instance]",
397              "If the curmsg is a personal message, the filter is\n"
398              "   the converstaion with that user.\n"
399              "If the curmsg is a class message, instance foo, recip *\n"
400              "   message, the filter is the class, inst.\n"
401              "If the curmsg is a class message, the filter is that class.\n"
402              "If the curmsg is a class message and '-i' is specied\n"
403              "    the filter is that <class,instance> pair\n"),
404
[7d4fbcd]405  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
406              "view messages matching a particular class",
407              "viewclass <class>",
408              "The viewclass command will automatically create a filter\n"
409              "matching the specified class and switch the current view\n"
410              "to it.\n\n"
411              "SEE ALSO: filter, view, viewuser\n"),
412  OWLCMD_ALIAS("vc", "viewclass"),
413
414  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
415              "view messages matching a particular user",
416              "viewuser <user>",
417              "The viewuser command will automatically create a filter\n"
418              "matching the specified user and switch the current\n"
419              "view to it.\n\n"
420              "SEE ALSO: filter, view, viewclass\n"),
421  OWLCMD_ALIAS("vu", "viewuser"),
422
423  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
424              "show information",
425              "show variables\n"
426              "show variable <variable>\n"
427              "show filters\n"
428              "show filter <filter>\n"
429              "show keymaps\n"
430              "show keymap <keymap>\n"
431              "show commands\n"
432              "show command <command>\n"
433              "show subs\n"
434              "show subscriptions\n"
435              "show zpunts\n"
436              "show colors\n"
437              "show terminal\n"
438              "show version\n"
439              "show status\n",
440
441              "Show colors will display a list of valid colors for the\n"
442              "     terminal."
443              "Show filters will list the names of all filters.\n"
444              "Show filter <filter> will show the definition of a particular\n"
445              "     filter.\n\n"
446              "Show zpunts will show the active zpunt filters.\n\n"
447              "Show keymaps will list the names of all keymaps.\n"
448              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
449              "Show commands will list the names of all keymaps.\n"
450              "Show command <command> will provide information about a command.\n\n"
451              "Show variables will list the names of all variables.\n\n"
452              "SEE ALSO: filter, view, alias, bindkey, help\n"),
453 
454  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
455              "mark a message for deletion",
[b950088]456              "delete [ -id msgid ] [ --no-move ]\n"
[7d4fbcd]457              "delete view\n"
458              "delete trash",
459              "If no message id is specified the current message is marked\n"
460              "for deletion.  Otherwise the message with the given message\n"
461              "id is marked for deltion.\n"
[b950088]462              "If '--no-move' is specified, don't move after deletion.\n"
[7d4fbcd]463              "If 'trash' is specified, deletes all trash/auto messages\n"
464              "in the current view.\n"
465              "If 'view' is specified, deletes all messages in the\n"
466              "current view.\n"),
467  OWLCMD_ALIAS("del", "delete"),
468
469  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
470              "unmark a message for deletion",
[b950088]471              "undelete [ -id msgid ] [ --no-move ]\n"
[7d4fbcd]472              "undelete view",
473              "If no message id is specified the current message is\n"
474              "unmarked for deletion.  Otherwise the message with the\n"
475              "given message id is marked for undeltion.\n"
[b950088]476              "If '--no-move' is specified, don't move after deletion.\n"
[7d4fbcd]477              "If 'view' is specified, undeletes all messages\n"
478              "in the current view.\n"),
479  OWLCMD_ALIAS("undel", "undelete"),
480
481  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
482              "ring the terminal bell",
483              "beep",
484              "Beep will ring the terminal bell.\n"
485              "If the variable 'bell' has been\n"
486              "set to 'off' this command does nothing.\n"),
487
488  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
489              "prints a message into the debug log",
490              "debug <message>", ""),
491
[8ee73f8d]492  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
493              "returns the name of the filter for the current view",
494              "", ""),
495
496  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
497              "returns the value of a variable",
498              "getvar <varname>", ""),
499
[7d4fbcd]500  /****************************************************************/
501  /************************* EDIT-SPECIFIC ************************/
502  /****************************************************************/
503
504  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
505                  OWL_CTX_EDIT,
506                  "moves cursor forward a word",
507                  "", ""),
508
509  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
510                  OWL_CTX_EDIT,
511                  "moves cursor backwards a word",
512                  "", ""),
513
514  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
515                  OWL_CTX_EDIT,
516                  "moves cursor to the top left (start) of the buffer",
517                  "", ""),
518
519  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
520                  OWL_CTX_EDIT,
521                  "moves cursor to the bottom right (end) of the buffer",
522                  "", ""),
523
524  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
525                  OWL_CTX_EDIT,
526                  "moves cursor to the end of the line",
527                  "", ""),
528
529  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
530                  OWL_CTX_EDIT,
531                  "moves cursor to the beginning of the line",
532                  "", ""),
533
534  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
535                  OWL_CTX_EDIT,
536                  "moves the cursor left by a character",
537                  "", ""),
538
539  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
540                  OWL_CTX_EDIT,
541                  "moves the cursor right by a character",
542                  "", ""),
543
544  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
545                  OWL_CTX_EDIT,
546                  "deletes the word to the right of the cursor",
547                  "", ""),
548
[b68f9cd]549  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
550                  OWL_CTX_EDIT,
551                  "deletes the word to the left of the cursor",
552                  "", ""),
553
[7d4fbcd]554  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
555                  OWL_CTX_EDIT,
556                  "deletes the character to the left of the cursor",
557                  "", ""),
558
559  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
560                  OWL_CTX_EDIT,
561                  "deletes the character to the right of the cursor",
562                  "", ""),
563
564  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
565                  OWL_CTX_EDIT,
566                  "deletes from the cursor to the end of the line",
567                  "", ""),
568
569  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
570                  OWL_CTX_EDIT,
571                  "deletes all of the contents of the buffer",
572                  "", ""),
573
574  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
575                  OWL_CTX_EDIT,
576                  "fills the current paragraph to line-wrap well",
577                  "", ""),
578
579  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
580                  OWL_CTX_EDIT,
581                  "recenters the buffer",
582                  "", ""),
583
584  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
585                  OWL_CTX_EDIT,
586                  "inserts text into the buffer",
587                  "edit:insert-text <text>", ""),
588
589  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
590                  OWL_CTX_EDIT,
591                  "cancels the current command",
592                  "", ""),
593
594  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
595                  OWL_CTX_EDITLINE,
596                  "replaces the text with the previous history",
597                  "", ""),
598
599  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
600                  OWL_CTX_EDITLINE,
601                  "replaces the text with the previous history",
602                  "", ""),
603
604  OWLCMD_VOID_CTX("editline:done", owl_command_editline_done, 
605                  OWL_CTX_EDITLINE,
606                  "completes the command (eg, executes command being composed)",
607                  "", ""),
608
609  OWLCMD_VOID_CTX("editmulti:move-up-line", owl_editwin_key_up, 
610                  OWL_CTX_EDITMULTI,
611                  "moves the cursor up one line",
612                  "", ""),
613
614  OWLCMD_VOID_CTX("editmulti:move-down-line", owl_editwin_key_down, 
615                  OWL_CTX_EDITMULTI,
616                  "moves the cursor down one line",
617                  "", ""),
618
619  OWLCMD_VOID_CTX("editmulti:done", owl_command_editmulti_done, 
620                  OWL_CTX_EDITMULTI,
621                  "completes the command (eg, sends message being composed)",
622                  "", ""),
623
624  /****************************************************************/
625  /********************** POPLESS-SPECIFIC ************************/
626  /****************************************************************/
627
628  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
629                  OWL_CTX_POPLESS,
630                  "scrolls down one page",
631                  "", ""),
632
633  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
634                  OWL_CTX_POPLESS,
635                  "scrolls down one line",
636                  "", ""),
637
638  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
639                  OWL_CTX_POPLESS,
640                  "scrolls up one page",
641                  "", ""),
642
643  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
644                  OWL_CTX_POPLESS,
645                  "scrolls up one line",
646                  "", ""),
647
648  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
649                  OWL_CTX_POPLESS,
650                  "scrolls to the top of the buffer",
651                  "", ""),
652
653  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
654                  OWL_CTX_POPLESS,
655                  "scrolls to the bottom of the buffer",
656                  "", ""),
657
658  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
659                  OWL_CTX_POPLESS,
660                  "scrolls right in the buffer",
661                  "popless:scroll-right <num-chars>", ""),
662
663  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
664                  OWL_CTX_POPLESS,
665                  "scrolls left in the buffer",
666                  "popless:scroll-left <num-chars>", ""),
667
668  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
669                  OWL_CTX_POPLESS,
670                  "exits the popless window",
671                  "", ""),
672
673  /* This line MUST be last! */
674  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
675
676};
677
678void owl_command_info() {
679  owl_function_info();
680}
681
682char *owl_command_help(int argc, char **argv, char *buff) {
683  if (argc!=2) {
684    owl_help();
685    return NULL;
686  }
687 
688  owl_function_help_for_command(argv[1]);
689  return NULL;
690}
691
692void owl_command_about() {
693  owl_function_about();
694}
695
696void owl_command_version() {
697  char buff[1024];
698
699  sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
700  owl_function_makemsg(buff);
701}
702
[b950088]703char *owl_command_next(int argc, char **argv, char *buff) {
704  char *filter=NULL;
705  int skip_deleted=0, last_if_none=0;
706  while (argc>1) {
707    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
708      skip_deleted=1;
709      argc-=1; argv+=1; 
710    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
711      last_if_none=1;
712      argc-=1; argv+=1; 
713    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
[7360fab]714      filter = owl_strdup(argv[2]);
715      argc-=2; argv+=2; 
716    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
717      filter = owl_function_smartfilter(0);
718      argc-=2; argv+=2; 
719    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
720      filter = owl_function_smartfilter(1);
[b950088]721      argc-=2; argv+=2; 
722    } else {
723      owl_function_makemsg("Invalid arguments to command 'next'.");
724      return(NULL);
725    }
726  }
727  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
[7360fab]728  if (filter) owl_free(filter);
[b950088]729  return(NULL);
[7d4fbcd]730}
731
[b950088]732char *owl_command_prev(int argc, char **argv, char *buff) {
733  char *filter=NULL;
734  int skip_deleted=0, first_if_none=0;
735  while (argc>1) {
736    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
737      skip_deleted=1;
738      argc-=1; argv+=1; 
739    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
740      first_if_none=1;
741      argc-=1; argv+=1; 
742    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
[7360fab]743      filter = owl_strdup(argv[2]);
[b950088]744      argc-=2; argv+=2; 
[7360fab]745    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
746      filter = owl_function_smartfilter(0);
747      argc-=2; argv+=2; 
748    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
749      filter = owl_function_smartfilter(1);
750      argc-=2; argv+=2; 
751   } else {
[b950088]752      owl_function_makemsg("Invalid arguments to command 'prev'.");
753      return(NULL);
754    }
755  }
756  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
[7360fab]757  if (filter) owl_free(filter);
[b950088]758  return(NULL);
[7d4fbcd]759}
760
761char *owl_command_smartnarrow(int argc, char **argv, char *buff) {
[7360fab]762  char *filtname = NULL;
763
[7d4fbcd]764  if (argc == 1) {
[7360fab]765    filtname = owl_function_smartfilter(0);
766  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
767    filtname = owl_function_smartfilter(1);
[7d4fbcd]768  } else {
769    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
770  }
[7360fab]771  if (filtname) {
772    owl_function_change_view(filtname);
773    owl_free(filtname);
774  }
[7d4fbcd]775  return NULL;
776}
777
[7360fab]778char *owl_command_smartfilter(int argc, char **argv, char *buff) {
779  char *filtname = NULL;
780
781  if (argc == 1) {
782    filtname = owl_function_smartfilter(0);
783  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
784    filtname = owl_function_smartfilter(1);
785  } else {
786    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
787  }
788  return filtname;
789}
790
[7d4fbcd]791void owl_command_expunge() {
792  owl_function_expunge();
793}
794
795void owl_command_first() {
796  owl_global_set_rightshift(&g, 0);
797  owl_function_firstmsg();
798}
799
800void owl_command_last() {
801  owl_function_lastmsg();
802}
803
804void owl_command_resize() {
805  owl_function_resize();
806}
807
808void owl_command_redisplay() {
809  owl_function_full_redisplay();
810  owl_global_set_needrefresh(&g);
811}
812
813void owl_command_shift_right() {
814  owl_function_shift_right();
815}
816
817void owl_command_shift_left() {
818  owl_function_shift_left();
819}
820
821void owl_command_unsuball() {
822  owl_function_unsuball();
823}
824
825char *owl_command_loadsubs(int argc, char **argv, char *buff) {
826  if (argc == 2) {
827    owl_function_loadsubs(argv[1]);
828  } else if (argc == 1) {
829    owl_function_loadsubs(NULL);
830  } else {
831    owl_function_makemsg("Wrong number of arguments for load-subs.");
832    return NULL;
833  }
834  return NULL;
835}
836
837void owl_command_suspend() {
838  owl_function_suspend();
839}
840
841char *owl_command_start_command(int argc, char **argv, char *buff) {
842  buff = skiptokens(buff, 1);
843  owl_function_start_command(buff);
844  return NULL;
845}
846
847char *owl_command_zaway(int argc, char **argv, char *buff) {
848 
849  if ((argc==1) ||
850      ((argc==2) && !strcmp(argv[1], "on"))) {
851    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
852    owl_function_zaway_on();
853    return NULL;
854  }
855
856  if (argc==2 && !strcmp(argv[1], "off")) {
857    owl_function_zaway_off();
858    return NULL;
859  }
860
861  if (argc==2 && !strcmp(argv[1], "toggle")) {
862    owl_function_zaway_toggle();
863    return NULL;
864  }
865
866  buff = skiptokens(buff, 1);
867  owl_global_set_zaway_msg(&g, buff);
868  owl_function_zaway_on();
869  return NULL;
870}
871
872
873char *owl_command_set(int argc, char **argv, char *buff) {
874  char *var, *val;
875  int  silent=0;
876
877  if (argc == 1) {
878    owl_function_printallvars();
879    return NULL;
880  } else if (argc == 4 && !strcmp("-q",argv[1])) {
881    silent = 1;
882    var=argv[2];
883    val=argv[3];
884  } else if (argc == 3) {
885    var=argv[1];
886    val=argv[2];
887  } else {
888    owl_function_makemsg("Wrong number of arguments for set command");
889    return NULL;
890  }
891
892  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent);
893  return NULL;
894}
895
896char *owl_command_print(int argc, char **argv, char *buff) {
897  char *var;
898  char valbuff[1024];
899
900  if (argc==1) {
901    owl_function_printallvars();
902    return NULL;
903  } else if (argc!=2) {
904    owl_function_makemsg("Wrong number of arguments for print command");
905    return NULL;
906  }
907
908  var=argv[1];
909   
910  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
911                                     var, valbuff, 1024)) {
912    owl_function_makemsg("%s = '%s'", var, valbuff);
913  } else {
914    owl_function_makemsg("Unknown variable '%s'.", var);
915  }
916  return NULL;
917}
918
919
920char *owl_command_exec(int argc, char **argv, char *buff) {
921  return owl_function_exec(argc, argv, buff, 0);
922}
923
924char *owl_command_pexec(int argc, char **argv, char *buff) {
925  return owl_function_exec(argc, argv, buff, 1);
926}
927
928char *owl_command_aexec(int argc, char **argv, char *buff) {
929  return owl_function_exec(argc, argv, buff, 2);
930}
931
932char *owl_command_perl(int argc, char **argv, char *buff) {
933  return owl_function_perl(argc, argv, buff, 0);
934}
935
936char *owl_command_pperl(int argc, char **argv, char *buff) {
937  return owl_function_perl(argc, argv, buff, 1);
938}
939
940char *owl_command_aperl(int argc, char **argv, char *buff) {
941  return owl_function_perl(argc, argv, buff, 2);
942}
943
944char *owl_command_multi(int argc, char **argv, char *buff) {
945  char *lastrv = NULL, *newbuff;
946  char **commands;
947  int  ncommands, i;
948  if (argc < 2) {
949    owl_function_makemsg("Invalid arguments to 'multi' command.");   
950    return NULL;
951  }
952  newbuff = owl_strdup(buff);
953  newbuff = skiptokens(newbuff, 1);
954  if (!strcmp(argv[0], "(")) {
955    for (i=strlen(newbuff)-1; i>=0; i--) {
956      if (newbuff[i] == ')') {
957        newbuff[i] = '\0';
958        break;
959      } else if (newbuff[i] != ' ') {
960        owl_function_makemsg("Invalid arguments to 'multi' command.");   
961        owl_free(newbuff);
962        return NULL;
963      }
964    }
965  }
966  commands = atokenize(newbuff, ";", &ncommands);
967  for (i=0; i<ncommands; i++) {
968    if (lastrv) {
969      owl_free(lastrv);
970    }
971    lastrv = owl_function_command(commands[i]);
972  }
973  atokenize_free(commands, ncommands);
974  return lastrv;
975}
976
977
978char *owl_command_alias(int argc, char **argv, char *buff) {
979  if (argc < 3) {
980    owl_function_makemsg("Invalid arguments to 'alias' command.");
981    return NULL;
982  }
983  buff = skiptokens(buff, 2);
984  owl_function_command_alias(argv[1], buff);
985  return (NULL);
986}
987
988
989char *owl_command_bindkey(int argc, char **argv, char *buff) {
990  owl_keymap *km;
991  int ret;
992
993  if (argc < 5 || strcmp(argv[3], "command")) {
994    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>", argv[3], argc);
995    return NULL;
996  }
997  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
998  if (!km) {
999    owl_function_makemsg("No such keymap '%s'", argv[1]);
1000    return NULL;
1001  }
1002  buff = skiptokens(buff, 4);
1003  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1004  if (ret!=0) {
1005    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1006                         argv[2], argv[1], buff);
1007    return NULL;
1008  }
1009  return NULL;
1010}
1011
1012void owl_command_quit() {
1013  owl_function_quit();
1014}
1015
1016char *owl_command_debug(int argc, char **argv, char *buff) {
1017  if (argc<2) {
1018    owl_function_makemsg("Need at least one argument to debug command");
1019    return NULL;
1020  }
1021
1022  if (!owl_global_is_debug_fast(&g)) {
1023    owl_function_makemsg("Debugging is not turned on");
1024    return NULL;
1025  }
1026
1027  owl_function_debugmsg(argv[1]);
1028  return NULL;
1029}
1030
1031char *owl_command_ktest(int argc, char **argv, char *buff) {
1032  owl_function_popless_text("foobar");
1033  return NULL;
1034}
1035
1036char *owl_command_zlog(int argc, char **argv, char *buff) {
1037  if (argc != 2) {
1038    owl_function_makemsg("Wrong number of arguments for zlog command");
1039    return NULL;
1040  }
1041
1042  if (!strcmp(argv[1], "in")) {
1043    owl_function_zlog_in();
1044  } else if (!strcmp(argv[1], "out")) {
1045    owl_function_zlog_out();
1046  } else {
1047    owl_function_makemsg("Invalid subcommand for zlog");
1048  }
1049  return NULL;
1050}
1051
1052
1053void owl_command_zlog_out() {
1054  owl_function_zlog_out();
1055}
1056
1057
1058char *owl_command_subscribe(int argc, char **argv, char *buff) {
1059  char *recip="";
1060
1061  if (argc<3) {
1062    owl_function_makemsg("Not enough arguments to the subscribe command");
1063    return NULL;
1064  } else if (argc>4) {
1065    owl_function_makemsg("Too many arguments to the subscribe command");
1066    return NULL;
1067  }
1068
1069  if (argc==3) {
1070    recip="";
1071  } else if (argc==4) {
1072    recip=argv[3];
1073  }
1074
1075  owl_function_subscribe(argv[1], argv[2], recip);
1076  return NULL;
1077}
1078
1079
1080char *owl_command_unsubscribe(int argc, char **argv, char *buff) {
1081  char *recip="";
1082
1083  if (argc<3) {
1084    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1085    return NULL;
1086  } else if (argc>4) {
1087    owl_function_makemsg("Too many arguments to the unsubscribe command");
1088    return NULL;
1089  }
1090
1091  if (argc==3) {
1092    recip="";
1093  } else if (argc==4) {
1094    recip=argv[3];
1095  }
1096
1097  owl_function_unsubscribe(argv[1], argv[2], recip);
1098  return NULL;
1099}
1100
1101char *owl_command_echo(int argc, char **argv, char *buff) {
1102  buff = skiptokens(buff, 1);
1103  owl_function_popless_text(buff);
1104  return NULL;
1105}
1106
1107void owl_command_getsubs() {
1108  owl_function_getsubs();
1109}
1110
1111void owl_command_status() {
1112  owl_function_status();
1113}
1114
1115char *owl_command_zwrite(int argc, char **argv, char *buff) {
[1c6c4d3]1116  char *tmpbuff, *pos, *cmd, *msg;
1117
1118  /* check for a zwrite -m */
1119  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
1120    if (!strncmp(pos, "-m ", 3)) {
1121      cmd = owl_strdup(buff);
1122      msg = cmd+(pos-buff);
1123      *msg = '\0';
1124      msg += 3;
1125      owl_zwrite_create_and_send_from_line(cmd, msg);
1126      owl_free(cmd);
1127      return NULL;
1128    }
1129  }
1130
[7d4fbcd]1131  if (argc < 2) {
1132    owl_function_makemsg("Not enough arguments to the zwrite command.");
1133  } else {
1134    tmpbuff = owl_strdup(buff);
1135    owl_function_zwrite_setup(tmpbuff);
1136    owl_global_set_buffercommand(&g, tmpbuff);
1137    owl_free(tmpbuff);
1138  }
1139  return NULL;
1140}
1141
1142char *owl_command_reply(int argc, char **argv, char *buff) {
1143  int edit=0;
1144 
1145  if (argc==2 && !strcmp("-e", argv[1])) {
1146    edit=1;
1147    argv++;
1148  }
1149
1150  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1151    owl_function_reply(0, !edit);
[e75011e]1152  } else if (argc==2 && !strcmp(argv[1], "sender")) {
[7d4fbcd]1153    owl_function_reply(1, !edit);
[e75011e]1154  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
1155    owl_message *m;
1156    owl_view    *v;
1157    v = owl_global_get_current_view(&g);   
1158    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
1159    if (m) owl_zephyr_zaway(m);
[7d4fbcd]1160  } else {
1161    owl_function_makemsg("Invalid arguments to the reply command.");
1162  }
1163  return NULL;
1164}
1165
1166char *owl_command_filter(int argc, char **argv, char *buff) {
1167  owl_function_create_filter(argc, argv);
1168  return NULL;
1169}
1170
1171char *owl_command_zlocate(int argc, char **argv, char *buff) {
1172  if (argc==2) {
1173    owl_function_zlocate(argv[1], 1);
1174  } else if (argc==3) {
1175    if (!strcmp(argv[1], "-d")) {
1176      owl_function_zlocate(argv[2], 0);
1177    } else {
1178      owl_function_makemsg("Invalid option to the zlocate command");
1179      return NULL;
1180    }
1181  } else {
1182    owl_function_makemsg("Wrong number of arguments for zlocate command");
1183    return NULL;
1184  }
1185  return NULL;
1186}
1187
1188char *owl_command_view(int argc, char **argv, char *buff) {
1189  if (argc<2) {
1190    owl_function_makemsg("Wrong number of arguments to view command");
1191    return NULL;
1192  }
1193
1194  if (argc == 2 && !strcmp(argv[1], "--home")) {
1195    owl_function_change_view(owl_global_get_view_home(&g));
1196    return NULL;
1197  }
1198
1199  /* is it a dynamic filter? */
1200  if (!strcmp(argv[1], "-d")) {
1201    char **myargv;
1202    int i;
1203
1204    myargv=owl_malloc((argc*sizeof(char *))+50);
1205    myargv[0]="";
1206    myargv[1]="owl-dynamic";
1207    for (i=2; i<argc; i++) {
1208      myargv[i]=argv[i];
1209    }
1210    owl_function_create_filter(argc, myargv);
1211    owl_function_change_view("owl-dynamic");
1212    owl_free(myargv);
1213    return NULL;
1214  }
1215
1216  /* otherwise it's a normal view command */
1217  if (argc>2) {
1218    owl_function_makemsg("Wrong number of arguments to view command");
1219    return NULL;
1220  }
1221  owl_function_change_view(argv[1]);
1222  return NULL;
1223}
1224
1225
1226char *owl_command_show(int argc, char **argv, char *buff) {
1227
1228  if (argc<2) {
1229    owl_function_help_for_command("show");
1230    return NULL;
1231  }
1232
1233  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1234    if (argc==2) {
1235      owl_function_show_filters();
1236    } else {
1237      owl_function_show_filter(argv[2]);
1238    }
1239  } else if (argc==2 
1240             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1241    owl_function_show_zpunts();
1242  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1243    if (argc==2) {
1244      owl_function_show_commands();
1245    } else {
1246      owl_function_show_command(argv[2]);
1247    }
1248  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1249    if (argc==2) {
1250      owl_function_show_variables();
1251    } else {
1252      owl_function_show_variable(argv[2]);
1253    }
1254  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1255    if (argc==2) {
1256      owl_function_show_keymaps();
1257    } else {
1258      owl_function_show_keymap(argv[2]);
1259    }
1260  } else if (!strcmp(argv[1], "colors")) {
1261    owl_function_show_colors();
1262  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1263    owl_function_getsubs();
1264  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1265    owl_function_show_term();
1266  } else if (!strcmp(argv[1], "version")) {
1267    owl_function_about();
1268  } else if (!strcmp(argv[1], "status")) {
1269    owl_function_status();
1270  } else {
1271    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1272    return NULL;
1273  }
1274  return NULL;
1275}
1276
1277char *owl_command_viewclass(int argc, char **argv, char *buff) {
[7360fab]1278  char *filtname;
[7d4fbcd]1279  if (argc!=2) {
1280    owl_function_makemsg("Wrong number of arguments to viewclass command");
1281    return NULL;
1282  }
[7360fab]1283  filtname = owl_function_fastclassinstfilt(argv[1], NULL);
1284  owl_function_change_view(filtname);
1285  owl_free(filtname);
[7d4fbcd]1286  return NULL;
1287}
1288
1289char *owl_command_viewuser(int argc, char **argv, char *buff) {
[7360fab]1290  char *filtname;
[7d4fbcd]1291  if (argc!=2) {
1292    owl_function_makemsg("Wrong number of arguments to viewuser command");
1293    return NULL;
1294  }
[7360fab]1295  filtname = owl_function_fastuserfilt(argv[1]);
1296  owl_function_change_view(filtname);
1297  owl_free(filtname);
[7d4fbcd]1298  return NULL;
1299}
1300
1301
1302void owl_command_pop_message(void) {
1303  owl_function_curmsg_to_popwin();
1304}
1305
1306void owl_command_openurl(void) {
1307  owl_function_openurl();
1308}
1309
1310char *owl_command_delete(int argc, char **argv, char *buff) {
[b950088]1311  int move_after = 1;
1312
[8ee73f8d]1313  if (argc>1 && !strcmp(argv[1], "--no-move")) {
[b950088]1314    move_after = 0;
1315    argc--; 
1316    argv++;
1317  }
1318
[7d4fbcd]1319  if (argc==1) {
[b950088]1320    owl_function_deletecur(move_after);
[7d4fbcd]1321    return NULL;
1322  }
1323
1324  if (argc==2 && !strcmp(argv[1], "view")) {
1325    owl_function_delete_curview_msgs(1);
1326    return NULL;
1327  }
1328
1329  if (argc==2 && !strcmp(argv[1], "trash")) {
1330    owl_function_delete_automsgs();
1331    return NULL;
1332  }
1333
[7360fab]1334  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
[7d4fbcd]1335    owl_function_delete_by_id(atoi(argv[2]), 1);
1336    return NULL;
1337  }
1338
1339  owl_function_makemsg("Unknown arguments to delete command");
1340  return NULL;
1341}
1342
1343char *owl_command_undelete(int argc, char **argv, char *buff) {
[b950088]1344  int move_after = 1;
1345
[8ee73f8d]1346  if (argc>1 && !strcmp(argv[1], "--no-move")) {
[b950088]1347    move_after = 0;
1348    argc--; 
1349    argv++;
1350  }
1351
[7d4fbcd]1352  if (argc==1) {
[b950088]1353    owl_function_undeletecur(move_after);
[7d4fbcd]1354    return NULL;
1355  }
1356
1357  if (argc==2 && !strcmp(argv[1], "view")) {
1358    owl_function_delete_curview_msgs(0);
1359    return NULL;
1360  }
1361
[7360fab]1362  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
[7d4fbcd]1363    owl_function_delete_by_id(atoi(argv[2]), 0);
1364    return NULL;
1365  }
1366
1367  owl_function_makemsg("Unknown arguments to delete command");
1368  return NULL;
1369}
1370
1371void owl_command_beep() {
1372  owl_function_beep();
1373}
1374
1375char *owl_command_colorview(int argc, char **argv, char *buff) {
1376  if (argc!=2) {
1377    owl_function_makemsg("Wrong number of arguments to colorview command");
1378    return NULL;
1379  }
1380  owl_function_color_current_filter(argv[1]);
1381  return NULL;
1382}
1383
1384char *owl_command_zpunt(int argc, char **argv, char *buff) {
1385  owl_command_zpunt_and_zunpunt(argc, argv, 0);
1386  return NULL;
1387}
1388
1389char *owl_command_zunpunt(int argc, char **argv, char *buff) {
1390  owl_command_zpunt_and_zunpunt(argc, argv, 1);
1391  return NULL;
1392}
1393
1394
1395void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type) {
1396  /* if type==0 then zpunt
1397   * if type==1 then zunpunt
1398   */
1399  char *class, *inst, *recip;
1400
1401  class="message";
1402  inst="";
1403  recip="*";
1404
1405  if (argc==1) {
1406    /* show current punt filters */
1407    owl_function_show_zpunts();
1408    return;
1409  } else if (argc==2) {
1410    inst=argv[1];
1411  } else if (argc==3) {
1412    class=argv[1];
1413    inst=argv[2];
1414  } else if (argc==4) {
1415    class=argv[1];
1416    inst=argv[2];
1417    recip=argv[3];
1418  } else {
1419    owl_function_makemsg("Wrong number of arguments to the zpunt command");
1420    return;
1421  }
1422
1423  owl_function_zpunt(class, inst, recip, type);
1424  if (type==0) {
1425    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
1426  } else if (type==1) {
1427    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
1428  }
1429}
1430
[d36f2cb]1431char *owl_command_smartzpunt(int argc, char **argv, char *buff) {
1432  if (argc == 1) {
1433    owl_function_smartzpunt(0);
1434  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1435    owl_function_smartzpunt(1);
1436  } else {
1437    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1438  }
1439  return NULL;
1440}
1441
[8ee73f8d]1442char *owl_command_getview(int argc, char **argv, char *buff) {
1443  char *filtname;
1444  if (argc != 1) {
1445    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1446    return NULL;
1447  }
1448  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
1449  if (filtname) filtname = owl_strdup(filtname);
1450  return filtname;
1451}
[d36f2cb]1452
[8ee73f8d]1453char *owl_command_getvar(int argc, char **argv, char *buff) {
1454  char tmpbuff[1024];
1455  if (argc != 2) {
1456    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1457    return NULL;
1458  }
1459  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
1460                                argv[1], tmpbuff, 1024)) {
1461    return NULL;
1462  }
1463  return owl_strdup(tmpbuff); 
1464}
[7d4fbcd]1465
1466/*********************************************************************/
1467/************************** EDIT SPECIFIC ****************************/
1468/*********************************************************************/
1469
1470void owl_command_edit_cancel(owl_editwin *e) {
1471  owl_function_makemsg("Command cancelled.");
1472  owl_editwin_fullclear(e);
1473  owl_global_set_needrefresh(&g);
1474  wnoutrefresh(owl_editwin_get_curswin(e));
1475  owl_global_set_typwin_inactive(&g);
1476  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE);
1477}
1478
1479void owl_command_edit_history_prev(owl_editwin *e) {
1480  owl_history *hist;
1481  char *ptr;
1482
1483  hist=owl_global_get_history(&g);
1484  if (!owl_history_is_touched(hist)) {
1485    owl_history_store(hist, owl_editwin_get_text(e));
1486    owl_history_set_partial(hist);
1487  }
1488  ptr=owl_history_get_prev(hist);
1489  if (ptr) {
1490    owl_editwin_clear(e);
1491    owl_editwin_insert_string(e, ptr);
1492    owl_editwin_redisplay(e, 0);
1493    owl_global_set_needrefresh(&g);
1494  } else {
1495    owl_function_beep();
1496  }
1497}
1498
1499void owl_command_edit_history_next(owl_editwin *e) {
1500  owl_history *hist;
1501  char *ptr;
1502
1503  hist=owl_global_get_history(&g);
1504  ptr=owl_history_get_next(hist);
1505  if (ptr) {
1506    owl_editwin_clear(e);
1507    owl_editwin_insert_string(e, ptr);
1508    owl_editwin_redisplay(e, 0);
1509    owl_global_set_needrefresh(&g);
1510  } else {
1511    owl_function_beep();
1512  }
1513}
1514
1515char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff) {
1516  buff = skiptokens(buff, 1);
1517  owl_editwin_insert_string(e, buff);
1518  owl_editwin_redisplay(e, 0);
1519  owl_global_set_needrefresh(&g); 
1520  return NULL;
1521}
1522
1523void owl_command_editline_done(owl_editwin *e) {
1524  owl_history *hist=owl_global_get_history(&g);
1525  char *rv;
1526
1527  owl_global_set_typwin_inactive(&g);
1528  owl_history_store(hist, owl_editwin_get_text(e));
1529  owl_history_reset(hist);
1530  rv = owl_function_command(owl_editwin_get_text(e));
1531 
1532  /* if we're still in ONELINE mode we can clear the buffer */
1533  if (owl_editwin_get_style(e)==OWL_EDITWIN_STYLE_ONELINE) {
1534    owl_editwin_fullclear(e);
1535  }
1536 
1537  wnoutrefresh(owl_editwin_get_curswin(e));
1538  owl_global_set_needrefresh(&g);
1539
1540  if (rv) {
1541    owl_function_makemsg("%s", rv);
1542    owl_free(rv);
1543  }
1544}
1545
1546void owl_command_editmulti_done(owl_editwin *e) {
1547  owl_function_run_buffercommand();
1548  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE);
1549  owl_editwin_fullclear(e);
1550  owl_global_set_typwin_inactive(&g);
1551  owl_global_set_needrefresh(&g);
1552  wnoutrefresh(owl_editwin_get_curswin(e));
1553}
1554
1555
1556/*********************************************************************/
1557/*********************** POPLESS SPECIFIC ****************************/
1558/*********************************************************************/
1559
1560void owl_command_popless_quit(owl_viewwin *vw) {
1561  owl_popwin_close(owl_global_get_popwin(&g));
1562  owl_viewwin_free(vw);
1563  owl_global_set_needrefresh(&g);
1564}
1565
Note: See TracBrowser for help on using the repository browser.