source: commands.c @ 2adaf1d

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