source: commands.c @ caac19d

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