source: commands.c @ 039213e

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