source: commands.c @ 7dfe886

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