source: commands.c @ 565a43c

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