source: commands.c @ 7933748

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 7933748 was 7933748, checked in by James M. Kretchmar <kretch@mit.edu>, 18 years ago
Added a 'loadloginsubs' command to load login subscriptions from a file Added a 'loadsubs' command to eventually phase out the 'load-subs' command
  • Property mode set to 100644
File size: 55.4 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_ARGS("loadsubs", owl_command_loadsubs, OWL_CTX_ANY,
369              "load subscriptions from a file",
370              "loadsubs <file>\n", ""),
371
372  OWLCMD_ARGS("loadloginsubs", owl_command_loadloginsubs, OWL_CTX_ANY,
373              "load login subscriptions from a file",
374              "loadloginsubs <file>\n",
375              "The file should contain a list of usernames, one per line."),
376
377  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
378              "print information about owl", "", ""),
379
380  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
381              "print status information about the running owl", "", ""),
382 
383  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
384              "locate a user",
385              "zlocate [-d] <user> ...", 
386              "Performs a zlocate on one ore more users and puts the result\n"
387              "int a popwin.  If -d is specified, does not authenticate\n"
388              "the lookup request.\n"),
389 
390  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
391              "create a message filter",
392              "filter <name> [ -c color ] [ <expression> ... ]",
393              "The filter command creates a filter with the specified name,\n"
394              "or if one already exists it is replaced.  Example filter\n"
395              "syntax would be:\n\n"
396              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
397              "Valid matching fields are class, instance, recipient, sender,\n"
398              "opcode and realm. Valid operations are 'and', 'or' and 'not'.\n"
399              "Spaces must be present before and after parenthesis.  If the\n"
400              "optional color argument is used it specifies the color that\n"
401              "messages matching this filter should be displayed in.\n\n"
402
403              "SEE ALSO: view, viewclass, viewuser\n"),
404
405  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
406              "change the color on the current filter",
407              "colorview <color>",
408              "The color of messages in the current filter will be changed\n"
409              "to <color>.  Use the 'show colors' command for a list\n"
410              "of valid colors.\n\n"
411              "SEE ALSO: 'show colors'\n"),
412
413  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
414              "view messages matching a filter",
415              "view <filter>\n"
416              "view -d <expression>\n"
417              "view --home",
418              "In the first usage, The view command sets the current view to\n"
419              "the specified filter.   This causes only messages matching\n"
420              "that filter to be displayed.\n"
421              "\n"
422              "In the second usage a filter expression\n"
423              "and be specified directly\n"
424              "after -d.  Owl will build an internal filter based on this\n"
425              "filter and change the current view to use it.\n\n"
426              "If --home is specified, switches to the view specified by\n"
427              "the 'view_home' variable.\n\n"
428              "SEE ALSO: filter, viewclass, viewuser\n"),
429
430  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
431              "view only messages similar to the current message",
432              "smartnarrow [-i | --instance]",
433              "If the curmsg is a personal message narrow\n"
434              "   to the converstaion with that user.\n"
435              "If the curmsg is a class message, instance foo, recip *\n"
436              "   message, narrow to the class, inst.\n"
437              "If the curmsg is a class message then narrow\n"
438              "    to the class.\n"
439              "If the curmsg is a class message and '-i' is specied\n"
440              "    then narrow to the class, instance\n"),
441
442  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
443              "returns the name of a filter based on the current message",
444              "smartfilter [-i | --instance]",
445              "If the curmsg is a personal message, the filter is\n"
446              "   the converstaion with that user.\n"
447              "If the curmsg is a class message, instance foo, recip *\n"
448              "   message, the filter is the class, inst.\n"
449              "If the curmsg is a class message, the filter is that class.\n"
450              "If the curmsg is a class message and '-i' is specied\n"
451              "    the filter is that <class,instance> pair\n"),
452
453  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
454              "view messages matching a particular class",
455              "viewclass <class>",
456              "The viewclass command will automatically create a filter\n"
457              "matching the specified class and switch the current view\n"
458              "to it.\n\n"
459              "SEE ALSO: filter, view, viewuser\n"),
460  OWLCMD_ALIAS("vc", "viewclass"),
461
462  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
463              "view messages matching a particular user",
464              "viewuser <user>",
465              "The viewuser command will automatically create a filter\n"
466              "matching the specified user and switch the current\n"
467              "view to it.\n\n"
468              "SEE ALSO: filter, view, viewclass\n"),
469  OWLCMD_ALIAS("vu", "viewuser"),
470
471  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
472              "show information",
473              "show variables\n"
474              "show variable <variable>\n"
475              "show filters\n"
476              "show filter <filter>\n"
477              "show keymaps\n"
478              "show keymap <keymap>\n"
479              "show commands\n"
480              "show command <command>\n"
481              "show subs\n"
482              "show subscriptions\n"
483              "show zpunts\n"
484              "show colors\n"
485              "show terminal\n"
486              "show version\n"
487              "show status\n",
488
489              "Show colors will display a list of valid colors for the\n"
490              "     terminal."
491              "Show filters will list the names of all filters.\n"
492              "Show filter <filter> will show the definition of a particular\n"
493              "     filter.\n\n"
494              "Show zpunts will show the active zpunt filters.\n\n"
495              "Show keymaps will list the names of all keymaps.\n"
496              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
497              "Show commands will list the names of all keymaps.\n"
498              "Show command <command> will provide information about a command.\n\n"
499              "Show variables will list the names of all variables.\n\n"
500              "SEE ALSO: filter, view, alias, bindkey, help\n"),
501 
502  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
503              "mark a message for deletion",
504              "delete [ -id msgid ] [ --no-move ]\n"
505              "delete view\n"
506              "delete trash",
507              "If no message id is specified the current message is marked\n"
508              "for deletion.  Otherwise the message with the given message\n"
509              "id is marked for deltion.\n"
510              "If '--no-move' is specified, don't move after deletion.\n"
511              "If 'trash' is specified, deletes all trash/auto messages\n"
512              "in the current view.\n"
513              "If 'view' is specified, deletes all messages in the\n"
514              "current view.\n"),
515  OWLCMD_ALIAS("del", "delete"),
516
517  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
518              "unmark a message for deletion",
519              "undelete [ -id msgid ] [ --no-move ]\n"
520              "undelete view",
521              "If no message id is specified the current message is\n"
522              "unmarked for deletion.  Otherwise the message with the\n"
523              "given message id is marked for undeltion.\n"
524              "If '--no-move' is specified, don't move after deletion.\n"
525              "If 'view' is specified, undeletes all messages\n"
526              "in the current view.\n"),
527  OWLCMD_ALIAS("undel", "undelete"),
528
529  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
530              "ring the terminal bell",
531              "beep",
532              "Beep will ring the terminal bell.\n"
533              "If the variable 'bell' has been\n"
534              "set to 'off' this command does nothing.\n"),
535
536  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
537              "prints a message into the debug log",
538              "debug <message>", ""),
539
540  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
541              "returns the name of the filter for the current view",
542              "", ""),
543
544  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
545              "returns the value of a variable",
546              "getvar <varname>", ""),
547
548  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
549              "search messages for a particular string",
550              "search [-r] [<string>]",
551              "The search command will find messages that contain the\n"
552              "specified string and move the cursor there.  If no string\n"
553              "argument is supplied then the previous one is used.  By\n"
554              "default searches are done fowards, if -r is used the search\n"
555              "is performed backwards"),
556
557  /****************************************************************/
558  /************************* EDIT-SPECIFIC ************************/
559  /****************************************************************/
560
561  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
562                  OWL_CTX_EDIT,
563                  "moves cursor forward a word",
564                  "", ""),
565
566  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
567                  OWL_CTX_EDIT,
568                  "moves cursor backwards a word",
569                  "", ""),
570
571  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
572                  OWL_CTX_EDIT,
573                  "moves cursor to the top left (start) of the buffer",
574                  "", ""),
575
576  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
577                  OWL_CTX_EDIT,
578                  "moves cursor to the bottom right (end) of the buffer",
579                  "", ""),
580
581  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
582                  OWL_CTX_EDIT,
583                  "moves cursor to the end of the line",
584                  "", ""),
585
586  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
587                  OWL_CTX_EDIT,
588                  "moves cursor to the beginning of the line",
589                  "", ""),
590
591  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
592                  OWL_CTX_EDIT,
593                  "moves the cursor left by a character",
594                  "", ""),
595
596  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
597                  OWL_CTX_EDIT,
598                  "moves the cursor right by a character",
599                  "", ""),
600
601  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
602                  OWL_CTX_EDIT,
603                  "deletes the word to the right of the cursor",
604                  "", ""),
605
606  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
607                  OWL_CTX_EDIT,
608                  "deletes the word to the left of the cursor",
609                  "", ""),
610
611  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
612                  OWL_CTX_EDIT,
613                  "deletes the character to the left of the cursor",
614                  "", ""),
615
616  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
617                  OWL_CTX_EDIT,
618                  "deletes the character to the right of the cursor",
619                  "", ""),
620
621  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
622                  OWL_CTX_EDIT,
623                  "deletes from the cursor to the end of the line",
624                  "", ""),
625
626  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
627                  OWL_CTX_EDIT,
628                  "deletes all of the contents of the buffer",
629                  "", ""),
630
631  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
632                  OWL_CTX_EDIT,
633                  "Interchange characters around point, moving forward one character.",
634                  "", ""),
635
636  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
637                  OWL_CTX_EDIT,
638                  "fills the current paragraph to line-wrap well",
639                  "", ""),
640
641  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
642                  OWL_CTX_EDIT,
643                  "recenters the buffer",
644                  "", ""),
645
646  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
647                  OWL_CTX_EDIT,
648                  "inserts text into the buffer",
649                  "edit:insert-text <text>", ""),
650
651  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
652                  OWL_CTX_EDIT,
653                  "cancels the current command",
654                  "", ""),
655
656  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
657                  OWL_CTX_EDIT,
658                  "replaces the text with the previous history",
659                  "", ""),
660
661  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
662                  OWL_CTX_EDIT,
663                  "replaces the text with the previous history",
664                  "", ""),
665
666  OWLCMD_VOID_CTX("editline:done", owl_command_editline_done, 
667                  OWL_CTX_EDITLINE,
668                  "completes the command (eg, executes command being composed)",
669                  "", ""),
670
671  OWLCMD_VOID_CTX("editmulti:move-up-line", owl_editwin_key_up, 
672                  OWL_CTX_EDITMULTI,
673                  "moves the cursor up one line",
674                  "", ""),
675
676  OWLCMD_VOID_CTX("editmulti:move-down-line", owl_editwin_key_down, 
677                  OWL_CTX_EDITMULTI,
678                  "moves the cursor down one line",
679                  "", ""),
680
681  OWLCMD_VOID_CTX("editmulti:done", owl_command_editmulti_done, 
682                  OWL_CTX_EDITMULTI,
683                  "completes the command (eg, sends message being composed)",
684                  "", ""),
685
686  OWLCMD_VOID_CTX("editmulti:done-or-delete", owl_command_editmulti_done_or_delete, 
687                  OWL_CTX_EDITMULTI,
688                  "completes the command, but only if at end of message",
689                  "", 
690                  "If only whitespace is to the right of the cursor,\n"
691                  "runs 'editmulti:done'.\n"\
692                  "Otherwise runs 'edit:delete-next-char'\n"),
693
694  /****************************************************************/
695  /********************** POPLESS-SPECIFIC ************************/
696  /****************************************************************/
697
698  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
699                  OWL_CTX_POPLESS,
700                  "scrolls down one page",
701                  "", ""),
702
703  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
704                  OWL_CTX_POPLESS,
705                  "scrolls down one line",
706                  "", ""),
707
708  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
709                  OWL_CTX_POPLESS,
710                  "scrolls up one page",
711                  "", ""),
712
713  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
714                  OWL_CTX_POPLESS,
715                  "scrolls up one line",
716                  "", ""),
717
718  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
719                  OWL_CTX_POPLESS,
720                  "scrolls to the top of the buffer",
721                  "", ""),
722
723  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
724                  OWL_CTX_POPLESS,
725                  "scrolls to the bottom of the buffer",
726                  "", ""),
727
728  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
729                  OWL_CTX_POPLESS,
730                  "scrolls right in the buffer",
731                  "popless:scroll-right <num-chars>", ""),
732
733  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
734                  OWL_CTX_POPLESS,
735                  "scrolls left in the buffer",
736                  "popless:scroll-left <num-chars>", ""),
737
738  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
739                  OWL_CTX_POPLESS,
740                  "exits the popless window",
741                  "", ""),
742
743  /* This line MUST be last! */
744  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
745
746};
747
748void owl_command_info() {
749  owl_function_info();
750}
751
752char *owl_command_help(int argc, char **argv, char *buff) {
753  if (argc!=2) {
754    owl_help();
755    return NULL;
756  }
757 
758  owl_function_help_for_command(argv[1]);
759  return NULL;
760}
761
762char *owl_command_zlist(int argc, char **argv, char *buff) {
763  int elapsed=0, timesort=0;
764  char *file=NULL;
765
766  argc--;
767  argv++;
768  while (argc) {
769    if (!strcmp(argv[0], "-e")) {
770      elapsed=1;
771      argc--;
772      argv++;
773    } else if (!strcmp(argv[0], "-t")) {
774      timesort=1;
775      argc--;
776      argv++;
777    } else if (!strcmp(argv[0], "-f")) {
778      if (argc==1) {
779        owl_function_makemsg("zlist: -f needs an argument");
780        return(NULL);
781      }
782      file=argv[1];
783      argc-=2;
784      argv+=2;
785    } else {
786      owl_function_makemsg("zlist: unknown argument");
787      return(NULL);
788    }
789  }
790  owl_function_zlist(file, elapsed, timesort);
791  return(NULL);
792}
793
794void owl_command_about() {
795  owl_function_about();
796}
797
798void owl_command_version() {
799  char buff[1024];
800
801  sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
802  owl_function_makemsg(buff);
803}
804
805char *owl_command_dump(int argc, char **argv, char *buff) {
806  if (argc!=2) {
807    owl_function_makemsg("usage: dump <filename>");
808    return(NULL);
809  }
810
811  owl_function_dump(argv[1]);
812  return(NULL);
813}
814
815char *owl_command_next(int argc, char **argv, char *buff) {
816  char *filter=NULL;
817  int skip_deleted=0, last_if_none=0;
818  while (argc>1) {
819    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
820      skip_deleted=1;
821      argc-=1; argv+=1; 
822    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
823      last_if_none=1;
824      argc-=1; argv+=1; 
825    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
826      filter = owl_strdup(argv[2]);
827      argc-=2; argv+=2; 
828    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
829      filter = owl_function_smartfilter(0);
830      argc-=2; argv+=2; 
831    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
832      filter = owl_function_smartfilter(1);
833      argc-=2; argv+=2; 
834    } else {
835      owl_function_makemsg("Invalid arguments to command 'next'.");
836      return(NULL);
837    }
838  }
839  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
840  if (filter) owl_free(filter);
841  return(NULL);
842}
843
844char *owl_command_prev(int argc, char **argv, char *buff) {
845  char *filter=NULL;
846  int skip_deleted=0, first_if_none=0;
847  while (argc>1) {
848    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
849      skip_deleted=1;
850      argc-=1; argv+=1; 
851    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
852      first_if_none=1;
853      argc-=1; argv+=1; 
854    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
855      filter = owl_strdup(argv[2]);
856      argc-=2; argv+=2; 
857    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
858      filter = owl_function_smartfilter(0);
859      argc-=2; argv+=2; 
860    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
861      filter = owl_function_smartfilter(1);
862      argc-=2; argv+=2; 
863   } else {
864      owl_function_makemsg("Invalid arguments to command 'prev'.");
865      return(NULL);
866    }
867  }
868  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
869  if (filter) owl_free(filter);
870  return(NULL);
871}
872
873char *owl_command_smartnarrow(int argc, char **argv, char *buff) {
874  char *filtname = NULL;
875
876  if (argc == 1) {
877    filtname = owl_function_smartfilter(0);
878  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
879    filtname = owl_function_smartfilter(1);
880  } else {
881    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
882  }
883  if (filtname) {
884    owl_function_change_view(filtname);
885    owl_free(filtname);
886  }
887  return NULL;
888}
889
890char *owl_command_smartfilter(int argc, char **argv, char *buff) {
891  char *filtname = NULL;
892
893  if (argc == 1) {
894    filtname = owl_function_smartfilter(0);
895  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
896    filtname = owl_function_smartfilter(1);
897  } else {
898    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
899  }
900  return filtname;
901}
902
903void owl_command_expunge() {
904  owl_function_expunge();
905}
906
907void owl_command_first() {
908  owl_global_set_rightshift(&g, 0);
909  owl_function_firstmsg();
910}
911
912void owl_command_last() {
913  owl_function_lastmsg();
914}
915
916void owl_command_resize() {
917  owl_function_resize();
918}
919
920void owl_command_redisplay() {
921  owl_function_full_redisplay();
922  owl_global_set_needrefresh(&g);
923}
924
925void owl_command_shift_right() {
926  owl_function_shift_right();
927}
928
929void owl_command_shift_left() {
930  owl_function_shift_left();
931}
932
933void owl_command_unsuball() {
934  owl_function_unsuball();
935}
936
937char *owl_command_loadsubs(int argc, char **argv, char *buff) {
938  if (argc == 2) {
939    owl_function_loadsubs(argv[1]);
940  } else if (argc == 1) {
941    owl_function_loadsubs(NULL);
942  } else {
943    owl_function_makemsg("Wrong number of arguments for load-subs.");
944    return(NULL);
945  }
946  return(NULL);
947}
948
949
950char *owl_command_loadloginsubs(int argc, char **argv, char *buff) {
951  if (argc == 2) {
952    owl_function_loadloginsubs(argv[1]);
953  } else if (argc == 1) {
954    owl_function_loadloginsubs(NULL);
955  } else {
956    owl_function_makemsg("Wrong number of arguments for load-subs.");
957    return(NULL);
958  }
959  return(NULL);
960}
961
962void owl_command_suspend() {
963  owl_function_suspend();
964}
965
966char *owl_command_start_command(int argc, char **argv, char *buff) {
967  buff = skiptokens(buff, 1);
968  owl_function_start_command(buff);
969  return NULL;
970}
971
972char *owl_command_zaway(int argc, char **argv, char *buff) {
973 
974  if ((argc==1) ||
975      ((argc==2) && !strcmp(argv[1], "on"))) {
976    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
977    owl_function_zaway_on();
978    return NULL;
979  }
980
981  if (argc==2 && !strcmp(argv[1], "off")) {
982    owl_function_zaway_off();
983    return NULL;
984  }
985
986  if (argc==2 && !strcmp(argv[1], "toggle")) {
987    owl_function_zaway_toggle();
988    return NULL;
989  }
990
991  buff = skiptokens(buff, 1);
992  owl_global_set_zaway_msg(&g, buff);
993  owl_function_zaway_on();
994  return NULL;
995}
996
997
998char *owl_command_set(int argc, char **argv, char *buff) {
999  char *var, *val;
1000  int  silent=0;
1001  int requirebool=0;
1002
1003  if (argc == 1) {
1004    owl_function_printallvars();
1005    return NULL;
1006  } 
1007
1008  if (argc > 1 && !strcmp("-q",argv[1])) {
1009    silent = 1;
1010    argc--; argv++;
1011  }
1012
1013  if (argc == 2) {
1014    var=argv[1];
1015    val="on";
1016    requirebool=1;
1017  } else if (argc == 3) {
1018    var=argv[1];
1019    val=argv[2];
1020  } else {
1021    owl_function_makemsg("Wrong number of arguments for set command");
1022    return NULL;
1023  }
1024  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1025  return NULL;
1026}
1027
1028char *owl_command_unset(int argc, char **argv, char *buff) {
1029  char *var, *val;
1030  int  silent=0;
1031
1032  if (argc > 1 && !strcmp("-q",argv[1])) {
1033    silent = 1;
1034    argc--; argv++;
1035  }
1036  if (argc == 2) {
1037    var=argv[1];
1038    val="off";
1039  } else {
1040    owl_function_makemsg("Wrong number of arguments for unset command");
1041    return NULL;
1042  }
1043  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1044  return NULL;
1045}
1046
1047char *owl_command_print(int argc, char **argv, char *buff) {
1048  char *var;
1049  char valbuff[1024];
1050
1051  if (argc==1) {
1052    owl_function_printallvars();
1053    return NULL;
1054  } else if (argc!=2) {
1055    owl_function_makemsg("Wrong number of arguments for print command");
1056    return NULL;
1057  }
1058
1059  var=argv[1];
1060   
1061  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1062                                     var, valbuff, 1024)) {
1063    owl_function_makemsg("%s = '%s'", var, valbuff);
1064  } else {
1065    owl_function_makemsg("Unknown variable '%s'.", var);
1066  }
1067  return NULL;
1068}
1069
1070
1071char *owl_command_exec(int argc, char **argv, char *buff) {
1072  return owl_function_exec(argc, argv, buff, 0);
1073}
1074
1075char *owl_command_pexec(int argc, char **argv, char *buff) {
1076  return owl_function_exec(argc, argv, buff, 1);
1077}
1078
1079char *owl_command_aexec(int argc, char **argv, char *buff) {
1080  return owl_function_exec(argc, argv, buff, 2);
1081}
1082
1083char *owl_command_perl(int argc, char **argv, char *buff) {
1084  return owl_function_perl(argc, argv, buff, 0);
1085}
1086
1087char *owl_command_pperl(int argc, char **argv, char *buff) {
1088  return owl_function_perl(argc, argv, buff, 1);
1089}
1090
1091char *owl_command_aperl(int argc, char **argv, char *buff) {
1092  return owl_function_perl(argc, argv, buff, 2);
1093}
1094
1095char *owl_command_multi(int argc, char **argv, char *buff) {
1096  char *lastrv = NULL, *newbuff;
1097  char **commands;
1098  int  ncommands, i;
1099  if (argc < 2) {
1100    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1101    return NULL;
1102  }
1103  newbuff = owl_strdup(buff);
1104  newbuff = skiptokens(newbuff, 1);
1105  if (!strcmp(argv[0], "(")) {
1106    for (i=strlen(newbuff)-1; i>=0; i--) {
1107      if (newbuff[i] == ')') {
1108        newbuff[i] = '\0';
1109        break;
1110      } else if (newbuff[i] != ' ') {
1111        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1112        owl_free(newbuff);
1113        return NULL;
1114      }
1115    }
1116  }
1117  commands = atokenize(newbuff, ";", &ncommands);
1118  for (i=0; i<ncommands; i++) {
1119    if (lastrv) {
1120      owl_free(lastrv);
1121    }
1122    lastrv = owl_function_command(commands[i]);
1123  }
1124  atokenize_free(commands, ncommands);
1125  return lastrv;
1126}
1127
1128
1129char *owl_command_alias(int argc, char **argv, char *buff) {
1130  if (argc < 3) {
1131    owl_function_makemsg("Invalid arguments to 'alias' command.");
1132    return NULL;
1133  }
1134  buff = skiptokens(buff, 2);
1135  owl_function_command_alias(argv[1], buff);
1136  return (NULL);
1137}
1138
1139
1140char *owl_command_bindkey(int argc, char **argv, char *buff) {
1141  owl_keymap *km;
1142  int ret;
1143
1144  if (argc < 5 || strcmp(argv[3], "command")) {
1145    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>", argv[3], argc);
1146    return NULL;
1147  }
1148  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1149  if (!km) {
1150    owl_function_makemsg("No such keymap '%s'", argv[1]);
1151    return NULL;
1152  }
1153  buff = skiptokens(buff, 4);
1154  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1155  if (ret!=0) {
1156    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1157                         argv[2], argv[1], buff);
1158    return NULL;
1159  }
1160  return NULL;
1161}
1162
1163void owl_command_quit() {
1164  owl_function_quit();
1165}
1166
1167char *owl_command_debug(int argc, char **argv, char *buff) {
1168  if (argc<2) {
1169    owl_function_makemsg("Need at least one argument to debug command");
1170    return NULL;
1171  }
1172
1173  if (!owl_global_is_debug_fast(&g)) {
1174    owl_function_makemsg("Debugging is not turned on");
1175    return NULL;
1176  }
1177
1178  owl_function_debugmsg(argv[1]);
1179  return NULL;
1180}
1181
1182char *owl_command_ktest(int argc, char **argv, char *buff) {
1183  owl_function_popless_text("foobar");
1184  return NULL;
1185}
1186
1187char *owl_command_zlog(int argc, char **argv, char *buff) {
1188  if ((argc<2) || (argc>3)) {
1189    owl_function_makemsg("Wrong number of arguments for zlog command");
1190    return(NULL);
1191  }
1192
1193  if (!strcmp(argv[1], "in")) {
1194    if (argc>2) {
1195      owl_global_set_tty(&g, argv[2]);
1196    }
1197    owl_function_zlog_in();
1198  } else if (!strcmp(argv[1], "out")) {
1199    if (argc!=2) {
1200      owl_function_makemsg("Wrong number of arguments for zlog command");
1201      return(NULL);
1202    }
1203    owl_function_zlog_out();
1204  } else {
1205    owl_function_makemsg("Invalid subcommand for zlog");
1206  }
1207  return(NULL);
1208}
1209
1210
1211void owl_command_zlog_out() {
1212  owl_function_zlog_out();
1213}
1214
1215
1216char *owl_command_subscribe(int argc, char **argv, char *buff) {
1217  char *recip="";
1218  int temp=0;
1219 
1220  if (argc<3) {
1221    owl_function_makemsg("Not enough arguments to the subscribe command");
1222    return(NULL);
1223  }
1224  argc--;
1225  argv++;
1226
1227  if (!strcmp(argv[0], "-t")) {
1228    temp=1;
1229    argc--;
1230    argv++;
1231  }
1232  if (argc<2) {
1233    owl_function_makemsg("Not enough arguments to the subscribe command");
1234    return(NULL);
1235  }
1236
1237  if (argc>3) {
1238    owl_function_makemsg("Too many arguments to the subscribe command");
1239    return(NULL);
1240  }
1241
1242  if (argc==2) {
1243    recip="";
1244  } else if (argc==3) {
1245    recip=argv[2];
1246  }
1247
1248  owl_function_subscribe(argv[0], argv[1], recip);
1249  if (!temp) {
1250    owl_zephyr_addsub(NULL, argv[0], argv[1], recip);
1251  }
1252  return(NULL);
1253}
1254
1255
1256char *owl_command_unsubscribe(int argc, char **argv, char *buff) {
1257  char *recip="";
1258  int temp=0;
1259
1260  if (argc<3) {
1261    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1262    return(NULL);
1263  }
1264  argc--;
1265  argv++;
1266
1267  if (!strcmp(argv[0], "-t")) {
1268    temp=1;
1269    argc--;
1270    argv++;
1271  }
1272  if (argc<2) {
1273    owl_function_makemsg("Not enough arguments to the subscribe command");
1274    return(NULL);
1275  }
1276
1277  if (argc>3) {
1278    owl_function_makemsg("Too many arguments to the unsubscribe command");
1279    return(NULL);
1280  }
1281
1282  if (argc==2) {
1283    recip="";
1284  } else if (argc==3) {
1285    recip=argv[2];
1286  }
1287
1288  owl_function_unsubscribe(argv[0], argv[1], recip);
1289  if (!temp) {
1290    owl_zephyr_delsub(NULL, argv[0], argv[1], recip);
1291  }
1292  return(NULL);
1293}
1294
1295char *owl_command_echo(int argc, char **argv, char *buff) {
1296  buff = skiptokens(buff, 1);
1297  owl_function_popless_text(buff);
1298  return NULL;
1299}
1300
1301void owl_command_getsubs() {
1302  owl_function_getsubs();
1303}
1304
1305void owl_command_status() {
1306  owl_function_status();
1307}
1308
1309char *owl_command_zwrite(int argc, char **argv, char *buff) {
1310  char *tmpbuff, *pos, *cmd, *msg;
1311
1312  /* check for a zwrite -m */
1313  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
1314    if (!strncmp(pos, "-m ", 3)) {
1315      cmd = owl_strdup(buff);
1316      msg = cmd+(pos-buff);
1317      *msg = '\0';
1318      msg += 3;
1319      owl_zwrite_create_and_send_from_line(cmd, msg);
1320      owl_free(cmd);
1321      return NULL;
1322    }
1323  }
1324
1325  if (argc < 2) {
1326    owl_function_makemsg("Not enough arguments to the zwrite command.");
1327  } else {
1328    tmpbuff = owl_strdup(buff);
1329    owl_function_zwrite_setup(tmpbuff);
1330    owl_global_set_buffercommand(&g, tmpbuff);
1331    owl_free(tmpbuff);
1332  }
1333  return NULL;
1334}
1335
1336char *owl_command_zcrypt(int argc, char **argv, char *buff) {
1337  char *tmpbuff, *pos, *cmd, *msg;
1338 
1339  /* check for a zwrite -m */
1340  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
1341    if (!strncmp(pos, "-m ", 3)) {
1342      cmd = owl_strdup(buff);
1343      msg = cmd+(pos-buff);
1344      *msg = '\0';
1345      msg += 3;
1346      owl_zwrite_create_and_send_from_line(cmd, msg);
1347      owl_free(cmd);
1348      return NULL;
1349    }
1350  }
1351
1352  if (argc < 2) {
1353    owl_function_makemsg("Not enough arguments to the zcrypt command.");
1354  } else {
1355    tmpbuff = owl_strdup(buff);
1356    owl_function_zwrite_setup(tmpbuff);
1357    owl_global_set_buffercommand(&g, tmpbuff);
1358    owl_free(tmpbuff);
1359  }
1360  return(NULL);
1361}
1362
1363char *owl_command_reply(int argc, char **argv, char *buff) {
1364  int edit=0;
1365 
1366  if (argc>=2 && !strcmp("-e", argv[1])) {
1367    edit=1;
1368    argv++;
1369    argc--;
1370  }
1371
1372  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1373    owl_function_reply(0, !edit);
1374  } else if (argc==2 && !strcmp(argv[1], "sender")) {
1375    owl_function_reply(1, !edit);
1376  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
1377    owl_message *m;
1378    owl_view    *v;
1379    v = owl_global_get_current_view(&g);   
1380    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
1381    if (m) owl_zephyr_zaway(m);
1382  } else {
1383    owl_function_makemsg("Invalid arguments to the reply command.");
1384  }
1385  return NULL;
1386}
1387
1388char *owl_command_filter(int argc, char **argv, char *buff) {
1389  owl_function_create_filter(argc, argv);
1390  return NULL;
1391}
1392
1393char *owl_command_zlocate(int argc, char **argv, char *buff) {
1394  int auth;
1395 
1396  if (argc<2) {
1397    owl_function_makemsg("Too few arguments for zlocate command");
1398    return NULL;
1399  }
1400
1401  auth=1;
1402  if (!strcmp(argv[1], "-d")) {
1403    if (argc>2) {
1404      auth=0;
1405      argc--;
1406      argv++;
1407    } else {
1408      owl_function_makemsg("Missing arguments for zlocate command");
1409      return NULL;
1410    }
1411  }
1412
1413  argc--;
1414  argv++;
1415  owl_function_zlocate(argc, argv, auth);
1416  return NULL;
1417}
1418
1419char *owl_command_view(int argc, char **argv, char *buff) {
1420  if (argc<2) {
1421    owl_function_makemsg("Wrong number of arguments to view command");
1422    return NULL;
1423  }
1424
1425  if (argc == 2 && !strcmp(argv[1], "--home")) {
1426    owl_function_change_view(owl_global_get_view_home(&g));
1427    return NULL;
1428  }
1429
1430  /* is it a dynamic filter? */
1431  if (!strcmp(argv[1], "-d")) {
1432    char **myargv;
1433    int i;
1434
1435    myargv=owl_malloc((argc*sizeof(char *))+50);
1436    myargv[0]="";
1437    myargv[1]="owl-dynamic";
1438    for (i=2; i<argc; i++) {
1439      myargv[i]=argv[i];
1440    }
1441    owl_function_create_filter(argc, myargv);
1442    owl_function_change_view("owl-dynamic");
1443    owl_free(myargv);
1444    return NULL;
1445  }
1446
1447  /* otherwise it's a normal view command */
1448  if (argc>2) {
1449    owl_function_makemsg("Wrong number of arguments to view command");
1450    return NULL;
1451  }
1452  owl_function_change_view(argv[1]);
1453  return NULL;
1454}
1455
1456
1457char *owl_command_show(int argc, char **argv, char *buff) {
1458
1459  if (argc<2) {
1460    owl_function_help_for_command("show");
1461    return NULL;
1462  }
1463
1464  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1465    if (argc==2) {
1466      owl_function_show_filters();
1467    } else {
1468      owl_function_show_filter(argv[2]);
1469    }
1470  } else if (argc==2 
1471             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1472    owl_function_show_zpunts();
1473  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1474    if (argc==2) {
1475      owl_function_show_commands();
1476    } else {
1477      owl_function_show_command(argv[2]);
1478    }
1479  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1480    if (argc==2) {
1481      owl_function_show_variables();
1482    } else {
1483      owl_function_show_variable(argv[2]);
1484    }
1485  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1486    if (argc==2) {
1487      owl_function_show_keymaps();
1488    } else {
1489      owl_function_show_keymap(argv[2]);
1490    }
1491  } else if (!strcmp(argv[1], "colors")) {
1492    owl_function_show_colors();
1493  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1494    owl_function_getsubs();
1495  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1496    owl_function_show_term();
1497  } else if (!strcmp(argv[1], "version")) {
1498    owl_function_about();
1499  } else if (!strcmp(argv[1], "status")) {
1500    owl_function_status();
1501  } else {
1502    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1503    return NULL;
1504  }
1505  return NULL;
1506}
1507
1508char *owl_command_viewclass(int argc, char **argv, char *buff) {
1509  char *filtname;
1510  if (argc!=2) {
1511    owl_function_makemsg("Wrong number of arguments to viewclass command");
1512    return NULL;
1513  }
1514  filtname = owl_function_fastclassinstfilt(argv[1], NULL);
1515  owl_function_change_view(filtname);
1516  owl_free(filtname);
1517  return NULL;
1518}
1519
1520char *owl_command_viewuser(int argc, char **argv, char *buff) {
1521  char *filtname;
1522  if (argc!=2) {
1523    owl_function_makemsg("Wrong number of arguments to viewuser command");
1524    return NULL;
1525  }
1526  filtname = owl_function_fastuserfilt(argv[1]);
1527  owl_function_change_view(filtname);
1528  owl_free(filtname);
1529  return NULL;
1530}
1531
1532
1533void owl_command_pop_message(void) {
1534  owl_function_curmsg_to_popwin();
1535}
1536
1537void owl_command_openurl(void) {
1538  owl_function_openurl();
1539}
1540
1541char *owl_command_delete(int argc, char **argv, char *buff) {
1542  int move_after = 1;
1543
1544  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1545    move_after = 0;
1546    argc--; 
1547    argv++;
1548  }
1549
1550  if (argc==1) {
1551    owl_function_deletecur(move_after);
1552    return NULL;
1553  }
1554
1555  if (argc==2 && !strcmp(argv[1], "view")) {
1556    owl_function_delete_curview_msgs(1);
1557    return NULL;
1558  }
1559
1560  if (argc==2 && !strcmp(argv[1], "trash")) {
1561    owl_function_delete_automsgs();
1562    return NULL;
1563  }
1564
1565  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1566    owl_function_delete_by_id(atoi(argv[2]), 1);
1567    return NULL;
1568  }
1569
1570  owl_function_makemsg("Unknown arguments to delete command");
1571  return NULL;
1572}
1573
1574char *owl_command_undelete(int argc, char **argv, char *buff) {
1575  int move_after = 1;
1576
1577  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1578    move_after = 0;
1579    argc--; 
1580    argv++;
1581  }
1582
1583  if (argc==1) {
1584    owl_function_undeletecur(move_after);
1585    return NULL;
1586  }
1587
1588  if (argc==2 && !strcmp(argv[1], "view")) {
1589    owl_function_delete_curview_msgs(0);
1590    return NULL;
1591  }
1592
1593  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1594    owl_function_delete_by_id(atoi(argv[2]), 0);
1595    return NULL;
1596  }
1597
1598  owl_function_makemsg("Unknown arguments to delete command");
1599  return NULL;
1600}
1601
1602void owl_command_beep() {
1603  owl_function_beep();
1604}
1605
1606char *owl_command_colorview(int argc, char **argv, char *buff) {
1607  if (argc!=2) {
1608    owl_function_makemsg("Wrong number of arguments to colorview command");
1609    return NULL;
1610  }
1611  owl_function_color_current_filter(argv[1]);
1612  return NULL;
1613}
1614
1615char *owl_command_zpunt(int argc, char **argv, char *buff) {
1616  owl_command_zpunt_and_zunpunt(argc, argv, 0);
1617  return NULL;
1618}
1619
1620char *owl_command_zunpunt(int argc, char **argv, char *buff) {
1621  owl_command_zpunt_and_zunpunt(argc, argv, 1);
1622  return NULL;
1623}
1624
1625
1626void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type) {
1627  /* if type==0 then zpunt
1628   * if type==1 then zunpunt
1629   */
1630  char *class, *inst, *recip;
1631
1632  class="message";
1633  inst="";
1634  recip="*";
1635
1636  if (argc==1) {
1637    /* show current punt filters */
1638    owl_function_show_zpunts();
1639    return;
1640  } else if (argc==2) {
1641    inst=argv[1];
1642  } else if (argc==3) {
1643    class=argv[1];
1644    inst=argv[2];
1645  } else if (argc==4) {
1646    class=argv[1];
1647    inst=argv[2];
1648    recip=argv[3];
1649  } else {
1650    owl_function_makemsg("Wrong number of arguments to the zpunt command");
1651    return;
1652  }
1653
1654  owl_function_zpunt(class, inst, recip, type);
1655  if (type==0) {
1656    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
1657  } else if (type==1) {
1658    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
1659  }
1660}
1661
1662char *owl_command_smartzpunt(int argc, char **argv, char *buff) {
1663  if (argc == 1) {
1664    owl_function_smartzpunt(0);
1665  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1666    owl_function_smartzpunt(1);
1667  } else {
1668    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1669  }
1670  return NULL;
1671}
1672
1673char *owl_command_getview(int argc, char **argv, char *buff) {
1674  char *filtname;
1675  if (argc != 1) {
1676    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1677    return NULL;
1678  }
1679  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
1680  if (filtname) filtname = owl_strdup(filtname);
1681  return filtname;
1682}
1683
1684char *owl_command_getvar(int argc, char **argv, char *buff) {
1685  char tmpbuff[1024];
1686  if (argc != 2) {
1687    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1688    return NULL;
1689  }
1690  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
1691                                argv[1], tmpbuff, 1024)) {
1692    return NULL;
1693  }
1694  return owl_strdup(tmpbuff); 
1695}
1696
1697char *owl_command_search(int argc, char **argv, char *buff) {
1698  int direction;
1699  char *buffstart;
1700
1701  direction=OWL_DIRECTION_DOWNWARDS;
1702  buffstart=skiptokens(buff, 1);
1703  if (argc>1 && !strcmp(argv[1], "-r")) {
1704    direction=OWL_DIRECTION_UPWARDS;
1705    buffstart=skiptokens(buff, 2);
1706  }
1707   
1708  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
1709    owl_function_search_continue(direction);
1710  } else {
1711    owl_function_search_start(buffstart, direction);
1712  }
1713 
1714  return(NULL);
1715}
1716
1717/*********************************************************************/
1718/************************** EDIT SPECIFIC ****************************/
1719/*********************************************************************/
1720
1721void owl_command_edit_cancel(owl_editwin *e) {
1722  owl_history *hist;
1723
1724  owl_function_makemsg("Command cancelled.");
1725
1726  hist=owl_editwin_get_history(e);
1727  owl_history_store(hist, owl_editwin_get_text(e));
1728  owl_history_reset(hist);
1729
1730  owl_editwin_fullclear(e);
1731  owl_global_set_needrefresh(&g);
1732  wnoutrefresh(owl_editwin_get_curswin(e));
1733  owl_global_set_typwin_inactive(&g);
1734  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1735}
1736
1737void owl_command_edit_history_prev(owl_editwin *e) {
1738  owl_history *hist;
1739  char *ptr;
1740
1741  hist=owl_editwin_get_history(e);
1742  if (!owl_history_is_touched(hist)) {
1743    owl_history_store(hist, owl_editwin_get_text(e));
1744    owl_history_set_partial(hist);
1745  }
1746  ptr=owl_history_get_prev(hist);
1747  if (ptr) {
1748    owl_editwin_clear(e);
1749    owl_editwin_insert_string(e, ptr);
1750    owl_editwin_redisplay(e, 0);
1751    owl_global_set_needrefresh(&g);
1752  } else {
1753    owl_function_beep();
1754  }
1755}
1756
1757void owl_command_edit_history_next(owl_editwin *e) {
1758  owl_history *hist;
1759  char *ptr;
1760
1761  hist=owl_editwin_get_history(e);
1762  ptr=owl_history_get_next(hist);
1763  if (ptr) {
1764    owl_editwin_clear(e);
1765    owl_editwin_insert_string(e, ptr);
1766    owl_editwin_redisplay(e, 0);
1767    owl_global_set_needrefresh(&g);
1768  } else {
1769    owl_function_beep();
1770  }
1771}
1772
1773char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff) {
1774  buff = skiptokens(buff, 1);
1775  owl_editwin_insert_string(e, buff);
1776  owl_editwin_redisplay(e, 0);
1777  owl_global_set_needrefresh(&g); 
1778  return NULL;
1779}
1780
1781void owl_command_editline_done(owl_editwin *e) {
1782  owl_history *hist=owl_editwin_get_history(e);
1783  char *rv, *cmd;
1784
1785  owl_history_store(hist, owl_editwin_get_text(e));
1786  owl_history_reset(hist);
1787  owl_global_set_typwin_inactive(&g);
1788  cmd = owl_strdup(owl_editwin_get_text(e));
1789  owl_editwin_fullclear(e);
1790  rv = owl_function_command(cmd);
1791  owl_free(cmd);
1792
1793  wnoutrefresh(owl_editwin_get_curswin(e));
1794  owl_global_set_needrefresh(&g);
1795
1796  if (rv) {
1797    owl_function_makemsg("%s", rv);
1798    owl_free(rv);
1799  }
1800}
1801
1802void owl_command_editmulti_done(owl_editwin *e) {
1803  owl_history *hist=owl_editwin_get_history(e);
1804
1805  owl_history_store(hist, owl_editwin_get_text(e));
1806  owl_history_reset(hist);
1807
1808  owl_function_run_buffercommand();
1809  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1810  owl_editwin_fullclear(e);
1811  owl_global_set_typwin_inactive(&g);
1812  owl_global_set_needrefresh(&g);
1813  wnoutrefresh(owl_editwin_get_curswin(e));
1814}
1815
1816void owl_command_editmulti_done_or_delete(owl_editwin *e) {
1817  if (owl_editwin_is_at_end(e)) {
1818    owl_command_editmulti_done(e);
1819  } else {
1820    owl_editwin_delete_char(e);
1821  }
1822}
1823
1824
1825/*********************************************************************/
1826/*********************** POPLESS SPECIFIC ****************************/
1827/*********************************************************************/
1828
1829void owl_command_popless_quit(owl_viewwin *vw) {
1830  owl_popwin_close(owl_global_get_popwin(&g));
1831  owl_viewwin_free(vw);
1832  owl_global_set_needrefresh(&g);
1833}
Note: See TracBrowser for help on using the repository browser.