source: commands.c @ 48848ae

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