source: commands.c @ 53d6269

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