source: commands.c @ bd482c3

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