source: commands.c @ e75011e

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