source: commands.c @ ec36247

Last change on this file since ec36247 was ec36247, checked in by Jason Gross <jasongross9@gmail.com>, 7 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: 87.2 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: smartfilter, smartnarrow, 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, smartfilter, smartnarrow, 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.\n\n"
609              "SEE ALSO: filter, smartfilter, view, viewclass, viewuser\n"),
610
611  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
612              "returns the name of a filter based on the current message",
613              "smartfilter [-i | --instance]",
614              "If the curmsg is a personal message, the filter is\n"
615              "   the conversation with that user.\n"
616              "If the curmsg is a <MESSAGE, foo, *>\n"
617              "   message, the filter is to that instance.\n"
618              "If the curmsg is a class message, the filter is that class.\n"
619              "If the curmsg is a class message and '-i' is specified\n"
620              "    the filter is to that class and instance.\n\n"
621              "SEE ALSO: filter, smartnarrow, view, viewclass, viewuser\n"),
622
623  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
624              "view messages matching a particular class",
625              "viewclass <class>",
626              "The viewclass command will automatically create a filter\n"
627              "matching the specified class and switch the current view\n"
628              "to it.\n\n"
629              "SEE ALSO: filter, smartfilter, smartnarrow, view, viewuser\n"),
630  OWLCMD_ALIAS("vc", "viewclass"),
631
632  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
633              "view messages matching a particular user",
634              "viewuser <user>",
635              "The viewuser command will automatically create a filter\n"
636              "matching the specified user and switch the current\n"
637              "view to it.\n\n"
638              "SEE ALSO: filter, smartfilter, smartnarrow, view, viewclass\n"),
639  OWLCMD_ALIAS("vu", "viewuser"),
640  OWLCMD_ALIAS("viewperson", "viewuser"),
641  OWLCMD_ALIAS("vp", "viewuser"),
642
643  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
644              "show information",
645              "show colors\n"
646              "show commands\n"
647              "show command <command>\n"
648              "show errors\n"
649              "show filters\n"
650              "show filter <filter>\n"
651              "show keymaps\n"
652              "show keymap <keymap>\n"
653              "show license\n"
654              "show quickstart\n"
655              "show startup\n"
656              "show status\n"
657              "show styles\n"
658              "show subscriptions / show subs\n"
659              "show terminal\n"
660              "show variables\n"
661              "show variable <variable>\n"
662              "show version\n"
663              "show view [<view>]\n"
664              "show zpunts\n",
665
666              "Show colors will display a list of valid colors for the\n"
667              "     terminal."
668              "Show filters will list the names of all filters.\n"
669              "Show filter <filter> will show the definition of a particular\n"
670              "     filter.\n\n"
671              "Show startup will display the custom startup config\n\n"
672              "Show zpunts will show the active zpunt filters.\n\n"
673              "Show keymaps will list the names of all keymaps.\n"
674              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
675              "Show commands will list the names of all keymaps.\n"
676              "Show command <command> will provide information about a command.\n\n"
677              "Show styles will list the names of all styles available\n"
678              "for formatting messages.\n\n"
679              "Show variables will list the names of all variables.\n\n"
680              "Show errors will show a list of errors encountered by BarnOwl.\n\n"
681              "SEE ALSO: filter, view, alias, bindkey, help\n"),
682 
683  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
684              "mark a message for deletion",
685              "delete [ -id msgid ] [ --no-move ]\n"
686              "delete view\n"
687              "delete trash",
688              "If no message id is specified the current message is marked\n"
689              "for deletion.  Otherwise the message with the given message\n"
690              "id is marked for deletion.\n"
691              "If '--no-move' is specified, don't move after deletion.\n"
692              "If 'trash' is specified, deletes all trash/auto messages\n"
693              "in the current view.\n"
694              "If 'view' is specified, deletes all messages in the\n"
695              "current view.\n"),
696  OWLCMD_ALIAS("del", "delete"),
697
698  OWLCMD_ARGS("delete-and-expunge", owl_command_delete_and_expunge, OWL_CTX_INTERACTIVE,
699              "delete a message",
700              "delete-and-expunge [-id msgid] [-q | --quiet]",
701              "If no message id is specified the current message is deleted.\n"
702              "Otherwise the message with the given message id is deleted.\n"
703              "If --quiet is specified, then there is no message displayed on\n"
704              "success.\n"),
705  OWLCMD_ALIAS("delx", "delete-and-expunge"),
706
707  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
708              "unmark a message for deletion",
709              "undelete [ -id msgid ] [ --no-move ]\n"
710              "undelete view",
711              "If no message id is specified the current message is\n"
712              "unmarked for deletion.  Otherwise the message with the\n"
713              "given message id is unmarked for deletion.\n"
714              "If '--no-move' is specified, don't move after deletion.\n"
715              "If 'view' is specified, undeletes all messages\n"
716              "in the current view.\n"),
717  OWLCMD_ALIAS("undel", "undelete"),
718
719  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
720              "ring the terminal bell",
721              "beep",
722              "Beep will ring the terminal bell.\n"
723              "If the variable 'bell' has been\n"
724              "set to 'off' this command does nothing.\n"),
725
726  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
727              "prints a message into the debug log",
728              "debug <message>", ""),
729
730  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
731              "returns the name of the filter for the current view",
732              "", ""),
733
734  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
735              "returns the value of a variable",
736              "getvar <varname>", ""),
737
738  OWLCMD_ARGS("getfilter", owl_command_getfilter, OWL_CTX_INTERACTIVE,
739              "returns the definition of a filter",
740              "getfilter <filtername>", ""),
741
742  OWLCMD_ARGS("getstyle", owl_command_getstyle, OWL_CTX_INTERACTIVE,
743              "returns the name of the style for the current view",
744              "", ""),
745
746  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
747              "search messages for a particular string",
748              "search [-r] [<string>]",
749              "The search command will find messages that contain the\n"
750              "specified string and move the cursor there.  If no string\n"
751              "argument is supplied then the previous one is used.  By\n"
752              "default searches are done forwards; if -r is used the search\n"
753              "is performed backwards"),
754
755  OWLCMD_ARGS("setsearch", owl_command_setsearch, OWL_CTX_INTERACTIVE,
756              "set the search highlight string without searching",
757              "setsearch <string>",
758              "The setsearch command highlights all occurrences of its\n"
759          "argument and makes it the default argument for future\n"
760          "search commands, but does not move the cursor.  With\n"
761          "no argument, it makes search highlighting inactive."),
762
763  OWLCMD_ARGS("aimlogin", owl_command_aimlogin, OWL_CTX_ANY,
764              "login to an AIM account",
765              "aimlogin <screenname> [<password>]\n",
766              ""),
767
768  OWLCMD_ARGS("aimlogout", owl_command_aimlogout, OWL_CTX_ANY,
769              "logout from AIM",
770              "aimlogout\n",
771              ""),
772
773  OWLCMD_ARGS("error", owl_command_error, OWL_CTX_ANY,
774              "Display an error message",
775              "error <message>",
776              ""),
777
778  OWLCMD_ARGS("message", owl_command_message, OWL_CTX_ANY,
779              "Display an informative message",
780              "message <message>",
781              ""),
782
783  OWLCMD_ARGS("add-cmd-history", owl_command_add_cmd_history, OWL_CTX_ANY,
784              "Add a command to the history",
785              "add-cmd-history <cmd>",
786              ""),
787
788  OWLCMD_ARGS("with-history", owl_command_with_history, OWL_CTX_ANY,
789              "Run a command and store it into the history",
790              "with-history <cmd>",
791              ""),
792
793  OWLCMD_VOID("yes", owl_command_yes, OWL_CTX_RECV,
794              "Answer yes to a question",
795              "yes",
796              ""),
797
798  OWLCMD_VOID("no", owl_command_no, OWL_CTX_RECV,
799              "Answer no to a question",
800              "no",
801              ""),
802
803  /****************************************************************/
804  /************************* EDIT-SPECIFIC ************************/
805  /****************************************************************/
806
807  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
808                  OWL_CTX_EDIT,
809                  "moves cursor forward a word",
810                  "", ""),
811
812  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
813                  OWL_CTX_EDIT,
814                  "moves cursor backwards a word",
815                  "", ""),
816
817  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
818                  OWL_CTX_EDIT,
819                  "moves cursor to the top left (start) of the buffer",
820                  "", ""),
821
822  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
823                  OWL_CTX_EDIT,
824                  "moves cursor to the bottom right (end) of the buffer",
825                  "", ""),
826
827  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
828                  OWL_CTX_EDIT,
829                  "moves cursor to the end of the line",
830                  "", ""),
831
832  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
833                  OWL_CTX_EDIT,
834                  "moves cursor to the beginning of the line",
835                  "", ""),
836
837  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
838                  OWL_CTX_EDIT,
839                  "moves the cursor left by a character",
840                  "", ""),
841
842  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
843                  OWL_CTX_EDIT,
844                  "moves the cursor right by a character",
845                  "", ""),
846
847  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
848                  OWL_CTX_EDIT,
849                  "deletes the word to the right of the cursor",
850                  "", ""),
851
852  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
853                  OWL_CTX_EDIT,
854                  "deletes the word to the left of the cursor",
855                  "", ""),
856
857  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
858                  OWL_CTX_EDIT,
859                  "deletes the character to the left of the cursor",
860                  "", ""),
861
862  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
863                  OWL_CTX_EDIT,
864                  "deletes the character to the right of the cursor",
865                  "", ""),
866
867  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
868                  OWL_CTX_EDIT,
869                  "deletes from the cursor to the end of the line",
870                  "", ""),
871
872  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
873                  OWL_CTX_EDIT,
874                  "deletes all of the contents of the buffer",
875                  "", ""),
876
877  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
878                  OWL_CTX_EDIT,
879                  "Interchange characters around point, moving forward one character.",
880                  "", ""),
881
882  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
883                  OWL_CTX_EDIT,
884                  "fills the current paragraph to line-wrap well",
885                  "", ""),
886
887  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
888                  OWL_CTX_EDIT,
889                  "recenters the buffer",
890                  "", ""),
891
892  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
893                  OWL_CTX_EDIT,
894                  "inserts text into the buffer",
895                  "edit:insert-text <text>", ""),
896
897  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
898                  OWL_CTX_EDIT,
899                  "cancels the current command",
900                  "", ""),
901
902  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
903                  OWL_CTX_EDIT,
904                  "replaces the text with the next history",
905                  "", ""),
906
907  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
908                  OWL_CTX_EDIT,
909                  "replaces the text with the previous history",
910                  "", ""),
911
912  OWLCMD_VOID_CTX("edit:set-mark", owl_editwin_set_mark,
913                  OWL_CTX_EDIT,
914                  "sets the mark",
915                  "", ""),
916
917  OWLCMD_VOID_CTX("edit:exchange-point-and-mark", owl_editwin_exchange_point_and_mark,
918                  OWL_CTX_EDIT,
919                  "exchanges the point and the mark",
920                  "", ""),
921
922  OWLCMD_VOID_CTX("edit:copy-region-as-kill", owl_editwin_copy_region_as_kill,
923                  OWL_CTX_EDIT,
924                  "copy the text between the point and the mark",
925                  "", ""),
926
927  OWLCMD_VOID_CTX("edit:kill-region", owl_editwin_kill_region,
928                  OWL_CTX_EDIT,
929                  "kill text between the point and the mark",
930                  "", ""),
931
932  OWLCMD_VOID_CTX("edit:yank", owl_editwin_yank,
933                  OWL_CTX_EDIT,
934                  "insert the current text from the kill buffer",
935                  "", ""),
936
937  OWLCMD_ALIAS   ("editline:done", "edit:done"),
938  OWLCMD_ALIAS   ("editresponse:done", "edit:done"),
939
940  OWLCMD_VOID_CTX("edit:move-up-line", owl_editwin_key_up, 
941                  OWL_CTX_EDITMULTI,
942                  "moves the cursor up one line",
943                  "", ""),
944
945  OWLCMD_VOID_CTX("edit:move-down-line", owl_editwin_key_down, 
946                  OWL_CTX_EDITMULTI,
947                  "moves the cursor down one line",
948                  "", ""),
949
950  OWLCMD_VOID_CTX("edit:done", owl_command_edit_done, 
951                  OWL_CTX_EDIT,
952                  "Finishes entering text in the editwin.",
953                  "", ""),
954
955  OWLCMD_VOID_CTX("edit:done-or-delete", owl_command_edit_done_or_delete, 
956                  OWL_CTX_EDITMULTI,
957                  "completes the command, but only if at end of message",
958                  "", 
959                  "If only whitespace is to the right of the cursor,\n"
960                  "runs 'edit:done'.\n"\
961                  "Otherwise runs 'edit:delete-next-char'\n"),
962
963  OWLCMD_VOID_CTX("edit:forward-paragraph", owl_editwin_forward_paragraph,
964                  OWL_CTX_EDITMULTI,
965                  "Move forward to end of paragraph.",
966                  "",
967                  "Move the point to the end of the current paragraph"),
968
969  OWLCMD_VOID_CTX("edit:backward-paragraph", owl_editwin_backward_paragraph,
970                  OWL_CTX_EDITMULTI,
971                  "Move backward to the start of paragraph.",
972                  "",
973                  "Move the point to the start of the current paragraph"),
974
975  /****************************************************************/
976  /********************** POPLESS-SPECIFIC ************************/
977  /****************************************************************/
978
979  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
980                  OWL_CTX_POPLESS,
981                  "scrolls down one page",
982                  "", ""),
983
984  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
985                  OWL_CTX_POPLESS,
986                  "scrolls down one line",
987                  "", ""),
988
989  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
990                  OWL_CTX_POPLESS,
991                  "scrolls up one page",
992                  "", ""),
993
994  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
995                  OWL_CTX_POPLESS,
996                  "scrolls up one line",
997                  "", ""),
998
999  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
1000                  OWL_CTX_POPLESS,
1001                  "scrolls to the top of the buffer",
1002                  "", ""),
1003
1004  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
1005                  OWL_CTX_POPLESS,
1006                  "scrolls to the bottom of the buffer",
1007                  "", ""),
1008
1009  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
1010                  OWL_CTX_POPLESS,
1011                  "scrolls right in the buffer",
1012                  "popless:scroll-right <num-chars>", ""),
1013
1014  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
1015                  OWL_CTX_POPLESS,
1016                  "scrolls left in the buffer",
1017                  "popless:scroll-left <num-chars>", ""),
1018
1019  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
1020                  OWL_CTX_POPLESS,
1021                  "exits the popless window",
1022                  "", ""),
1023
1024  OWLCMD_ARGS_CTX("popless:start-command", owl_viewwin_start_command,
1025                  OWL_CTX_POPLESS,
1026                  "starts a command line in the popless",
1027                  "popless:start-command [initial-value]",
1028                  "Initializes the command field to initial-value"),
1029
1030  OWLCMD_ARGS_CTX("popless:search", owl_viewwin_command_search, OWL_CTX_POPLESS,
1031                  "search lines for a particular string",
1032                  "popless:search [-r] [<string>]",
1033                  "The popless:search command will find lines that contain the\n"
1034                  "specified string and scroll the popwin there.  If no string\n"
1035                  "argument is supplied then the previous one is used.  By\n"
1036                  "default searches are done forwards; if -r is used the search\n"
1037                  "is performed backwards"),
1038
1039  OWLCMD_ARGS_CTX("popless:start-search", owl_viewwin_command_start_search, OWL_CTX_POPLESS,
1040                  "starts a command line to search for particular string",
1041                  "popless:start-search [-r] [initial-value]",
1042                  "Initializes the command-line to search for initial-value. If\n"
1043                  "-r is used, the search will be performed backwards.\n\n"
1044                  "SEE ALSO: popless:search"),
1045
1046  OWLCMD_ALIAS("webzephyr", "zwrite " OWL_WEBZEPHYR_PRINCIPAL " -c " OWL_WEBZEPHYR_CLASS " -i"),
1047
1048  /* This line MUST be last! */
1049  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1050
1051  };
1052
1053  owl_cmddict_add_from_list(cd, commands_to_init);
1054  owl_cmd *cmd;
1055  for (cmd = commands_to_init; cmd->name != NULL; cmd++)
1056    owl_cmd_cleanup(cmd);
1057}
1058
1059void owl_command_info(void)
1060{
1061  owl_function_info();
1062}
1063
1064void owl_command_nop(void)
1065{
1066}
1067
1068char *owl_command_help(int argc, const char *const *argv, const char *buff)
1069{
1070  if (argc!=2) {
1071    owl_help();
1072    return NULL;
1073  }
1074 
1075  owl_function_help_for_command(argv[1]);
1076  return NULL;
1077}
1078
1079char *owl_command_zlist(int argc, const char *const *argv, const char *buff)
1080{
1081  const char *file=NULL;
1082
1083  argc--;
1084  argv++;
1085  while (argc) {
1086    if (!strcmp(argv[0], "-f")) {
1087      if (argc==1) {
1088        owl_function_makemsg("zlist: -f needs an argument");
1089        return(NULL);
1090      }
1091      file=argv[1];
1092      argc-=2;
1093      argv+=2;
1094    } else {
1095      owl_function_makemsg("zlist: unknown argument");
1096      return(NULL);
1097    }
1098  }
1099  owl_function_buddylist(0, 1, file);
1100  return(NULL);
1101}
1102
1103void owl_command_alist(void)
1104{
1105  owl_function_buddylist(1, 0, NULL);
1106}
1107
1108void owl_command_blist(void)
1109{
1110  owl_function_buddylist(1, 1, NULL);
1111}
1112
1113void owl_command_toggleoneline(void)
1114{
1115  owl_function_toggleoneline();
1116}
1117
1118void owl_command_about(void)
1119{
1120  owl_function_about();
1121}
1122
1123void owl_command_version(void)
1124{
1125  owl_function_makemsg("BarnOwl version %s", version);
1126}
1127
1128char *owl_command_aim(int argc, const char *const *argv, const char *buff)
1129{
1130  if (argc<2) {
1131    owl_function_makemsg("not enough arguments to aim command");
1132    return(NULL);
1133  }
1134
1135  if (!strcmp(argv[1], "search")) {
1136    if (argc!=3) {
1137      owl_function_makemsg("not enough arguments to aim search command");
1138      return(NULL);
1139    }
1140    owl_aim_search(argv[2]);
1141  } else {
1142    owl_function_makemsg("unknown subcommand '%s' for aim command", argv[1]);
1143    return(NULL);
1144  }
1145  return(NULL);
1146}
1147
1148char *owl_command_addbuddy(int argc, const char *const *argv, const char *buff)
1149{
1150  if (argc!=3) {
1151    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1152    return(NULL);
1153  }
1154
1155  if (!strcasecmp(argv[1], "aim")) {
1156    if (!owl_global_is_aimloggedin(&g)) {
1157      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
1158      return(NULL);
1159    }
1160    /*
1161    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
1162    return(NULL);
1163    */
1164    owl_aim_addbuddy(argv[2]);
1165    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1166  } else if (!strcasecmp(argv[1], "zephyr")) {
1167    owl_zephyr_addbuddy(argv[2]);
1168    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1169  } else {
1170    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1171  }
1172
1173  return(NULL);
1174}
1175
1176char *owl_command_delbuddy(int argc, const char *const *argv, const char *buff)
1177{
1178  if (argc!=3) {
1179    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1180    return(NULL);
1181  }
1182
1183  if (!strcasecmp(argv[1], "aim")) {
1184    if (!owl_global_is_aimloggedin(&g)) {
1185      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
1186      return(NULL);
1187    }
1188    owl_aim_delbuddy(argv[2]);
1189    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1190  } else if (!strcasecmp(argv[1], "zephyr")) {
1191    owl_zephyr_delbuddy(argv[2]);
1192    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1193  } else {
1194    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1195  }
1196
1197  return(NULL);
1198}
1199
1200char *owl_command_join(int argc, const char *const *argv, const char *buff)
1201{
1202  if (argc!=3 && argc!=4) {
1203    owl_function_makemsg("usage: join <protocol> <buddyname> [exchange]");
1204    return(NULL);
1205  }
1206
1207  if (!strcasecmp(argv[1], "aim")) {
1208    if (!owl_global_is_aimloggedin(&g)) {
1209      owl_function_makemsg("join aim: You must be logged into aim to use this command.");
1210      return(NULL);
1211    }
1212    if (argc==3) {
1213      owl_aim_chat_join(argv[2], 4);
1214    } else {
1215      owl_aim_chat_join(argv[2], atoi(argv[3]));
1216    }
1217    /* owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g)); */
1218  } else {
1219    owl_function_makemsg("join: currently the only supported protocol is 'aim'");
1220  }
1221  return(NULL);
1222}
1223
1224char *owl_command_startup(int argc, const char *const *argv, const char *buff)
1225{
1226  const char *ptr;
1227
1228  if (argc<2) {
1229    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1230    return(NULL);
1231  }
1232
1233  ptr = skiptokens(buff, 1);
1234
1235  owl_function_command_norv(ptr);
1236  owl_function_addstartup(ptr);
1237
1238  return(NULL);
1239}
1240
1241char *owl_command_unstartup(int argc, const char *const *argv, const char *buff)
1242{
1243  const char *ptr;
1244
1245  if (argc<2) {
1246    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1247    return(NULL);
1248  }
1249
1250  ptr = skiptokens(buff, 1);
1251
1252  owl_function_delstartup(ptr);
1253
1254  return(NULL);
1255}
1256
1257char *owl_command_dump(int argc, const char *const *argv, const char *buff)
1258{
1259  char *filename;
1260 
1261  if (argc!=2) {
1262    owl_function_makemsg("usage: dump <filename>");
1263    return(NULL);
1264  }
1265  filename=owl_util_makepath(argv[1]);
1266  owl_function_dump(filename);
1267  g_free(filename);
1268  return(NULL);
1269}
1270
1271char *owl_command_source(int argc, const char *const *argv, const char *buff)
1272{
1273  if (argc!=2) {
1274    owl_function_makemsg("usage: source <filename>");
1275    return(NULL);
1276  }
1277
1278  owl_function_source(argv[1]);
1279  return(NULL);
1280}
1281
1282char *owl_command_next(int argc, const char *const *argv, const char *buff)
1283{
1284  char *filter=NULL;
1285  int skip_deleted=0, last_if_none=0;
1286  while (argc>1) {
1287    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1288      skip_deleted=1;
1289      argc-=1; argv+=1; 
1290    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1291      last_if_none=1;
1292      argc-=1; argv+=1; 
1293    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1294      filter = g_strdup(argv[2]);
1295      argc-=2; argv+=2; 
1296    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1297      filter = owl_function_smartfilter(0, 0);
1298      argc-=2; argv+=2; 
1299    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1300      filter = owl_function_smartfilter(1, 0);
1301      argc-=2; argv+=2; 
1302    } else {
1303      owl_function_makemsg("Invalid arguments to command 'next'.");
1304      return(NULL);
1305    }
1306  }
1307  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1308  g_free(filter);
1309  return(NULL);
1310}
1311
1312char *owl_command_prev(int argc, const char *const *argv, const char *buff)
1313{
1314  char *filter=NULL;
1315  int skip_deleted=0, first_if_none=0;
1316  while (argc>1) {
1317    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1318      skip_deleted=1;
1319      argc-=1; argv+=1; 
1320    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1321      first_if_none=1;
1322      argc-=1; argv+=1; 
1323    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1324      filter = g_strdup(argv[2]);
1325      argc-=2; argv+=2; 
1326    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1327      filter = owl_function_smartfilter(0, 0);
1328      argc-=2; argv+=2; 
1329    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1330      filter = owl_function_smartfilter(1, 0);
1331      argc-=2; argv+=2; 
1332   } else {
1333      owl_function_makemsg("Invalid arguments to command 'prev'.");
1334      return(NULL);
1335    }
1336  }
1337  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1338  g_free(filter);
1339  return(NULL);
1340}
1341
1342char *owl_command_smartnarrow(int argc, const char *const *argv, const char *buff)
1343{
1344  char *filtname = NULL;
1345
1346  char opt;
1347  int instance = 0, related = 0, i;
1348  const char **tmp_argv = g_new(const char *, argc);
1349
1350  static const struct option options[] = {
1351    {"instance", 0, 0, 'i'},
1352    {"related",  0, 0, 'r'},
1353    {NULL,       0, 0, 0}};
1354
1355  for (i = 0; i < argc; i++)
1356    tmp_argv[i] = argv[i];
1357
1358  optind = 0;
1359  while ((opt = getopt_long(argc, (char **)tmp_argv, "ir", options, NULL)) != -1) {
1360    switch (opt) {
1361      case 'i':
1362        instance = 1;
1363        break;
1364      case 'r':
1365        related = 1;
1366        break;
1367      default:
1368        owl_function_makemsg("Wrong number of arguments for %s (%c)", argv[0], opt);
1369        goto done;
1370    }
1371  }
1372
1373  filtname = owl_function_smartfilter(instance, related);
1374
1375  if (filtname) {
1376    owl_function_change_currentview_filter(filtname);
1377    g_free(filtname);
1378  }
1379
1380done:
1381  g_free(tmp_argv);
1382
1383  return NULL;
1384}
1385
1386CALLER_OWN char *owl_command_smartfilter(int argc, const char *const *argv, const char *buff)
1387{
1388  char *filtname = NULL;
1389
1390  if (argc == 1) {
1391    filtname = owl_function_smartfilter(0, 0);
1392  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1393    filtname = owl_function_smartfilter(1, 0);
1394  } else {
1395    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1396  }
1397  return filtname;
1398}
1399
1400void owl_command_expunge(void)
1401{
1402  owl_function_expunge();
1403}
1404
1405void owl_command_first(void)
1406{
1407  owl_global_set_rightshift(&g, 0);
1408  owl_function_firstmsg();
1409}
1410
1411void owl_command_last(void)
1412{
1413  owl_function_lastmsg();
1414}
1415
1416void owl_command_resize(void)
1417{
1418  owl_function_resize();
1419}
1420
1421void owl_command_redisplay(void)
1422{
1423  owl_function_full_redisplay();
1424}
1425
1426CALLER_OWN char *owl_command_get_shift(int argc, const char *const *argv, const char *buff)
1427{
1428  if(argc != 1)
1429  {
1430    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1431    return NULL;
1432  }
1433  return g_strdup_printf("%d", owl_global_get_rightshift(&g));
1434}
1435
1436void owl_command_set_shift(int shift)
1437{
1438  owl_global_set_rightshift(&g, shift);
1439}
1440
1441void owl_command_unsuball(void)
1442{
1443  owl_function_unsuball();
1444}
1445
1446void owl_command_flushlogs(void)
1447{
1448  owl_log_flush_logs();
1449}
1450
1451char *owl_command_loadsubs(int argc, const char *const *argv, const char *buff)
1452{
1453  if (argc == 2) {
1454    owl_function_loadsubs(argv[1]);
1455  } else if (argc == 1) {
1456    owl_function_loadsubs(NULL);
1457  } else {
1458    owl_function_makemsg("Wrong number of arguments for load-subs.");
1459    return(NULL);
1460  }
1461  return(NULL);
1462}
1463
1464
1465char *owl_command_loadloginsubs(int argc, const char *const *argv, const char *buff)
1466{
1467  if (argc == 2) {
1468    owl_function_loadloginsubs(argv[1]);
1469  } else if (argc == 1) {
1470    owl_function_loadloginsubs(NULL);
1471  } else {
1472    owl_function_makemsg("Wrong number of arguments for load-subs.");
1473    return(NULL);
1474  }
1475  return(NULL);
1476}
1477
1478void owl_command_suspend(void)
1479{
1480  owl_function_suspend();
1481}
1482
1483char *owl_command_start_command(int argc, const char *const *argv, const char *buff)
1484{
1485  buff = skiptokens(buff, 1);
1486  owl_function_start_command(buff);
1487  return(NULL);
1488}
1489
1490char *owl_command_zaway(int argc, const char *const *argv, const char *buff)
1491{
1492  if ((argc==1) ||
1493      ((argc==2) && !strcmp(argv[1], "on"))) {
1494    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1495    owl_function_zaway_on();
1496    return NULL;
1497  }
1498
1499  if (argc==2 && !strcmp(argv[1], "off")) {
1500    owl_function_zaway_off();
1501    return NULL;
1502  }
1503
1504  if (argc==2 && !strcmp(argv[1], "toggle")) {
1505    owl_function_zaway_toggle();
1506    return NULL;
1507  }
1508
1509  buff = skiptokens(buff, 1);
1510  owl_global_set_zaway_msg(&g, buff);
1511  owl_function_zaway_on();
1512  return NULL;
1513}
1514
1515
1516char *owl_command_aaway(int argc, const char *const *argv, const char *buff)
1517{
1518  if ((argc==1) ||
1519      ((argc==2) && !strcmp(argv[1], "on"))) {
1520    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1521    owl_function_aaway_on();
1522    return NULL;
1523  }
1524
1525  if (argc==2 && !strcmp(argv[1], "off")) {
1526    owl_function_aaway_off();
1527    return NULL;
1528  }
1529
1530  if (argc==2 && !strcmp(argv[1], "toggle")) {
1531    owl_function_aaway_toggle();
1532    return NULL;
1533  }
1534
1535  buff = skiptokens(buff, 1);
1536  owl_global_set_aaway_msg(&g, buff);
1537  owl_function_aaway_on();
1538  return NULL;
1539}
1540
1541
1542char *owl_command_away(int argc, const char *const *argv, const char *buff)
1543{
1544  bool away_off;
1545  const char *message = NULL;
1546
1547  if (argc == 1 ||
1548      (argc == 2 && !strcmp(argv[1], "on"))) {
1549    away_off = false;
1550    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1551    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1552  } else if (argc == 2 && !strcmp(argv[1], "off")) {
1553    away_off = true;
1554  } else if (argc == 2 && !strcmp(argv[1], "toggle")) {
1555    away_off = owl_function_is_away();
1556  } else {
1557    away_off = false;
1558    message = skiptokens(buff, 1);
1559  }
1560
1561  if (away_off) {
1562    owl_function_aaway_off();
1563    owl_function_zaway_off();
1564    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_off", 0, NULL);
1565    owl_function_makemsg("Away messages off.");
1566  } else if (message != NULL) {
1567    owl_global_set_aaway_msg(&g, message);
1568    owl_global_set_zaway_msg(&g, message);
1569    owl_function_aaway_on();
1570    owl_function_zaway_on();
1571    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 1, &message);
1572    owl_function_makemsg("Away messages set (%s).", message);
1573  } else {
1574    owl_function_aaway_on();
1575    owl_function_zaway_on();
1576    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 0, NULL);
1577    owl_function_makemsg("Away messages set.");
1578  }
1579
1580  return NULL;
1581}
1582
1583char *owl_command_set(int argc, const char *const *argv, const char *buff)
1584{
1585  const char *var, *val;
1586  int  silent=0;
1587  int requirebool=0;
1588  owl_variable *v;
1589
1590  if (argc == 1) {
1591    owl_function_printallvars();
1592    return NULL;
1593  } 
1594
1595  if (argc > 1 && !strcmp("-q",argv[1])) {
1596    silent = 1;
1597    argc--; argv++;
1598  }
1599
1600  if (argc == 2) {
1601    var=argv[1];
1602    val="on";
1603    requirebool=1;
1604  } else if (argc == 3) {
1605    var=argv[1];
1606    val=argv[2];
1607  } else {
1608    owl_function_makemsg("Wrong number of arguments for set command");
1609    return NULL;
1610  }
1611
1612  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1613  if (v == NULL) {
1614    if (!silent) owl_function_error("Unknown variable '%s'", var);
1615  } else if (requirebool && !v->takes_on_off) {
1616    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1617  } else {
1618    owl_variable_set_fromstring(v, val, !silent);
1619  }
1620  return NULL;
1621}
1622
1623char *owl_command_unset(int argc, const char *const *argv, const char *buff)
1624{
1625  owl_variable *v;
1626  const char *var, *val;
1627  int  silent=0;
1628
1629  if (argc > 1 && !strcmp("-q",argv[1])) {
1630    silent = 1;
1631    argc--; argv++;
1632  }
1633  if (argc == 2) {
1634    var=argv[1];
1635    val="off";
1636  } else {
1637    owl_function_makemsg("Wrong number of arguments for unset command");
1638    return NULL;
1639  }
1640
1641  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1642  if (v == NULL) {
1643    if (!silent) owl_function_error("Unknown variable '%s'", var);
1644  } else if (!v->takes_on_off) {
1645    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1646  } else {
1647    owl_variable_set_fromstring(v, val, !silent);
1648  }
1649  return NULL;
1650}
1651
1652char *owl_command_print(int argc, const char *const *argv, const char *buff)
1653{
1654  const char *var;
1655  char *value;
1656  const owl_variable *v;
1657
1658  if (argc==1) {
1659    owl_function_printallvars();
1660    return NULL;
1661  } else if (argc!=2) {
1662    owl_function_makemsg("Wrong number of arguments for print command");
1663    return NULL;
1664  }
1665
1666  var=argv[1];
1667   
1668  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1669  if (v) {
1670    value = owl_variable_get_tostring(v);
1671    if (value == NULL)
1672      owl_function_makemsg("%s = <null>", var);
1673    else
1674      owl_function_makemsg("%s = '%s'", var, value);
1675    g_free(value);
1676  } else {
1677    owl_function_makemsg("Unknown variable '%s'.", var);
1678  }
1679  return NULL;
1680}
1681
1682
1683CALLER_OWN char *owl_command_exec(int argc, const char *const *argv, const char *buff)
1684{
1685  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_RETURN);
1686}
1687
1688CALLER_OWN char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
1689{
1690  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_POPUP);
1691}
1692
1693CALLER_OWN char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
1694{
1695  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1696}
1697
1698CALLER_OWN char *owl_command_perl(int argc, const char *const *argv, const char *buff)
1699{
1700  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_RETURN);
1701}
1702
1703CALLER_OWN char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
1704{
1705  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_POPUP);
1706}
1707
1708CALLER_OWN char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
1709{
1710  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1711}
1712
1713CALLER_OWN char *owl_command_multi(int argc, const char *const *argv, const char *buff)
1714{
1715  char *lastrv = NULL, *newbuff;
1716  char **commands;
1717  int  i;
1718  if (argc < 2) {
1719    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1720    return NULL;
1721  }
1722  newbuff = g_strdup(skiptokens(buff, 1));
1723  if (!strcmp(argv[0], "(")) {
1724    for (i=strlen(newbuff)-1; i>=0; i--) {
1725      if (newbuff[i] == ')') {
1726        newbuff[i] = '\0';
1727        break;
1728      } else if (newbuff[i] != ' ') {
1729        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1730        g_free(newbuff);
1731        return NULL;
1732      }
1733    }
1734  }
1735  commands = g_strsplit_set(newbuff, ";", 0);
1736  for (i = 0; commands[i] != NULL; i++) {
1737    g_free(lastrv);
1738    lastrv = owl_function_command(commands[i]);
1739  }
1740  g_free(newbuff);
1741  g_strfreev(commands);
1742  return lastrv;
1743}
1744
1745
1746char *owl_command_alias(int argc, const char *const *argv, const char *buff)
1747{
1748  if (argc < 3) {
1749    owl_function_makemsg("Invalid arguments to 'alias' command.");
1750    return NULL;
1751  }
1752  buff = skiptokens(buff, 2);
1753  owl_function_command_alias(argv[1], buff);
1754  return (NULL);
1755}
1756
1757
1758char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
1759{
1760  owl_keymap *km;
1761  int ret;
1762
1763  if (argc < 5 || strcmp(argv[3], "command")) {
1764    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1765    return NULL;
1766  }
1767  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1768  if (!km) {
1769    owl_function_makemsg("No such keymap '%s'", argv[1]);
1770    return NULL;
1771  }
1772  buff = skiptokens(buff, 4);
1773  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1774  if (ret!=0) {
1775    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1776                         argv[2], argv[1], buff);
1777    return NULL;
1778  }
1779  return NULL;
1780}
1781
1782
1783char *owl_command_unbindkey(int argc, const char *const *argv, const char *buf)
1784{
1785  owl_keymap *km;
1786  int ret;
1787
1788  if (argc < 3) {
1789    owl_function_makemsg("Usage: unbindkey <keymap> <binding>");
1790    return NULL;
1791  }
1792  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1793  if (!km) {
1794    owl_function_makemsg("No such keymap '%s'", argv[1]);
1795    return NULL;
1796  }
1797  ret = owl_keymap_remove_binding(km, argv[2]);
1798  if (ret == -1) {
1799    owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
1800                         argv[2], argv[1]);
1801    return NULL;
1802  } else if (ret == -2) {
1803    owl_function_makemsg("No such binding '%s' in keymap '%s'.",
1804                         argv[2], argv[1]);
1805  }
1806  return NULL;
1807}
1808
1809
1810void owl_command_quit(void)
1811{
1812  owl_function_quit();
1813}
1814
1815char *owl_command_debug(int argc, const char *const *argv, const char *buff)
1816{
1817  if (argc<2) {
1818    owl_function_makemsg("Need at least one argument to debug command");
1819    return(NULL);
1820  }
1821
1822  if (!owl_global_is_debug_fast(&g)) {
1823    owl_function_makemsg("Debugging is not turned on");
1824    return(NULL);
1825  }
1826
1827  owl_function_debugmsg("%s", argv[1]);
1828  return(NULL);
1829}
1830
1831char *owl_command_term(int argc, const char *const *argv, const char *buff)
1832{
1833  if (argc<2) {
1834    owl_function_makemsg("Need at least one argument to the term command");
1835    return(NULL);
1836  }
1837
1838  if (!strcmp(argv[1], "raise")) {
1839    owl_function_xterm_raise();
1840  } else if (!strcmp(argv[1], "deiconify")) {
1841    owl_function_xterm_deiconify();
1842  } else {
1843    owl_function_makemsg("Unknown terminal subcommand");
1844  }
1845  return(NULL);
1846}
1847
1848char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
1849{
1850  if ((argc<2) || (argc>3)) {
1851    owl_function_makemsg("Wrong number of arguments for zlog command");
1852    return(NULL);
1853  }
1854
1855  if (!strcmp(argv[1], "in")) {
1856    if (argc>2) {
1857      owl_global_set_tty(&g, argv[2]);
1858    }
1859    owl_zephyr_zlog_in();
1860  } else if (!strcmp(argv[1], "out")) {
1861    if (argc!=2) {
1862      owl_function_makemsg("Wrong number of arguments for zlog command");
1863      return(NULL);
1864    }
1865    owl_zephyr_zlog_out();
1866  } else {
1867    owl_function_makemsg("Invalid subcommand for zlog");
1868  }
1869  return(NULL);
1870}
1871
1872char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
1873{
1874  const char *class, *instance, *recip="";
1875  int temp=0;
1876  int ret=0;
1877
1878  if (argc < 2) {
1879    owl_function_makemsg("Not enough arguments to the subscribe command");
1880    return(NULL);
1881  }
1882  argc--;
1883  argv++;
1884
1885  if (!strcmp(argv[0], "-t")) {
1886    temp=1;
1887    argc--;
1888    argv++;
1889  }
1890  if (argc < 1) {
1891    owl_function_makemsg("Not enough arguments to the subscribe command");
1892    return(NULL);
1893  }
1894
1895  if (argc > 3) {
1896    owl_function_makemsg("Too many arguments to the subscribe command");
1897    return(NULL);
1898  }
1899
1900  class = argv[0];
1901
1902  if (argc == 1) {
1903    instance = "*";
1904  } else {
1905    instance = argv[1];
1906  }
1907
1908  if (argc <= 2) {
1909    recip="";
1910  } else if (argc==3) {
1911    recip=argv[2];
1912  }
1913
1914  ret = owl_function_subscribe(class, instance, recip);
1915  if (!temp && !ret) {
1916    owl_zephyr_addsub(NULL, class, instance, recip);
1917  }
1918  return(NULL);
1919}
1920
1921
1922char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
1923{
1924  const char *class, *instance, *recip="";
1925  int temp=0;
1926
1927  if (argc < 2) {
1928    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1929    return(NULL);
1930  }
1931  argc--;
1932  argv++;
1933
1934  if (!strcmp(argv[0], "-t")) {
1935    temp=1;
1936    argc--;
1937    argv++;
1938  }
1939  if (argc < 1) {
1940    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1941    return(NULL);
1942  }
1943
1944  if (argc > 3) {
1945    owl_function_makemsg("Too many arguments to the unsubscribe command");
1946    return(NULL);
1947  }
1948
1949  class = argv[0];
1950
1951  if (argc == 1) {
1952    instance = "*";
1953  } else {
1954    instance = argv[1];
1955  }
1956
1957  if (argc <= 2) {
1958    recip="";
1959  } else if (argc==3) {
1960    recip=argv[2];
1961  }
1962
1963  owl_function_unsubscribe(class, instance, recip);
1964  if (!temp) {
1965    owl_zephyr_delsub(NULL, class, instance, recip);
1966  }
1967  return(NULL);
1968}
1969
1970char *owl_command_echo(int argc, const char *const *argv, const char *buff)
1971{
1972  buff = skiptokens(buff, 1);
1973  owl_function_popless_text(buff);
1974  return NULL;
1975}
1976
1977void owl_command_getsubs(void)
1978{
1979  owl_function_getsubs();
1980}
1981
1982void owl_command_status(void)
1983{
1984  owl_function_status();
1985}
1986
1987char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
1988{
1989  owl_zwrite *z;
1990
1991  if (!owl_global_is_havezephyr(&g)) {
1992    owl_function_makemsg("Zephyr is not available");
1993    return(NULL);
1994  }
1995  /* check for a zwrite -m */
1996  z = owl_zwrite_new(argc, argv);
1997  if (!z) {
1998    owl_function_error("Error in zwrite arguments");
1999    return NULL;
2000  }
2001
2002  if (owl_zwrite_is_message_set(z)) {
2003    owl_function_zwrite(z, NULL);
2004    owl_zwrite_delete(z);
2005    return NULL;
2006  }
2007
2008  if (argc < 2) {
2009    owl_zwrite_delete(z);
2010    owl_function_makemsg("Not enough arguments to the zwrite command.");
2011  } else {
2012    owl_function_zwrite_setup(z);
2013  }
2014  return(NULL);
2015}
2016
2017char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
2018{
2019  char *message = NULL;
2020  GString *recip = g_string_new("");
2021  const char *const *myargv;
2022  int myargc;
2023 
2024  if (!owl_global_is_aimloggedin(&g)) {
2025    owl_function_error("You are not logged in to AIM.");
2026    goto err;
2027  }
2028
2029  /* Skip argv[0]. */
2030  myargv = argv+1;
2031  myargc = argc-1;
2032  while (myargc) {
2033    if (!strcmp(myargv[0], "-m")) {
2034      if (myargc <= 1) {
2035        owl_function_error("No message specified.");
2036        goto err;
2037      }
2038      /* Once we have -m, gobble up everything else on the line */
2039      myargv++;
2040      myargc--;
2041      message = g_strjoinv(" ", (char**)myargv);
2042      break;
2043    } else {
2044      /* squish arguments together to make one screenname w/o spaces for now */
2045      g_string_append(recip, myargv[0]);
2046      myargv++;
2047      myargc--;
2048    }
2049  }
2050
2051  if (recip->str[0] == '\0') {
2052    owl_function_error("No recipient specified");
2053    goto err;
2054  }
2055
2056  if (message != NULL)
2057    owl_function_aimwrite(recip->str, message, false);
2058  else
2059    owl_function_aimwrite_setup(recip->str);
2060 err:
2061  g_string_free(recip, true);
2062  g_free(message);
2063  return NULL;
2064}
2065
2066char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
2067{
2068  owl_function_loopwrite_setup();
2069  return(NULL);
2070}
2071
2072char *owl_command_reply(int argc, const char *const *argv, const char *buff)
2073{
2074  int edit=0;
2075 
2076  if (argc>=2 && !strcmp("-e", argv[1])) {
2077    edit=1;
2078    argv++;
2079    argc--;
2080  }
2081
2082  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2083    owl_function_reply(0, !edit);
2084  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2085    owl_function_reply(1, !edit);
2086  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2087    const owl_message *m;
2088    const owl_view    *v;
2089    v = owl_global_get_current_view(&g);   
2090    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2091    if (m) owl_zephyr_zaway(m);
2092  } else {
2093    owl_function_makemsg("Invalid arguments to the reply command.");
2094  }
2095  return NULL;
2096}
2097
2098char *owl_command_filter(int argc, const char *const *argv, const char *buff)
2099{
2100  owl_function_create_filter(argc, argv);
2101  return NULL;
2102}
2103
2104char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
2105{
2106  int auth;
2107 
2108  if (argc<2) {
2109    owl_function_makemsg("Too few arguments for zlocate command");
2110    return NULL;
2111  }
2112
2113  auth=1;
2114  if (!strcmp(argv[1], "-d")) {
2115    if (argc>2) {
2116      auth=0;
2117      argc--;
2118      argv++;
2119    } else {
2120      owl_function_makemsg("Missing arguments for zlocate command");
2121      return NULL;
2122    }
2123  }
2124
2125  argc--;
2126  argv++;
2127  owl_function_zlocate(argc, argv, auth);
2128  return NULL;
2129}
2130
2131
2132/* Backwards compatability has made this kind of complicated:
2133 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2134 * view <filter>
2135 * view -d <expression>
2136 * view --home
2137 */
2138char *owl_command_view(int argc, const char *const *argv, const char *buff)
2139{
2140  /* First take the 'view --home' and 'view -r' cases */
2141  if (argc == 2) {
2142    if (!strcmp(argv[1], "--home")) {
2143      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2144      return(NULL);
2145    } else if (!strcmp(argv[1], "-r")) {
2146      char *foo;
2147      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2148      owl_function_change_currentview_filter(foo);
2149      g_free(foo);
2150      return(NULL);
2151    }
2152  }
2153
2154  /* Now look for 'view <filter>' */
2155  if (argc==2) {
2156    owl_function_change_currentview_filter(argv[1]);
2157    return(NULL);
2158  }
2159
2160  /* Now get 'view -d <expression>' */
2161  if (argc>=3 && !strcmp(argv[1], "-d")) {
2162    const char **myargv;
2163    int i;
2164
2165    /* Allocate one more than argc for the trailing NULL. */
2166    myargv = g_new0(const char*, argc+1);
2167    myargv[0]="";
2168    myargv[1]="owl-dynamic";
2169    for (i=2; i<argc; i++) {
2170      myargv[i]=argv[i];
2171    }
2172    if (owl_function_create_filter(argc, myargv)) {
2173      owl_function_change_currentview_filter("owl-dynamic");
2174    }
2175    g_free(myargv);
2176    return NULL;
2177  }
2178
2179  /* Finally handle the general case */
2180  if (argc<3) {
2181    owl_function_makemsg("Too few arguments to the view command.");
2182    return(NULL);
2183  }
2184  argc--;
2185  argv++;
2186  if (strcmp(argv[0], "-f") &&
2187      strcmp(argv[0], "-d") &&
2188      strcmp(argv[0], "--home") &&
2189      strcmp(argv[0], "-s") &&
2190      strcmp(argv[0], "-r")) {
2191    if (strcmp(argv[0], "main")) {
2192      owl_function_makemsg("No view named '%s'", argv[0]);
2193      return(NULL);
2194    }
2195    argc--;
2196    argv++;
2197  }
2198  while (argc) {
2199    if (!strcmp(argv[0], "-f")) {
2200      if (argc<2) {
2201        owl_function_makemsg("Too few arguments to the view command");
2202        return(NULL);
2203      }
2204      owl_function_change_currentview_filter(argv[1]);
2205      argc-=2;
2206      argv+=2;
2207    } else if (!strcmp(argv[0], "--home")) {
2208      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2209      argc--;
2210      argv++;
2211    } else if (!strcmp(argv[0], "-s")) {
2212      if (argc<2) {
2213        owl_function_makemsg("Too few arguments to the view command");
2214        return(NULL);
2215      }
2216      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2217      argc-=2;
2218      argv+=2;
2219    } else {
2220      owl_function_makemsg("Too few arguments to the view command");
2221      return(NULL);
2222    }
2223   
2224  }
2225  return(NULL);
2226}
2227
2228char *owl_command_show(int argc, const char *const *argv, const char *buff)
2229{
2230  if (argc<2) {
2231    owl_function_help_for_command("show");
2232    return NULL;
2233  }
2234
2235  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2236    if (argc==2) {
2237      owl_function_show_filters();
2238    } else {
2239      owl_function_show_filter(argv[2]);
2240    }
2241  } else if (argc==2 
2242             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2243    owl_function_show_zpunts();
2244  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2245    if (argc==2) {
2246      owl_function_show_commands();
2247    } else {
2248      owl_function_show_command(argv[2]);
2249    }
2250  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2251    if (argc==2) {
2252      owl_function_show_variables();
2253    } else {
2254      owl_function_show_variable(argv[2]);
2255    }
2256  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2257    if (argc==2) {
2258      owl_function_show_keymaps();
2259    } else {
2260      owl_function_show_keymap(argv[2]);
2261    }
2262  } else if (!strcmp(argv[1], "view")) {
2263    if (argc==3) {
2264      owl_function_show_view(argv[2]);
2265    } else {
2266      owl_function_show_view(NULL);
2267    }
2268  } else if (!strcmp(argv[1], "colors")) {
2269    owl_function_show_colors();
2270  } else if (!strcmp(argv[1], "styles")) {
2271    owl_function_show_styles();
2272  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2273    owl_function_getsubs();
2274  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2275    owl_function_show_term();
2276  } else if (!strcmp(argv[1], "version")) {
2277    owl_function_about();
2278  } else if (!strcmp(argv[1], "status")) {
2279    owl_function_status();
2280  } else if (!strcmp(argv[1], "license")) {
2281    owl_function_show_license();
2282  } else if (!strcmp(argv[1], "quickstart")) {
2283    owl_function_show_quickstart();
2284  } else if (!strcmp(argv[1], "startup")) {
2285    const char *filename;
2286   
2287    filename=owl_global_get_startupfile(&g);
2288    owl_function_popless_file(filename);
2289  } else if (!strcmp(argv[1], "errors")) {
2290    owl_function_showerrs();
2291  } else {
2292    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2293    return NULL;
2294  }
2295  return NULL;
2296}
2297
2298char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
2299{
2300  char *filtname;
2301  if (argc!=2) {
2302    owl_function_makemsg("Wrong number of arguments to viewclass command");
2303    return NULL;
2304  }
2305  filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2306  if (filtname) {
2307    owl_function_change_currentview_filter(filtname);
2308    g_free(filtname);
2309  }
2310  return NULL;
2311}
2312
2313char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
2314{
2315  char *filtname;
2316  char *longuser;
2317  if (argc!=2) {
2318    owl_function_makemsg("Wrong number of arguments to viewuser command");
2319    return NULL;
2320  }
2321  longuser = long_zuser(argv[1]);
2322  filtname = owl_function_zuserfilt(longuser);
2323  g_free(longuser);
2324  if (filtname) {
2325    owl_function_change_currentview_filter(filtname);
2326    g_free(filtname);
2327  }
2328  return NULL;
2329}
2330
2331
2332void owl_command_pop_message(void)
2333{
2334  owl_function_curmsg_to_popwin();
2335}
2336
2337char *owl_command_delete(int argc, const char *const *argv, const char *buff)
2338{
2339  int move_after = 1;
2340
2341  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2342    move_after = 0;
2343    argc--; 
2344    argv++;
2345  }
2346
2347  if (argc==1) {
2348    owl_function_deletecur(move_after);
2349    return NULL;
2350  }
2351
2352  if (argc==2 && !strcmp(argv[1], "view")) {
2353    owl_function_delete_curview_msgs(1);
2354    return NULL;
2355  }
2356
2357  if (argc==2 && !strcmp(argv[1], "trash")) {
2358    owl_function_delete_automsgs();
2359    return NULL;
2360  }
2361
2362  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2363    owl_function_delete_by_id(atoi(argv[2]), 1);
2364    return NULL;
2365  }
2366
2367  owl_function_makemsg("Unknown arguments to delete command");
2368  return NULL;
2369}
2370
2371char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff)
2372{
2373  bool exclaim_success = true;
2374
2375  if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) {
2376    exclaim_success = false;
2377    argc--;
2378    argv++;
2379  } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) {
2380    exclaim_success = false;
2381    argc--;
2382  }
2383
2384  if (argc == 1) {
2385    owl_function_delete_and_expunge_cur(exclaim_success);
2386    return NULL;
2387  }
2388
2389  if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2390    owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success);
2391    return NULL;
2392  }
2393
2394  owl_function_makemsg("Unknown arguments to delete-and-expunge command");
2395  return NULL;
2396}
2397
2398char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
2399{
2400  int move_after = 1;
2401
2402  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2403    move_after = 0;
2404    argc--; 
2405    argv++;
2406  }
2407
2408  if (argc==1) {
2409    owl_function_undeletecur(move_after);
2410    return NULL;
2411  }
2412
2413  if (argc==2 && !strcmp(argv[1], "view")) {
2414    owl_function_delete_curview_msgs(0);
2415    return NULL;
2416  }
2417
2418  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2419    owl_function_delete_by_id(atoi(argv[2]), 0);
2420    return NULL;
2421  }
2422
2423  owl_function_makemsg("Unknown arguments to delete command");
2424  return NULL;
2425}
2426
2427void owl_command_beep(void)
2428{
2429  owl_function_beep();
2430}
2431
2432char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
2433{
2434  if (argc < 2 || argc > 3) {
2435    owl_function_makemsg("Wrong number of arguments to colorview command");
2436    return NULL;
2437  }
2438  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2439  return NULL;
2440}
2441
2442char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
2443{
2444  char *filtname;
2445 
2446  if (argc < 3 || argc > 4) {
2447    owl_function_makemsg("Wrong number of arguments to colorclass command");
2448    return NULL;
2449  }
2450
2451  filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2452  if (filtname) {
2453    (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2454    g_free(filtname);
2455  }
2456  return NULL;
2457}
2458
2459char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
2460{
2461  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2462  return NULL;
2463}
2464
2465char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
2466{
2467  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2468  return NULL;
2469}
2470
2471void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
2472{
2473  /* if type==0 then zpunt
2474   * if type==1 then zunpunt
2475   */
2476  const char *class, *inst, *recip;
2477
2478  class="message";
2479  inst="";
2480  recip="*";
2481
2482  if (argc==1) {
2483    /* show current punt filters */
2484    owl_function_show_zpunts();
2485    return;
2486  } else if (argc==2) {
2487    inst=argv[1];
2488  } else if (argc==3) {
2489    class=argv[1];
2490    inst=argv[2];
2491  } else if (argc==4) {
2492    class=argv[1];
2493    inst=argv[2];
2494    recip=argv[3];
2495  } else {
2496    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2497    return;
2498  }
2499
2500  owl_function_zpunt(class, inst, recip, type);
2501  if (type==0) {
2502    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2503  } else if (type==1) {
2504    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2505  }
2506}
2507
2508char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
2509{
2510  if (argc == 1) {
2511    owl_function_smartzpunt(0);
2512  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2513    owl_function_smartzpunt(1);
2514  } else {
2515    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2516  }
2517  return NULL;
2518}
2519
2520char *owl_command_punt(int argc, const char *const *argv, const char *buff)
2521{
2522  owl_command_punt_unpunt(argc, argv, buff, 0);
2523  return NULL;
2524}
2525
2526char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
2527{
2528  owl_command_punt_unpunt(argc, argv, buff, 1);
2529  return NULL;
2530}
2531
2532void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
2533{
2534  GPtrArray * fl;
2535  int i;
2536
2537  fl = owl_global_get_puntlist(&g);
2538  if(argc == 1) {
2539    owl_function_show_zpunts();
2540  } else if(argc == 2) {
2541    /* Handle :unpunt <number> */
2542    if (unpunt && (i = atoi(argv[1])) > 0) {
2543      i--;      /* Accept 1-based indexing */
2544      if (i < fl->len) {
2545        owl_filter_delete(g_ptr_array_remove_index(fl, i));
2546        return;
2547      } else {
2548        owl_function_makemsg("No such filter number: %d.", i+1);
2549      }
2550    }
2551    const char *filter[] = {"filter", argv[1]};
2552    owl_function_punt(2, filter, unpunt);
2553  } else {
2554    /* Pass in argv[1]..argv[argc-1]. */
2555    owl_function_punt(argc - 1, argv + 1, unpunt);
2556  }
2557}
2558
2559
2560char *owl_command_getview(int argc, const char *const *argv, const char *buff)
2561{
2562  const char *filtname;
2563  if (argc != 1) {
2564    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2565    return NULL;
2566  }
2567  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2568  if (filtname) return g_strdup(filtname);
2569  return NULL;
2570}
2571
2572CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
2573{
2574  const owl_variable *v;
2575  if (argc != 2) {
2576    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2577    return NULL;
2578  }
2579  v = owl_variable_get_var(owl_global_get_vardict(&g), argv[1]);
2580  if (v == NULL) return NULL;
2581  return owl_variable_get_tostring(v);
2582}
2583
2584char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
2585{
2586  const owl_filter *f;
2587  if (argc != 2) {
2588    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2589    return NULL;
2590  }
2591  f = owl_global_get_filter(&g, argv[1]);
2592  if (!f) {
2593    return NULL;
2594  }
2595  return owl_filter_print(f);
2596}
2597
2598char *owl_command_search(int argc, const char *const *argv, const char *buff)
2599{
2600  int direction;
2601  const char *buffstart;
2602
2603  direction=OWL_DIRECTION_DOWNWARDS;
2604  buffstart=skiptokens(buff, 1);
2605  if (argc>1 && !strcmp(argv[1], "-r")) {
2606    direction=OWL_DIRECTION_UPWARDS;
2607    buffstart=skiptokens(buff, 2);
2608  }
2609   
2610  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2611    /* When continuing a search, don't consider the current message. */
2612    owl_function_search_helper(false, direction);
2613  } else {
2614    owl_function_set_search(buffstart);
2615    owl_function_search_helper(true, direction);
2616  }
2617 
2618  return(NULL);
2619}
2620
2621char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
2622{
2623  const char *buffstart;
2624
2625  buffstart=skiptokens(buff, 1);
2626  owl_function_set_search(*buffstart ? buffstart : NULL);
2627 
2628  return(NULL);
2629}
2630
2631char *owl_command_aimlogin(int argc, const char *const *argv, const char *buff)
2632{
2633  if ((argc<2) || (argc>3)) {
2634    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2635    return(NULL);
2636  }
2637
2638  /* if we get two arguments, ask for the password */
2639  if (argc==2) {
2640    owl_editwin *e = owl_function_start_password("AIM Password: ");
2641    owl_editwin_set_cbdata(e, g_strdup(argv[1]), g_free);
2642    owl_editwin_set_callback(e, owl_callback_aimlogin);
2643    return(NULL);
2644  } else {
2645    owl_function_aimlogin(argv[1], argv[2]);
2646  }
2647
2648  /* this is a test */
2649  return(NULL);
2650}
2651
2652char *owl_command_aimlogout(int argc, const char *const *argv, const char *buff)
2653{
2654  /* clear the buddylist */
2655  owl_buddylist_clear(owl_global_get_buddylist(&g));
2656
2657  owl_aim_logout();
2658  return(NULL);
2659}
2660
2661CALLER_OWN char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
2662{
2663  const char *stylename;
2664  if (argc != 1) {
2665    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2666    return NULL;
2667  }
2668  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2669  if (stylename) return g_strdup(stylename);
2670  return NULL;
2671}
2672
2673char *owl_command_error(int argc, const char *const *argv, const char *buff)
2674{
2675    buff = skiptokens(buff, 1);
2676    owl_function_error("%s", buff);
2677    return NULL;
2678}
2679
2680char *owl_command_message(int argc, const char *const *argv, const char *buff)
2681{
2682    buff = skiptokens(buff, 1);
2683    owl_function_makemsg("%s", buff);
2684    return NULL;
2685}
2686
2687char *owl_command_add_cmd_history(int argc, const char *const *argv, const char *buff)
2688{
2689  owl_history *hist;
2690  const char *ptr;
2691
2692  if (argc < 2) {
2693    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
2694    return NULL;
2695  }
2696
2697  ptr = skiptokens(buff, 1);
2698  hist = owl_global_get_cmd_history(&g);
2699  owl_history_store(hist, ptr, false);
2700  /* owl_function_makemsg("History '%s' stored successfully", ptr+1); */
2701  return NULL;
2702}
2703
2704CALLER_OWN char *owl_command_with_history(int argc, const char *const *argv, const char *buff)
2705{
2706  owl_history *hist;
2707  const char *ptr;
2708
2709  if (argc < 2) {
2710    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
2711    return NULL;
2712  }
2713
2714  ptr = skiptokens(buff, 1);
2715  if (!ptr) {
2716    owl_function_makemsg("Parse error finding command");
2717    return NULL;
2718  }
2719
2720  hist = owl_global_get_cmd_history(&g);
2721  owl_history_store(hist, ptr, false);
2722  return owl_function_command(ptr);
2723}
2724
2725void owl_command_yes(void)
2726{
2727  owl_message *m;
2728  const owl_view *v;
2729  const char *cmd;
2730
2731  v = owl_global_get_current_view(&g);
2732
2733  /* bail if there's no current message */
2734  if (owl_view_get_size(v) < 1) {
2735    owl_function_error("No current message.");
2736    return;
2737  }
2738
2739  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2740  if(!owl_message_is_question(m)) {
2741    owl_function_error("That message isn't a question.");
2742    return;
2743  }
2744  if(owl_message_is_answered(m)) {
2745    owl_function_error("You already answered that question.");
2746    return;
2747  }
2748  cmd = owl_message_get_attribute_value(m, "yescommand");
2749  if(!cmd) {
2750    owl_function_error("No 'yes' command!");
2751    return;
2752  }
2753
2754  owl_function_command_norv(cmd);
2755  owl_message_set_isanswered(m);
2756  return;
2757}
2758
2759void owl_command_no(void)
2760{
2761  owl_message *m;
2762  const owl_view *v;
2763  const char *cmd;
2764
2765  v = owl_global_get_current_view(&g);
2766
2767  /* bail if there's no current message */
2768  if (owl_view_get_size(v) < 1) {
2769    owl_function_error("No current message.");
2770    return;
2771  }
2772
2773  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2774  if(!owl_message_is_question(m)) {
2775    owl_function_error("That message isn't a question.");
2776    return;
2777  }
2778  if(owl_message_is_answered(m)) {
2779    owl_function_error("You already answered that question.");
2780    return;
2781  }
2782  cmd = owl_message_get_attribute_value(m, "nocommand");
2783  if(!cmd) {
2784    owl_function_error("No 'no' command!");
2785    return;
2786  }
2787
2788  owl_function_command_norv(cmd);
2789  owl_message_set_isanswered(m);
2790  return;
2791}
2792
2793/*********************************************************************/
2794/************************** EDIT SPECIFIC ****************************/
2795/*********************************************************************/
2796
2797void owl_command_edit_cancel(owl_editwin *e)
2798{
2799  owl_history *hist;
2800
2801  owl_function_makemsg("Command cancelled.");
2802
2803  hist = owl_editwin_get_history(e);
2804  if (hist)
2805    owl_history_store(hist, owl_editwin_get_text(e), false);
2806
2807  /* Take a reference to the editwin, so that it survives the pop
2808   * context. TODO: We should perhaps refcount or otherwise protect
2809   * the context so that, even if a command pops a context, the
2810   * context itself will last until the command returns. */
2811  owl_editwin_ref(e);
2812  owl_global_pop_context(&g);
2813
2814  owl_editwin_do_callback(e, false);
2815  owl_editwin_unref(e);
2816}
2817
2818void owl_command_edit_history_prev(owl_editwin *e)
2819{
2820  owl_history *hist;
2821  const char *ptr;
2822
2823  hist=owl_editwin_get_history(e);
2824  if (!hist)
2825    return;
2826  if (!owl_history_is_touched(hist))
2827    owl_history_store(hist, owl_editwin_get_text(e), true);
2828  ptr=owl_history_get_prev(hist);
2829  if (ptr) {
2830    owl_editwin_clear(e);
2831    owl_editwin_insert_string(e, ptr);
2832  } else {
2833    owl_function_beep();
2834  }
2835}
2836
2837void owl_command_edit_history_next(owl_editwin *e)
2838{
2839  owl_history *hist;
2840  const char *ptr;
2841
2842  hist=owl_editwin_get_history(e);
2843  if (!hist)
2844    return;
2845  ptr=owl_history_get_next(hist);
2846  if (ptr) {
2847    owl_editwin_clear(e);
2848    owl_editwin_insert_string(e, ptr);
2849  } else {
2850    owl_function_beep();
2851  }
2852}
2853
2854char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
2855{
2856  buff = skiptokens(buff, 1);
2857  owl_editwin_insert_string(e, buff);
2858  return NULL;
2859}
2860
2861void owl_command_edit_done(owl_editwin *e)
2862{
2863  owl_history *hist=owl_editwin_get_history(e);
2864
2865  if (hist)
2866    owl_history_store(hist, owl_editwin_get_text(e), false);
2867
2868  /* Take a reference to the editwin, so that it survives the pop
2869   * context. TODO: We should perhaps refcount or otherwise protect
2870   * the context so that, even if a command pops a context, the
2871   * context itself will last until the command returns. */
2872  owl_editwin_ref(e);
2873  owl_global_pop_context(&g);
2874
2875  owl_editwin_do_callback(e, true);
2876  owl_editwin_unref(e);
2877}
2878
2879void owl_command_edit_done_or_delete(owl_editwin *e)
2880{
2881  if (owl_editwin_is_at_end(e)) {
2882    owl_command_edit_done(e);
2883  } else {
2884    owl_editwin_delete_char(e);
2885  }
2886}
2887
2888
2889/*********************************************************************/
2890/*********************** POPLESS SPECIFIC ****************************/
2891/*********************************************************************/
2892
2893void owl_command_popless_quit(owl_viewwin *vw)
2894{
2895  owl_popwin *pw;
2896  pw = owl_global_get_popwin(&g);
2897  owl_global_set_popwin(&g, NULL);
2898  /* Kind of a hack, but you can only have one active viewwin right
2899   * now anyway. */
2900  if (vw == owl_global_get_viewwin(&g))
2901    owl_global_set_viewwin(&g, NULL);
2902  owl_viewwin_delete(vw);
2903  owl_popwin_delete(pw);
2904  owl_global_pop_context(&g);
2905}
Note: See TracBrowser for help on using the repository browser.