source: commands.c @ 2527615

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 2527615 was 2527615, checked in by James M. Kretchmar <kretch@mit.edu>, 18 years ago
The 'zlocate' command can now handle multiple users
  • 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 one ore more users and puts the result\n"
370              "int 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  int auth;
1338 
1339  if (argc<2) {
1340    owl_function_makemsg("Too few arguments for zlocate command");
1341    return NULL;
1342  }
1343
1344  auth=1;
1345  if (!strcmp(argv[1], "-d")) {
1346    if (argc>2) {
1347      auth=0;
1348      argc--;
1349      argv++;
1350    } else {
1351      owl_function_makemsg("Missing arguments for zlocate command");
1352      return NULL;
1353    }
1354  }
1355
1356  argc--;
1357  argv++;
1358  owl_function_zlocate(argc, argv, auth);
1359  return NULL;
1360}
1361
1362char *owl_command_view(int argc, char **argv, char *buff) {
1363  if (argc<2) {
1364    owl_function_makemsg("Wrong number of arguments to view command");
1365    return NULL;
1366  }
1367
1368  if (argc == 2 && !strcmp(argv[1], "--home")) {
1369    owl_function_change_view(owl_global_get_view_home(&g));
1370    return NULL;
1371  }
1372
1373  /* is it a dynamic filter? */
1374  if (!strcmp(argv[1], "-d")) {
1375    char **myargv;
1376    int i;
1377
1378    myargv=owl_malloc((argc*sizeof(char *))+50);
1379    myargv[0]="";
1380    myargv[1]="owl-dynamic";
1381    for (i=2; i<argc; i++) {
1382      myargv[i]=argv[i];
1383    }
1384    owl_function_create_filter(argc, myargv);
1385    owl_function_change_view("owl-dynamic");
1386    owl_free(myargv);
1387    return NULL;
1388  }
1389
1390  /* otherwise it's a normal view command */
1391  if (argc>2) {
1392    owl_function_makemsg("Wrong number of arguments to view command");
1393    return NULL;
1394  }
1395  owl_function_change_view(argv[1]);
1396  return NULL;
1397}
1398
1399
1400char *owl_command_show(int argc, char **argv, char *buff) {
1401
1402  if (argc<2) {
1403    owl_function_help_for_command("show");
1404    return NULL;
1405  }
1406
1407  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1408    if (argc==2) {
1409      owl_function_show_filters();
1410    } else {
1411      owl_function_show_filter(argv[2]);
1412    }
1413  } else if (argc==2 
1414             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1415    owl_function_show_zpunts();
1416  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1417    if (argc==2) {
1418      owl_function_show_commands();
1419    } else {
1420      owl_function_show_command(argv[2]);
1421    }
1422  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1423    if (argc==2) {
1424      owl_function_show_variables();
1425    } else {
1426      owl_function_show_variable(argv[2]);
1427    }
1428  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1429    if (argc==2) {
1430      owl_function_show_keymaps();
1431    } else {
1432      owl_function_show_keymap(argv[2]);
1433    }
1434  } else if (!strcmp(argv[1], "colors")) {
1435    owl_function_show_colors();
1436  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1437    owl_function_getsubs();
1438  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1439    owl_function_show_term();
1440  } else if (!strcmp(argv[1], "version")) {
1441    owl_function_about();
1442  } else if (!strcmp(argv[1], "status")) {
1443    owl_function_status();
1444  } else {
1445    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1446    return NULL;
1447  }
1448  return NULL;
1449}
1450
1451char *owl_command_viewclass(int argc, char **argv, char *buff) {
1452  char *filtname;
1453  if (argc!=2) {
1454    owl_function_makemsg("Wrong number of arguments to viewclass command");
1455    return NULL;
1456  }
1457  filtname = owl_function_fastclassinstfilt(argv[1], NULL);
1458  owl_function_change_view(filtname);
1459  owl_free(filtname);
1460  return NULL;
1461}
1462
1463char *owl_command_viewuser(int argc, char **argv, char *buff) {
1464  char *filtname;
1465  if (argc!=2) {
1466    owl_function_makemsg("Wrong number of arguments to viewuser command");
1467    return NULL;
1468  }
1469  filtname = owl_function_fastuserfilt(argv[1]);
1470  owl_function_change_view(filtname);
1471  owl_free(filtname);
1472  return NULL;
1473}
1474
1475
1476void owl_command_pop_message(void) {
1477  owl_function_curmsg_to_popwin();
1478}
1479
1480void owl_command_openurl(void) {
1481  owl_function_openurl();
1482}
1483
1484char *owl_command_delete(int argc, char **argv, char *buff) {
1485  int move_after = 1;
1486
1487  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1488    move_after = 0;
1489    argc--; 
1490    argv++;
1491  }
1492
1493  if (argc==1) {
1494    owl_function_deletecur(move_after);
1495    return NULL;
1496  }
1497
1498  if (argc==2 && !strcmp(argv[1], "view")) {
1499    owl_function_delete_curview_msgs(1);
1500    return NULL;
1501  }
1502
1503  if (argc==2 && !strcmp(argv[1], "trash")) {
1504    owl_function_delete_automsgs();
1505    return NULL;
1506  }
1507
1508  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1509    owl_function_delete_by_id(atoi(argv[2]), 1);
1510    return NULL;
1511  }
1512
1513  owl_function_makemsg("Unknown arguments to delete command");
1514  return NULL;
1515}
1516
1517char *owl_command_undelete(int argc, char **argv, char *buff) {
1518  int move_after = 1;
1519
1520  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1521    move_after = 0;
1522    argc--; 
1523    argv++;
1524  }
1525
1526  if (argc==1) {
1527    owl_function_undeletecur(move_after);
1528    return NULL;
1529  }
1530
1531  if (argc==2 && !strcmp(argv[1], "view")) {
1532    owl_function_delete_curview_msgs(0);
1533    return NULL;
1534  }
1535
1536  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1537    owl_function_delete_by_id(atoi(argv[2]), 0);
1538    return NULL;
1539  }
1540
1541  owl_function_makemsg("Unknown arguments to delete command");
1542  return NULL;
1543}
1544
1545void owl_command_beep() {
1546  owl_function_beep();
1547}
1548
1549char *owl_command_colorview(int argc, char **argv, char *buff) {
1550  if (argc!=2) {
1551    owl_function_makemsg("Wrong number of arguments to colorview command");
1552    return NULL;
1553  }
1554  owl_function_color_current_filter(argv[1]);
1555  return NULL;
1556}
1557
1558char *owl_command_zpunt(int argc, char **argv, char *buff) {
1559  owl_command_zpunt_and_zunpunt(argc, argv, 0);
1560  return NULL;
1561}
1562
1563char *owl_command_zunpunt(int argc, char **argv, char *buff) {
1564  owl_command_zpunt_and_zunpunt(argc, argv, 1);
1565  return NULL;
1566}
1567
1568
1569void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type) {
1570  /* if type==0 then zpunt
1571   * if type==1 then zunpunt
1572   */
1573  char *class, *inst, *recip;
1574
1575  class="message";
1576  inst="";
1577  recip="*";
1578
1579  if (argc==1) {
1580    /* show current punt filters */
1581    owl_function_show_zpunts();
1582    return;
1583  } else if (argc==2) {
1584    inst=argv[1];
1585  } else if (argc==3) {
1586    class=argv[1];
1587    inst=argv[2];
1588  } else if (argc==4) {
1589    class=argv[1];
1590    inst=argv[2];
1591    recip=argv[3];
1592  } else {
1593    owl_function_makemsg("Wrong number of arguments to the zpunt command");
1594    return;
1595  }
1596
1597  owl_function_zpunt(class, inst, recip, type);
1598  if (type==0) {
1599    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
1600  } else if (type==1) {
1601    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
1602  }
1603}
1604
1605char *owl_command_smartzpunt(int argc, char **argv, char *buff) {
1606  if (argc == 1) {
1607    owl_function_smartzpunt(0);
1608  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1609    owl_function_smartzpunt(1);
1610  } else {
1611    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1612  }
1613  return NULL;
1614}
1615
1616char *owl_command_getview(int argc, char **argv, char *buff) {
1617  char *filtname;
1618  if (argc != 1) {
1619    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1620    return NULL;
1621  }
1622  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
1623  if (filtname) filtname = owl_strdup(filtname);
1624  return filtname;
1625}
1626
1627char *owl_command_getvar(int argc, char **argv, char *buff) {
1628  char tmpbuff[1024];
1629  if (argc != 2) {
1630    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1631    return NULL;
1632  }
1633  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
1634                                argv[1], tmpbuff, 1024)) {
1635    return NULL;
1636  }
1637  return owl_strdup(tmpbuff); 
1638}
1639
1640char *owl_command_search(int argc, char **argv, char *buff) {
1641  int direction;
1642  char *buffstart;
1643
1644  direction=OWL_DIRECTION_DOWNWARDS;
1645  buffstart=skiptokens(buff, 1);
1646  if (argc>1 && !strcmp(argv[1], "-r")) {
1647    direction=OWL_DIRECTION_UPWARDS;
1648    buffstart=skiptokens(buff, 2);
1649  }
1650   
1651  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
1652    owl_function_search_continue(direction);
1653  } else {
1654    owl_function_search_start(buffstart, direction);
1655  }
1656 
1657  return(NULL);
1658}
1659
1660/*********************************************************************/
1661/************************** EDIT SPECIFIC ****************************/
1662/*********************************************************************/
1663
1664void owl_command_edit_cancel(owl_editwin *e) {
1665  owl_history *hist;
1666
1667  owl_function_makemsg("Command cancelled.");
1668
1669  hist=owl_editwin_get_history(e);
1670  owl_history_store(hist, owl_editwin_get_text(e));
1671  owl_history_reset(hist);
1672
1673  owl_editwin_fullclear(e);
1674  owl_global_set_needrefresh(&g);
1675  wnoutrefresh(owl_editwin_get_curswin(e));
1676  owl_global_set_typwin_inactive(&g);
1677  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1678}
1679
1680void owl_command_edit_history_prev(owl_editwin *e) {
1681  owl_history *hist;
1682  char *ptr;
1683
1684  hist=owl_editwin_get_history(e);
1685  if (!owl_history_is_touched(hist)) {
1686    owl_history_store(hist, owl_editwin_get_text(e));
1687    owl_history_set_partial(hist);
1688  }
1689  ptr=owl_history_get_prev(hist);
1690  if (ptr) {
1691    owl_editwin_clear(e);
1692    owl_editwin_insert_string(e, ptr);
1693    owl_editwin_redisplay(e, 0);
1694    owl_global_set_needrefresh(&g);
1695  } else {
1696    owl_function_beep();
1697  }
1698}
1699
1700void owl_command_edit_history_next(owl_editwin *e) {
1701  owl_history *hist;
1702  char *ptr;
1703
1704  hist=owl_editwin_get_history(e);
1705  ptr=owl_history_get_next(hist);
1706  if (ptr) {
1707    owl_editwin_clear(e);
1708    owl_editwin_insert_string(e, ptr);
1709    owl_editwin_redisplay(e, 0);
1710    owl_global_set_needrefresh(&g);
1711  } else {
1712    owl_function_beep();
1713  }
1714}
1715
1716char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff) {
1717  buff = skiptokens(buff, 1);
1718  owl_editwin_insert_string(e, buff);
1719  owl_editwin_redisplay(e, 0);
1720  owl_global_set_needrefresh(&g); 
1721  return NULL;
1722}
1723
1724void owl_command_editline_done(owl_editwin *e) {
1725  owl_history *hist=owl_editwin_get_history(e);
1726  char *rv, *cmd;
1727
1728  owl_history_store(hist, owl_editwin_get_text(e));
1729  owl_history_reset(hist);
1730  owl_global_set_typwin_inactive(&g);
1731  cmd = owl_strdup(owl_editwin_get_text(e));
1732  owl_editwin_fullclear(e);
1733  rv = owl_function_command(cmd);
1734  owl_free(cmd);
1735
1736  wnoutrefresh(owl_editwin_get_curswin(e));
1737  owl_global_set_needrefresh(&g);
1738
1739  if (rv) {
1740    owl_function_makemsg("%s", rv);
1741    owl_free(rv);
1742  }
1743}
1744
1745void owl_command_editmulti_done(owl_editwin *e) {
1746  owl_history *hist=owl_editwin_get_history(e);
1747
1748  owl_history_store(hist, owl_editwin_get_text(e));
1749  owl_history_reset(hist);
1750
1751  owl_function_run_buffercommand();
1752  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1753  owl_editwin_fullclear(e);
1754  owl_global_set_typwin_inactive(&g);
1755  owl_global_set_needrefresh(&g);
1756  wnoutrefresh(owl_editwin_get_curswin(e));
1757}
1758
1759void owl_command_editmulti_done_or_delete(owl_editwin *e) {
1760  if (owl_editwin_is_at_end(e)) {
1761    owl_command_editmulti_done(e);
1762  } else {
1763    owl_editwin_delete_char(e);
1764  }
1765}
1766
1767
1768/*********************************************************************/
1769/*********************** POPLESS SPECIFIC ****************************/
1770/*********************************************************************/
1771
1772void owl_command_popless_quit(owl_viewwin *vw) {
1773  owl_popwin_close(owl_global_get_popwin(&g));
1774  owl_viewwin_free(vw);
1775  owl_global_set_needrefresh(&g);
1776}
Note: See TracBrowser for help on using the repository browser.