source: commands.c @ 66dc2c6

Last change on this file since 66dc2c6 was 66dc2c6, checked in by Jason Gross <jgross@mit.edu>, 8 years ago
Defer failed log messages Previously, when we failed to open a logging file, we errored, and dropped the log message. This commit makes it so that, if the reason we failed was a permissions error, we instead add the log entry to a queue of messages to be logged eventually, and inform the user that logging has been suspended. The user must run :flush-logs to resume logging. If :flush-log has an fopen that fails with EPERM or EACCES, we re-defer messages and inform the user. On shutdown, BarnOwl will attempt to log all messages currently in the queue one last time.
  • Property mode set to 100644
File size: 86.9 KB
Line 
1#include "owl.h"
2#include <getopt.h>
3
4/* fn is "char *foo(int argc, const char *const *argv, const char *buff)" */
5#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
6        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
7          NULL, fn, NULL, NULL, NULL, NULL, NULL, NULL }
8
9/* fn is "void foo(void)" */
10#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
11        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
12          NULL, NULL, fn, NULL, NULL, NULL, NULL, NULL }
13
14/* fn is "void foo(int)" */
15#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
16        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
17          NULL, NULL, NULL, fn, NULL, NULL, NULL, NULL }
18
19#define OWLCMD_ALIAS(name, actualname) \
20        { g_strdup(name), g_strdup(OWL_CMD_ALIAS_SUMMARY_PREFIX actualname), g_strdup(""), g_strdup(""), OWL_CTX_ANY, \
21          g_strdup(actualname), NULL, NULL, NULL, NULL, NULL, NULL, NULL }
22
23/* fn is "char *foo(void *ctx, int argc, const char *const *argv, const char *buff)" */
24#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
25        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
26          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,const char*const *,const char*))fn), NULL, NULL, NULL }
27
28/* fn is "void foo(void)" */
29#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
30        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
31          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL, NULL }
32
33/* fn is "void foo(int)" */
34#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
35        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
36          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn), NULL }
37
38
39void owl_cmd_add_defaults(owl_cmddict *cd)
40{
41  owl_cmd commands_to_init[] = {
42
43  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
44              "send a login or logout notification",
45              "zlog in [tty]\nzlog out",
46              "zlog in will send a login notification, zlog out will send a\n"
47              "logout notification.  By default a login notification is sent\n"
48              "when BarnOwl is started and a logout notification is sent when owl\n"
49              "is exited.  This behavior can be changed with the 'startuplogin'\n"
50              "and 'shutdownlogout' variables.  If a tty is specified for zlog in\n"
51              "then the BarnOwl variable 'tty' will be set to that string, causing\n"
52              "it to be used as the zephyr location tty.\n"),
53
54  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
55              "exit BarnOwl",
56              "",
57              "Exit BarnOwl and run any shutdown activities."),
58  OWLCMD_ALIAS("exit", "quit"),
59  OWLCMD_ALIAS("q",    "quit"),
60
61  OWLCMD_ARGS("term", owl_command_term, OWL_CTX_ANY,
62              "control the terminal",
63              "term raise\n"
64              "term deiconify\n",
65              ""),
66
67  OWLCMD_VOID("nop", owl_command_nop, OWL_CTX_ANY,
68              "do nothing",
69              "",
70              ""),
71 
72  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
73              "prompts the user to enter a command",
74              "start-command [initial-value]",
75              "Initializes the command field to initial-value."),
76
77  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
78              "creates a command alias",
79              "alias <new_command> <old_command>",
80              "Creates a command alias from new_command to old_command.\n"
81              "Any arguments passed to <new_command> will be appended to\n"
82              "<old_command> before it is executed.\n"),
83
84  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
85              "creates a binding in a keymap",
86              "bindkey <keymap> <keyseq> command <command>",
87              "(Note: There is a literal word \"command\" between <keyseq>\n"
88              " and <command>.)\n"
89              "Binds a key sequence to a command within a keymap.\n"
90              "Use 'show keymaps' to see the existing keymaps.\n"
91              "Key sequences may be things like M-C-t or NPAGE.\n\n"
92              "Ex.: bindkey recv C-b command zwrite -c barnowl\n"
93              "Ex.: bindkey recv m command start-command zwrite -c my-class -i \n\n"
94              "SEE ALSO: unbindkey, start-command"),
95
96  OWLCMD_ARGS("unbindkey", owl_command_unbindkey, OWL_CTX_ANY,
97              "removes a binding in a keymap",
98              "unbindkey <keymap> <keyseq>",
99              "Removes a binding of a key sequence within a keymap.\n"
100              "Use 'show keymaps' to see the existing keymaps.\n"
101              "Ex.: unbindkey recv H\n\n"
102              "SEE ALSO: bindkey"),
103
104  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
105              "send a zephyr",
106              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [<user> ...] [-m <message...>]",
107              "Zwrite send a zephyr to the one or more users specified.\n\n"
108              "The following options are available:\n\n"
109              "-m    Specifies a message to send without prompting.\n"
110              "      Note that this does not yet log an outgoing message.\n"
111              "      This must be the last argument.\n\n"
112              "-n    Do not send a ping message.\n\n"
113              "-C    If the message is sent to more than one user include a\n"
114              "      \"cc:\" line in the text\n\n"
115              "-c class\n"
116              "      Send to the specified zephyr class\n\n"
117              "-i instance\n"
118              "      Send to the specified zephyr instance\n\n"
119              "-r realm\n"
120              "      Send to a foreign realm\n"
121              "-O opcode\n"
122              "      Send to the specified opcode\n"),
123
124  OWLCMD_ARGS("aimwrite", owl_command_aimwrite, OWL_CTX_INTERACTIVE,
125              "send an AIM message",
126              "aimwrite <user> [-m <message...>]",
127              "Send an aim message to a user.\n\n" 
128              "The following options are available:\n\n"
129              "-m    Specifies a message to send without prompting.\n"),
130
131  OWLCMD_ARGS("loopwrite", owl_command_loopwrite, OWL_CTX_INTERACTIVE,
132              "send a loopback message",
133              "loopwrite",
134              "Send a local message.\n"),
135
136  OWLCMD_ARGS("zcrypt", owl_command_zwrite, OWL_CTX_INTERACTIVE,
137              "send an encrypted zephyr",
138              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [-m <message...>]\n",
139              "Behaves like zwrite but uses encryption.  Not for use with\n"
140              "personal messages\n"),
141 
142  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
143              "reply to the current message",
144              "reply [-e] [ sender | all | zaway ]",
145              "If -e is specified, the zwrite command line is presented to\n"
146              "allow editing.\n\n"
147              "If 'sender' is specified, reply to the sender.\n\n"
148              "If 'all' or no args are specified, reply publicly to the\n"
149              "same class/instance for non-personal messages and to the\n"
150              "sender for personal messages.\n\n"
151              "If 'zaway' is specified, replies with a zaway message.\n\n"),
152
153  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
154              "set a variable value",
155              "set [-q] [<variable>] [<value>]\n"
156              "set",
157              "Set the named variable to the specified value.  If no\n"
158              "arguments are given, print the value of all variables.\n"
159              "If the value is unspecified and the variable is a boolean, it will be\n"
160              "set to 'on'.  If -q is used, set is silent and does not print a\n"
161              "message.\n"),
162
163  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
164              "unset a boolean variable value",
165              "unset [-q] <variable>\n"
166              "unset",
167              "Set the named boolean variable to off.\n"
168              "If -q is specified, is silent and doesn't print a message.\n"),
169
170  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
171              "print a variable value",
172              "print <variable>\n"
173              "print",
174              "Print the value of the named variable.  If no arguments\n"
175              "are used print the value of all variables.\n"),
176
177  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
178              "run a command and set it to be run at every BarnOwl startup",
179              "startup <commands> ...",
180              "Everything on the command line after the startup command\n"
181              "is executed as a normal BarnOwl command and is also placed in\n"
182              "a file so that the command is executed every time BarnOwl\n"
183              "is started"),
184
185  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
186              "remove a command from the list of those to be run at BarnOwl startup",
187              "unstartup <commands> ...",
188              ""),
189
190  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
191              "print the version of the running BarnOwl", "", ""),
192
193  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
194              "subscribe to a zephyr class, instance, recipient",
195              "subscribe [-t] <class> [instance [recipient]]",
196              "Subscribe to the specified class and instance.  If the\n"
197              "instance or recipient is not listed on the command\n"
198              "line they default to * (the wildcard recipient).\n"
199              "If the -t option is present the subscription will\n"
200              "only be temporary, i.e., it will not be written to\n"
201              "the subscription file and will therefore not be\n"
202              "present the next time BarnOwl is started.\n"),
203  OWLCMD_ALIAS("sub", "subscribe"),
204
205  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
206              "unsubscribe from a zephyr class, instance, recipient",
207              "unsubscribe [-t] <class> [instance [recipient]]",
208              "Unsubscribe from the specified class and instance.  If the\n"
209              "instance or recipient is not listed on the command\n"
210              "line they default to * (the wildcard recipient).\n"
211              "If the -t option is present the unsubscription will\n"
212              "only be temporary, i.e., it will not be updated in\n"
213              "the subscription file and will therefore not be\n"
214              "in effect the next time BarnOwl is started.\n"),
215  OWLCMD_ALIAS("unsub", "unsubscribe"),
216
217  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
218              "unsubscribe from all zephyrs", "", ""),
219 
220  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
221              "print all current subscriptions",
222              "getsubs",
223              "getsubs retrieves the current subscriptions from the server\n"
224              "and displays them.\n"),
225
226  OWLCMD_ARGS("dump", owl_command_dump, OWL_CTX_ANY,
227              "dump messages to a file",
228              "dump <filename>",
229              "Dump messages in current view to the named file."),
230
231  OWLCMD_ARGS("source", owl_command_source, OWL_CTX_ANY,
232              "execute BarnOwl commands from a file",
233              "source <filename>",
234              "Execute the BarnOwl commands in <filename>.\n"),
235
236  OWLCMD_ARGS("aim", owl_command_aim, OWL_CTX_INTERACTIVE,
237              "AIM specific commands",
238              "aim search <email>",
239              ""),
240
241  OWLCMD_ARGS("addbuddy", owl_command_addbuddy, OWL_CTX_INTERACTIVE,
242              "add a buddy to a buddylist",
243              "addbuddy <protocol> <screenname>",
244              "Add the named buddy to your buddylist.  <protocol> can be aim or zephyr\n"),
245
246  OWLCMD_ARGS("delbuddy", owl_command_delbuddy, OWL_CTX_INTERACTIVE,
247              "delete a buddy from a buddylist",
248              "delbuddy <protocol> <screenname>",
249              "Delete the named buddy from your buddylist.  <protocol> can be aim or zephyr\n"),
250
251  OWLCMD_ARGS("join", owl_command_join, OWL_CTX_INTERACTIVE,
252              "join a chat group",
253              "join aim <groupname> [exchange]",
254              "Join the AIM chatroom with 'groupname'.\n"),
255
256  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
257              "creates a zpunt based on the current message",
258              "smartzpunt [-i | --instance]",
259              "Starts a zpunt command based on the current message's class\n"
260              "(and instance if -i is specified).\n"),
261
262  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
263              "suppress a given zephyr triplet",
264              "zpunt <class> <instance> [recipient]\n"
265              "zpunt <instance>",
266              "The zpunt command will suppress messages to the specified\n"
267              "zephyr triplet.  In the second usage messages are suppressed\n"
268              "for class MESSAGE and the named instance.\n\n"
269              "SEE ALSO:  zunpunt, show zpunts\n"),
270
271  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
272              "undo a previous zpunt",
273              "zunpunt <class> <instance> [recipient]\n"
274              "zunpunt <instance>",
275              "The zunpunt command will allow messages that were previously\n"
276              "suppressed to be received again.\n\n"
277              "SEE ALSO:  zpunt, show zpunts\n"),
278
279  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
280              "suppress an arbitrary filter",
281              "punt <filter-name>\n"
282              "punt <filter-text (multiple words)>",
283              "The punt command will suppress messages to the specified\n"
284              "filter\n\n"
285              "SEE ALSO:  unpunt, zpunt, show zpunts\n"),
286
287  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
288              "remove an entry from the punt list",
289              "unpunt <number>\n"
290              "unpunt <filter-name>\n"
291              "unpunt <filter-text (multiple words)>",
292              "The unpunt command will remove an entry from the puntlist.\n"
293              "The last two forms correspond to the two forms of the :punt\n"
294              "command. The first allows you to remove a specific entry from\n"
295              "the list (see :show zpunts)\n\n"
296              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
297
298  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
299              "display detailed information about the current message",
300              "", ""),
301 
302  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
303              "display help on using BarnOwl",
304              "help [command]", ""),
305
306  OWLCMD_ARGS("zlist", owl_command_zlist, OWL_CTX_INTERACTIVE,
307              "List users logged in",
308              "znol [-f file]",
309              "Print a znol-style listing of users logged in"),
310
311  OWLCMD_VOID("alist", owl_command_alist, OWL_CTX_INTERACTIVE,
312              "List AIM users logged in",
313              "alist",
314              "Print a listing of AIM users logged in"),
315
316  OWLCMD_VOID("blist", owl_command_blist, OWL_CTX_INTERACTIVE,
317              "List all buddies logged in",
318              "blist",
319              "Print a listing of buddies logged in, regardless of protocol."),
320
321  OWLCMD_VOID("toggle-oneline", owl_command_toggleoneline, OWL_CTX_INTERACTIVE,
322              "Toggle the style between oneline and the default style",
323              "toggle-oneline",
324              ""),
325
326  OWLCMD_ARGS("recv:getshift", owl_command_get_shift, OWL_CTX_INTERACTIVE,
327              "gets position of receive window scrolling", "", ""),
328
329  OWLCMD_INT("recv:setshift", owl_command_set_shift, OWL_CTX_INTERACTIVE,
330              "scrolls receive window to specified position", "", ""),
331
332  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
333              OWL_CTX_INTERACTIVE,
334              "scrolls down by a page", "", ""),
335
336  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
337              "scrolls up by a page", "", ""),
338
339  OWLCMD_VOID("recv:mark", owl_function_mark_message,
340              OWL_CTX_INTERACTIVE,
341              "mark the current message", "", ""),
342
343  OWLCMD_VOID("recv:swapmark", owl_function_swap_cur_marked,
344              OWL_CTX_INTERACTIVE,
345              "swap the positions of the pointer and the mark", "", ""),
346
347  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
348              "scrolls current message up or down", 
349              "recv:scroll <numlines>", 
350              "Scrolls the current message up or down by <numlines>.\n"
351              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
352
353  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
354              "move the pointer to the next message",
355              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
356              "          [ --smart-filter | --smart-filter-instance ]",
357              "Moves the pointer to the next message in the current view.\n"
358              "If --filter is specified, will only consider messages in\n"
359              "the filter <name>.\n"
360              "If --smart-filter or --smart-filter-instance is specified,\n"
361              "goes to the next message that is similar to the current message.\n"
362              "If --skip-deleted is specified, deleted messages will\n"
363              "be skipped.\n"
364              "If --last-if-none is specified, will stop at last message\n"
365              "in the view if no other suitable messages are found.\n"),
366  OWLCMD_ALIAS("recv:next", "next"),
367
368  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
369              "move the pointer to the previous message",
370              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
371              "          [ --smart-filter | --smart-filter-instance ]",
372              "Moves the pointer to the next message in the current view.\n"
373              "If --filter is specified, will only consider messages in\n"
374              "the filter <name>.\n"
375              "If --smart-filter or --smart-filter-instance is specified,\n"
376              "goes to the previous message that is similar to the current message.\n"
377              "If --skip-deleted is specified, deleted messages will\n"
378              "be skipped.\n"
379              "If --first-if-none is specified, will stop at first message\n"
380              "in the view if no other suitable messages are found.\n"),
381  OWLCMD_ALIAS("recv:prev", "prev"),
382
383  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
384  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
385
386  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
387  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
388
389  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
390
391  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
392
393  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
394              "move the pointer to the first message", "", ""),
395  OWLCMD_ALIAS("recv:first", "first"),
396
397  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
398              "move the pointer to the last message", "", 
399              "Moves the pointer to the last message in the view.\n"
400              "If we are already at the last message in the view,\n"
401              "blanks the screen and moves just past the end of the view\n"
402              "so that new messages will appear starting at the top\n"
403              "of the screen.\n"),
404  OWLCMD_ALIAS("recv:last", "last"),
405
406  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
407              "remove all messages marked for deletion", "", ""),
408
409  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
410              "resize the window to the current screen size", "", ""),
411
412  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
413              "redraw the entire window", "", ""),
414
415  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
416              "suspend BarnOwl", "", ""),
417
418  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
419              "pops up a message in popup window",
420              "echo [args .. ]\n\n", ""),
421
422  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
423              "run a command from the shell",
424              "exec [args .. ]", ""),
425
426  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
427              "run a command from the shell and display in an admin message",
428              "aexec [args .. ]", ""),
429
430  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
431              "run a command from the shell and display in a popup window",
432              "pexec [args .. ]", ""),
433
434  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
435              "run a perl expression",
436              "perl [args .. ]", ""),
437
438  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
439              "run a perl expression and display in an admin message",
440              "aperl [args .. ]", ""),
441
442  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
443              "run a perl expression and display in a popup window",
444              "pperl [args .. ]", ""),
445
446  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
447              "runs multiple ;-separated commands",
448              "multi <command1> ( ; <command2> )*\n",
449              "Runs multiple semicolon-separated commands in order.\n"
450              "Note quoting isn't supported here yet.\n"
451              "If you want to do something fancy, use perl.\n"),
452
453  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
454              "runs multiple ;-separated commands",
455              "'(' <command1> ( ; <command2> )* ')'\n",
456              "Runs multiple semicolon-separated commands in order.\n"
457              "You must have a space before the final ')'\n"
458              "Note quoting isn't supported here yet.\n"
459              "If you want to do something fancy, use perl.\n"),
460
461  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
462              "pops up a message in a window", "", ""),
463
464  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
465              "Set, enable or disable zephyr away message",
466              "zaway [ on | off | toggle ]\n"
467              "zaway <message>",
468              "Turn on or off a zaway message.  If 'message' is\n"
469              "specified turn on zaway with that message, otherwise\n"
470              "use the default.\n"),
471
472  OWLCMD_ARGS("aaway", owl_command_aaway, OWL_CTX_INTERACTIVE,
473              "Set, enable or disable AIM away message",
474              "aaway [ on | off | toggle ]\n"
475              "aaway <message>",
476              "Turn on or off the AIM away message.  If 'message' is\n"
477              "specified turn on aaway with that message, otherwise\n"
478              "use the default.\n"),
479
480  OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
481              "Set, enable or disable all away messages",
482              "away [ on | off | toggle ]\n"
483              "away <message>",
484              "Turn on or off all away messages.  If\n"
485              "'message' is specified turn them on with that message,\n"
486              "otherwise use the default.\n"
487              "\n"
488              "SEE ALSO: aaway, zaway"),
489
490  OWLCMD_VOID("flush-logs", owl_command_flushlogs, OWL_CTX_ANY,
491              "flush the queue of messages waiting to be logged",
492              "",
493              "If BarnOwl failed to log a file, this command tells\n"
494              "BarnOwl to try logging the messages that have since\n"
495              "come in, and to resume logging normally."),
496
497  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
498              "load subscriptions from a file",
499              "load-subs <file>\n", ""),
500
501  OWLCMD_ARGS("loadsubs", owl_command_loadsubs, OWL_CTX_ANY,
502              "load subscriptions from a file",
503              "loadsubs <file>\n", ""),
504
505  OWLCMD_ARGS("loadloginsubs", owl_command_loadloginsubs, OWL_CTX_ANY,
506              "load login subscriptions from a file",
507              "loadloginsubs <file>\n",
508              "The file should contain a list of usernames, one per line."),
509
510  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
511              "print information about BarnOwl", "", ""),
512
513  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
514              "print status information about the running BarnOwl", "", ""),
515 
516  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
517              "locate a user",
518              "zlocate [-d] <user> ...", 
519              "Performs a zlocate on one ore more users and puts the result\n"
520              "int a popwin.  If -d is specified, does not authenticate\n"
521              "the lookup request.\n"),
522 
523  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
524              "create a message filter",
525              "filter <name> [ -c fgcolor ] [ -b bgcolor ] [ <expression> ... ]",
526              "The filter command creates a filter with the specified name,\n"
527              "or if one already exists it is replaced.  Example filter\n"
528              "syntax would be:\n\n"
529              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
530              "Valid matching fields are:\n"
531              "    sender     -  sender\n"
532              "    recipient  -  recipient\n"
533              "    class      -  zephyr class name\n"
534              "    instance   -  zephyr instance name\n"
535              "    opcode     -  zephyr opcode\n"
536              "    realm      -  zephyr realm\n"
537              "    body       -  message body\n"
538              "    hostname   -  hostname of sending host\n"
539              "    type       -  message type (zephyr, aim, admin)\n"
540              "    direction  -  either 'in' 'out' or 'none'\n"
541              "    login      -  either 'login' 'logout' or 'none'\n"
542              "Also you may match on the validity of another filter:\n"
543              "    filter <filtername>\n"
544              "Also you may pass the message to a perl function returning 0 or 1,\n"
545              "where 1 indicates that the function matches the filter:\n"
546              "    perl <subname>\n"
547              "Valid operators are:\n"
548              "    and\n"
549              "    or\n"
550              "    not\n"
551              "And additionally you may use the static values:\n"
552              "    true\n"
553              "    false\n"
554              "Spaces must be present before and after parentheses.  If the\n"
555              "optional color arguments are used they specifies the colors that\n"
556              "messages matching this filter should be displayed in.\n\n"
557              "SEE ALSO: view, viewclass, viewuser\n"),
558
559  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
560              "change the colors on the current filter",
561              "colorview <fgcolor> [<bgcolor>]",
562              "The colors of messages in the current filter will be changed\n"
563              "to <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
564              "of valid colors.\n\n"
565              "SEE ALSO: 'show colors'\n"),
566
567  OWLCMD_ARGS("colorclass", owl_command_colorclass, OWL_CTX_INTERACTIVE,
568              "create a filter to color messages of the given class name",
569              "colorclass <class> <fgcolor> [<bgcolor>]",
570              "A filter will be created to color messages in <class>"
571              "in <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
572              "of valid colors.\n\n"
573              "SEE ALSO: 'show colors'\n"),
574
575  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
576              "view messages matching a filter",
577              "view [<viewname>] [-f <filter> | --home | -r ] [-s <style>]\n"
578              "view <filter>\n"
579              "view -d <expression>\n"
580              "view --home",
581              "The view command sets information associated with a particular view,\n"
582              "such as view's filter or style.  In the first general usage listed\n"
583              "above <viewname> is the name of the view to be changed.  If not\n"
584              "specified the default view 'main' will be used.  A filter can be set\n"
585              "for the view by listing a named filter after the -f argument.  If\n"
586              "the --home argument is used the filter will be set to the filter named\n"
587              "by the\n 'view_home' variable.  The style can be set by listing the\n"
588              "name style after the -s argument.\n"
589              "\n"
590              "The other usages listed above are abbreviated forms that simply set\n"
591              "the filter of the current view. The -d option allows you to write a\n"
592              "filter expression that will be dynamically created by BarnOwl and then\n"
593              "applied as the view's filter\n"
594              "SEE ALSO: filter, viewclass, viewuser\n"),
595
596  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
597              "view only messages similar to the current message",
598              "smartnarrow [-i | --instance]  [-r | --related]",
599              "If the curmsg is a personal message narrow\n"
600              "   to the conversation with that user.\n"
601              "If the curmsg is a <MESSAGE, foo, *>\n"
602              "   message, narrow to the instance.\n"
603              "If the curmsg is a class message, narrow\n"
604              "    to the class.\n"
605              "If the curmsg is a class message and '-i' is specified\n"
606              "    then narrow to the class and instance.\n"
607              "If '-r' or '--related' is specified, behave as though the\n"
608              "    'narrow-related' variable was inverted."),
609
610  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
611              "returns the name of a filter based on the current message",
612              "smartfilter [-i | --instance]",
613              "If the curmsg is a personal message, the filter is\n"
614              "   the conversation with that user.\n"
615              "If the curmsg is a <MESSAGE, foo, *>\n"
616              "   message, the filter is to that instance.\n"
617              "If the curmsg is a class message, the filter is that class.\n"
618              "If the curmsg is a class message and '-i' is specified\n"
619              "    the filter is to that class and instance.\n"),
620
621  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
622              "view messages matching a particular class",
623              "viewclass <class>",
624              "The viewclass command will automatically create a filter\n"
625              "matching the specified class and switch the current view\n"
626              "to it.\n\n"
627              "SEE ALSO: filter, view, viewuser\n"),
628  OWLCMD_ALIAS("vc", "viewclass"),
629
630  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
631              "view messages matching a particular user",
632              "viewuser <user>",
633              "The viewuser command will automatically create a filter\n"
634              "matching the specified user and switch the current\n"
635              "view to it.\n\n"
636              "SEE ALSO: filter, view, viewclass\n"),
637  OWLCMD_ALIAS("vu", "viewuser"),
638  OWLCMD_ALIAS("viewperson", "viewuser"),
639  OWLCMD_ALIAS("vp", "viewuser"),
640
641  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
642              "show information",
643              "show colors\n"
644              "show commands\n"
645              "show command <command>\n"
646              "show errors\n"
647              "show filters\n"
648              "show filter <filter>\n"
649              "show keymaps\n"
650              "show keymap <keymap>\n"
651              "show license\n"
652              "show quickstart\n"
653              "show startup\n"
654              "show status\n"
655              "show styles\n"
656              "show subscriptions / show subs\n"
657              "show terminal\n"
658              "show variables\n"
659              "show variable <variable>\n"
660              "show version\n"
661              "show view [<view>]\n"
662              "show zpunts\n",
663
664              "Show colors will display a list of valid colors for the\n"
665              "     terminal."
666              "Show filters will list the names of all filters.\n"
667              "Show filter <filter> will show the definition of a particular\n"
668              "     filter.\n\n"
669              "Show startup will display the custom startup config\n\n"
670              "Show zpunts will show the active zpunt filters.\n\n"
671              "Show keymaps will list the names of all keymaps.\n"
672              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
673              "Show commands will list the names of all keymaps.\n"
674              "Show command <command> will provide information about a command.\n\n"
675              "Show styles will list the names of all styles available\n"
676              "for formatting messages.\n\n"
677              "Show variables will list the names of all variables.\n\n"
678              "Show errors will show a list of errors encountered by BarnOwl.\n\n"
679              "SEE ALSO: filter, view, alias, bindkey, help\n"),
680 
681  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
682              "mark a message for deletion",
683              "delete [ -id msgid ] [ --no-move ]\n"
684              "delete view\n"
685              "delete trash",
686              "If no message id is specified the current message is marked\n"
687              "for deletion.  Otherwise the message with the given message\n"
688              "id is marked for deletion.\n"
689              "If '--no-move' is specified, don't move after deletion.\n"
690              "If 'trash' is specified, deletes all trash/auto messages\n"
691              "in the current view.\n"
692              "If 'view' is specified, deletes all messages in the\n"
693              "current view.\n"),
694  OWLCMD_ALIAS("del", "delete"),
695
696  OWLCMD_ARGS("delete-and-expunge", owl_command_delete_and_expunge, OWL_CTX_INTERACTIVE,
697              "delete a message",
698              "delete-and-expunge [-id msgid] [-q | --quiet]",
699              "If no message id is specified the current message is deleted.\n"
700              "Otherwise the message with the given message id is deleted.\n"
701              "If --quiet is specified, then there is no message displayed on\n"
702              "success.\n"),
703  OWLCMD_ALIAS("delx", "delete-and-expunge"),
704
705  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
706              "unmark a message for deletion",
707              "undelete [ -id msgid ] [ --no-move ]\n"
708              "undelete view",
709              "If no message id is specified the current message is\n"
710              "unmarked for deletion.  Otherwise the message with the\n"
711              "given message id is unmarked for deletion.\n"
712              "If '--no-move' is specified, don't move after deletion.\n"
713              "If 'view' is specified, undeletes all messages\n"
714              "in the current view.\n"),
715  OWLCMD_ALIAS("undel", "undelete"),
716
717  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
718              "ring the terminal bell",
719              "beep",
720              "Beep will ring the terminal bell.\n"
721              "If the variable 'bell' has been\n"
722              "set to 'off' this command does nothing.\n"),
723
724  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
725              "prints a message into the debug log",
726              "debug <message>", ""),
727
728  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
729              "returns the name of the filter for the current view",
730              "", ""),
731
732  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
733              "returns the value of a variable",
734              "getvar <varname>", ""),
735
736  OWLCMD_ARGS("getfilter", owl_command_getfilter, OWL_CTX_INTERACTIVE,
737              "returns the definition of a filter",
738              "getfilter <filtername>", ""),
739
740  OWLCMD_ARGS("getstyle", owl_command_getstyle, OWL_CTX_INTERACTIVE,
741              "returns the name of the style for the current view",
742              "", ""),
743
744  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
745              "search messages for a particular string",
746              "search [-r] [<string>]",
747              "The search command will find messages that contain the\n"
748              "specified string and move the cursor there.  If no string\n"
749              "argument is supplied then the previous one is used.  By\n"
750              "default searches are done forwards; if -r is used the search\n"
751              "is performed backwards"),
752
753  OWLCMD_ARGS("setsearch", owl_command_setsearch, OWL_CTX_INTERACTIVE,
754              "set the search highlight string without searching",
755              "setsearch <string>",
756              "The setsearch command highlights all occurrences of its\n"
757          "argument and makes it the default argument for future\n"
758          "search commands, but does not move the cursor.  With\n"
759          "no argument, it makes search highlighting inactive."),
760
761  OWLCMD_ARGS("aimlogin", owl_command_aimlogin, OWL_CTX_ANY,
762              "login to an AIM account",
763              "aimlogin <screenname> [<password>]\n",
764              ""),
765
766  OWLCMD_ARGS("aimlogout", owl_command_aimlogout, OWL_CTX_ANY,
767              "logout from AIM",
768              "aimlogout\n",
769              ""),
770
771  OWLCMD_ARGS("error", owl_command_error, OWL_CTX_ANY,
772              "Display an error message",
773              "error <message>",
774              ""),
775
776  OWLCMD_ARGS("message", owl_command_message, OWL_CTX_ANY,
777              "Display an informative message",
778              "message <message>",
779              ""),
780
781  OWLCMD_ARGS("add-cmd-history", owl_command_add_cmd_history, OWL_CTX_ANY,
782              "Add a command to the history",
783              "add-cmd-history <cmd>",
784              ""),
785
786  OWLCMD_ARGS("with-history", owl_command_with_history, OWL_CTX_ANY,
787              "Run a command and store it into the history",
788              "with-history <cmd>",
789              ""),
790
791  OWLCMD_VOID("yes", owl_command_yes, OWL_CTX_RECV,
792              "Answer yes to a question",
793              "yes",
794              ""),
795
796  OWLCMD_VOID("no", owl_command_no, OWL_CTX_RECV,
797              "Answer no to a question",
798              "no",
799              ""),
800
801  /****************************************************************/
802  /************************* EDIT-SPECIFIC ************************/
803  /****************************************************************/
804
805  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
806                  OWL_CTX_EDIT,
807                  "moves cursor forward a word",
808                  "", ""),
809
810  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
811                  OWL_CTX_EDIT,
812                  "moves cursor backwards a word",
813                  "", ""),
814
815  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
816                  OWL_CTX_EDIT,
817                  "moves cursor to the top left (start) of the buffer",
818                  "", ""),
819
820  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
821                  OWL_CTX_EDIT,
822                  "moves cursor to the bottom right (end) of the buffer",
823                  "", ""),
824
825  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
826                  OWL_CTX_EDIT,
827                  "moves cursor to the end of the line",
828                  "", ""),
829
830  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
831                  OWL_CTX_EDIT,
832                  "moves cursor to the beginning of the line",
833                  "", ""),
834
835  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
836                  OWL_CTX_EDIT,
837                  "moves the cursor left by a character",
838                  "", ""),
839
840  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
841                  OWL_CTX_EDIT,
842                  "moves the cursor right by a character",
843                  "", ""),
844
845  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
846                  OWL_CTX_EDIT,
847                  "deletes the word to the right of the cursor",
848                  "", ""),
849
850  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
851                  OWL_CTX_EDIT,
852                  "deletes the word to the left of the cursor",
853                  "", ""),
854
855  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
856                  OWL_CTX_EDIT,
857                  "deletes the character to the left of the cursor",
858                  "", ""),
859
860  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
861                  OWL_CTX_EDIT,
862                  "deletes the character to the right of the cursor",
863                  "", ""),
864
865  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
866                  OWL_CTX_EDIT,
867                  "deletes from the cursor to the end of the line",
868                  "", ""),
869
870  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
871                  OWL_CTX_EDIT,
872                  "deletes all of the contents of the buffer",
873                  "", ""),
874
875  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
876                  OWL_CTX_EDIT,
877                  "Interchange characters around point, moving forward one character.",
878                  "", ""),
879
880  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
881                  OWL_CTX_EDIT,
882                  "fills the current paragraph to line-wrap well",
883                  "", ""),
884
885  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
886                  OWL_CTX_EDIT,
887                  "recenters the buffer",
888                  "", ""),
889
890  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
891                  OWL_CTX_EDIT,
892                  "inserts text into the buffer",
893                  "edit:insert-text <text>", ""),
894
895  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
896                  OWL_CTX_EDIT,
897                  "cancels the current command",
898                  "", ""),
899
900  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
901                  OWL_CTX_EDIT,
902                  "replaces the text with the next history",
903                  "", ""),
904
905  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
906                  OWL_CTX_EDIT,
907                  "replaces the text with the previous history",
908                  "", ""),
909
910  OWLCMD_VOID_CTX("edit:set-mark", owl_editwin_set_mark,
911                  OWL_CTX_EDIT,
912                  "sets the mark",
913                  "", ""),
914
915  OWLCMD_VOID_CTX("edit:exchange-point-and-mark", owl_editwin_exchange_point_and_mark,
916                  OWL_CTX_EDIT,
917                  "exchanges the point and the mark",
918                  "", ""),
919
920  OWLCMD_VOID_CTX("edit:copy-region-as-kill", owl_editwin_copy_region_as_kill,
921                  OWL_CTX_EDIT,
922                  "copy the text between the point and the mark",
923                  "", ""),
924
925  OWLCMD_VOID_CTX("edit:kill-region", owl_editwin_kill_region,
926                  OWL_CTX_EDIT,
927                  "kill text between the point and the mark",
928                  "", ""),
929
930  OWLCMD_VOID_CTX("edit:yank", owl_editwin_yank,
931                  OWL_CTX_EDIT,
932                  "insert the current text from the kill buffer",
933                  "", ""),
934
935  OWLCMD_ALIAS   ("editline:done", "edit:done"),
936  OWLCMD_ALIAS   ("editresponse:done", "edit:done"),
937
938  OWLCMD_VOID_CTX("edit:move-up-line", owl_editwin_key_up, 
939                  OWL_CTX_EDITMULTI,
940                  "moves the cursor up one line",
941                  "", ""),
942
943  OWLCMD_VOID_CTX("edit:move-down-line", owl_editwin_key_down, 
944                  OWL_CTX_EDITMULTI,
945                  "moves the cursor down one line",
946                  "", ""),
947
948  OWLCMD_VOID_CTX("edit:done", owl_command_edit_done, 
949                  OWL_CTX_EDIT,
950                  "Finishes entering text in the editwin.",
951                  "", ""),
952
953  OWLCMD_VOID_CTX("edit:done-or-delete", owl_command_edit_done_or_delete, 
954                  OWL_CTX_EDITMULTI,
955                  "completes the command, but only if at end of message",
956                  "", 
957                  "If only whitespace is to the right of the cursor,\n"
958                  "runs 'edit:done'.\n"\
959                  "Otherwise runs 'edit:delete-next-char'\n"),
960
961  OWLCMD_VOID_CTX("edit:forward-paragraph", owl_editwin_forward_paragraph,
962                  OWL_CTX_EDITMULTI,
963                  "Move forward to end of paragraph.",
964                  "",
965                  "Move the point to the end of the current paragraph"),
966
967  OWLCMD_VOID_CTX("edit:backward-paragraph", owl_editwin_backward_paragraph,
968                  OWL_CTX_EDITMULTI,
969                  "Move backward to the start of paragraph.",
970                  "",
971                  "Move the point to the start of the current paragraph"),
972
973  /****************************************************************/
974  /********************** POPLESS-SPECIFIC ************************/
975  /****************************************************************/
976
977  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
978                  OWL_CTX_POPLESS,
979                  "scrolls down one page",
980                  "", ""),
981
982  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
983                  OWL_CTX_POPLESS,
984                  "scrolls down one line",
985                  "", ""),
986
987  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
988                  OWL_CTX_POPLESS,
989                  "scrolls up one page",
990                  "", ""),
991
992  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
993                  OWL_CTX_POPLESS,
994                  "scrolls up one line",
995                  "", ""),
996
997  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
998                  OWL_CTX_POPLESS,
999                  "scrolls to the top of the buffer",
1000                  "", ""),
1001
1002  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
1003                  OWL_CTX_POPLESS,
1004                  "scrolls to the bottom of the buffer",
1005                  "", ""),
1006
1007  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
1008                  OWL_CTX_POPLESS,
1009                  "scrolls right in the buffer",
1010                  "popless:scroll-right <num-chars>", ""),
1011
1012  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
1013                  OWL_CTX_POPLESS,
1014                  "scrolls left in the buffer",
1015                  "popless:scroll-left <num-chars>", ""),
1016
1017  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
1018                  OWL_CTX_POPLESS,
1019                  "exits the popless window",
1020                  "", ""),
1021
1022  OWLCMD_ARGS_CTX("popless:start-command", owl_viewwin_start_command,
1023                  OWL_CTX_POPLESS,
1024                  "starts a command line in the popless",
1025                  "popless:start-command [initial-value]",
1026                  "Initializes the command field to initial-value"),
1027
1028  OWLCMD_ARGS_CTX("popless:search", owl_viewwin_command_search, OWL_CTX_POPLESS,
1029                  "search lines for a particular string",
1030                  "popless:search [-r] [<string>]",
1031                  "The popless:search command will find lines that contain the\n"
1032                  "specified string and scroll the popwin there.  If no string\n"
1033                  "argument is supplied then the previous one is used.  By\n"
1034                  "default searches are done forwards; if -r is used the search\n"
1035                  "is performed backwards"),
1036
1037  OWLCMD_ARGS_CTX("popless:start-search", owl_viewwin_command_start_search, OWL_CTX_POPLESS,
1038                  "starts a command line to search for particular string",
1039                  "popless:start-search [-r] [initial-value]",
1040                  "Initializes the command-line to search for initial-value. If\n"
1041                  "-r is used, the search will be performed backwards.\n\n"
1042                  "SEE ALSO: popless:search"),
1043
1044  OWLCMD_ALIAS("webzephyr", "zwrite " OWL_WEBZEPHYR_PRINCIPAL " -c " OWL_WEBZEPHYR_CLASS " -i"),
1045
1046  /* This line MUST be last! */
1047  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1048
1049  };
1050
1051  owl_cmddict_add_from_list(cd, commands_to_init);
1052  owl_cmd *cmd;
1053  for (cmd = commands_to_init; cmd->name != NULL; cmd++)
1054    owl_cmd_cleanup(cmd);
1055}
1056
1057void owl_command_info(void)
1058{
1059  owl_function_info();
1060}
1061
1062void owl_command_nop(void)
1063{
1064}
1065
1066char *owl_command_help(int argc, const char *const *argv, const char *buff)
1067{
1068  if (argc!=2) {
1069    owl_help();
1070    return NULL;
1071  }
1072 
1073  owl_function_help_for_command(argv[1]);
1074  return NULL;
1075}
1076
1077char *owl_command_zlist(int argc, const char *const *argv, const char *buff)
1078{
1079  const char *file=NULL;
1080
1081  argc--;
1082  argv++;
1083  while (argc) {
1084    if (!strcmp(argv[0], "-f")) {
1085      if (argc==1) {
1086        owl_function_makemsg("zlist: -f needs an argument");
1087        return(NULL);
1088      }
1089      file=argv[1];
1090      argc-=2;
1091      argv+=2;
1092    } else {
1093      owl_function_makemsg("zlist: unknown argument");
1094      return(NULL);
1095    }
1096  }
1097  owl_function_buddylist(0, 1, file);
1098  return(NULL);
1099}
1100
1101void owl_command_alist(void)
1102{
1103  owl_function_buddylist(1, 0, NULL);
1104}
1105
1106void owl_command_blist(void)
1107{
1108  owl_function_buddylist(1, 1, NULL);
1109}
1110
1111void owl_command_toggleoneline(void)
1112{
1113  owl_function_toggleoneline();
1114}
1115
1116void owl_command_about(void)
1117{
1118  owl_function_about();
1119}
1120
1121void owl_command_version(void)
1122{
1123  owl_function_makemsg("BarnOwl version %s", version);
1124}
1125
1126char *owl_command_aim(int argc, const char *const *argv, const char *buff)
1127{
1128  if (argc<2) {
1129    owl_function_makemsg("not enough arguments to aim command");
1130    return(NULL);
1131  }
1132
1133  if (!strcmp(argv[1], "search")) {
1134    if (argc!=3) {
1135      owl_function_makemsg("not enough arguments to aim search command");
1136      return(NULL);
1137    }
1138    owl_aim_search(argv[2]);
1139  } else {
1140    owl_function_makemsg("unknown subcommand '%s' for aim command", argv[1]);
1141    return(NULL);
1142  }
1143  return(NULL);
1144}
1145
1146char *owl_command_addbuddy(int argc, const char *const *argv, const char *buff)
1147{
1148  if (argc!=3) {
1149    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1150    return(NULL);
1151  }
1152
1153  if (!strcasecmp(argv[1], "aim")) {
1154    if (!owl_global_is_aimloggedin(&g)) {
1155      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
1156      return(NULL);
1157    }
1158    /*
1159    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
1160    return(NULL);
1161    */
1162    owl_aim_addbuddy(argv[2]);
1163    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1164  } else if (!strcasecmp(argv[1], "zephyr")) {
1165    owl_zephyr_addbuddy(argv[2]);
1166    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1167  } else {
1168    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1169  }
1170
1171  return(NULL);
1172}
1173
1174char *owl_command_delbuddy(int argc, const char *const *argv, const char *buff)
1175{
1176  if (argc!=3) {
1177    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1178    return(NULL);
1179  }
1180
1181  if (!strcasecmp(argv[1], "aim")) {
1182    if (!owl_global_is_aimloggedin(&g)) {
1183      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
1184      return(NULL);
1185    }
1186    owl_aim_delbuddy(argv[2]);
1187    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1188  } else if (!strcasecmp(argv[1], "zephyr")) {
1189    owl_zephyr_delbuddy(argv[2]);
1190    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1191  } else {
1192    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1193  }
1194
1195  return(NULL);
1196}
1197
1198char *owl_command_join(int argc, const char *const *argv, const char *buff)
1199{
1200  if (argc!=3 && argc!=4) {
1201    owl_function_makemsg("usage: join <protocol> <buddyname> [exchange]");
1202    return(NULL);
1203  }
1204
1205  if (!strcasecmp(argv[1], "aim")) {
1206    if (!owl_global_is_aimloggedin(&g)) {
1207      owl_function_makemsg("join aim: You must be logged into aim to use this command.");
1208      return(NULL);
1209    }
1210    if (argc==3) {
1211      owl_aim_chat_join(argv[2], 4);
1212    } else {
1213      owl_aim_chat_join(argv[2], atoi(argv[3]));
1214    }
1215    /* owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g)); */
1216  } else {
1217    owl_function_makemsg("join: currently the only supported protocol is 'aim'");
1218  }
1219  return(NULL);
1220}
1221
1222char *owl_command_startup(int argc, const char *const *argv, const char *buff)
1223{
1224  const char *ptr;
1225
1226  if (argc<2) {
1227    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1228    return(NULL);
1229  }
1230
1231  ptr = skiptokens(buff, 1);
1232
1233  owl_function_command_norv(ptr);
1234  owl_function_addstartup(ptr);
1235
1236  return(NULL);
1237}
1238
1239char *owl_command_unstartup(int argc, const char *const *argv, const char *buff)
1240{
1241  const char *ptr;
1242
1243  if (argc<2) {
1244    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1245    return(NULL);
1246  }
1247
1248  ptr = skiptokens(buff, 1);
1249
1250  owl_function_delstartup(ptr);
1251
1252  return(NULL);
1253}
1254
1255char *owl_command_dump(int argc, const char *const *argv, const char *buff)
1256{
1257  char *filename;
1258 
1259  if (argc!=2) {
1260    owl_function_makemsg("usage: dump <filename>");
1261    return(NULL);
1262  }
1263  filename=owl_util_makepath(argv[1]);
1264  owl_function_dump(filename);
1265  g_free(filename);
1266  return(NULL);
1267}
1268
1269char *owl_command_source(int argc, const char *const *argv, const char *buff)
1270{
1271  if (argc!=2) {
1272    owl_function_makemsg("usage: source <filename>");
1273    return(NULL);
1274  }
1275
1276  owl_function_source(argv[1]);
1277  return(NULL);
1278}
1279
1280char *owl_command_next(int argc, const char *const *argv, const char *buff)
1281{
1282  char *filter=NULL;
1283  int skip_deleted=0, last_if_none=0;
1284  while (argc>1) {
1285    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1286      skip_deleted=1;
1287      argc-=1; argv+=1; 
1288    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1289      last_if_none=1;
1290      argc-=1; argv+=1; 
1291    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1292      filter = g_strdup(argv[2]);
1293      argc-=2; argv+=2; 
1294    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1295      filter = owl_function_smartfilter(0, 0);
1296      argc-=2; argv+=2; 
1297    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1298      filter = owl_function_smartfilter(1, 0);
1299      argc-=2; argv+=2; 
1300    } else {
1301      owl_function_makemsg("Invalid arguments to command 'next'.");
1302      return(NULL);
1303    }
1304  }
1305  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1306  g_free(filter);
1307  return(NULL);
1308}
1309
1310char *owl_command_prev(int argc, const char *const *argv, const char *buff)
1311{
1312  char *filter=NULL;
1313  int skip_deleted=0, first_if_none=0;
1314  while (argc>1) {
1315    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1316      skip_deleted=1;
1317      argc-=1; argv+=1; 
1318    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1319      first_if_none=1;
1320      argc-=1; argv+=1; 
1321    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1322      filter = g_strdup(argv[2]);
1323      argc-=2; argv+=2; 
1324    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1325      filter = owl_function_smartfilter(0, 0);
1326      argc-=2; argv+=2; 
1327    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1328      filter = owl_function_smartfilter(1, 0);
1329      argc-=2; argv+=2; 
1330   } else {
1331      owl_function_makemsg("Invalid arguments to command 'prev'.");
1332      return(NULL);
1333    }
1334  }
1335  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1336  g_free(filter);
1337  return(NULL);
1338}
1339
1340char *owl_command_smartnarrow(int argc, const char *const *argv, const char *buff)
1341{
1342  char *filtname = NULL;
1343
1344  char opt;
1345  int instance = 0, related = 0, i;
1346  const char **tmp_argv = g_new(const char *, argc);
1347
1348  static const struct option options[] = {
1349    {"instance", 0, 0, 'i'},
1350    {"related",  0, 0, 'r'},
1351    {NULL,       0, 0, 0}};
1352
1353  for (i = 0; i < argc; i++)
1354    tmp_argv[i] = argv[i];
1355
1356  optind = 0;
1357  while ((opt = getopt_long(argc, (char **)tmp_argv, "ir", options, NULL)) != -1) {
1358    switch (opt) {
1359      case 'i':
1360        instance = 1;
1361        break;
1362      case 'r':
1363        related = 1;
1364        break;
1365      default:
1366        owl_function_makemsg("Wrong number of arguments for %s (%c)", argv[0], opt);
1367        goto done;
1368    }
1369  }
1370
1371  filtname = owl_function_smartfilter(instance, related);
1372
1373  if (filtname) {
1374    owl_function_change_currentview_filter(filtname);
1375    g_free(filtname);
1376  }
1377
1378done:
1379  g_free(tmp_argv);
1380
1381  return NULL;
1382}
1383
1384CALLER_OWN char *owl_command_smartfilter(int argc, const char *const *argv, const char *buff)
1385{
1386  char *filtname = NULL;
1387
1388  if (argc == 1) {
1389    filtname = owl_function_smartfilter(0, 0);
1390  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1391    filtname = owl_function_smartfilter(1, 0);
1392  } else {
1393    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1394  }
1395  return filtname;
1396}
1397
1398void owl_command_expunge(void)
1399{
1400  owl_function_expunge();
1401}
1402
1403void owl_command_first(void)
1404{
1405  owl_global_set_rightshift(&g, 0);
1406  owl_function_firstmsg();
1407}
1408
1409void owl_command_last(void)
1410{
1411  owl_function_lastmsg();
1412}
1413
1414void owl_command_resize(void)
1415{
1416  owl_function_resize();
1417}
1418
1419void owl_command_redisplay(void)
1420{
1421  owl_function_full_redisplay();
1422}
1423
1424CALLER_OWN char *owl_command_get_shift(int argc, const char *const *argv, const char *buff)
1425{
1426  if(argc != 1)
1427  {
1428    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1429    return NULL;
1430  }
1431  return g_strdup_printf("%d", owl_global_get_rightshift(&g));
1432}
1433
1434void owl_command_set_shift(int shift)
1435{
1436  owl_global_set_rightshift(&g, shift);
1437}
1438
1439void owl_command_unsuball(void)
1440{
1441  owl_function_unsuball();
1442}
1443
1444void owl_command_flushlogs(void)
1445{
1446  owl_log_flush_logs();
1447}
1448
1449char *owl_command_loadsubs(int argc, const char *const *argv, const char *buff)
1450{
1451  if (argc == 2) {
1452    owl_function_loadsubs(argv[1]);
1453  } else if (argc == 1) {
1454    owl_function_loadsubs(NULL);
1455  } else {
1456    owl_function_makemsg("Wrong number of arguments for load-subs.");
1457    return(NULL);
1458  }
1459  return(NULL);
1460}
1461
1462
1463char *owl_command_loadloginsubs(int argc, const char *const *argv, const char *buff)
1464{
1465  if (argc == 2) {
1466    owl_function_loadloginsubs(argv[1]);
1467  } else if (argc == 1) {
1468    owl_function_loadloginsubs(NULL);
1469  } else {
1470    owl_function_makemsg("Wrong number of arguments for load-subs.");
1471    return(NULL);
1472  }
1473  return(NULL);
1474}
1475
1476void owl_command_suspend(void)
1477{
1478  owl_function_suspend();
1479}
1480
1481char *owl_command_start_command(int argc, const char *const *argv, const char *buff)
1482{
1483  buff = skiptokens(buff, 1);
1484  owl_function_start_command(buff);
1485  return(NULL);
1486}
1487
1488char *owl_command_zaway(int argc, const char *const *argv, const char *buff)
1489{
1490  if ((argc==1) ||
1491      ((argc==2) && !strcmp(argv[1], "on"))) {
1492    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1493    owl_function_zaway_on();
1494    return NULL;
1495  }
1496
1497  if (argc==2 && !strcmp(argv[1], "off")) {
1498    owl_function_zaway_off();
1499    return NULL;
1500  }
1501
1502  if (argc==2 && !strcmp(argv[1], "toggle")) {
1503    owl_function_zaway_toggle();
1504    return NULL;
1505  }
1506
1507  buff = skiptokens(buff, 1);
1508  owl_global_set_zaway_msg(&g, buff);
1509  owl_function_zaway_on();
1510  return NULL;
1511}
1512
1513
1514char *owl_command_aaway(int argc, const char *const *argv, const char *buff)
1515{
1516  if ((argc==1) ||
1517      ((argc==2) && !strcmp(argv[1], "on"))) {
1518    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1519    owl_function_aaway_on();
1520    return NULL;
1521  }
1522
1523  if (argc==2 && !strcmp(argv[1], "off")) {
1524    owl_function_aaway_off();
1525    return NULL;
1526  }
1527
1528  if (argc==2 && !strcmp(argv[1], "toggle")) {
1529    owl_function_aaway_toggle();
1530    return NULL;
1531  }
1532
1533  buff = skiptokens(buff, 1);
1534  owl_global_set_aaway_msg(&g, buff);
1535  owl_function_aaway_on();
1536  return NULL;
1537}
1538
1539
1540char *owl_command_away(int argc, const char *const *argv, const char *buff)
1541{
1542  bool away_off;
1543  const char *message = NULL;
1544
1545  if (argc == 1 ||
1546      (argc == 2 && !strcmp(argv[1], "on"))) {
1547    away_off = false;
1548    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1549    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1550  } else if (argc == 2 && !strcmp(argv[1], "off")) {
1551    away_off = true;
1552  } else if (argc == 2 && !strcmp(argv[1], "toggle")) {
1553    away_off = owl_function_is_away();
1554  } else {
1555    away_off = false;
1556    message = skiptokens(buff, 1);
1557  }
1558
1559  if (away_off) {
1560    owl_function_aaway_off();
1561    owl_function_zaway_off();
1562    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_off", 0, NULL);
1563    owl_function_makemsg("Away messages off.");
1564  } else if (message != NULL) {
1565    owl_global_set_aaway_msg(&g, message);
1566    owl_global_set_zaway_msg(&g, message);
1567    owl_function_aaway_on();
1568    owl_function_zaway_on();
1569    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 1, &message);
1570    owl_function_makemsg("Away messages set (%s).", message);
1571  } else {
1572    owl_function_aaway_on();
1573    owl_function_zaway_on();
1574    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 0, NULL);
1575    owl_function_makemsg("Away messages set.");
1576  }
1577
1578  return NULL;
1579}
1580
1581char *owl_command_set(int argc, const char *const *argv, const char *buff)
1582{
1583  const char *var, *val;
1584  int  silent=0;
1585  int requirebool=0;
1586  owl_variable *v;
1587
1588  if (argc == 1) {
1589    owl_function_printallvars();
1590    return NULL;
1591  } 
1592
1593  if (argc > 1 && !strcmp("-q",argv[1])) {
1594    silent = 1;
1595    argc--; argv++;
1596  }
1597
1598  if (argc == 2) {
1599    var=argv[1];
1600    val="on";
1601    requirebool=1;
1602  } else if (argc == 3) {
1603    var=argv[1];
1604    val=argv[2];
1605  } else {
1606    owl_function_makemsg("Wrong number of arguments for set command");
1607    return NULL;
1608  }
1609
1610  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1611  if (v == NULL) {
1612    if (!silent) owl_function_error("Unknown variable '%s'", var);
1613  } else if (requirebool && !v->takes_on_off) {
1614    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1615  } else {
1616    owl_variable_set_fromstring(v, val, !silent);
1617  }
1618  return NULL;
1619}
1620
1621char *owl_command_unset(int argc, const char *const *argv, const char *buff)
1622{
1623  owl_variable *v;
1624  const char *var, *val;
1625  int  silent=0;
1626
1627  if (argc > 1 && !strcmp("-q",argv[1])) {
1628    silent = 1;
1629    argc--; argv++;
1630  }
1631  if (argc == 2) {
1632    var=argv[1];
1633    val="off";
1634  } else {
1635    owl_function_makemsg("Wrong number of arguments for unset command");
1636    return NULL;
1637  }
1638
1639  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1640  if (v == NULL) {
1641    if (!silent) owl_function_error("Unknown variable '%s'", var);
1642  } else if (!v->takes_on_off) {
1643    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1644  } else {
1645    owl_variable_set_fromstring(v, val, !silent);
1646  }
1647  return NULL;
1648}
1649
1650char *owl_command_print(int argc, const char *const *argv, const char *buff)
1651{
1652  const char *var;
1653  char *value;
1654  const owl_variable *v;
1655
1656  if (argc==1) {
1657    owl_function_printallvars();
1658    return NULL;
1659  } else if (argc!=2) {
1660    owl_function_makemsg("Wrong number of arguments for print command");
1661    return NULL;
1662  }
1663
1664  var=argv[1];
1665   
1666  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1667  if (v) {
1668    value = owl_variable_get_tostring(v);
1669    if (value == NULL)
1670      owl_function_makemsg("%s = <null>", var);
1671    else
1672      owl_function_makemsg("%s = '%s'", var, value);
1673    g_free(value);
1674  } else {
1675    owl_function_makemsg("Unknown variable '%s'.", var);
1676  }
1677  return NULL;
1678}
1679
1680
1681CALLER_OWN char *owl_command_exec(int argc, const char *const *argv, const char *buff)
1682{
1683  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_RETURN);
1684}
1685
1686CALLER_OWN char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
1687{
1688  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_POPUP);
1689}
1690
1691CALLER_OWN char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
1692{
1693  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1694}
1695
1696CALLER_OWN char *owl_command_perl(int argc, const char *const *argv, const char *buff)
1697{
1698  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_RETURN);
1699}
1700
1701CALLER_OWN char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
1702{
1703  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_POPUP);
1704}
1705
1706CALLER_OWN char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
1707{
1708  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1709}
1710
1711CALLER_OWN char *owl_command_multi(int argc, const char *const *argv, const char *buff)
1712{
1713  char *lastrv = NULL, *newbuff;
1714  char **commands;
1715  int  i;
1716  if (argc < 2) {
1717    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1718    return NULL;
1719  }
1720  newbuff = g_strdup(skiptokens(buff, 1));
1721  if (!strcmp(argv[0], "(")) {
1722    for (i=strlen(newbuff)-1; i>=0; i--) {
1723      if (newbuff[i] == ')') {
1724        newbuff[i] = '\0';
1725        break;
1726      } else if (newbuff[i] != ' ') {
1727        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1728        g_free(newbuff);
1729        return NULL;
1730      }
1731    }
1732  }
1733  commands = g_strsplit_set(newbuff, ";", 0);
1734  for (i = 0; commands[i] != NULL; i++) {
1735    g_free(lastrv);
1736    lastrv = owl_function_command(commands[i]);
1737  }
1738  g_free(newbuff);
1739  g_strfreev(commands);
1740  return lastrv;
1741}
1742
1743
1744char *owl_command_alias(int argc, const char *const *argv, const char *buff)
1745{
1746  if (argc < 3) {
1747    owl_function_makemsg("Invalid arguments to 'alias' command.");
1748    return NULL;
1749  }
1750  buff = skiptokens(buff, 2);
1751  owl_function_command_alias(argv[1], buff);
1752  return (NULL);
1753}
1754
1755
1756char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
1757{
1758  owl_keymap *km;
1759  int ret;
1760
1761  if (argc < 5 || strcmp(argv[3], "command")) {
1762    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1763    return NULL;
1764  }
1765  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1766  if (!km) {
1767    owl_function_makemsg("No such keymap '%s'", argv[1]);
1768    return NULL;
1769  }
1770  buff = skiptokens(buff, 4);
1771  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1772  if (ret!=0) {
1773    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1774                         argv[2], argv[1], buff);
1775    return NULL;
1776  }
1777  return NULL;
1778}
1779
1780
1781char *owl_command_unbindkey(int argc, const char *const *argv, const char *buf)
1782{
1783  owl_keymap *km;
1784  int ret;
1785
1786  if (argc < 3) {
1787    owl_function_makemsg("Usage: unbindkey <keymap> <binding>");
1788    return NULL;
1789  }
1790  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1791  if (!km) {
1792    owl_function_makemsg("No such keymap '%s'", argv[1]);
1793    return NULL;
1794  }
1795  ret = owl_keymap_remove_binding(km, argv[2]);
1796  if (ret == -1) {
1797    owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
1798                         argv[2], argv[1]);
1799    return NULL;
1800  } else if (ret == -2) {
1801    owl_function_makemsg("No such binding '%s' in keymap '%s'.",
1802                         argv[2], argv[1]);
1803  }
1804  return NULL;
1805}
1806
1807
1808void owl_command_quit(void)
1809{
1810  owl_function_quit();
1811}
1812
1813char *owl_command_debug(int argc, const char *const *argv, const char *buff)
1814{
1815  if (argc<2) {
1816    owl_function_makemsg("Need at least one argument to debug command");
1817    return(NULL);
1818  }
1819
1820  if (!owl_global_is_debug_fast(&g)) {
1821    owl_function_makemsg("Debugging is not turned on");
1822    return(NULL);
1823  }
1824
1825  owl_function_debugmsg("%s", argv[1]);
1826  return(NULL);
1827}
1828
1829char *owl_command_term(int argc, const char *const *argv, const char *buff)
1830{
1831  if (argc<2) {
1832    owl_function_makemsg("Need at least one argument to the term command");
1833    return(NULL);
1834  }
1835
1836  if (!strcmp(argv[1], "raise")) {
1837    owl_function_xterm_raise();
1838  } else if (!strcmp(argv[1], "deiconify")) {
1839    owl_function_xterm_deiconify();
1840  } else {
1841    owl_function_makemsg("Unknown terminal subcommand");
1842  }
1843  return(NULL);
1844}
1845
1846char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
1847{
1848  if ((argc<2) || (argc>3)) {
1849    owl_function_makemsg("Wrong number of arguments for zlog command");
1850    return(NULL);
1851  }
1852
1853  if (!strcmp(argv[1], "in")) {
1854    if (argc>2) {
1855      owl_global_set_tty(&g, argv[2]);
1856    }
1857    owl_zephyr_zlog_in();
1858  } else if (!strcmp(argv[1], "out")) {
1859    if (argc!=2) {
1860      owl_function_makemsg("Wrong number of arguments for zlog command");
1861      return(NULL);
1862    }
1863    owl_zephyr_zlog_out();
1864  } else {
1865    owl_function_makemsg("Invalid subcommand for zlog");
1866  }
1867  return(NULL);
1868}
1869
1870char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
1871{
1872  const char *class, *instance, *recip="";
1873  int temp=0;
1874  int ret=0;
1875
1876  if (argc < 2) {
1877    owl_function_makemsg("Not enough arguments to the subscribe command");
1878    return(NULL);
1879  }
1880  argc--;
1881  argv++;
1882
1883  if (!strcmp(argv[0], "-t")) {
1884    temp=1;
1885    argc--;
1886    argv++;
1887  }
1888  if (argc < 1) {
1889    owl_function_makemsg("Not enough arguments to the subscribe command");
1890    return(NULL);
1891  }
1892
1893  if (argc > 3) {
1894    owl_function_makemsg("Too many arguments to the subscribe command");
1895    return(NULL);
1896  }
1897
1898  class = argv[0];
1899
1900  if (argc == 1) {
1901    instance = "*";
1902  } else {
1903    instance = argv[1];
1904  }
1905
1906  if (argc <= 2) {
1907    recip="";
1908  } else if (argc==3) {
1909    recip=argv[2];
1910  }
1911
1912  ret = owl_function_subscribe(class, instance, recip);
1913  if (!temp && !ret) {
1914    owl_zephyr_addsub(NULL, class, instance, recip);
1915  }
1916  return(NULL);
1917}
1918
1919
1920char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
1921{
1922  const char *class, *instance, *recip="";
1923  int temp=0;
1924
1925  if (argc < 2) {
1926    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1927    return(NULL);
1928  }
1929  argc--;
1930  argv++;
1931
1932  if (!strcmp(argv[0], "-t")) {
1933    temp=1;
1934    argc--;
1935    argv++;
1936  }
1937  if (argc < 1) {
1938    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1939    return(NULL);
1940  }
1941
1942  if (argc > 3) {
1943    owl_function_makemsg("Too many arguments to the unsubscribe command");
1944    return(NULL);
1945  }
1946
1947  class = argv[0];
1948
1949  if (argc == 1) {
1950    instance = "*";
1951  } else {
1952    instance = argv[1];
1953  }
1954
1955  if (argc <= 2) {
1956    recip="";
1957  } else if (argc==3) {
1958    recip=argv[2];
1959  }
1960
1961  owl_function_unsubscribe(class, instance, recip);
1962  if (!temp) {
1963    owl_zephyr_delsub(NULL, class, instance, recip);
1964  }
1965  return(NULL);
1966}
1967
1968char *owl_command_echo(int argc, const char *const *argv, const char *buff)
1969{
1970  buff = skiptokens(buff, 1);
1971  owl_function_popless_text(buff);
1972  return NULL;
1973}
1974
1975void owl_command_getsubs(void)
1976{
1977  owl_function_getsubs();
1978}
1979
1980void owl_command_status(void)
1981{
1982  owl_function_status();
1983}
1984
1985char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
1986{
1987  owl_zwrite *z;
1988
1989  if (!owl_global_is_havezephyr(&g)) {
1990    owl_function_makemsg("Zephyr is not available");
1991    return(NULL);
1992  }
1993  /* check for a zwrite -m */
1994  z = owl_zwrite_new(argc, argv);
1995  if (!z) {
1996    owl_function_error("Error in zwrite arguments");
1997    return NULL;
1998  }
1999
2000  if (owl_zwrite_is_message_set(z)) {
2001    owl_function_zwrite(z, NULL);
2002    owl_zwrite_delete(z);
2003    return NULL;
2004  }
2005
2006  if (argc < 2) {
2007    owl_zwrite_delete(z);
2008    owl_function_makemsg("Not enough arguments to the zwrite command.");
2009  } else {
2010    owl_function_zwrite_setup(z);
2011  }
2012  return(NULL);
2013}
2014
2015char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
2016{
2017  char *message = NULL;
2018  GString *recip = g_string_new("");
2019  const char *const *myargv;
2020  int myargc;
2021 
2022  if (!owl_global_is_aimloggedin(&g)) {
2023    owl_function_error("You are not logged in to AIM.");
2024    goto err;
2025  }
2026
2027  /* Skip argv[0]. */
2028  myargv = argv+1;
2029  myargc = argc-1;
2030  while (myargc) {
2031    if (!strcmp(myargv[0], "-m")) {
2032      if (myargc <= 1) {
2033        owl_function_error("No message specified.");
2034        goto err;
2035      }
2036      /* Once we have -m, gobble up everything else on the line */
2037      myargv++;
2038      myargc--;
2039      message = g_strjoinv(" ", (char**)myargv);
2040      break;
2041    } else {
2042      /* squish arguments together to make one screenname w/o spaces for now */
2043      g_string_append(recip, myargv[0]);
2044      myargv++;
2045      myargc--;
2046    }
2047  }
2048
2049  if (recip->str[0] == '\0') {
2050    owl_function_error("No recipient specified");
2051    goto err;
2052  }
2053
2054  if (message != NULL)
2055    owl_function_aimwrite(recip->str, message, false);
2056  else
2057    owl_function_aimwrite_setup(recip->str);
2058 err:
2059  g_string_free(recip, true);
2060  g_free(message);
2061  return NULL;
2062}
2063
2064char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
2065{
2066  owl_function_loopwrite_setup();
2067  return(NULL);
2068}
2069
2070char *owl_command_reply(int argc, const char *const *argv, const char *buff)
2071{
2072  int edit=0;
2073 
2074  if (argc>=2 && !strcmp("-e", argv[1])) {
2075    edit=1;
2076    argv++;
2077    argc--;
2078  }
2079
2080  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2081    owl_function_reply(0, !edit);
2082  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2083    owl_function_reply(1, !edit);
2084  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2085    const owl_message *m;
2086    const owl_view    *v;
2087    v = owl_global_get_current_view(&g);   
2088    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2089    if (m) owl_zephyr_zaway(m);
2090  } else {
2091    owl_function_makemsg("Invalid arguments to the reply command.");
2092  }
2093  return NULL;
2094}
2095
2096char *owl_command_filter(int argc, const char *const *argv, const char *buff)
2097{
2098  owl_function_create_filter(argc, argv);
2099  return NULL;
2100}
2101
2102char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
2103{
2104  int auth;
2105 
2106  if (argc<2) {
2107    owl_function_makemsg("Too few arguments for zlocate command");
2108    return NULL;
2109  }
2110
2111  auth=1;
2112  if (!strcmp(argv[1], "-d")) {
2113    if (argc>2) {
2114      auth=0;
2115      argc--;
2116      argv++;
2117    } else {
2118      owl_function_makemsg("Missing arguments for zlocate command");
2119      return NULL;
2120    }
2121  }
2122
2123  argc--;
2124  argv++;
2125  owl_function_zlocate(argc, argv, auth);
2126  return NULL;
2127}
2128
2129
2130/* Backwards compatability has made this kind of complicated:
2131 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2132 * view <filter>
2133 * view -d <expression>
2134 * view --home
2135 */
2136char *owl_command_view(int argc, const char *const *argv, const char *buff)
2137{
2138  /* First take the 'view --home' and 'view -r' cases */
2139  if (argc == 2) {
2140    if (!strcmp(argv[1], "--home")) {
2141      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2142      return(NULL);
2143    } else if (!strcmp(argv[1], "-r")) {
2144      char *foo;
2145      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2146      owl_function_change_currentview_filter(foo);
2147      g_free(foo);
2148      return(NULL);
2149    }
2150  }
2151
2152  /* Now look for 'view <filter>' */
2153  if (argc==2) {
2154    owl_function_change_currentview_filter(argv[1]);
2155    return(NULL);
2156  }
2157
2158  /* Now get 'view -d <expression>' */
2159  if (argc>=3 && !strcmp(argv[1], "-d")) {
2160    const char **myargv;
2161    int i;
2162
2163    /* Allocate one more than argc for the trailing NULL. */
2164    myargv = g_new0(const char*, argc+1);
2165    myargv[0]="";
2166    myargv[1]="owl-dynamic";
2167    for (i=2; i<argc; i++) {
2168      myargv[i]=argv[i];
2169    }
2170    if (owl_function_create_filter(argc, myargv)) {
2171      owl_function_change_currentview_filter("owl-dynamic");
2172    }
2173    g_free(myargv);
2174    return NULL;
2175  }
2176
2177  /* Finally handle the general case */
2178  if (argc<3) {
2179    owl_function_makemsg("Too few arguments to the view command.");
2180    return(NULL);
2181  }
2182  argc--;
2183  argv++;
2184  if (strcmp(argv[0], "-f") &&
2185      strcmp(argv[0], "-d") &&
2186      strcmp(argv[0], "--home") &&
2187      strcmp(argv[0], "-s") &&
2188      strcmp(argv[0], "-r")) {
2189    if (strcmp(argv[0], "main")) {
2190      owl_function_makemsg("No view named '%s'", argv[0]);
2191      return(NULL);
2192    }
2193    argc--;
2194    argv++;
2195  }
2196  while (argc) {
2197    if (!strcmp(argv[0], "-f")) {
2198      if (argc<2) {
2199        owl_function_makemsg("Too few arguments to the view command");
2200        return(NULL);
2201      }
2202      owl_function_change_currentview_filter(argv[1]);
2203      argc-=2;
2204      argv+=2;
2205    } else if (!strcmp(argv[0], "--home")) {
2206      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2207      argc--;
2208      argv++;
2209    } else if (!strcmp(argv[0], "-s")) {
2210      if (argc<2) {
2211        owl_function_makemsg("Too few arguments to the view command");
2212        return(NULL);
2213      }
2214      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2215      argc-=2;
2216      argv+=2;
2217    } else {
2218      owl_function_makemsg("Too few arguments to the view command");
2219      return(NULL);
2220    }
2221   
2222  }
2223  return(NULL);
2224}
2225
2226char *owl_command_show(int argc, const char *const *argv, const char *buff)
2227{
2228  if (argc<2) {
2229    owl_function_help_for_command("show");
2230    return NULL;
2231  }
2232
2233  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2234    if (argc==2) {
2235      owl_function_show_filters();
2236    } else {
2237      owl_function_show_filter(argv[2]);
2238    }
2239  } else if (argc==2 
2240             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2241    owl_function_show_zpunts();
2242  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2243    if (argc==2) {
2244      owl_function_show_commands();
2245    } else {
2246      owl_function_show_command(argv[2]);
2247    }
2248  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2249    if (argc==2) {
2250      owl_function_show_variables();
2251    } else {
2252      owl_function_show_variable(argv[2]);
2253    }
2254  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2255    if (argc==2) {
2256      owl_function_show_keymaps();
2257    } else {
2258      owl_function_show_keymap(argv[2]);
2259    }
2260  } else if (!strcmp(argv[1], "view")) {
2261    if (argc==3) {
2262      owl_function_show_view(argv[2]);
2263    } else {
2264      owl_function_show_view(NULL);
2265    }
2266  } else if (!strcmp(argv[1], "colors")) {
2267    owl_function_show_colors();
2268  } else if (!strcmp(argv[1], "styles")) {
2269    owl_function_show_styles();
2270  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2271    owl_function_getsubs();
2272  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2273    owl_function_show_term();
2274  } else if (!strcmp(argv[1], "version")) {
2275    owl_function_about();
2276  } else if (!strcmp(argv[1], "status")) {
2277    owl_function_status();
2278  } else if (!strcmp(argv[1], "license")) {
2279    owl_function_show_license();
2280  } else if (!strcmp(argv[1], "quickstart")) {
2281    owl_function_show_quickstart();
2282  } else if (!strcmp(argv[1], "startup")) {
2283    const char *filename;
2284   
2285    filename=owl_global_get_startupfile(&g);
2286    owl_function_popless_file(filename);
2287  } else if (!strcmp(argv[1], "errors")) {
2288    owl_function_showerrs();
2289  } else {
2290    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2291    return NULL;
2292  }
2293  return NULL;
2294}
2295
2296char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
2297{
2298  char *filtname;
2299  if (argc!=2) {
2300    owl_function_makemsg("Wrong number of arguments to viewclass command");
2301    return NULL;
2302  }
2303  filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2304  if (filtname) {
2305    owl_function_change_currentview_filter(filtname);
2306    g_free(filtname);
2307  }
2308  return NULL;
2309}
2310
2311char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
2312{
2313  char *filtname;
2314  char *longuser;
2315  if (argc!=2) {
2316    owl_function_makemsg("Wrong number of arguments to viewuser command");
2317    return NULL;
2318  }
2319  longuser = long_zuser(argv[1]);
2320  filtname = owl_function_zuserfilt(longuser);
2321  g_free(longuser);
2322  if (filtname) {
2323    owl_function_change_currentview_filter(filtname);
2324    g_free(filtname);
2325  }
2326  return NULL;
2327}
2328
2329
2330void owl_command_pop_message(void)
2331{
2332  owl_function_curmsg_to_popwin();
2333}
2334
2335char *owl_command_delete(int argc, const char *const *argv, const char *buff)
2336{
2337  int move_after = 1;
2338
2339  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2340    move_after = 0;
2341    argc--; 
2342    argv++;
2343  }
2344
2345  if (argc==1) {
2346    owl_function_deletecur(move_after);
2347    return NULL;
2348  }
2349
2350  if (argc==2 && !strcmp(argv[1], "view")) {
2351    owl_function_delete_curview_msgs(1);
2352    return NULL;
2353  }
2354
2355  if (argc==2 && !strcmp(argv[1], "trash")) {
2356    owl_function_delete_automsgs();
2357    return NULL;
2358  }
2359
2360  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2361    owl_function_delete_by_id(atoi(argv[2]), 1);
2362    return NULL;
2363  }
2364
2365  owl_function_makemsg("Unknown arguments to delete command");
2366  return NULL;
2367}
2368
2369char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff)
2370{
2371  bool exclaim_success = true;
2372
2373  if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) {
2374    exclaim_success = false;
2375    argc--;
2376    argv++;
2377  } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) {
2378    exclaim_success = false;
2379    argc--;
2380  }
2381
2382  if (argc == 1) {
2383    owl_function_delete_and_expunge_cur(exclaim_success);
2384    return NULL;
2385  }
2386
2387  if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2388    owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success);
2389    return NULL;
2390  }
2391
2392  owl_function_makemsg("Unknown arguments to delete-and-expunge command");
2393  return NULL;
2394}
2395
2396char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
2397{
2398  int move_after = 1;
2399
2400  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2401    move_after = 0;
2402    argc--; 
2403    argv++;
2404  }
2405
2406  if (argc==1) {
2407    owl_function_undeletecur(move_after);
2408    return NULL;
2409  }
2410
2411  if (argc==2 && !strcmp(argv[1], "view")) {
2412    owl_function_delete_curview_msgs(0);
2413    return NULL;
2414  }
2415
2416  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2417    owl_function_delete_by_id(atoi(argv[2]), 0);
2418    return NULL;
2419  }
2420
2421  owl_function_makemsg("Unknown arguments to delete command");
2422  return NULL;
2423}
2424
2425void owl_command_beep(void)
2426{
2427  owl_function_beep();
2428}
2429
2430char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
2431{
2432  if (argc < 2 || argc > 3) {
2433    owl_function_makemsg("Wrong number of arguments to colorview command");
2434    return NULL;
2435  }
2436  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2437  return NULL;
2438}
2439
2440char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
2441{
2442  char *filtname;
2443 
2444  if (argc < 3 || argc > 4) {
2445    owl_function_makemsg("Wrong number of arguments to colorclass command");
2446    return NULL;
2447  }
2448
2449  filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2450  if (filtname) {
2451    (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2452    g_free(filtname);
2453  }
2454  return NULL;
2455}
2456
2457char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
2458{
2459  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2460  return NULL;
2461}
2462
2463char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
2464{
2465  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2466  return NULL;
2467}
2468
2469void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
2470{
2471  /* if type==0 then zpunt
2472   * if type==1 then zunpunt
2473   */
2474  const char *class, *inst, *recip;
2475
2476  class="message";
2477  inst="";
2478  recip="*";
2479
2480  if (argc==1) {
2481    /* show current punt filters */
2482    owl_function_show_zpunts();
2483    return;
2484  } else if (argc==2) {
2485    inst=argv[1];
2486  } else if (argc==3) {
2487    class=argv[1];
2488    inst=argv[2];
2489  } else if (argc==4) {
2490    class=argv[1];
2491    inst=argv[2];
2492    recip=argv[3];
2493  } else {
2494    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2495    return;
2496  }
2497
2498  owl_function_zpunt(class, inst, recip, type);
2499  if (type==0) {
2500    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2501  } else if (type==1) {
2502    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2503  }
2504}
2505
2506char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
2507{
2508  if (argc == 1) {
2509    owl_function_smartzpunt(0);
2510  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2511    owl_function_smartzpunt(1);
2512  } else {
2513    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2514  }
2515  return NULL;
2516}
2517
2518char *owl_command_punt(int argc, const char *const *argv, const char *buff)
2519{
2520  owl_command_punt_unpunt(argc, argv, buff, 0);
2521  return NULL;
2522}
2523
2524char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
2525{
2526  owl_command_punt_unpunt(argc, argv, buff, 1);
2527  return NULL;
2528}
2529
2530void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
2531{
2532  GPtrArray * fl;
2533  int i;
2534
2535  fl = owl_global_get_puntlist(&g);
2536  if(argc == 1) {
2537    owl_function_show_zpunts();
2538  } else if(argc == 2) {
2539    /* Handle :unpunt <number> */
2540    if (unpunt && (i = atoi(argv[1])) > 0) {
2541      i--;      /* Accept 1-based indexing */
2542      if (i < fl->len) {
2543        owl_filter_delete(g_ptr_array_remove_index(fl, i));
2544        return;
2545      } else {
2546        owl_function_makemsg("No such filter number: %d.", i+1);
2547      }
2548    }
2549    const char *filter[] = {"filter", argv[1]};
2550    owl_function_punt(2, filter, unpunt);
2551  } else {
2552    /* Pass in argv[1]..argv[argc-1]. */
2553    owl_function_punt(argc - 1, argv + 1, unpunt);
2554  }
2555}
2556
2557
2558char *owl_command_getview(int argc, const char *const *argv, const char *buff)
2559{
2560  const char *filtname;
2561  if (argc != 1) {
2562    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2563    return NULL;
2564  }
2565  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2566  if (filtname) return g_strdup(filtname);
2567  return NULL;
2568}
2569
2570CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
2571{
2572  const owl_variable *v;
2573  if (argc != 2) {
2574    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2575    return NULL;
2576  }
2577  v = owl_variable_get_var(owl_global_get_vardict(&g), argv[1]);
2578  if (v == NULL) return NULL;
2579  return owl_variable_get_tostring(v);
2580}
2581
2582char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
2583{
2584  const owl_filter *f;
2585  if (argc != 2) {
2586    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2587    return NULL;
2588  }
2589  f = owl_global_get_filter(&g, argv[1]);
2590  if (!f) {
2591    return NULL;
2592  }
2593  return owl_filter_print(f);
2594}
2595
2596char *owl_command_search(int argc, const char *const *argv, const char *buff)
2597{
2598  int direction;
2599  const char *buffstart;
2600
2601  direction=OWL_DIRECTION_DOWNWARDS;
2602  buffstart=skiptokens(buff, 1);
2603  if (argc>1 && !strcmp(argv[1], "-r")) {
2604    direction=OWL_DIRECTION_UPWARDS;
2605    buffstart=skiptokens(buff, 2);
2606  }
2607   
2608  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2609    /* When continuing a search, don't consider the current message. */
2610    owl_function_search_helper(false, direction);
2611  } else {
2612    owl_function_set_search(buffstart);
2613    owl_function_search_helper(true, direction);
2614  }
2615 
2616  return(NULL);
2617}
2618
2619char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
2620{
2621  const char *buffstart;
2622
2623  buffstart=skiptokens(buff, 1);
2624  owl_function_set_search(*buffstart ? buffstart : NULL);
2625 
2626  return(NULL);
2627}
2628
2629char *owl_command_aimlogin(int argc, const char *const *argv, const char *buff)
2630{
2631  if ((argc<2) || (argc>3)) {
2632    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2633    return(NULL);
2634  }
2635
2636  /* if we get two arguments, ask for the password */
2637  if (argc==2) {
2638    owl_editwin *e = owl_function_start_password("AIM Password: ");
2639    owl_editwin_set_cbdata(e, g_strdup(argv[1]), g_free);
2640    owl_editwin_set_callback(e, owl_callback_aimlogin);
2641    return(NULL);
2642  } else {
2643    owl_function_aimlogin(argv[1], argv[2]);
2644  }
2645
2646  /* this is a test */
2647  return(NULL);
2648}
2649
2650char *owl_command_aimlogout(int argc, const char *const *argv, const char *buff)
2651{
2652  /* clear the buddylist */
2653  owl_buddylist_clear(owl_global_get_buddylist(&g));
2654
2655  owl_aim_logout();
2656  return(NULL);
2657}
2658
2659CALLER_OWN char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
2660{
2661  const char *stylename;
2662  if (argc != 1) {
2663    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2664    return NULL;
2665  }
2666  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2667  if (stylename) return g_strdup(stylename);
2668  return NULL;
2669}
2670
2671char *owl_command_error(int argc, const char *const *argv, const char *buff)
2672{
2673    buff = skiptokens(buff, 1);
2674    owl_function_error("%s", buff);
2675    return NULL;
2676}
2677
2678char *owl_command_message(int argc, const char *const *argv, const char *buff)
2679{
2680    buff = skiptokens(buff, 1);
2681    owl_function_makemsg("%s", buff);
2682    return NULL;
2683}
2684
2685char *owl_command_add_cmd_history(int argc, const char *const *argv, const char *buff)
2686{
2687  owl_history *hist;
2688  const char *ptr;
2689
2690  if (argc < 2) {
2691    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
2692    return NULL;
2693  }
2694
2695  ptr = skiptokens(buff, 1);
2696  hist = owl_global_get_cmd_history(&g);
2697  owl_history_store(hist, ptr, false);
2698  /* owl_function_makemsg("History '%s' stored successfully", ptr+1); */
2699  return NULL;
2700}
2701
2702CALLER_OWN char *owl_command_with_history(int argc, const char *const *argv, const char *buff)
2703{
2704  owl_history *hist;
2705  const char *ptr;
2706
2707  if (argc < 2) {
2708    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
2709    return NULL;
2710  }
2711
2712  ptr = skiptokens(buff, 1);
2713  if (!ptr) {
2714    owl_function_makemsg("Parse error finding command");
2715    return NULL;
2716  }
2717
2718  hist = owl_global_get_cmd_history(&g);
2719  owl_history_store(hist, ptr, false);
2720  return owl_function_command(ptr);
2721}
2722
2723void owl_command_yes(void)
2724{
2725  owl_message *m;
2726  const owl_view *v;
2727  const char *cmd;
2728
2729  v = owl_global_get_current_view(&g);
2730
2731  /* bail if there's no current message */
2732  if (owl_view_get_size(v) < 1) {
2733    owl_function_error("No current message.");
2734    return;
2735  }
2736
2737  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2738  if(!owl_message_is_question(m)) {
2739    owl_function_error("That message isn't a question.");
2740    return;
2741  }
2742  if(owl_message_is_answered(m)) {
2743    owl_function_error("You already answered that question.");
2744    return;
2745  }
2746  cmd = owl_message_get_attribute_value(m, "yescommand");
2747  if(!cmd) {
2748    owl_function_error("No 'yes' command!");
2749    return;
2750  }
2751
2752  owl_function_command_norv(cmd);
2753  owl_message_set_isanswered(m);
2754  return;
2755}
2756
2757void owl_command_no(void)
2758{
2759  owl_message *m;
2760  const owl_view *v;
2761  const char *cmd;
2762
2763  v = owl_global_get_current_view(&g);
2764
2765  /* bail if there's no current message */
2766  if (owl_view_get_size(v) < 1) {
2767    owl_function_error("No current message.");
2768    return;
2769  }
2770
2771  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2772  if(!owl_message_is_question(m)) {
2773    owl_function_error("That message isn't a question.");
2774    return;
2775  }
2776  if(owl_message_is_answered(m)) {
2777    owl_function_error("You already answered that question.");
2778    return;
2779  }
2780  cmd = owl_message_get_attribute_value(m, "nocommand");
2781  if(!cmd) {
2782    owl_function_error("No 'no' command!");
2783    return;
2784  }
2785
2786  owl_function_command_norv(cmd);
2787  owl_message_set_isanswered(m);
2788  return;
2789}
2790
2791/*********************************************************************/
2792/************************** EDIT SPECIFIC ****************************/
2793/*********************************************************************/
2794
2795void owl_command_edit_cancel(owl_editwin *e)
2796{
2797  owl_history *hist;
2798
2799  owl_function_makemsg("Command cancelled.");
2800
2801  hist = owl_editwin_get_history(e);
2802  if (hist)
2803    owl_history_store(hist, owl_editwin_get_text(e), false);
2804
2805  /* Take a reference to the editwin, so that it survives the pop
2806   * context. TODO: We should perhaps refcount or otherwise protect
2807   * the context so that, even if a command pops a context, the
2808   * context itself will last until the command returns. */
2809  owl_editwin_ref(e);
2810  owl_global_pop_context(&g);
2811
2812  owl_editwin_do_callback(e, false);
2813  owl_editwin_unref(e);
2814}
2815
2816void owl_command_edit_history_prev(owl_editwin *e)
2817{
2818  owl_history *hist;
2819  const char *ptr;
2820
2821  hist=owl_editwin_get_history(e);
2822  if (!hist)
2823    return;
2824  if (!owl_history_is_touched(hist))
2825    owl_history_store(hist, owl_editwin_get_text(e), true);
2826  ptr=owl_history_get_prev(hist);
2827  if (ptr) {
2828    owl_editwin_clear(e);
2829    owl_editwin_insert_string(e, ptr);
2830  } else {
2831    owl_function_beep();
2832  }
2833}
2834
2835void owl_command_edit_history_next(owl_editwin *e)
2836{
2837  owl_history *hist;
2838  const char *ptr;
2839
2840  hist=owl_editwin_get_history(e);
2841  if (!hist)
2842    return;
2843  ptr=owl_history_get_next(hist);
2844  if (ptr) {
2845    owl_editwin_clear(e);
2846    owl_editwin_insert_string(e, ptr);
2847  } else {
2848    owl_function_beep();
2849  }
2850}
2851
2852char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
2853{
2854  buff = skiptokens(buff, 1);
2855  owl_editwin_insert_string(e, buff);
2856  return NULL;
2857}
2858
2859void owl_command_edit_done(owl_editwin *e)
2860{
2861  owl_history *hist=owl_editwin_get_history(e);
2862
2863  if (hist)
2864    owl_history_store(hist, owl_editwin_get_text(e), false);
2865
2866  /* Take a reference to the editwin, so that it survives the pop
2867   * context. TODO: We should perhaps refcount or otherwise protect
2868   * the context so that, even if a command pops a context, the
2869   * context itself will last until the command returns. */
2870  owl_editwin_ref(e);
2871  owl_global_pop_context(&g);
2872
2873  owl_editwin_do_callback(e, true);
2874  owl_editwin_unref(e);
2875}
2876
2877void owl_command_edit_done_or_delete(owl_editwin *e)
2878{
2879  if (owl_editwin_is_at_end(e)) {
2880    owl_command_edit_done(e);
2881  } else {
2882    owl_editwin_delete_char(e);
2883  }
2884}
2885
2886
2887/*********************************************************************/
2888/*********************** POPLESS SPECIFIC ****************************/
2889/*********************************************************************/
2890
2891void owl_command_popless_quit(owl_viewwin *vw)
2892{
2893  owl_popwin *pw;
2894  pw = owl_global_get_popwin(&g);
2895  owl_global_set_popwin(&g, NULL);
2896  /* Kind of a hack, but you can only have one active viewwin right
2897   * now anyway. */
2898  if (vw == owl_global_get_viewwin(&g))
2899    owl_global_set_viewwin(&g, NULL);
2900  owl_viewwin_delete(vw);
2901  owl_popwin_delete(pw);
2902  owl_global_pop_context(&g);
2903}
Note: See TracBrowser for help on using the repository browser.