source: commands.c @ 5c7b1b1

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