source: commands.c @ 353719a

Last change on this file since 353719a was 353719a, checked in by David Benjamin <davidben@mit.edu>, 8 years ago
Start of perlvariables iteration N+1 New plan: the C <-> perl interface deals entirely with strings. Storage is entirely perl-side. C does not know and doesn't care about the underlying perl-side types. Note that this means an "int" variable in C land and an "int" variable in perl land have no relation.
  • Property mode set to 100644
File size: 86.9 KB
Line 
1#include "owl.h"
2#include <getopt.h>
3
4/* fn is "char *foo(int argc, const char *const *argv, const char *buff)" */
5#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
6        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
7          NULL, fn, NULL, NULL, NULL, NULL, NULL, NULL }
8
9/* fn is "void foo(void)" */
10#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
11        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
12          NULL, NULL, fn, NULL, NULL, NULL, NULL, NULL }
13
14/* fn is "void foo(int)" */
15#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
16        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
17          NULL, NULL, NULL, fn, NULL, NULL, NULL, NULL }
18
19#define OWLCMD_ALIAS(name, actualname) \
20        { g_strdup(name), g_strdup(OWL_CMD_ALIAS_SUMMARY_PREFIX actualname), g_strdup(""), g_strdup(""), OWL_CTX_ANY, \
21          g_strdup(actualname), NULL, NULL, NULL, NULL, NULL, NULL, NULL }
22
23/* fn is "char *foo(void *ctx, int argc, const char *const *argv, const char *buff)" */
24#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
25        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
26          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,const char*const *,const char*))fn), NULL, NULL, NULL }
27
28/* fn is "void foo(void)" */
29#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
30        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
31          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL, NULL }
32
33/* fn is "void foo(int)" */
34#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
35        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
36          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn), NULL }
37
38
39void owl_cmd_add_defaults(owl_cmddict *cd)
40{
41  owl_cmd commands_to_init[] = {
42
43  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
44              "send a login or logout notification",
45              "zlog in [tty]\nzlog out",
46              "zlog in will send a login notification, zlog out will send a\n"
47              "logout notification.  By default a login notification is sent\n"
48              "when BarnOwl is started and a logout notification is sent when owl\n"
49              "is exited.  This behavior can be changed with the 'startuplogin'\n"
50              "and 'shutdownlogout' variables.  If a tty is specified for zlog in\n"
51              "then the BarnOwl variable 'tty' will be set to that string, causing\n"
52              "it to be used as the zephyr location tty.\n"),
53
54  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
55              "exit BarnOwl",
56              "",
57              "Exit BarnOwl and run any shutdown activities."),
58  OWLCMD_ALIAS("exit", "quit"),
59  OWLCMD_ALIAS("q",    "quit"),
60
61  OWLCMD_ARGS("term", owl_command_term, OWL_CTX_ANY,
62              "control the terminal",
63              "term raise\n"
64              "term deiconify\n",
65              ""),
66
67  OWLCMD_VOID("nop", owl_command_nop, OWL_CTX_ANY,
68              "do nothing",
69              "",
70              ""),
71 
72  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
73              "prompts the user to enter a command",
74              "start-command [initial-value]",
75              "Initializes the command field to initial-value."),
76
77  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
78              "creates a command alias",
79              "alias <new_command> <old_command>",
80              "Creates a command alias from new_command to old_command.\n"
81              "Any arguments passed to <new_command> will be appended to\n"
82              "<old_command> before it is executed.\n"),
83
84  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
85              "creates a binding in a keymap",
86              "bindkey <keymap> <keyseq> command <command>",
87              "(Note: There is a literal word \"command\" between <keyseq>\n"
88              " and <command>.)\n"
89              "Binds a key sequence to a command within a keymap.\n"
90              "Use 'show keymaps' to see the existing keymaps.\n"
91              "Key sequences may be things like M-C-t or NPAGE.\n\n"
92              "Ex.: bindkey recv C-b command zwrite -c barnowl\n"
93              "Ex.: bindkey recv m command start-command zwrite -c my-class -i \n\n"
94              "SEE ALSO: unbindkey, start-command"),
95
96  OWLCMD_ARGS("unbindkey", owl_command_unbindkey, OWL_CTX_ANY,
97              "removes a binding in a keymap",
98              "unbindkey <keymap> <keyseq>",
99              "Removes a binding of a key sequence within a keymap.\n"
100              "Use 'show keymaps' to see the existing keymaps.\n"
101              "Ex.: unbindkey recv H\n\n"
102              "SEE ALSO: bindkey"),
103
104  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
105              "send a zephyr",
106              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [<user> ...] [-m <message...>]",
107              "Zwrite send a zephyr to the one or more users specified.\n\n"
108              "The following options are available:\n\n"
109              "-m    Specifies a message to send without prompting.\n"
110              "      Note that this does not yet log an outgoing message.\n"
111              "      This must be the last argument.\n\n"
112              "-n    Do not send a ping message.\n\n"
113              "-C    If the message is sent to more than one user include a\n"
114              "      \"cc:\" line in the text\n\n"
115              "-c class\n"
116              "      Send to the specified zephyr class\n\n"
117              "-i instance\n"
118              "      Send to the specified zephyr instance\n\n"
119              "-r realm\n"
120              "      Send to a foreign realm\n"
121              "-O opcode\n"
122              "      Send to the specified opcode\n"),
123
124  OWLCMD_ARGS("aimwrite", owl_command_aimwrite, OWL_CTX_INTERACTIVE,
125              "send an AIM message",
126              "aimwrite <user> [-m <message...>]",
127              "Send an aim message to a user.\n\n" 
128              "The following options are available:\n\n"
129              "-m    Specifies a message to send without prompting.\n"),
130
131  OWLCMD_ARGS("loopwrite", owl_command_loopwrite, OWL_CTX_INTERACTIVE,
132              "send a loopback message",
133              "loopwrite",
134              "Send a local message.\n"),
135
136  OWLCMD_ARGS("zcrypt", owl_command_zwrite, OWL_CTX_INTERACTIVE,
137              "send an encrypted zephyr",
138              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [-m <message...>]\n",
139              "Behaves like zwrite but uses encryption.  Not for use with\n"
140              "personal messages\n"),
141 
142  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
143              "reply to the current message",
144              "reply [-e] [ sender | all | zaway ]",
145              "If -e is specified, the zwrite command line is presented to\n"
146              "allow editing.\n\n"
147              "If 'sender' is specified, reply to the sender.\n\n"
148              "If 'all' or no args are specified, reply publicly to the\n"
149              "same class/instance for non-personal messages and to the\n"
150              "sender for personal messages.\n\n"
151              "If 'zaway' is specified, replies with a zaway message.\n\n"),
152
153  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
154              "set a variable value",
155              "set [-q] [<variable>] [<value>]\n"
156              "set",
157              "Set the named variable to the specified value.  If no\n"
158              "arguments are given, print the value of all variables.\n"
159              "If the value is unspecified and the variable is a boolean, it will be\n"
160              "set to 'on'.  If -q is used, set is silent and does not print a\n"
161              "message.\n"),
162
163  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
164              "unset a boolean variable value",
165              "unset [-q] <variable>\n"
166              "unset",
167              "Set the named boolean variable to off.\n"
168              "If -q is specified, is silent and doesn't print a message.\n"),
169
170  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
171              "print a variable value",
172              "print <variable>\n"
173              "print",
174              "Print the value of the named variable.  If no arguments\n"
175              "are used print the value of all variables.\n"),
176
177  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
178              "run a command and set it to be run at every BarnOwl startup",
179              "startup <commands> ...",
180              "Everything on the command line after the startup command\n"
181              "is executed as a normal BarnOwl command and is also placed in\n"
182              "a file so that the command is executed every time BarnOwl\n"
183              "is started"),
184
185  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
186              "remove a command from the list of those to be run at BarnOwl startup",
187              "unstartup <commands> ...",
188              ""),
189
190  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
191              "print the version of the running BarnOwl", "", ""),
192
193  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
194              "subscribe to a zephyr class, instance, recipient",
195              "subscribe [-t] <class> [instance [recipient]]",
196              "Subscribe to the specified class and instance.  If the\n"
197              "instance or recipient is not listed on the command\n"
198              "line they default to * (the wildcard recipient).\n"
199              "If the -t option is present the subscription will\n"
200              "only be temporary, i.e., it will not be written to\n"
201              "the subscription file and will therefore not be\n"
202              "present the next time BarnOwl is started.\n"),
203  OWLCMD_ALIAS("sub", "subscribe"),
204
205  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
206              "unsubscribe from a zephyr class, instance, recipient",
207              "unsubscribe [-t] <class> [instance [recipient]]",
208              "Unsubscribe from the specified class and instance.  If the\n"
209              "instance or recipient is not listed on the command\n"
210              "line they default to * (the wildcard recipient).\n"
211              "If the -t option is present the unsubscription will\n"
212              "only be temporary, i.e., it will not be updated in\n"
213              "the subscription file and will therefore not be\n"
214              "in effect the next time BarnOwl is started.\n"),
215  OWLCMD_ALIAS("unsub", "unsubscribe"),
216
217  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
218              "unsubscribe from all zephyrs", "", ""),
219 
220  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
221              "print all current subscriptions",
222              "getsubs",
223              "getsubs retrieves the current subscriptions from the server\n"
224              "and displays them.\n"),
225
226  OWLCMD_ARGS("dump", owl_command_dump, OWL_CTX_ANY,
227              "dump messages to a file",
228              "dump <filename>",
229              "Dump messages in current view to the named file."),
230
231  OWLCMD_ARGS("source", owl_command_source, OWL_CTX_ANY,
232              "execute BarnOwl commands from a file",
233              "source <filename>",
234              "Execute the BarnOwl commands in <filename>.\n"),
235
236  OWLCMD_ARGS("aim", owl_command_aim, OWL_CTX_INTERACTIVE,
237              "AIM specific commands",
238              "aim search <email>",
239              ""),
240
241  OWLCMD_ARGS("addbuddy", owl_command_addbuddy, OWL_CTX_INTERACTIVE,
242              "add a buddy to a buddylist",
243              "addbuddy <protocol> <screenname>",
244              "Add the named buddy to your buddylist.  <protocol> can be aim or zephyr\n"),
245
246  OWLCMD_ARGS("delbuddy", owl_command_delbuddy, OWL_CTX_INTERACTIVE,
247              "delete a buddy from a buddylist",
248              "delbuddy <protocol> <screenname>",
249              "Delete the named buddy from your buddylist.  <protocol> can be aim or zephyr\n"),
250
251  OWLCMD_ARGS("join", owl_command_join, OWL_CTX_INTERACTIVE,
252              "join a chat group",
253              "join aim <groupname> [exchange]",
254              "Join the AIM chatroom with 'groupname'.\n"),
255
256  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
257              "creates a zpunt based on the current message",
258              "smartzpunt [-i | --instance]",
259              "Starts a zpunt command based on the current message's class\n"
260              "(and instance if -i is specified).\n"),
261
262  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
263              "suppress a given zephyr triplet",
264              "zpunt <class> <instance> [recipient]\n"
265              "zpunt <instance>",
266              "The zpunt command will suppress messages to the specified\n"
267              "zephyr triplet.  In the second usage messages are suppressed\n"
268              "for class MESSAGE and the named instance.\n\n"
269              "SEE ALSO:  zunpunt, show zpunts\n"),
270
271  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
272              "undo a previous zpunt",
273              "zunpunt <class> <instance> [recipient]\n"
274              "zunpunt <instance>",
275              "The zunpunt command will allow messages that were previously\n"
276              "suppressed to be received again.\n\n"
277              "SEE ALSO:  zpunt, show zpunts\n"),
278
279  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
280              "suppress an arbitrary filter",
281              "punt <filter-name>\n"
282              "punt <filter-text (multiple words)>",
283              "The punt command will suppress messages to the specified\n"
284              "filter\n\n"
285              "SEE ALSO:  unpunt, zpunt, show zpunts\n"),
286
287  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
288              "remove an entry from the punt list",
289              "unpunt <number>\n"
290              "unpunt <filter-name>\n"
291              "unpunt <filter-text (multiple words)>",
292              "The unpunt command will remove an entry from the puntlist.\n"
293              "The last two forms correspond to the two forms of the :punt\n"
294              "command. The first allows you to remove a specific entry from\n"
295              "the list (see :show zpunts)\n\n"
296              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
297
298  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
299              "display detailed information about the current message",
300              "", ""),
301 
302  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
303              "display help on using BarnOwl",
304              "help [command]", ""),
305
306  OWLCMD_ARGS("zlist", owl_command_zlist, OWL_CTX_INTERACTIVE,
307              "List users logged in",
308              "znol [-f file]",
309              "Print a znol-style listing of users logged in"),
310
311  OWLCMD_VOID("alist", owl_command_alist, OWL_CTX_INTERACTIVE,
312              "List AIM users logged in",
313              "alist",
314              "Print a listing of AIM users logged in"),
315
316  OWLCMD_VOID("blist", owl_command_blist, OWL_CTX_INTERACTIVE,
317              "List all buddies logged in",
318              "blist",
319              "Print a listing of buddies logged in, regardless of protocol."),
320
321  OWLCMD_VOID("toggle-oneline", owl_command_toggleoneline, OWL_CTX_INTERACTIVE,
322              "Toggle the style between oneline and the default style",
323              "toggle-oneline",
324              ""),
325
326  OWLCMD_ARGS("recv:getshift", owl_command_get_shift, OWL_CTX_INTERACTIVE,
327              "gets position of receive window scrolling", "", ""),
328
329  OWLCMD_INT("recv:setshift", owl_command_set_shift, OWL_CTX_INTERACTIVE,
330              "scrolls receive window to specified position", "", ""),
331
332  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
333              OWL_CTX_INTERACTIVE,
334              "scrolls down by a page", "", ""),
335
336  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
337              "scrolls up by a page", "", ""),
338
339  OWLCMD_VOID("recv:mark", owl_function_mark_message,
340              OWL_CTX_INTERACTIVE,
341              "mark the current message", "", ""),
342
343  OWLCMD_VOID("recv:swapmark", owl_function_swap_cur_marked,
344              OWL_CTX_INTERACTIVE,
345              "swap the positions of the pointer and the mark", "", ""),
346
347  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
348              "scrolls current message up or down", 
349              "recv:scroll <numlines>", 
350              "Scrolls the current message up or down by <numlines>.\n"
351              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
352
353  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
354              "move the pointer to the next message",
355              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
356              "          [ --smart-filter | --smart-filter-instance ]",
357              "Moves the pointer to the next message in the current view.\n"
358              "If --filter is specified, will only consider messages in\n"
359              "the filter <name>.\n"
360              "If --smart-filter or --smart-filter-instance is specified,\n"
361              "goes to the next message that is similar to the current message.\n"
362              "If --skip-deleted is specified, deleted messages will\n"
363              "be skipped.\n"
364              "If --last-if-none is specified, will stop at last message\n"
365              "in the view if no other suitable messages are found.\n"),
366  OWLCMD_ALIAS("recv:next", "next"),
367
368  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
369              "move the pointer to the previous message",
370              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
371              "          [ --smart-filter | --smart-filter-instance ]",
372              "Moves the pointer to the next message in the current view.\n"
373              "If --filter is specified, will only consider messages in\n"
374              "the filter <name>.\n"
375              "If --smart-filter or --smart-filter-instance is specified,\n"
376              "goes to the previous message that is similar to the current message.\n"
377              "If --skip-deleted is specified, deleted messages will\n"
378              "be skipped.\n"
379              "If --first-if-none is specified, will stop at first message\n"
380              "in the view if no other suitable messages are found.\n"),
381  OWLCMD_ALIAS("recv:prev", "prev"),
382
383  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
384  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
385
386  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
387  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
388
389  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
390
391  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
392
393  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
394              "move the pointer to the first message", "", ""),
395  OWLCMD_ALIAS("recv:first", "first"),
396
397  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
398              "move the pointer to the last message", "", 
399              "Moves the pointer to the last message in the view.\n"
400              "If we are already at the last message in the view,\n"
401              "blanks the screen and moves just past the end of the view\n"
402              "so that new messages will appear starting at the top\n"
403              "of the screen.\n"),
404  OWLCMD_ALIAS("recv:last", "last"),
405
406  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
407              "remove all messages marked for deletion", "", ""),
408
409  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
410              "resize the window to the current screen size", "", ""),
411
412  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
413              "redraw the entire window", "", ""),
414
415  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
416              "suspend BarnOwl", "", ""),
417
418  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
419              "pops up a message in popup window",
420              "echo [args .. ]\n\n", ""),
421
422  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
423              "run a command from the shell",
424              "exec [args .. ]", ""),
425
426  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
427              "run a command from the shell and display in an admin message",
428              "aexec [args .. ]", ""),
429
430  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
431              "run a command from the shell and display in a popup window",
432              "pexec [args .. ]", ""),
433
434  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
435              "run a perl expression",
436              "perl [args .. ]", ""),
437
438  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
439              "run a perl expression and display in an admin message",
440              "aperl [args .. ]", ""),
441
442  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
443              "run a perl expression and display in a popup window",
444              "pperl [args .. ]", ""),
445
446  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
447              "runs multiple ;-separated commands",
448              "multi <command1> ( ; <command2> )*\n",
449              "Runs multiple semicolon-separated commands in order.\n"
450              "Note quoting isn't supported here yet.\n"
451              "If you want to do something fancy, use perl.\n"),
452
453  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
454              "runs multiple ;-separated commands",
455              "'(' <command1> ( ; <command2> )* ')'\n",
456              "Runs multiple semicolon-separated commands in order.\n"
457              "You must have a space before the final ')'\n"
458              "Note quoting isn't supported here yet.\n"
459              "If you want to do something fancy, use perl.\n"),
460
461  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
462              "pops up a message in a window", "", ""),
463
464  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
465              "Set, enable or disable zephyr away message",
466              "zaway [ on | off | toggle ]\n"
467              "zaway <message>",
468              "Turn on or off a zaway message.  If 'message' is\n"
469              "specified turn on zaway with that message, otherwise\n"
470              "use the default.\n"),
471
472  OWLCMD_ARGS("aaway", owl_command_aaway, OWL_CTX_INTERACTIVE,
473              "Set, enable or disable AIM away message",
474              "aaway [ on | off | toggle ]\n"
475              "aaway <message>",
476              "Turn on or off the AIM away message.  If 'message' is\n"
477              "specified turn on aaway with that message, otherwise\n"
478              "use the default.\n"),
479
480  OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
481              "Set, enable or disable both AIM and zephyr away messages",
482              "away [ on | off | toggle ]\n"
483              "away <message>",
484              "Turn on or off the AIM and zephyr away message.  If\n"
485              "'message' is specified turn them on with that message,\n"
486              "otherwise use the default.\n"
487              "\n"
488              "This command really just runs the 'aaway' and 'zaway'\n"
489              "commands together\n"
490              "\n"
491              "SEE ALSO: aaway, zaway"),
492
493  OWLCMD_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] [initial-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    // FIXME: The above won't work when we make perl variables OWL_VARIABLE_SV
1608    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1609  } else {
1610    owl_variable_set_fromstring(v, val, !silent);
1611  }
1612  return NULL;
1613}
1614
1615char *owl_command_unset(int argc, const char *const *argv, const char *buff)
1616{
1617  owl_variable *v;
1618  const char *var, *val;
1619  int  silent=0;
1620
1621  if (argc > 1 && !strcmp("-q",argv[1])) {
1622    silent = 1;
1623    argc--; argv++;
1624  }
1625  if (argc == 2) {
1626    var=argv[1];
1627    val="off";
1628  } else {
1629    owl_function_makemsg("Wrong number of arguments for unset command");
1630    return NULL;
1631  }
1632
1633  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1634  if (v == NULL) {
1635    if (!silent) owl_function_error("Unknown variable '%s'", var);
1636  } else if (owl_variable_get_type(v) != OWL_VARIABLE_BOOL) {
1637    // FIXME: The above won't work when we make perl variables OWL_VARIABLE_SV
1638    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1639  } else {
1640    owl_variable_set_fromstring(v, val, !silent);
1641  }
1642  return NULL;
1643}
1644
1645char *owl_command_print(int argc, const char *const *argv, const char *buff)
1646{
1647  const char *var;
1648  char *value;
1649  const owl_variable *v;
1650
1651  if (argc==1) {
1652    owl_function_printallvars();
1653    return NULL;
1654  } else if (argc!=2) {
1655    owl_function_makemsg("Wrong number of arguments for print command");
1656    return NULL;
1657  }
1658
1659  var=argv[1];
1660   
1661  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1662  if (v) {
1663    value = owl_variable_get_tostring(v);
1664    if (value == NULL)
1665      owl_function_makemsg("%s = <null>", var);
1666    else
1667      owl_function_makemsg("%s = '%s'", var, value);
1668    g_free(value);
1669  } else {
1670    owl_function_makemsg("Unknown variable '%s'.", var);
1671  }
1672  return NULL;
1673}
1674
1675
1676CALLER_OWN char *owl_command_exec(int argc, const char *const *argv, const char *buff)
1677{
1678  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_RETURN);
1679}
1680
1681CALLER_OWN char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
1682{
1683  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_POPUP);
1684}
1685
1686CALLER_OWN char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
1687{
1688  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1689}
1690
1691CALLER_OWN char *owl_command_perl(int argc, const char *const *argv, const char *buff)
1692{
1693  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_RETURN);
1694}
1695
1696CALLER_OWN char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
1697{
1698  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_POPUP);
1699}
1700
1701CALLER_OWN char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
1702{
1703  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1704}
1705
1706CALLER_OWN char *owl_command_multi(int argc, const char *const *argv, const char *buff)
1707{
1708  char *lastrv = NULL, *newbuff;
1709  char **commands;
1710  int  i;
1711  if (argc < 2) {
1712    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1713    return NULL;
1714  }
1715  newbuff = g_strdup(skiptokens(buff, 1));
1716  if (!strcmp(argv[0], "(")) {
1717    for (i=strlen(newbuff)-1; i>=0; i--) {
1718      if (newbuff[i] == ')') {
1719        newbuff[i] = '\0';
1720        break;
1721      } else if (newbuff[i] != ' ') {
1722        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1723        g_free(newbuff);
1724        return NULL;
1725      }
1726    }
1727  }
1728  commands = g_strsplit_set(newbuff, ";", 0);
1729  for (i = 0; commands[i] != NULL; i++) {
1730    g_free(lastrv);
1731    lastrv = owl_function_command(commands[i]);
1732  }
1733  g_free(newbuff);
1734  g_strfreev(commands);
1735  return lastrv;
1736}
1737
1738
1739char *owl_command_alias(int argc, const char *const *argv, const char *buff)
1740{
1741  if (argc < 3) {
1742    owl_function_makemsg("Invalid arguments to 'alias' command.");
1743    return NULL;
1744  }
1745  buff = skiptokens(buff, 2);
1746  owl_function_command_alias(argv[1], buff);
1747  return (NULL);
1748}
1749
1750
1751char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
1752{
1753  owl_keymap *km;
1754  int ret;
1755
1756  if (argc < 5 || strcmp(argv[3], "command")) {
1757    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1758    return NULL;
1759  }
1760  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1761  if (!km) {
1762    owl_function_makemsg("No such keymap '%s'", argv[1]);
1763    return NULL;
1764  }
1765  buff = skiptokens(buff, 4);
1766  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1767  if (ret!=0) {
1768    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1769                         argv[2], argv[1], buff);
1770    return NULL;
1771  }
1772  return NULL;
1773}
1774
1775
1776char *owl_command_unbindkey(int argc, const char *const *argv, const char *buf)
1777{
1778  owl_keymap *km;
1779  int ret;
1780
1781  if (argc < 3) {
1782    owl_function_makemsg("Usage: unbindkey <keymap> <binding>");
1783    return NULL;
1784  }
1785  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1786  if (!km) {
1787    owl_function_makemsg("No such keymap '%s'", argv[1]);
1788    return NULL;
1789  }
1790  ret = owl_keymap_remove_binding(km, argv[2]);
1791  if (ret == -1) {
1792    owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
1793                         argv[2], argv[1]);
1794    return NULL;
1795  } else if (ret == -2) {
1796    owl_function_makemsg("No such binding '%s' in keymap '%s'.",
1797                         argv[2], argv[1]);
1798  }
1799  return NULL;
1800}
1801
1802
1803void owl_command_quit(void)
1804{
1805  owl_function_quit();
1806}
1807
1808char *owl_command_debug(int argc, const char *const *argv, const char *buff)
1809{
1810  if (argc<2) {
1811    owl_function_makemsg("Need at least one argument to debug command");
1812    return(NULL);
1813  }
1814
1815  if (!owl_global_is_debug_fast(&g)) {
1816    owl_function_makemsg("Debugging is not turned on");
1817    return(NULL);
1818  }
1819
1820  owl_function_debugmsg("%s", argv[1]);
1821  return(NULL);
1822}
1823
1824char *owl_command_term(int argc, const char *const *argv, const char *buff)
1825{
1826  if (argc<2) {
1827    owl_function_makemsg("Need at least one argument to the term command");
1828    return(NULL);
1829  }
1830
1831  if (!strcmp(argv[1], "raise")) {
1832    owl_function_xterm_raise();
1833  } else if (!strcmp(argv[1], "deiconify")) {
1834    owl_function_xterm_deiconify();
1835  } else {
1836    owl_function_makemsg("Unknown terminal subcommand");
1837  }
1838  return(NULL);
1839}
1840
1841char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
1842{
1843  if ((argc<2) || (argc>3)) {
1844    owl_function_makemsg("Wrong number of arguments for zlog command");
1845    return(NULL);
1846  }
1847
1848  if (!strcmp(argv[1], "in")) {
1849    if (argc>2) {
1850      owl_global_set_tty(&g, argv[2]);
1851    }
1852    owl_zephyr_zlog_in();
1853  } else if (!strcmp(argv[1], "out")) {
1854    if (argc!=2) {
1855      owl_function_makemsg("Wrong number of arguments for zlog command");
1856      return(NULL);
1857    }
1858    owl_zephyr_zlog_out();
1859  } else {
1860    owl_function_makemsg("Invalid subcommand for zlog");
1861  }
1862  return(NULL);
1863}
1864
1865char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
1866{
1867  const char *class, *instance, *recip="";
1868  int temp=0;
1869  int ret=0;
1870
1871  if (argc < 2) {
1872    owl_function_makemsg("Not enough arguments to the subscribe command");
1873    return(NULL);
1874  }
1875  argc--;
1876  argv++;
1877
1878  if (!strcmp(argv[0], "-t")) {
1879    temp=1;
1880    argc--;
1881    argv++;
1882  }
1883  if (argc < 1) {
1884    owl_function_makemsg("Not enough arguments to the subscribe command");
1885    return(NULL);
1886  }
1887
1888  if (argc > 3) {
1889    owl_function_makemsg("Too many arguments to the subscribe command");
1890    return(NULL);
1891  }
1892
1893  class = argv[0];
1894
1895  if (argc == 1) {
1896    instance = "*";
1897  } else {
1898    instance = argv[1];
1899  }
1900
1901  if (argc <= 2) {
1902    recip="";
1903  } else if (argc==3) {
1904    recip=argv[2];
1905  }
1906
1907  ret = owl_function_subscribe(class, instance, recip);
1908  if (!temp && !ret) {
1909    owl_zephyr_addsub(NULL, class, instance, recip);
1910  }
1911  return(NULL);
1912}
1913
1914
1915char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
1916{
1917  const char *class, *instance, *recip="";
1918  int temp=0;
1919
1920  if (argc < 2) {
1921    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1922    return(NULL);
1923  }
1924  argc--;
1925  argv++;
1926
1927  if (!strcmp(argv[0], "-t")) {
1928    temp=1;
1929    argc--;
1930    argv++;
1931  }
1932  if (argc < 1) {
1933    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1934    return(NULL);
1935  }
1936
1937  if (argc > 3) {
1938    owl_function_makemsg("Too many arguments to the unsubscribe command");
1939    return(NULL);
1940  }
1941
1942  class = argv[0];
1943
1944  if (argc == 1) {
1945    instance = "*";
1946  } else {
1947    instance = argv[1];
1948  }
1949
1950  if (argc <= 2) {
1951    recip="";
1952  } else if (argc==3) {
1953    recip=argv[2];
1954  }
1955
1956  owl_function_unsubscribe(class, instance, recip);
1957  if (!temp) {
1958    owl_zephyr_delsub(NULL, class, instance, recip);
1959  }
1960  return(NULL);
1961}
1962
1963char *owl_command_echo(int argc, const char *const *argv, const char *buff)
1964{
1965  buff = skiptokens(buff, 1);
1966  owl_function_popless_text(buff);
1967  return NULL;
1968}
1969
1970void owl_command_getsubs(void)
1971{
1972  owl_function_getsubs();
1973}
1974
1975void owl_command_status(void)
1976{
1977  owl_function_status();
1978}
1979
1980char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
1981{
1982  owl_zwrite *z;
1983
1984  if (!owl_global_is_havezephyr(&g)) {
1985    owl_function_makemsg("Zephyr is not available");
1986    return(NULL);
1987  }
1988  /* check for a zwrite -m */
1989  z = owl_zwrite_new(argc, argv);
1990  if (!z) {
1991    owl_function_error("Error in zwrite arguments");
1992    return NULL;
1993  }
1994
1995  if (owl_zwrite_is_message_set(z)) {
1996    owl_function_zwrite(z, NULL);
1997    owl_zwrite_delete(z);
1998    return NULL;
1999  }
2000
2001  if (argc < 2) {
2002    owl_zwrite_delete(z);
2003    owl_function_makemsg("Not enough arguments to the zwrite command.");
2004  } else {
2005    owl_function_zwrite_setup(z);
2006  }
2007  return(NULL);
2008}
2009
2010char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
2011{
2012  char *message = NULL;
2013  GString *recip = g_string_new("");
2014  const char *const *myargv;
2015  int myargc;
2016 
2017  if (!owl_global_is_aimloggedin(&g)) {
2018    owl_function_error("You are not logged in to AIM.");
2019    goto err;
2020  }
2021
2022  /* Skip argv[0]. */
2023  myargv = argv+1;
2024  myargc = argc-1;
2025  while (myargc) {
2026    if (!strcmp(myargv[0], "-m")) {
2027      if (myargc <= 1) {
2028        owl_function_error("No message specified.");
2029        goto err;
2030      }
2031      /* Once we have -m, gobble up everything else on the line */
2032      myargv++;
2033      myargc--;
2034      message = g_strjoinv(" ", (char**)myargv);
2035      break;
2036    } else {
2037      /* squish arguments together to make one screenname w/o spaces for now */
2038      g_string_append(recip, myargv[0]);
2039      myargv++;
2040      myargc--;
2041    }
2042  }
2043
2044  if (recip->str[0] == '\0') {
2045    owl_function_error("No recipient specified");
2046    goto err;
2047  }
2048
2049  if (message != NULL)
2050    owl_function_aimwrite(recip->str, message, false);
2051  else
2052    owl_function_aimwrite_setup(recip->str);
2053 err:
2054  g_string_free(recip, true);
2055  g_free(message);
2056  return NULL;
2057}
2058
2059char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
2060{
2061  owl_function_loopwrite_setup();
2062  return(NULL);
2063}
2064
2065char *owl_command_reply(int argc, const char *const *argv, const char *buff)
2066{
2067  int edit=0;
2068 
2069  if (argc>=2 && !strcmp("-e", argv[1])) {
2070    edit=1;
2071    argv++;
2072    argc--;
2073  }
2074
2075  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2076    owl_function_reply(0, !edit);
2077  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2078    owl_function_reply(1, !edit);
2079  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2080    const owl_message *m;
2081    const owl_view    *v;
2082    v = owl_global_get_current_view(&g);   
2083    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2084    if (m) owl_zephyr_zaway(m);
2085  } else {
2086    owl_function_makemsg("Invalid arguments to the reply command.");
2087  }
2088  return NULL;
2089}
2090
2091char *owl_command_filter(int argc, const char *const *argv, const char *buff)
2092{
2093  owl_function_create_filter(argc, argv);
2094  return NULL;
2095}
2096
2097char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
2098{
2099  int auth;
2100 
2101  if (argc<2) {
2102    owl_function_makemsg("Too few arguments for zlocate command");
2103    return NULL;
2104  }
2105
2106  auth=1;
2107  if (!strcmp(argv[1], "-d")) {
2108    if (argc>2) {
2109      auth=0;
2110      argc--;
2111      argv++;
2112    } else {
2113      owl_function_makemsg("Missing arguments for zlocate command");
2114      return NULL;
2115    }
2116  }
2117
2118  argc--;
2119  argv++;
2120  owl_function_zlocate(argc, argv, auth);
2121  return NULL;
2122}
2123
2124
2125/* Backwards compatability has made this kind of complicated:
2126 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2127 * view <filter>
2128 * view -d <expression>
2129 * view --home
2130 */
2131char *owl_command_view(int argc, const char *const *argv, const char *buff)
2132{
2133  /* First take the 'view --home' and 'view -r' cases */
2134  if (argc == 2) {
2135    if (!strcmp(argv[1], "--home")) {
2136      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2137      return(NULL);
2138    } else if (!strcmp(argv[1], "-r")) {
2139      char *foo;
2140      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2141      owl_function_change_currentview_filter(foo);
2142      g_free(foo);
2143      return(NULL);
2144    }
2145  }
2146
2147  /* Now look for 'view <filter>' */
2148  if (argc==2) {
2149    owl_function_change_currentview_filter(argv[1]);
2150    return(NULL);
2151  }
2152
2153  /* Now get 'view -d <expression>' */
2154  if (argc>=3 && !strcmp(argv[1], "-d")) {
2155    const char **myargv;
2156    int i;
2157
2158    /* Allocate one more than argc for the trailing NULL. */
2159    myargv = g_new0(const char*, argc+1);
2160    myargv[0]="";
2161    myargv[1]="owl-dynamic";
2162    for (i=2; i<argc; i++) {
2163      myargv[i]=argv[i];
2164    }
2165    if (owl_function_create_filter(argc, myargv)) {
2166      owl_function_change_currentview_filter("owl-dynamic");
2167    }
2168    g_free(myargv);
2169    return NULL;
2170  }
2171
2172  /* Finally handle the general case */
2173  if (argc<3) {
2174    owl_function_makemsg("Too few arguments to the view command.");
2175    return(NULL);
2176  }
2177  argc--;
2178  argv++;
2179  if (strcmp(argv[0], "-f") &&
2180      strcmp(argv[0], "-d") &&
2181      strcmp(argv[0], "--home") &&
2182      strcmp(argv[0], "-s") &&
2183      strcmp(argv[0], "-r")) {
2184    if (strcmp(argv[0], "main")) {
2185      owl_function_makemsg("No view named '%s'", argv[0]);
2186      return(NULL);
2187    }
2188    argc--;
2189    argv++;
2190  }
2191  while (argc) {
2192    if (!strcmp(argv[0], "-f")) {
2193      if (argc<2) {
2194        owl_function_makemsg("Too few arguments to the view command");
2195        return(NULL);
2196      }
2197      owl_function_change_currentview_filter(argv[1]);
2198      argc-=2;
2199      argv+=2;
2200    } else if (!strcmp(argv[0], "--home")) {
2201      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2202      argc--;
2203      argv++;
2204    } else if (!strcmp(argv[0], "-s")) {
2205      if (argc<2) {
2206        owl_function_makemsg("Too few arguments to the view command");
2207        return(NULL);
2208      }
2209      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2210      argc-=2;
2211      argv+=2;
2212    } else {
2213      owl_function_makemsg("Too few arguments to the view command");
2214      return(NULL);
2215    }
2216   
2217  }
2218  return(NULL);
2219}
2220
2221char *owl_command_show(int argc, const char *const *argv, const char *buff)
2222{
2223  if (argc<2) {
2224    owl_function_help_for_command("show");
2225    return NULL;
2226  }
2227
2228  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2229    if (argc==2) {
2230      owl_function_show_filters();
2231    } else {
2232      owl_function_show_filter(argv[2]);
2233    }
2234  } else if (argc==2 
2235             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2236    owl_function_show_zpunts();
2237  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2238    if (argc==2) {
2239      owl_function_show_commands();
2240    } else {
2241      owl_function_show_command(argv[2]);
2242    }
2243  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2244    if (argc==2) {
2245      owl_function_show_variables();
2246    } else {
2247      owl_function_show_variable(argv[2]);
2248    }
2249  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2250    if (argc==2) {
2251      owl_function_show_keymaps();
2252    } else {
2253      owl_function_show_keymap(argv[2]);
2254    }
2255  } else if (!strcmp(argv[1], "view")) {
2256    if (argc==3) {
2257      owl_function_show_view(argv[2]);
2258    } else {
2259      owl_function_show_view(NULL);
2260    }
2261  } else if (!strcmp(argv[1], "colors")) {
2262    owl_function_show_colors();
2263  } else if (!strcmp(argv[1], "styles")) {
2264    owl_function_show_styles();
2265  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2266    owl_function_getsubs();
2267  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2268    owl_function_show_term();
2269  } else if (!strcmp(argv[1], "version")) {
2270    owl_function_about();
2271  } else if (!strcmp(argv[1], "status")) {
2272    owl_function_status();
2273  } else if (!strcmp(argv[1], "license")) {
2274    owl_function_show_license();
2275  } else if (!strcmp(argv[1], "quickstart")) {
2276    owl_function_show_quickstart();
2277  } else if (!strcmp(argv[1], "startup")) {
2278    const char *filename;
2279   
2280    filename=owl_global_get_startupfile(&g);
2281    owl_function_popless_file(filename);
2282  } else if (!strcmp(argv[1], "errors")) {
2283    owl_function_showerrs();
2284  } else {
2285    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2286    return NULL;
2287  }
2288  return NULL;
2289}
2290
2291char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
2292{
2293  char *filtname;
2294  if (argc!=2) {
2295    owl_function_makemsg("Wrong number of arguments to viewclass command");
2296    return NULL;
2297  }
2298  filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2299  if (filtname) {
2300    owl_function_change_currentview_filter(filtname);
2301    g_free(filtname);
2302  }
2303  return NULL;
2304}
2305
2306char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
2307{
2308  char *filtname;
2309  char *longuser;
2310  if (argc!=2) {
2311    owl_function_makemsg("Wrong number of arguments to viewuser command");
2312    return NULL;
2313  }
2314  longuser = long_zuser(argv[1]);
2315  filtname = owl_function_zuserfilt(longuser);
2316  g_free(longuser);
2317  if (filtname) {
2318    owl_function_change_currentview_filter(filtname);
2319    g_free(filtname);
2320  }
2321  return NULL;
2322}
2323
2324
2325void owl_command_pop_message(void)
2326{
2327  owl_function_curmsg_to_popwin();
2328}
2329
2330char *owl_command_delete(int argc, const char *const *argv, const char *buff)
2331{
2332  int move_after = 1;
2333
2334  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2335    move_after = 0;
2336    argc--; 
2337    argv++;
2338  }
2339
2340  if (argc==1) {
2341    owl_function_deletecur(move_after);
2342    return NULL;
2343  }
2344
2345  if (argc==2 && !strcmp(argv[1], "view")) {
2346    owl_function_delete_curview_msgs(1);
2347    return NULL;
2348  }
2349
2350  if (argc==2 && !strcmp(argv[1], "trash")) {
2351    owl_function_delete_automsgs();
2352    return NULL;
2353  }
2354
2355  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2356    owl_function_delete_by_id(atoi(argv[2]), 1);
2357    return NULL;
2358  }
2359
2360  owl_function_makemsg("Unknown arguments to delete command");
2361  return NULL;
2362}
2363
2364char *owl_command_delete_and_expunge(int argc, const char *const *argv, const char *buff)
2365{
2366  bool exclaim_success = true;
2367
2368  if (argc > 1 && (!strcmp(argv[1], "-q") || !strcmp(argv[1], "--quiet"))) {
2369    exclaim_success = false;
2370    argc--;
2371    argv++;
2372  } else if (!strcmp(argv[argc - 1], "-q") || !strcmp(argv[argc - 1], "--quiet")) {
2373    exclaim_success = false;
2374    argc--;
2375  }
2376
2377  if (argc == 1) {
2378    owl_function_delete_and_expunge_cur(exclaim_success);
2379    return NULL;
2380  }
2381
2382  if (argc == 3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2383    owl_function_delete_and_expunge_by_id(atoi(argv[2]), exclaim_success);
2384    return NULL;
2385  }
2386
2387  owl_function_makemsg("Unknown arguments to delete-and-expunge command");
2388  return NULL;
2389}
2390
2391char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
2392{
2393  int move_after = 1;
2394
2395  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2396    move_after = 0;
2397    argc--; 
2398    argv++;
2399  }
2400
2401  if (argc==1) {
2402    owl_function_undeletecur(move_after);
2403    return NULL;
2404  }
2405
2406  if (argc==2 && !strcmp(argv[1], "view")) {
2407    owl_function_delete_curview_msgs(0);
2408    return NULL;
2409  }
2410
2411  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2412    owl_function_delete_by_id(atoi(argv[2]), 0);
2413    return NULL;
2414  }
2415
2416  owl_function_makemsg("Unknown arguments to delete command");
2417  return NULL;
2418}
2419
2420void owl_command_beep(void)
2421{
2422  owl_function_beep();
2423}
2424
2425char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
2426{
2427  if (argc < 2 || argc > 3) {
2428    owl_function_makemsg("Wrong number of arguments to colorview command");
2429    return NULL;
2430  }
2431  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2432  return NULL;
2433}
2434
2435char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
2436{
2437  char *filtname;
2438 
2439  if (argc < 3 || argc > 4) {
2440    owl_function_makemsg("Wrong number of arguments to colorclass command");
2441    return NULL;
2442  }
2443
2444  filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2445  if (filtname) {
2446    (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2447    g_free(filtname);
2448  }
2449  return NULL;
2450}
2451
2452char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
2453{
2454  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2455  return NULL;
2456}
2457
2458char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
2459{
2460  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2461  return NULL;
2462}
2463
2464void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
2465{
2466  /* if type==0 then zpunt
2467   * if type==1 then zunpunt
2468   */
2469  const char *class, *inst, *recip;
2470
2471  class="message";
2472  inst="";
2473  recip="*";
2474
2475  if (argc==1) {
2476    /* show current punt filters */
2477    owl_function_show_zpunts();
2478    return;
2479  } else if (argc==2) {
2480    inst=argv[1];
2481  } else if (argc==3) {
2482    class=argv[1];
2483    inst=argv[2];
2484  } else if (argc==4) {
2485    class=argv[1];
2486    inst=argv[2];
2487    recip=argv[3];
2488  } else {
2489    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2490    return;
2491  }
2492
2493  owl_function_zpunt(class, inst, recip, type);
2494  if (type==0) {
2495    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2496  } else if (type==1) {
2497    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2498  }
2499}
2500
2501char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
2502{
2503  if (argc == 1) {
2504    owl_function_smartzpunt(0);
2505  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2506    owl_function_smartzpunt(1);
2507  } else {
2508    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2509  }
2510  return NULL;
2511}
2512
2513char *owl_command_punt(int argc, const char *const *argv, const char *buff)
2514{
2515  owl_command_punt_unpunt(argc, argv, buff, 0);
2516  return NULL;
2517}
2518
2519char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
2520{
2521  owl_command_punt_unpunt(argc, argv, buff, 1);
2522  return NULL;
2523}
2524
2525void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
2526{
2527  GPtrArray * fl;
2528  int i;
2529
2530  fl = owl_global_get_puntlist(&g);
2531  if(argc == 1) {
2532    owl_function_show_zpunts();
2533  } else if(argc == 2) {
2534    /* Handle :unpunt <number> */
2535    if (unpunt && (i = atoi(argv[1])) > 0) {
2536      i--;      /* Accept 1-based indexing */
2537      if (i < fl->len) {
2538        owl_filter_delete(g_ptr_array_remove_index(fl, i));
2539        return;
2540      } else {
2541        owl_function_makemsg("No such filter number: %d.", i+1);
2542      }
2543    }
2544    const char *filter[] = {"filter", argv[1]};
2545    owl_function_punt(2, filter, unpunt);
2546  } else {
2547    /* Pass in argv[1]..argv[argc-1]. */
2548    owl_function_punt(argc - 1, argv + 1, unpunt);
2549  }
2550}
2551
2552
2553char *owl_command_getview(int argc, const char *const *argv, const char *buff)
2554{
2555  const char *filtname;
2556  if (argc != 1) {
2557    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2558    return NULL;
2559  }
2560  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2561  if (filtname) return g_strdup(filtname);
2562  return NULL;
2563}
2564
2565CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
2566{
2567  const owl_variable *v;
2568  if (argc != 2) {
2569    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2570    return NULL;
2571  }
2572  v = owl_variable_get_var(owl_global_get_vardict(&g), argv[1]);
2573  if (v == NULL) return NULL;
2574  return owl_variable_get_tostring(v);
2575}
2576
2577char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
2578{
2579  const owl_filter *f;
2580  if (argc != 2) {
2581    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2582    return NULL;
2583  }
2584  f = owl_global_get_filter(&g, argv[1]);
2585  if (!f) {
2586    return NULL;
2587  }
2588  return owl_filter_print(f);
2589}
2590
2591char *owl_command_search(int argc, const char *const *argv, const char *buff)
2592{
2593  int direction;
2594  const char *buffstart;
2595
2596  direction=OWL_DIRECTION_DOWNWARDS;
2597  buffstart=skiptokens(buff, 1);
2598  if (argc>1 && !strcmp(argv[1], "-r")) {
2599    direction=OWL_DIRECTION_UPWARDS;
2600    buffstart=skiptokens(buff, 2);
2601  }
2602   
2603  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2604    /* When continuing a search, don't consider the current message. */
2605    owl_function_search_helper(false, direction);
2606  } else {
2607    owl_function_set_search(buffstart);
2608    owl_function_search_helper(true, direction);
2609  }
2610 
2611  return(NULL);
2612}
2613
2614char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
2615{
2616  const char *buffstart;
2617
2618  buffstart=skiptokens(buff, 1);
2619  owl_function_set_search(*buffstart ? buffstart : NULL);
2620 
2621  return(NULL);
2622}
2623
2624char *owl_command_aimlogin(int argc, const char *const *argv, const char *buff)
2625{
2626  if ((argc<2) || (argc>3)) {
2627    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2628    return(NULL);
2629  }
2630
2631  /* if we get two arguments, ask for the password */
2632  if (argc==2) {
2633    owl_editwin *e = owl_function_start_password("AIM Password: ");
2634    owl_editwin_set_cbdata(e, g_strdup(argv[1]), g_free);
2635    owl_editwin_set_callback(e, owl_callback_aimlogin);
2636    return(NULL);
2637  } else {
2638    owl_function_aimlogin(argv[1], argv[2]);
2639  }
2640
2641  /* this is a test */
2642  return(NULL);
2643}
2644
2645char *owl_command_aimlogout(int argc, const char *const *argv, const char *buff)
2646{
2647  /* clear the buddylist */
2648  owl_buddylist_clear(owl_global_get_buddylist(&g));
2649
2650  owl_aim_logout();
2651  return(NULL);
2652}
2653
2654CALLER_OWN char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
2655{
2656  const char *stylename;
2657  if (argc != 1) {
2658    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2659    return NULL;
2660  }
2661  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2662  if (stylename) return g_strdup(stylename);
2663  return NULL;
2664}
2665
2666char *owl_command_error(int argc, const char *const *argv, const char *buff)
2667{
2668    buff = skiptokens(buff, 1);
2669    owl_function_error("%s", buff);
2670    return NULL;
2671}
2672
2673char *owl_command_message(int argc, const char *const *argv, const char *buff)
2674{
2675    buff = skiptokens(buff, 1);
2676    owl_function_makemsg("%s", buff);
2677    return NULL;
2678}
2679
2680char *owl_command_add_cmd_history(int argc, const char *const *argv, const char *buff)
2681{
2682  owl_history *hist;
2683  const char *ptr;
2684
2685  if (argc < 2) {
2686    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
2687    return NULL;
2688  }
2689
2690  ptr = skiptokens(buff, 1);
2691  hist = owl_global_get_cmd_history(&g);
2692  owl_history_store(hist, ptr, false);
2693  /* owl_function_makemsg("History '%s' stored successfully", ptr+1); */
2694  return NULL;
2695}
2696
2697CALLER_OWN char *owl_command_with_history(int argc, const char *const *argv, const char *buff)
2698{
2699  owl_history *hist;
2700  const char *ptr;
2701
2702  if (argc < 2) {
2703    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
2704    return NULL;
2705  }
2706
2707  ptr = skiptokens(buff, 1);
2708  if (!ptr) {
2709    owl_function_makemsg("Parse error finding command");
2710    return NULL;
2711  }
2712
2713  hist = owl_global_get_cmd_history(&g);
2714  owl_history_store(hist, ptr, false);
2715  return owl_function_command(ptr);
2716}
2717
2718void owl_command_yes(void)
2719{
2720  owl_message *m;
2721  const owl_view *v;
2722  const char *cmd;
2723
2724  v = owl_global_get_current_view(&g);
2725
2726  /* bail if there's no current message */
2727  if (owl_view_get_size(v) < 1) {
2728    owl_function_error("No current message.");
2729    return;
2730  }
2731
2732  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2733  if(!owl_message_is_question(m)) {
2734    owl_function_error("That message isn't a question.");
2735    return;
2736  }
2737  if(owl_message_is_answered(m)) {
2738    owl_function_error("You already answered that question.");
2739    return;
2740  }
2741  cmd = owl_message_get_attribute_value(m, "yescommand");
2742  if(!cmd) {
2743    owl_function_error("No 'yes' command!");
2744    return;
2745  }
2746
2747  owl_function_command_norv(cmd);
2748  owl_message_set_isanswered(m);
2749  return;
2750}
2751
2752void owl_command_no(void)
2753{
2754  owl_message *m;
2755  const owl_view *v;
2756  const char *cmd;
2757
2758  v = owl_global_get_current_view(&g);
2759
2760  /* bail if there's no current message */
2761  if (owl_view_get_size(v) < 1) {
2762    owl_function_error("No current message.");
2763    return;
2764  }
2765
2766  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2767  if(!owl_message_is_question(m)) {
2768    owl_function_error("That message isn't a question.");
2769    return;
2770  }
2771  if(owl_message_is_answered(m)) {
2772    owl_function_error("You already answered that question.");
2773    return;
2774  }
2775  cmd = owl_message_get_attribute_value(m, "nocommand");
2776  if(!cmd) {
2777    owl_function_error("No 'no' command!");
2778    return;
2779  }
2780
2781  owl_function_command_norv(cmd);
2782  owl_message_set_isanswered(m);
2783  return;
2784}
2785
2786/*********************************************************************/
2787/************************** EDIT SPECIFIC ****************************/
2788/*********************************************************************/
2789
2790void owl_command_edit_cancel(owl_editwin *e)
2791{
2792  owl_history *hist;
2793
2794  owl_function_makemsg("Command cancelled.");
2795
2796  hist = owl_editwin_get_history(e);
2797  if (hist)
2798    owl_history_store(hist, owl_editwin_get_text(e), false);
2799
2800  /* Take a reference to the editwin, so that it survives the pop
2801   * context. TODO: We should perhaps refcount or otherwise protect
2802   * the context so that, even if a command pops a context, the
2803   * context itself will last until the command returns. */
2804  owl_editwin_ref(e);
2805  owl_global_pop_context(&g);
2806
2807  owl_editwin_do_callback(e, false);
2808  owl_editwin_unref(e);
2809}
2810
2811void owl_command_edit_history_prev(owl_editwin *e)
2812{
2813  owl_history *hist;
2814  const char *ptr;
2815
2816  hist=owl_editwin_get_history(e);
2817  if (!hist)
2818    return;
2819  if (!owl_history_is_touched(hist))
2820    owl_history_store(hist, owl_editwin_get_text(e), true);
2821  ptr=owl_history_get_prev(hist);
2822  if (ptr) {
2823    owl_editwin_clear(e);
2824    owl_editwin_insert_string(e, ptr);
2825  } else {
2826    owl_function_beep();
2827  }
2828}
2829
2830void owl_command_edit_history_next(owl_editwin *e)
2831{
2832  owl_history *hist;
2833  const char *ptr;
2834
2835  hist=owl_editwin_get_history(e);
2836  if (!hist)
2837    return;
2838  ptr=owl_history_get_next(hist);
2839  if (ptr) {
2840    owl_editwin_clear(e);
2841    owl_editwin_insert_string(e, ptr);
2842  } else {
2843    owl_function_beep();
2844  }
2845}
2846
2847char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
2848{
2849  buff = skiptokens(buff, 1);
2850  owl_editwin_insert_string(e, buff);
2851  return NULL;
2852}
2853
2854void owl_command_edit_done(owl_editwin *e)
2855{
2856  owl_history *hist=owl_editwin_get_history(e);
2857
2858  if (hist)
2859    owl_history_store(hist, owl_editwin_get_text(e), false);
2860
2861  /* Take a reference to the editwin, so that it survives the pop
2862   * context. TODO: We should perhaps refcount or otherwise protect
2863   * the context so that, even if a command pops a context, the
2864   * context itself will last until the command returns. */
2865  owl_editwin_ref(e);
2866  owl_global_pop_context(&g);
2867
2868  owl_editwin_do_callback(e, true);
2869  owl_editwin_unref(e);
2870}
2871
2872void owl_command_edit_done_or_delete(owl_editwin *e)
2873{
2874  if (owl_editwin_is_at_end(e)) {
2875    owl_command_edit_done(e);
2876  } else {
2877    owl_editwin_delete_char(e);
2878  }
2879}
2880
2881
2882/*********************************************************************/
2883/*********************** POPLESS SPECIFIC ****************************/
2884/*********************************************************************/
2885
2886void owl_command_popless_quit(owl_viewwin *vw)
2887{
2888  owl_popwin *pw;
2889  pw = owl_global_get_popwin(&g);
2890  owl_global_set_popwin(&g, NULL);
2891  /* Kind of a hack, but you can only have one active viewwin right
2892   * now anyway. */
2893  if (vw == owl_global_get_viewwin(&g))
2894    owl_global_set_viewwin(&g, NULL);
2895  owl_viewwin_delete(vw);
2896  owl_popwin_delete(pw);
2897  owl_global_pop_context(&g);
2898}
Note: See TracBrowser for help on using the repository browser.