source: commands.c @ 5eeea3b

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