source: commands.c @ f1e629d

barnowl_perlaimdebianowlrelease-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f1e629d was f1e629d, checked in by Erik Nygren <nygren@mit.edu>, 17 years ago
New API for perl message formatting functions. Legacy variables are still supported for owl::format_msg and owl::receive_msg, but these functions are now also passed an owl::Message object which contains methods for accessing the contents of the message. See perlwrap.pm (and docs TBD) for the available methods. *** WARNING: The exact API for owl::Message has *** not yet stabilized. Added "style" command for creating new styles. Usage: style <name> perl <function_name> Added support for "show styles". Changed global style table from list to dictionary. Changed AIM password prompt from "Password:" to "AIM Password:". Messages are reformatted after a window resize to allow styles to take into account the width of the window. When perl throws an error, the message is put in the msgwin if possible. Added perl functions for: owl::getcurmsg() -- returns an owl::Message object for the active message in the current view. owl::getnumcols() -- returns the column width of the window owl::zephyr_getrealm() -- returns the zephyr realm owl::zephyr_getsender() -- returns the zephyr sender Made owl::COMMAND("foo"); be syntactic sugar for owl::command("COMMAND foo"); *** Is this a good or bad idea? *** This feature may be taken out before release. Added perlwrap.pm to contain perl code to be compiled into the binary. This is transformed into perlwrap.c by encapsulate.pl. Renamed readconfig.c to perlconfig.c and changed variables accordingly. Minor bugfixes in cmd.c and commands.c
  • Property mode set to 100644
File size: 66.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include "owl.h"
6
7static const char fileIdent[] = "$Id$";
8
9/* fn is "char *foo(int argc, char **argv, char *buff)" */
10#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
11        { name, summary, usage, description, ctx, \
12          NULL, fn, NULL, NULL, NULL, NULL, NULL }
13
14/* fn is "void foo(void)" */
15#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
16        { name, summary, usage, description, ctx, \
17          NULL, NULL, fn, NULL, NULL, NULL, NULL }
18
19/* fn is "void foo(int)" */
20#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
21        { name, summary, usage, description, ctx, \
22          NULL, NULL, NULL, fn, NULL, NULL, NULL }
23
24#define OWLCMD_ALIAS(name, actualname) \
25        { name, OWL_CMD_ALIAS_SUMMARY_PREFIX actualname, "", "", OWL_CTX_ANY, \
26          actualname, NULL, NULL, NULL, NULL, NULL, NULL }
27
28/* fn is "char *foo(void *ctx, int argc, char **argv, char *buff)" */
29#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
30        { name, summary, usage, description, ctx, \
31          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,char**,char*))fn), NULL, NULL }
32
33/* fn is "void foo(void)" */
34#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
35        { name, summary, usage, description, ctx, \
36          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL }
37
38/* fn is "void foo(int)" */
39#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
40        { name, summary, usage, description, ctx, \
41          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn) }
42
43
44owl_cmd commands_to_init[]
45  = {
46  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
47              "send a login or logout notification",
48              "zlog in [tty]\nzlog out",
49              "zlog in will send a login notification, zlog out will send a\n"
50              "logout notification.  By default a login notification is sent\n"
51              "when owl is started and a logout notification is sent when owl\n"
52              "is exited.  This behavior can be changed with the 'startuplogin'\n"
53              "and 'shudownlogout' variables.  If a tty is specified for zlog in\n"
54              "then the owl variable 'tty' will be set to that string, causing\n"
55              "it to be used as the zephyr location tty.\n"),
56
57  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
58              "exit owl",
59              "",
60              "Exit owl and run any shutdown activities."),
61  OWLCMD_ALIAS("exit", "quit"),
62  OWLCMD_ALIAS("q",    "quit"),
63
64  OWLCMD_ARGS("term", owl_command_term, OWL_CTX_ANY,
65              "control the terminal",
66              "term raise\n"
67              "term deiconify\n",
68              ""),
69
70  OWLCMD_VOID("nop", owl_command_nop, OWL_CTX_ANY,
71              "do nothing",
72              "",
73              ""),
74 
75  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
76              "prompts the user to enter a command",
77              "start-command [initial-value]",
78              "Initializes the command field to initial-value."),
79
80  OWLCMD_ARGS("start-question", owl_command_start_question, OWL_CTX_INTERACTIVE,
81              "prompts the user to enter a response to some question",
82              "start-command <question>",
83              ""),
84
85  OWLCMD_ARGS("start-password", owl_command_start_password, OWL_CTX_INTERACTIVE,
86              "prompts the user to enter a password",
87              "start-password <question>",
88              ""),
89
90  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
91              "creates a command alias",
92              "alias <new_command> <old_command>",
93              "Creates a command alias from new_command to old_command.\n"
94              "Any arguments passed to <new_command> will be appended to\n"
95              "<old_command> before it is executed.\n"),
96
97  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
98              "creates a binding in a keymap",
99              "bindkey <keymap> <keyseq> command <command>",
100              "Binds a key sequence to a command within a keymap.\n"
101              "Use 'show keymaps' to see the existing keymaps.\n"
102              "Key sequences may be things like M-C-t or NPAGE.\n"),
103
104  OWLCMD_ARGS("style", owl_command_style, OWL_CTX_ANY,
105              "creates a new style",
106              "style <name> perl <function_name>",
107              "Creates a new style for formatting messages.\n"
108              "A style named <name> will be created that will\n"
109              "format messages using the perl function <function_name>.\n\n"
110              "SEE ALSO: show styles, view -s, filter -s\n"),
111
112  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
113              "send a zephyr",
114              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
115              "Zwrite send a zephyr to the one or more users specified.\n\n"
116              "The following options are available:\n\n"
117              "-m    Specifies a message to send without prompting.\n"
118              "      Note that this does not yet log an outgoing message.\n"
119              "      This must be the last argument.\n\n"
120              "-n    Do not send a ping message.\n\n"
121              "-C    If the message is sent to more than one user include a\n"
122              "      \"cc:\" line in the text\n\n"
123              "-c class\n"
124              "      Send to the specified zephyr class\n\n"
125              "-i instance\n"
126              "      Send to the specified zephyr instance\n\n"
127              "-r realm\n"
128              "      Send to a foreign realm\n"
129              "-O opcode\n"
130              "      Send to the specified opcode\n"),
131
132  OWLCMD_ARGS("aimwrite", owl_command_aimwrite, OWL_CTX_INTERACTIVE,
133              "send an AIM message",
134              "aimzwrite <user>",
135              "Send an aim message to a user.\n"),
136
137  OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
138              "send an encrypted zephyr",
139              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [-m <message...>]\n",
140              "Behaves like zwrite but uses encryption.  Not for use with\n"
141              "personal messages\n"),
142 
143  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
144              "reply to the current message",
145              "reply [-e] [ sender | all | zaway ]",
146              "If -e is specified, the zwrite command line is presented to\n"
147              "allow editing.\n\n"
148              "If 'sender' is specified, reply to the sender.\n\n"
149              "If 'all' or no args are specified, reply publically to the\n"
150              "same class/instance for non-personal messages and to the\n"
151              "sender for personal messages.\n\n"
152              "If 'zaway' is specified, replies with a zaway message.\n\n"),
153
154  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
155              "set a variable value",
156              "set [-q] <variable> [<value>]\n"
157              "set",
158              "Set the named variable to the specified value.  If no\n"
159              "arguments are used print the value of all variables.\n"
160              "If value is unspecified and the variable is a boolean, will set it to 'on'.\n"
161              "If -q is specified, is silent and doesn't print a message.\n"),
162
163  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
164              "unset a boolean variable value",
165              "set [-q] <variable>\n"
166              "set",
167              "Set the named boolean variable to off.\n"
168              "If -q is specified, is silent and doesn't print a message.\n"),
169
170  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
171              "print a variable value",
172              "print <variable>\n"
173              "print",
174              "Print the value of the named variable.  If no arugments\n"
175              "are used print the value of all variables.\n"),
176
177  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
178              "run a command and set it to be run at every Owl startup",
179              "startup <commands> ...",
180              "Everything on the command line after the startup command\n"
181              "is executed as a normal owl command and is also placed in\n"
182              "a file so that the command is executed every time owl\n"
183              "is started"),
184
185  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
186              "remove a command from the list of those to be run at Owl startup",
187              "unstartup <commands> ...",
188              ""),
189
190  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
191              "print the version of the running owl", "", ""),
192
193  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
194              "subscribe to a zephyr class, instance, recipient",
195              "subscribe [-t] <class> <instance> [recipient]",
196              "Subscribe the specified class and instance.  If the recipient\n"
197              "is not listed on the command line it defaults\n"
198              "to * (the wildcard recipient).  If the -t option is present\n"
199              "the subscription will only be temporary, i.e., it will not\n"
200              "be written to the subscription file and will therefore not\n"
201              "be present the next time owl is started.\n"),
202  OWLCMD_ALIAS("sub", "subscribe"),
203
204  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
205              "unsubscribe from a zephyr class, instance, recipient",
206              "unsubscribe [-t] <class> <instance> [recipient]",
207              "Unsubscribe from the specified class and instance.  If the\n"
208              "recipient is not listed on the command line it defaults\n"
209              "to * (the wildcard recipient).  If the -t option is present\n"
210              "the unsubscription will only be temporary, i.e., it will not\n"
211              "be updated in the subscription file and will therefore not\n"
212              "be in effect the next time owl is started.\n"),
213  OWLCMD_ALIAS("unsub", "unsubscribe"),
214
215  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
216              "unsubscribe from all zephyrs", "", ""),
217 
218  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
219              "print all current subscriptions",
220              "getsubs",
221              "getsubs retrieves the current subscriptions from the server\n"
222              "and displays them.\n"),
223
224  OWLCMD_ARGS("dump", owl_command_dump, OWL_CTX_ANY,
225              "dump messages to a file",
226              "dump <filename>",
227              "Dump messages in current view to the named file."),
228
229  OWLCMD_ARGS("addbuddy", owl_command_addbuddy, OWL_CTX_INTERACTIVE,
230              "add a buddy to a buddylist",
231              "addbuddy aim <screenname>",
232              "Add the named buddy to your buddylist.  Eventually other protocols,\n"
233              "such as zephyr, will also be able to use this command.  For now the\n"
234              "only available protocol is 'aim', specified as the first argument."),
235
236  OWLCMD_ARGS("delbuddy", owl_command_delbuddy, OWL_CTX_INTERACTIVE,
237              "delete a buddy from a buddylist",
238              "delbuddy aim <screenname>",
239              "Delete the named buddy to your buddylist.  Eventually other protocols,\n"
240              "such as zephyr, will also be able to use this command.  For now the\n"
241              "only available protocol is 'aim', specified as the first argument.\n"),
242
243  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
244              "creates a zpunt based on the current message",
245              "smartzpunt [-i | --instance]",
246              "Starts a zpunt command based on the current message's class\n"
247              "(and instance if -i is specified).\n"),
248
249  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
250              "suppress a given zephyr triplet",
251              "zpunt <class> <instance> [recipient]\n"
252              "zpunt <instance>",
253              "The zpunt command will supress message to the specified\n"
254              "zephyr triplet.  In the second usage messages as supressed\n"
255              "for class MESSAGE and the named instance.\n\n"
256              "SEE ALSO:  zunpunt, show zpunts\n"),
257
258  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
259              "undo a previous zpunt",
260              "zunpunt <class> <instance> [recipient]\n"
261              "zunpunt <instance>",
262              "The zunpunt command will allow messages that were previosly\n"
263              "suppressed to be received again.\n\n"
264              "SEE ALSO:  zpunt, show zpunts\n"),
265
266  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
267              "display detailed information about the current message",
268              "", ""),
269 
270  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
271              "display help on using owl",
272              "help [command]", ""),
273
274  OWLCMD_ARGS("zlist", owl_command_zlist, OWL_CTX_INTERACTIVE,
275              "List users logged in",
276              "znol [-f file]",
277              "Print a znol-style listing of users logged in"),
278
279  OWLCMD_ARGS("alist", owl_command_alist, OWL_CTX_INTERACTIVE,
280              "List AIM users logged in",
281              "alist",
282              "Print a listing of AIM users logged in"),
283
284  OWLCMD_ARGS("blist", owl_command_blist, OWL_CTX_INTERACTIVE,
285              "List all buddies logged in",
286              "alist",
287              "Print a listing of buddies logged in, regardless of protocol."),
288
289  OWLCMD_ARGS("toggle-oneline", owl_command_toggleoneline, OWL_CTX_INTERACTIVE,
290              "Toggle the style between oneline and the default style",
291              "toggle-oneline",
292              ""),
293
294  OWLCMD_VOID("recv:shiftleft", owl_command_shift_left, OWL_CTX_INTERACTIVE,
295              "scrolls receive window to the left", "", ""),
296
297  OWLCMD_VOID("recv:shiftright", owl_command_shift_right, OWL_CTX_INTERACTIVE,
298              "scrolls receive window to the left", "", ""),
299
300  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
301              OWL_CTX_INTERACTIVE,
302              "scrolls down by a page", "", ""),
303
304  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
305              "scrolls up by a page", "", ""),
306
307  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
308              "scrolls current message up or down", 
309              "recv:scroll <numlines>", 
310              "Scrolls the current message up or down by <numlines>.\n"
311              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
312
313  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
314              "move the pointer to the next message",
315              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
316              "          [ --smart-filter | --smart-filter-instance ]",
317              "Moves the pointer to the next message in the current view.\n"
318              "If --filter is specified, will only consider messages in\n"
319              "the filter <name>.\n"
320              "If --smart-filter or --smart-filter-instance is specified,\n"
321              "goes to the next message that is similar to the current message.\n"
322              "If --skip-deleted is specified, deleted messages will\n"
323              "be skipped.\n"
324              "If --last-if-none is specified, will stop at last message\n"
325              "in the view if no other suitable messages are found.\n"),
326  OWLCMD_ALIAS("recv:next", "next"),
327
328  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
329              "move the pointer to the previous message",
330              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
331              "          [ --smart-filter | --smart-filter-instance ]",
332              "Moves the pointer to the next message in the current view.\n"
333              "If --filter is specified, will only consider messages in\n"
334              "the filter <name>.\n"
335              "If --smart-filter or --smart-filter-instance is specified,\n"
336              "goes to the previous message that is similar to the current message.\n"
337              "If --skip-deleted is specified, deleted messages will\n"
338              "be skipped.\n"
339              "If --first-if-none is specified, will stop at first message\n"
340              "in the view if no other suitable messages are found.\n"),
341  OWLCMD_ALIAS("recv:prev", "prev"),
342
343  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
344  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
345
346  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
347  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
348
349  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
350
351  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
352
353  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
354              "move the pointer to the first message", "", ""),
355  OWLCMD_ALIAS("recv:first", "first"),
356
357  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
358              "move the pointer to the last message", "", 
359              "Moves the pointer to the last message in the view.\n"
360              "If we are already at the last message in the view,\n"
361              "blanks the screen and moves just past the end of the view\n"
362              "so that new messages will appear starting at the top\n"
363              "of the screen.\n"),
364  OWLCMD_ALIAS("recv:last", "last"),
365
366  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
367              "remove all messages marked for deletion", "", ""),
368
369  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
370              "resize the window to the current screen size", "", ""),
371
372  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
373              "redraw the entire window", "", ""),
374
375  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
376              "suspend owl", "", ""),
377
378  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
379              "pops up a message in popup window",
380              "echo [args .. ]\n\n", ""),
381
382  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
383              "run a command from the shell",
384              "exec [args .. ]", ""),
385
386  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
387              "run a command from the shell and display in an admin message",
388              "aexec [args .. ]", ""),
389
390  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
391              "run a command from the shell and display in a popup window",
392              "pexec [args .. ]", ""),
393
394  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
395              "run a perl expression",
396              "perl [args .. ]", ""),
397
398  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
399              "run a perl expression and display in an admin message",
400              "aperl [args .. ]", ""),
401
402  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
403              "run a perl expression and display in a popup window",
404              "pperl [args .. ]", ""),
405
406  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
407              "runs multiple ;-separated commands",
408              "multi <command1> ( ; <command2> )*\n",
409              "Runs multiple semicolon-separated commands in order.\n"
410              "Note quoting isn't supported here yet.\n"
411              "If you want to do something fancy, use perl.\n"),
412
413  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
414              "runs multiple ;-separated commands",
415              "'(' <command1> ( ; <command2> )* ')'\n",
416              "Runs multiple semicolon-separated commands in order.\n"
417              "You must have a space before the final ')'\n"
418              "Note quoting isn't supported here yet.\n"
419              "If you want to do something fancy, use perl.\n"),
420
421  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
422              "pops up a message in a window", "", ""),
423
424  OWLCMD_VOID("openurl", owl_command_openurl, OWL_CTX_INTERACTIVE,
425              "opens up a URL from the current message",
426              "", 
427              "Uses the 'webbrowser' variable to determine\n"
428              "which browser to use.  Currently, 'netscape'\n"
429              "and 'galeon' are supported.\n"),
430
431  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
432              "running a command from the shell",
433              "zaway [ on | off | toggle ]\n"
434              "zaway <message>",
435              "Turn on or off the default zaway message.  If a message is\n"
436              "specified turn on zaway with that message\n"),
437
438  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
439              "load subscriptions from a file",
440              "load-subs <file>\n", ""),
441
442  OWLCMD_ARGS("loadsubs", owl_command_loadsubs, OWL_CTX_ANY,
443              "load subscriptions from a file",
444              "loadsubs <file>\n", ""),
445
446  OWLCMD_ARGS("loadloginsubs", owl_command_loadloginsubs, OWL_CTX_ANY,
447              "load login subscriptions from a file",
448              "loadloginsubs <file>\n",
449              "The file should contain a list of usernames, one per line."),
450
451  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
452              "print information about owl", "", ""),
453
454  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
455              "print status information about the running owl", "", ""),
456 
457  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
458              "locate a user",
459              "zlocate [-d] <user> ...", 
460              "Performs a zlocate on one ore more users and puts the result\n"
461              "int a popwin.  If -d is specified, does not authenticate\n"
462              "the lookup request.\n"),
463 
464  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
465              "create a message filter",
466              "filter <name> [ -c color ] [ <expression> ... ]",
467              "The filter command creates a filter with the specified name,\n"
468              "or if one already exists it is replaced.  Example filter\n"
469              "syntax would be:\n\n"
470              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
471              "Valid matching fields are:\n"
472              "    sender     -  sender\n"
473              "    recipient  -  recipient\n"
474              "    class      -  zephyr class name\n"
475              "    instance   -  zephyr instance name\n"
476              "    opcode     -  zephyr opcode\n"
477              "    realm      -  zephyr realm\n"
478              "    body       -  message body\n"
479              "    type       -  message type (zephyr, aim, admin)\n"
480              "    direction  -  either 'in' 'out' or 'none'\n"
481              "    login      -  either 'login' 'logout' or 'none'\n" 
482              "Valid operators are:\n"
483              "    and\n"
484              "    or\n"
485              "    not\n"
486              "And additionally you may use the static values:\n"
487              "    true\n"
488              "    false\n"
489              "Spaces must be present before and after parenthesis.  If the\n"
490              "optional color argument is used it specifies the color that\n"
491              "messages matching this filter should be displayed in.\n\n"
492              "SEE ALSO: view, viewclass, viewuser\n"),
493
494  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
495              "change the color on the current filter",
496              "colorview <color>",
497              "The color of messages in the current filter will be changed\n"
498              "to <color>.  Use the 'show colors' command for a list\n"
499              "of valid colors.\n\n"
500              "SEE ALSO: 'show colors'\n"),
501
502  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
503              "view messages matching a filter",
504              "view [<viewname>] [-f <filter> | --home ] [-s <style>]\n"
505              "view <filter>\n"
506              "view -d <expression>\n"
507              "view --home",
508              "The view command sets information associated with a particular view,\n"
509              "such as view's filter or style.  In the first general usage listed\n"
510              "above <viewname> is the name of the view to be changed.  If not\n"
511              "specified the default view 'main' will be used.  A filter can be set\n"
512              "for the view by listing a named filter after the -f argument.  If\n"
513              "the --home argument is used the filter will be set to the filter named\n"
514              "by the\n 'view_home' variable.  The style can be set by listing the\n"
515              "name style after the -s argument.\n"
516              "\n"
517              "The other usages listed above are abbreivated forms that simply set\n"
518              "the filter of the current view. The -d option allows you to write a\n"
519              "filter expression that will be dynamically created by owl and then\n"
520              "applied as the view's filter\n"
521              "SEE ALSO: filter, viewclass, viewuser\n"),
522
523  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
524              "view only messages similar to the current message",
525              "smartnarrow [-i | --instance]",
526              "If the curmsg is a personal message narrow\n"
527              "   to the converstaion with that user.\n"
528              "If the curmsg is a class message, instance foo, recip *\n"
529              "   message, narrow to the class, inst.\n"
530              "If the curmsg is a class message then narrow\n"
531              "    to the class.\n"
532              "If the curmsg is a class message and '-i' is specied\n"
533              "    then narrow to the class, instance\n"),
534
535  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
536              "returns the name of a filter based on the current message",
537              "smartfilter [-i | --instance]",
538              "If the curmsg is a personal message, the filter is\n"
539              "   the converstaion with that user.\n"
540              "If the curmsg is a class message, instance foo, recip *\n"
541              "   message, the filter is the class, inst.\n"
542              "If the curmsg is a class message, the filter is that class.\n"
543              "If the curmsg is a class message and '-i' is specied\n"
544              "    the filter is that <class,instance> pair\n"),
545
546  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
547              "view messages matching a particular class",
548              "viewclass <class>",
549              "The viewclass command will automatically create a filter\n"
550              "matching the specified class and switch the current view\n"
551              "to it.\n\n"
552              "SEE ALSO: filter, view, viewuser\n"),
553  OWLCMD_ALIAS("vc", "viewclass"),
554
555  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
556              "view messages matching a particular user",
557              "viewuser <user>",
558              "The viewuser command will automatically create a filter\n"
559              "matching the specified user and switch the current\n"
560              "view to it.\n\n"
561              "SEE ALSO: filter, view, viewclass\n"),
562  OWLCMD_ALIAS("vu", "viewuser"),
563
564  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
565              "show information",
566              "show variables\n"
567              "show variable <variable>\n"
568              "show filters\n"
569              "show filter <filter>\n"
570              "show keymaps\n"
571              "show keymap <keymap>\n"
572              "show commands\n"
573              "show command <command>\n"
574              "show subs\n"
575              "show subscriptions\n"
576              "show zpunts\n"
577              "show styles\n"
578              "show colors\n"
579              "show terminal\n"
580              "show version\n"
581              "show view [<view>]\n"
582              "show status\n",
583
584              "Show colors will display a list of valid colors for the\n"
585              "     terminal."
586              "Show filters will list the names of all filters.\n"
587              "Show filter <filter> will show the definition of a particular\n"
588              "     filter.\n\n"
589              "Show zpunts will show the active zpunt filters.\n\n"
590              "Show keymaps will list the names of all keymaps.\n"
591              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
592              "Show commands will list the names of all keymaps.\n"
593              "Show command <command> will provide information about a command.\n\n"
594              "Show styles will list the names of all styles available\n"
595              "for formatting messages.\n\n"
596              "Show variables will list the names of all variables.\n\n"
597              "SEE ALSO: filter, view, alias, bindkey, help\n"),
598 
599  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
600              "mark a message for deletion",
601              "delete [ -id msgid ] [ --no-move ]\n"
602              "delete view\n"
603              "delete trash",
604              "If no message id is specified the current message is marked\n"
605              "for deletion.  Otherwise the message with the given message\n"
606              "id is marked for deltion.\n"
607              "If '--no-move' is specified, don't move after deletion.\n"
608              "If 'trash' is specified, deletes all trash/auto messages\n"
609              "in the current view.\n"
610              "If 'view' is specified, deletes all messages in the\n"
611              "current view.\n"),
612  OWLCMD_ALIAS("del", "delete"),
613
614  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
615              "unmark a message for deletion",
616              "undelete [ -id msgid ] [ --no-move ]\n"
617              "undelete view",
618              "If no message id is specified the current message is\n"
619              "unmarked for deletion.  Otherwise the message with the\n"
620              "given message id is marked for undeltion.\n"
621              "If '--no-move' is specified, don't move after deletion.\n"
622              "If 'view' is specified, undeletes all messages\n"
623              "in the current view.\n"),
624  OWLCMD_ALIAS("undel", "undelete"),
625
626  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
627              "ring the terminal bell",
628              "beep",
629              "Beep will ring the terminal bell.\n"
630              "If the variable 'bell' has been\n"
631              "set to 'off' this command does nothing.\n"),
632
633  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
634              "prints a message into the debug log",
635              "debug <message>", ""),
636
637  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
638              "returns the name of the filter for the current view",
639              "", ""),
640
641  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
642              "returns the value of a variable",
643              "getvar <varname>", ""),
644
645  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
646              "search messages for a particular string",
647              "search [-r] [<string>]",
648              "The search command will find messages that contain the\n"
649              "specified string and move the cursor there.  If no string\n"
650              "argument is supplied then the previous one is used.  By\n"
651              "default searches are done fowards, if -r is used the search\n"
652              "is performed backwards"),
653
654  OWLCMD_ARGS("aimlogin", owl_command_aimlogin, OWL_CTX_ANY,
655              "login to an AIM account",
656              "aimlogin <screenname> [<password>]\n",
657              ""),
658
659  OWLCMD_ARGS("aimlogout", owl_command_aimlogout, OWL_CTX_ANY,
660              "logout from AIM",
661              "aimlogout\n",
662              ""),
663
664
665  /****************************************************************/
666  /************************* EDIT-SPECIFIC ************************/
667  /****************************************************************/
668
669  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
670                  OWL_CTX_EDIT,
671                  "moves cursor forward a word",
672                  "", ""),
673
674  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
675                  OWL_CTX_EDIT,
676                  "moves cursor backwards a word",
677                  "", ""),
678
679  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
680                  OWL_CTX_EDIT,
681                  "moves cursor to the top left (start) of the buffer",
682                  "", ""),
683
684  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
685                  OWL_CTX_EDIT,
686                  "moves cursor to the bottom right (end) of the buffer",
687                  "", ""),
688
689  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
690                  OWL_CTX_EDIT,
691                  "moves cursor to the end of the line",
692                  "", ""),
693
694  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
695                  OWL_CTX_EDIT,
696                  "moves cursor to the beginning of the line",
697                  "", ""),
698
699  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
700                  OWL_CTX_EDIT,
701                  "moves the cursor left by a character",
702                  "", ""),
703
704  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
705                  OWL_CTX_EDIT,
706                  "moves the cursor right by a character",
707                  "", ""),
708
709  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
710                  OWL_CTX_EDIT,
711                  "deletes the word to the right of the cursor",
712                  "", ""),
713
714  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
715                  OWL_CTX_EDIT,
716                  "deletes the word to the left of the cursor",
717                  "", ""),
718
719  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
720                  OWL_CTX_EDIT,
721                  "deletes the character to the left of the cursor",
722                  "", ""),
723
724  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
725                  OWL_CTX_EDIT,
726                  "deletes the character to the right of the cursor",
727                  "", ""),
728
729  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
730                  OWL_CTX_EDIT,
731                  "deletes from the cursor to the end of the line",
732                  "", ""),
733
734  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
735                  OWL_CTX_EDIT,
736                  "deletes all of the contents of the buffer",
737                  "", ""),
738
739  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
740                  OWL_CTX_EDIT,
741                  "Interchange characters around point, moving forward one character.",
742                  "", ""),
743
744  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
745                  OWL_CTX_EDIT,
746                  "fills the current paragraph to line-wrap well",
747                  "", ""),
748
749  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
750                  OWL_CTX_EDIT,
751                  "recenters the buffer",
752                  "", ""),
753
754  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
755                  OWL_CTX_EDIT,
756                  "inserts text into the buffer",
757                  "edit:insert-text <text>", ""),
758
759  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
760                  OWL_CTX_EDIT,
761                  "cancels the current command",
762                  "", ""),
763
764  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
765                  OWL_CTX_EDIT,
766                  "replaces the text with the previous history",
767                  "", ""),
768
769  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
770                  OWL_CTX_EDIT,
771                  "replaces the text with the previous history",
772                  "", ""),
773
774  OWLCMD_VOID_CTX("editline:done", owl_command_editline_done, 
775                  OWL_CTX_EDITLINE,
776                  "completes the command (eg, executes command being composed)",
777                  "", ""),
778
779  OWLCMD_VOID_CTX("editresponse:done", owl_command_editresponse_done, 
780                  OWL_CTX_EDITRESPONSE,
781                  "completes the response to a question",
782                  "", ""),
783
784  OWLCMD_VOID_CTX("editmulti:move-up-line", owl_editwin_key_up, 
785                  OWL_CTX_EDITMULTI,
786                  "moves the cursor up one line",
787                  "", ""),
788
789  OWLCMD_VOID_CTX("editmulti:move-down-line", owl_editwin_key_down, 
790                  OWL_CTX_EDITMULTI,
791                  "moves the cursor down one line",
792                  "", ""),
793
794  OWLCMD_VOID_CTX("editmulti:done", owl_command_editmulti_done, 
795                  OWL_CTX_EDITMULTI,
796                  "completes the command (eg, sends message being composed)",
797                  "", ""),
798
799  OWLCMD_VOID_CTX("editmulti:done-or-delete", owl_command_editmulti_done_or_delete, 
800                  OWL_CTX_EDITMULTI,
801                  "completes the command, but only if at end of message",
802                  "", 
803                  "If only whitespace is to the right of the cursor,\n"
804                  "runs 'editmulti:done'.\n"\
805                  "Otherwise runs 'edit:delete-next-char'\n"),
806
807  /****************************************************************/
808  /********************** POPLESS-SPECIFIC ************************/
809  /****************************************************************/
810
811  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
812                  OWL_CTX_POPLESS,
813                  "scrolls down one page",
814                  "", ""),
815
816  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
817                  OWL_CTX_POPLESS,
818                  "scrolls down one line",
819                  "", ""),
820
821  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
822                  OWL_CTX_POPLESS,
823                  "scrolls up one page",
824                  "", ""),
825
826  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
827                  OWL_CTX_POPLESS,
828                  "scrolls up one line",
829                  "", ""),
830
831  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
832                  OWL_CTX_POPLESS,
833                  "scrolls to the top of the buffer",
834                  "", ""),
835
836  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
837                  OWL_CTX_POPLESS,
838                  "scrolls to the bottom of the buffer",
839                  "", ""),
840
841  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
842                  OWL_CTX_POPLESS,
843                  "scrolls right in the buffer",
844                  "popless:scroll-right <num-chars>", ""),
845
846  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
847                  OWL_CTX_POPLESS,
848                  "scrolls left in the buffer",
849                  "popless:scroll-left <num-chars>", ""),
850
851  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
852                  OWL_CTX_POPLESS,
853                  "exits the popless window",
854                  "", ""),
855
856  /* This line MUST be last! */
857  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
858
859};
860
861void owl_command_info()
862{
863  owl_function_info();
864}
865
866void owl_command_nop()
867{
868}
869
870char *owl_command_help(int argc, char **argv, char *buff)
871{
872  if (argc!=2) {
873    owl_help();
874    return NULL;
875  }
876 
877  owl_function_help_for_command(argv[1]);
878  return NULL;
879}
880
881char *owl_command_zlist(int argc, char **argv, char *buff)
882{
883  int elapsed=0, timesort=0;
884  char *file=NULL;
885
886  argc--;
887  argv++;
888  while (argc) {
889    if (!strcmp(argv[0], "-e")) {
890      elapsed=1;
891      argc--;
892      argv++;
893    } else if (!strcmp(argv[0], "-t")) {
894      timesort=1;
895      argc--;
896      argv++;
897    } else if (!strcmp(argv[0], "-f")) {
898      if (argc==1) {
899        owl_function_makemsg("zlist: -f needs an argument");
900        return(NULL);
901      }
902      file=argv[1];
903      argc-=2;
904      argv+=2;
905    } else {
906      owl_function_makemsg("zlist: unknown argument");
907      return(NULL);
908    }
909  }
910  owl_function_buddylist(0, 1, file);
911  return(NULL);
912}
913
914char *owl_command_alist()
915{
916  owl_function_buddylist(1, 0, NULL);
917  return(NULL);
918}
919
920char *owl_command_blist()
921{
922  owl_function_buddylist(1, 1, NULL);
923  return(NULL);
924}
925
926char *owl_command_toggleoneline()
927{
928  owl_function_toggleoneline();
929  return(NULL);
930}
931
932void owl_command_about()
933{
934  owl_function_about();
935}
936
937void owl_command_version()
938{
939  char buff[1024];
940
941  sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
942  owl_function_makemsg(buff);
943}
944
945char *owl_command_addbuddy(int argc, char **argv, char *buff)
946{
947  if (argc!=3) {
948    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
949    return(NULL);
950  }
951
952  if (!strcasecmp(argv[1], "aim")) {
953    if (!owl_global_is_aimloggedin(&g)) {
954      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
955      return(NULL);
956    }
957    /*
958    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
959    return(NULL);
960    */
961    owl_aim_addbuddy(argv[2]);
962    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
963  } else if (!strcasecmp(argv[1], "zephyr")) {
964    owl_zephyr_addbuddy(argv[2]);
965    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
966  } else {
967    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
968  }
969
970  return(NULL);
971}
972
973char *owl_command_delbuddy(int argc, char **argv, char *buff)
974{
975  if (argc!=3) {
976    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
977    return(NULL);
978  }
979
980  if (!strcasecmp(argv[1], "aim")) {
981    if (!owl_global_is_aimloggedin(&g)) {
982      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
983      return(NULL);
984    }
985    /*
986    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
987    return(NULL);
988    */
989    owl_aim_delbuddy(argv[2]);
990    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
991  } else if (!strcasecmp(argv[1], "zephyr")) {
992    owl_zephyr_delbuddy(argv[2]);
993    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
994  } else {
995    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
996  }
997
998
999  return(NULL);
1000}
1001
1002char *owl_command_startup(int argc, char **argv, char *buff)
1003{
1004  char *ptr;
1005
1006  if (argc<2) {
1007    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1008    return(NULL);
1009  }
1010
1011  ptr=strchr(buff, ' ');
1012  if (!ptr) {
1013    owl_function_makemsg("Parse error finding command for startup");
1014    return(NULL);
1015  }
1016
1017  owl_function_command(ptr+1);
1018  owl_function_addstartup(ptr+1);
1019
1020  return(NULL);
1021}
1022
1023char *owl_command_unstartup(int argc, char **argv, char *buff)
1024{
1025  char *ptr;
1026
1027  if (argc<2) {
1028    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1029    return(NULL);
1030  }
1031
1032  ptr=strchr(buff, ' ');
1033  if (!ptr) {
1034    owl_function_makemsg("Parse error finding command for unstartup");
1035    return(NULL);
1036  }
1037
1038  owl_function_delstartup(ptr+1);
1039
1040  return(NULL);
1041}
1042
1043char *owl_command_dump(int argc, char **argv, char *buff)
1044{
1045  if (argc!=2) {
1046    owl_function_makemsg("usage: dump <filename>");
1047    return(NULL);
1048  }
1049
1050  owl_function_dump(argv[1]);
1051  return(NULL);
1052}
1053
1054char *owl_command_next(int argc, char **argv, char *buff)
1055{
1056  char *filter=NULL;
1057  int skip_deleted=0, last_if_none=0;
1058  while (argc>1) {
1059    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1060      skip_deleted=1;
1061      argc-=1; argv+=1; 
1062    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1063      last_if_none=1;
1064      argc-=1; argv+=1; 
1065    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1066      filter = owl_strdup(argv[2]);
1067      argc-=2; argv+=2; 
1068    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1069      filter = owl_function_smartfilter(0);
1070      argc-=2; argv+=2; 
1071    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1072      filter = owl_function_smartfilter(1);
1073      argc-=2; argv+=2; 
1074    } else {
1075      owl_function_makemsg("Invalid arguments to command 'next'.");
1076      return(NULL);
1077    }
1078  }
1079  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1080  if (filter) owl_free(filter);
1081  return(NULL);
1082}
1083
1084char *owl_command_prev(int argc, char **argv, char *buff)
1085{
1086  char *filter=NULL;
1087  int skip_deleted=0, first_if_none=0;
1088  while (argc>1) {
1089    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1090      skip_deleted=1;
1091      argc-=1; argv+=1; 
1092    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1093      first_if_none=1;
1094      argc-=1; argv+=1; 
1095    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1096      filter = owl_strdup(argv[2]);
1097      argc-=2; argv+=2; 
1098    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1099      filter = owl_function_smartfilter(0);
1100      argc-=2; argv+=2; 
1101    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1102      filter = owl_function_smartfilter(1);
1103      argc-=2; argv+=2; 
1104   } else {
1105      owl_function_makemsg("Invalid arguments to command 'prev'.");
1106      return(NULL);
1107    }
1108  }
1109  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1110  if (filter) owl_free(filter);
1111  return(NULL);
1112}
1113
1114char *owl_command_smartnarrow(int argc, char **argv, char *buff)
1115{
1116  char *filtname = NULL;
1117
1118  if (argc == 1) {
1119    filtname = owl_function_smartfilter(0);
1120  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1121    filtname = owl_function_smartfilter(1);
1122  } else {
1123    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1124  }
1125  if (filtname) {
1126    owl_function_change_view(filtname);
1127    owl_free(filtname);
1128  }
1129  return NULL;
1130}
1131
1132char *owl_command_smartfilter(int argc, char **argv, char *buff)
1133{
1134  char *filtname = NULL;
1135
1136  if (argc == 1) {
1137    filtname = owl_function_smartfilter(0);
1138  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1139    filtname = owl_function_smartfilter(1);
1140  } else {
1141    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1142  }
1143  return filtname;
1144}
1145
1146void owl_command_expunge()
1147{
1148  owl_function_expunge();
1149}
1150
1151void owl_command_first()
1152{
1153  owl_global_set_rightshift(&g, 0);
1154  owl_function_firstmsg();
1155}
1156
1157void owl_command_last()
1158{
1159  owl_function_lastmsg();
1160}
1161
1162void owl_command_resize()
1163{
1164  owl_function_resize();
1165}
1166
1167void owl_command_redisplay()
1168{
1169  owl_function_full_redisplay();
1170  owl_global_set_needrefresh(&g);
1171}
1172
1173void owl_command_shift_right()
1174{
1175  owl_function_shift_right();
1176}
1177
1178void owl_command_shift_left()
1179{
1180  owl_function_shift_left();
1181}
1182
1183void owl_command_unsuball()
1184{
1185  owl_function_unsuball();
1186}
1187
1188char *owl_command_loadsubs(int argc, char **argv, char *buff)
1189{
1190  if (argc == 2) {
1191    owl_function_loadsubs(argv[1]);
1192  } else if (argc == 1) {
1193    owl_function_loadsubs(NULL);
1194  } else {
1195    owl_function_makemsg("Wrong number of arguments for load-subs.");
1196    return(NULL);
1197  }
1198  return(NULL);
1199}
1200
1201
1202char *owl_command_loadloginsubs(int argc, char **argv, char *buff)
1203{
1204  if (argc == 2) {
1205    owl_function_loadloginsubs(argv[1]);
1206  } else if (argc == 1) {
1207    owl_function_loadloginsubs(NULL);
1208  } else {
1209    owl_function_makemsg("Wrong number of arguments for load-subs.");
1210    return(NULL);
1211  }
1212  return(NULL);
1213}
1214
1215void owl_command_suspend()
1216{
1217  owl_function_suspend();
1218}
1219
1220char *owl_command_start_command(int argc, char **argv, char *buff)
1221{
1222  buff = skiptokens(buff, 1);
1223  owl_function_start_command(buff);
1224  return(NULL);
1225}
1226
1227char *owl_command_start_question(int argc, char **argv, char *buff)
1228{
1229  buff = skiptokens(buff, 1);
1230  owl_function_start_question(buff);
1231  return(NULL);
1232}
1233
1234char *owl_command_start_password(int argc, char **argv, char *buff)
1235{
1236  buff = skiptokens(buff, 1);
1237  owl_function_start_password(buff);
1238  return(NULL);
1239}
1240
1241char *owl_command_zaway(int argc, char **argv, char *buff)
1242{
1243  if ((argc==1) ||
1244      ((argc==2) && !strcmp(argv[1], "on"))) {
1245    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1246    owl_function_zaway_on();
1247    return NULL;
1248  }
1249
1250  if (argc==2 && !strcmp(argv[1], "off")) {
1251    owl_function_zaway_off();
1252    return NULL;
1253  }
1254
1255  if (argc==2 && !strcmp(argv[1], "toggle")) {
1256    owl_function_zaway_toggle();
1257    return NULL;
1258  }
1259
1260  buff = skiptokens(buff, 1);
1261  owl_global_set_zaway_msg(&g, buff);
1262  owl_function_zaway_on();
1263  return NULL;
1264}
1265
1266
1267char *owl_command_set(int argc, char **argv, char *buff)
1268{
1269  char *var, *val;
1270  int  silent=0;
1271  int requirebool=0;
1272
1273  if (argc == 1) {
1274    owl_function_printallvars();
1275    return NULL;
1276  } 
1277
1278  if (argc > 1 && !strcmp("-q",argv[1])) {
1279    silent = 1;
1280    argc--; argv++;
1281  }
1282
1283  if (argc == 2) {
1284    var=argv[1];
1285    val="on";
1286    requirebool=1;
1287  } else if (argc == 3) {
1288    var=argv[1];
1289    val=argv[2];
1290  } else {
1291    owl_function_makemsg("Wrong number of arguments for set command");
1292    return NULL;
1293  }
1294  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1295  return NULL;
1296}
1297
1298char *owl_command_unset(int argc, char **argv, char *buff)
1299{
1300  char *var, *val;
1301  int  silent=0;
1302
1303  if (argc > 1 && !strcmp("-q",argv[1])) {
1304    silent = 1;
1305    argc--; argv++;
1306  }
1307  if (argc == 2) {
1308    var=argv[1];
1309    val="off";
1310  } else {
1311    owl_function_makemsg("Wrong number of arguments for unset command");
1312    return NULL;
1313  }
1314  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1315  return NULL;
1316}
1317
1318char *owl_command_print(int argc, char **argv, char *buff)
1319{
1320  char *var;
1321  char valbuff[1024];
1322
1323  if (argc==1) {
1324    owl_function_printallvars();
1325    return NULL;
1326  } else if (argc!=2) {
1327    owl_function_makemsg("Wrong number of arguments for print command");
1328    return NULL;
1329  }
1330
1331  var=argv[1];
1332   
1333  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1334                                     var, valbuff, 1024)) {
1335    owl_function_makemsg("%s = '%s'", var, valbuff);
1336  } else {
1337    owl_function_makemsg("Unknown variable '%s'.", var);
1338  }
1339  return NULL;
1340}
1341
1342
1343char *owl_command_exec(int argc, char **argv, char *buff)
1344{
1345  return owl_function_exec(argc, argv, buff, 0);
1346}
1347
1348char *owl_command_pexec(int argc, char **argv, char *buff)
1349{
1350  return owl_function_exec(argc, argv, buff, 1);
1351}
1352
1353char *owl_command_aexec(int argc, char **argv, char *buff)
1354{
1355  return owl_function_exec(argc, argv, buff, 2);
1356}
1357
1358char *owl_command_perl(int argc, char **argv, char *buff)
1359{
1360  return owl_function_perl(argc, argv, buff, 0);
1361}
1362
1363char *owl_command_pperl(int argc, char **argv, char *buff)
1364{
1365  return owl_function_perl(argc, argv, buff, 1);
1366}
1367
1368char *owl_command_aperl(int argc, char **argv, char *buff)
1369{
1370  return owl_function_perl(argc, argv, buff, 2);
1371}
1372
1373char *owl_command_multi(int argc, char **argv, char *buff)
1374{
1375  char *lastrv = NULL, *newbuff;
1376  char **commands;
1377  int  ncommands, i;
1378  if (argc < 2) {
1379    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1380    return NULL;
1381  }
1382  newbuff = owl_strdup(buff);
1383  newbuff = skiptokens(newbuff, 1);
1384  if (!strcmp(argv[0], "(")) {
1385    for (i=strlen(newbuff)-1; i>=0; i--) {
1386      if (newbuff[i] == ')') {
1387        newbuff[i] = '\0';
1388        break;
1389      } else if (newbuff[i] != ' ') {
1390        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1391        owl_free(newbuff);
1392        return NULL;
1393      }
1394    }
1395  }
1396  commands = atokenize(newbuff, ";", &ncommands);
1397  for (i=0; i<ncommands; i++) {
1398    if (lastrv) {
1399      owl_free(lastrv);
1400    }
1401    lastrv = owl_function_command(commands[i]);
1402  }
1403  atokenize_free(commands, ncommands);
1404  return lastrv;
1405}
1406
1407
1408char *owl_command_alias(int argc, char **argv, char *buff)
1409{
1410  if (argc < 3) {
1411    owl_function_makemsg("Invalid arguments to 'alias' command.");
1412    return NULL;
1413  }
1414  buff = skiptokens(buff, 2);
1415  owl_function_command_alias(argv[1], buff);
1416  return (NULL);
1417}
1418
1419
1420char *owl_command_bindkey(int argc, char **argv, char *buff)
1421{
1422  owl_keymap *km;
1423  int ret;
1424
1425  if (argc < 5 || strcmp(argv[3], "command")) {
1426    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1427    return NULL;
1428  }
1429  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1430  if (!km) {
1431    owl_function_makemsg("No such keymap '%s'", argv[1]);
1432    return NULL;
1433  }
1434  buff = skiptokens(buff, 4);
1435  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1436  if (ret!=0) {
1437    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1438                         argv[2], argv[1], buff);
1439    return NULL;
1440  }
1441  return NULL;
1442}
1443
1444char *owl_command_style(int argc, char **argv, char *buff) {
1445  owl_style *s;
1446
1447  /* Usage: style <name> perl <function> */
1448  if (argc != 4 || strcmp(argv[2], "perl")) {
1449    owl_function_makemsg("Usage: style <name> perl <function>");
1450    return NULL;
1451  }
1452  if (!owl_perlconfig_is_function(argv[3])) {
1453    owl_function_makemsg("Unable to create style '%s': no perl function '%s'",
1454                         argv[1], argv[3]);
1455    return NULL;
1456  }
1457  s=owl_malloc(sizeof(owl_style));
1458  owl_style_create_perl(s, argv[1], argv[3], NULL);
1459  owl_global_add_style(&g, s);
1460
1461  return NULL;
1462}
1463
1464
1465void owl_command_quit()
1466{
1467  owl_function_quit();
1468}
1469
1470char *owl_command_debug(int argc, char **argv, char *buff)
1471{
1472  if (argc<2) {
1473    owl_function_makemsg("Need at least one argument to debug command");
1474    return(NULL);
1475  }
1476
1477  if (!owl_global_is_debug_fast(&g)) {
1478    owl_function_makemsg("Debugging is not turned on");
1479    return(NULL);
1480  }
1481
1482  owl_function_debugmsg(argv[1]);
1483  return(NULL);
1484}
1485
1486char *owl_command_term(int argc, char **argv, char *buff)
1487{
1488  if (argc<2) {
1489    owl_function_makemsg("Need at least one argument to the term command");
1490    return(NULL);
1491  }
1492
1493  if (!strcmp(argv[1], "raise")) {
1494    owl_function_xterm_raise();
1495  } else if (!strcmp(argv[1], "deiconify")) {
1496    owl_function_xterm_deiconify();
1497  } else {
1498    owl_function_makemsg("Unknown terminal subcommand");
1499  }
1500  return(NULL);
1501}
1502
1503char *owl_command_zlog(int argc, char **argv, char *buff)
1504{
1505  if ((argc<2) || (argc>3)) {
1506    owl_function_makemsg("Wrong number of arguments for zlog command");
1507    return(NULL);
1508  }
1509
1510  if (!strcmp(argv[1], "in")) {
1511    if (argc>2) {
1512      owl_global_set_tty(&g, argv[2]);
1513    }
1514    owl_zephyr_zlog_in();
1515  } else if (!strcmp(argv[1], "out")) {
1516    if (argc!=2) {
1517      owl_function_makemsg("Wrong number of arguments for zlog command");
1518      return(NULL);
1519    }
1520    owl_zephyr_zlog_out();
1521  } else {
1522    owl_function_makemsg("Invalid subcommand for zlog");
1523  }
1524  return(NULL);
1525}
1526
1527
1528void owl_command_zlog_out(void)
1529{
1530  owl_zephyr_zlog_out();
1531}
1532
1533
1534char *owl_command_subscribe(int argc, char **argv, char *buff)
1535{
1536  char *recip="";
1537  int temp=0;
1538 
1539  if (argc<3) {
1540    owl_function_makemsg("Not enough arguments to the subscribe command");
1541    return(NULL);
1542  }
1543  argc--;
1544  argv++;
1545
1546  if (!strcmp(argv[0], "-t")) {
1547    temp=1;
1548    argc--;
1549    argv++;
1550  }
1551  if (argc<2) {
1552    owl_function_makemsg("Not enough arguments to the subscribe command");
1553    return(NULL);
1554  }
1555
1556  if (argc>3) {
1557    owl_function_makemsg("Too many arguments to the subscribe command");
1558    return(NULL);
1559  }
1560
1561  if (argc==2) {
1562    recip="";
1563  } else if (argc==3) {
1564    recip=argv[2];
1565  }
1566
1567  owl_function_subscribe(argv[0], argv[1], recip);
1568  if (!temp) {
1569    owl_zephyr_addsub(NULL, argv[0], argv[1], recip);
1570  }
1571  return(NULL);
1572}
1573
1574
1575char *owl_command_unsubscribe(int argc, char **argv, char *buff)
1576{
1577  char *recip="";
1578  int temp=0;
1579
1580  if (argc<3) {
1581    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1582    return(NULL);
1583  }
1584  argc--;
1585  argv++;
1586
1587  if (!strcmp(argv[0], "-t")) {
1588    temp=1;
1589    argc--;
1590    argv++;
1591  }
1592  if (argc<2) {
1593    owl_function_makemsg("Not enough arguments to the subscribe command");
1594    return(NULL);
1595  }
1596
1597  if (argc>3) {
1598    owl_function_makemsg("Too many arguments to the unsubscribe command");
1599    return(NULL);
1600  }
1601
1602  if (argc==2) {
1603    recip="";
1604  } else if (argc==3) {
1605    recip=argv[2];
1606  }
1607
1608  owl_function_unsubscribe(argv[0], argv[1], recip);
1609  if (!temp) {
1610    owl_zephyr_delsub(NULL, argv[0], argv[1], recip);
1611  }
1612  return(NULL);
1613}
1614
1615char *owl_command_echo(int argc, char **argv, char *buff)
1616{
1617  buff = skiptokens(buff, 1);
1618  owl_function_popless_text(buff);
1619  return NULL;
1620}
1621
1622void owl_command_getsubs(void)
1623{
1624  owl_function_getsubs();
1625}
1626
1627void owl_command_status(void)
1628{
1629  owl_function_status();
1630}
1631
1632char *owl_command_zwrite(int argc, char **argv, char *buff)
1633{
1634  owl_zwrite z;
1635
1636  if (!owl_global_is_havezephyr(&g)) {
1637    owl_function_makemsg("Zephyr is not available");
1638    return(NULL);
1639  }
1640  /* check for a zwrite -m */
1641  owl_zwrite_create_from_line(&z, buff);
1642  if (owl_zwrite_is_message_set(&z)) {
1643    owl_function_zwrite(buff, NULL);
1644    owl_zwrite_free(&z);
1645    return (NULL);
1646  }
1647
1648  if (argc < 2) {
1649    owl_function_makemsg("Not enough arguments to the zwrite command.");
1650  } else {
1651    owl_function_zwrite_setup(buff);
1652  }
1653  return(NULL);
1654}
1655
1656char *owl_command_aimwrite(int argc, char **argv, char *buff)
1657{
1658  char *newbuff;
1659  int i, j;
1660 
1661  if (!owl_global_is_aimloggedin(&g)) {
1662    owl_function_makemsg("You are not logged in to AIM.");
1663    return(NULL);
1664  }
1665
1666  if (argc < 2) {
1667    owl_function_makemsg("Not enough arguments to the aimwrite command.");
1668    return(NULL);
1669  }
1670
1671  /* squish arguments together to make one screenname w/o spaces for now */
1672  newbuff=owl_malloc(strlen(buff)+5);
1673  sprintf(newbuff, "%s ", argv[0]);
1674  j=argc-1;
1675  for (i=0; i<j; i++) {
1676    strcat(newbuff, argv[i+1]);
1677  }
1678   
1679  owl_function_aimwrite_setup(newbuff);
1680  owl_free(newbuff);
1681  return(NULL);
1682}
1683
1684char *owl_command_zcrypt(int argc, char **argv, char *buff)
1685{
1686#ifdef OWL_ENABLE_ZCRYPT
1687  owl_zwrite z;
1688
1689  if (!owl_global_is_havezephyr(&g)) {
1690    owl_function_makemsg("Zephyr is not available");
1691    return(NULL);
1692  }
1693  /* check for a zcrypt -m */
1694  owl_zwrite_create_from_line(&z, buff);
1695  if (owl_zwrite_is_message_set(&z)) {
1696    owl_function_zcrypt(buff, NULL);
1697    owl_zwrite_free(&z);
1698    return (NULL);
1699  }
1700
1701  if (argc < 2) {
1702    owl_function_makemsg("Not enough arguments to the zcrypt command.");
1703  } else {
1704    owl_function_zwrite_setup(buff);
1705  }
1706  return(NULL);
1707#else
1708  owl_function_makemsg("This Owl does not support zcrypt");
1709#endif
1710}
1711
1712char *owl_command_reply(int argc, char **argv, char *buff)
1713{
1714  int edit=0;
1715 
1716  if (argc>=2 && !strcmp("-e", argv[1])) {
1717    edit=1;
1718    argv++;
1719    argc--;
1720  }
1721
1722  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1723    owl_function_reply(0, !edit);
1724  } else if (argc==2 && !strcmp(argv[1], "sender")) {
1725    owl_function_reply(1, !edit);
1726  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
1727    owl_message *m;
1728    owl_view    *v;
1729    v = owl_global_get_current_view(&g);   
1730    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
1731    if (m) owl_zephyr_zaway(m);
1732  } else {
1733    owl_function_makemsg("Invalid arguments to the reply command.");
1734  }
1735  return NULL;
1736}
1737
1738char *owl_command_filter(int argc, char **argv, char *buff)
1739{
1740  owl_function_create_filter(argc, argv);
1741  return NULL;
1742}
1743
1744char *owl_command_zlocate(int argc, char **argv, char *buff)
1745{
1746  int auth;
1747 
1748  if (argc<2) {
1749    owl_function_makemsg("Too few arguments for zlocate command");
1750    return NULL;
1751  }
1752
1753  auth=1;
1754  if (!strcmp(argv[1], "-d")) {
1755    if (argc>2) {
1756      auth=0;
1757      argc--;
1758      argv++;
1759    } else {
1760      owl_function_makemsg("Missing arguments for zlocate command");
1761      return NULL;
1762    }
1763  }
1764
1765  argc--;
1766  argv++;
1767  owl_function_zlocate(argc, argv, auth);
1768  return NULL;
1769}
1770
1771char *owl_command_view(int argc, char **argv, char *buff)
1772{
1773
1774  /* Backwards compatability has made this kind of complicated:
1775   * view [<viewname>] [-f <filter> | -d <expression> | --home ] [-s <style>]
1776   * view <filter>
1777   * view -d <expression>
1778   * view --home
1779   */
1780
1781  /* First take the 'view --home' case */
1782  if (argc == 2 && !strcmp(argv[1], "--home")) {
1783    owl_function_change_view(owl_global_get_view_home(&g));
1784    return(NULL);
1785  }
1786
1787  /* Now look for 'view <filter>' */
1788  if (argc==2) {
1789    owl_function_change_view(argv[1]);
1790    return(NULL);
1791  }
1792
1793  /* Now get 'view -d <expression>' */
1794  if (argc>=3 && !strcmp(argv[1], "-d")) {
1795    char **myargv;
1796    int i;
1797
1798    myargv=owl_malloc((argc*sizeof(char *))+50);
1799    myargv[0]="";
1800    myargv[1]="owl-dynamic";
1801    for (i=2; i<argc; i++) {
1802      myargv[i]=argv[i];
1803    }
1804    owl_function_create_filter(argc, myargv);
1805    owl_function_change_view("owl-dynamic");
1806    owl_free(myargv);
1807    return NULL;
1808  }
1809
1810  /* Finally handle the general case */
1811  if (argc<3) {
1812    owl_function_makemsg("Too few arguments to the view command.");
1813    return(NULL);
1814  }
1815  argc--;
1816  argv++;
1817  if (strcmp(argv[0], "-f") && strcmp(argv[0], "-d") && strcmp(argv[0], "--home") && strcmp(argv[0], "-s")) {
1818    if (strcmp(argv[0], "main")) {
1819      owl_function_makemsg("No view named '%s'", argv[0]);
1820      return(NULL);
1821    }
1822    argc--;
1823    argv++;
1824  }
1825  while (argc) {
1826    if (!strcmp(argv[0], "-f")) {
1827      if (argc<2) {
1828        owl_function_makemsg("Too few argments to the view command");
1829        return(NULL);
1830      }
1831      owl_function_change_view(argv[1]);
1832      argc-=2;
1833      argv+=2;
1834    } else if (!strcmp(argv[0], "--home")) {
1835      owl_function_change_view(owl_global_get_view_home(&g));
1836      argc--;
1837      argv++;
1838    } else if (!strcmp(argv[0], "-s")) {
1839      if (argc<2) {
1840        owl_function_makemsg("Too few argments to the view command");
1841        return(NULL);
1842      }
1843      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
1844      argc-=2;
1845      argv+=2;
1846    } else {
1847      owl_function_makemsg("Too few argments to the view command");
1848      return(NULL);
1849    }
1850   
1851  }
1852  return(NULL);
1853}
1854
1855
1856char *owl_command_show(int argc, char **argv, char *buff)
1857{
1858  if (argc<2) {
1859    owl_function_help_for_command("show");
1860    return NULL;
1861  }
1862
1863  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1864    if (argc==2) {
1865      owl_function_show_filters();
1866    } else {
1867      owl_function_show_filter(argv[2]);
1868    }
1869  } else if (argc==2 
1870             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1871    owl_function_show_zpunts();
1872  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1873    if (argc==2) {
1874      owl_function_show_commands();
1875    } else {
1876      owl_function_show_command(argv[2]);
1877    }
1878  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1879    if (argc==2) {
1880      owl_function_show_variables();
1881    } else {
1882      owl_function_show_variable(argv[2]);
1883    }
1884  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1885    if (argc==2) {
1886      owl_function_show_keymaps();
1887    } else {
1888      owl_function_show_keymap(argv[2]);
1889    }
1890  } else if (!strcmp(argv[1], "view")) {
1891    if (argc==3) {
1892      owl_function_show_view(argv[2]);
1893    } else {
1894      owl_function_show_view(NULL);
1895    }
1896  } else if (!strcmp(argv[1], "colors")) {
1897    owl_function_show_colors();
1898  } else if (!strcmp(argv[1], "styles")) {
1899    owl_function_show_styles();
1900  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1901    owl_function_getsubs();
1902  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1903    owl_function_show_term();
1904  } else if (!strcmp(argv[1], "version")) {
1905    owl_function_about();
1906  } else if (!strcmp(argv[1], "status")) {
1907    owl_function_status();
1908  } else {
1909    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1910    return NULL;
1911  }
1912  return NULL;
1913}
1914
1915char *owl_command_viewclass(int argc, char **argv, char *buff)
1916{
1917  char *filtname;
1918  if (argc!=2) {
1919    owl_function_makemsg("Wrong number of arguments to viewclass command");
1920    return NULL;
1921  }
1922  filtname = owl_function_classinstfilt(argv[1], NULL);
1923  owl_function_change_view(filtname);
1924  owl_free(filtname);
1925  return NULL;
1926}
1927
1928char *owl_command_viewuser(int argc, char **argv, char *buff)
1929{
1930  char *filtname;
1931  if (argc!=2) {
1932    owl_function_makemsg("Wrong number of arguments to viewuser command");
1933    return NULL;
1934  }
1935  filtname=owl_function_zuserfilt(argv[1]);
1936  owl_function_change_view(filtname);
1937  owl_free(filtname);
1938  return NULL;
1939}
1940
1941
1942void owl_command_pop_message(void)
1943{
1944  owl_function_curmsg_to_popwin();
1945}
1946
1947void owl_command_openurl(void)
1948{
1949  owl_function_openurl();
1950}
1951
1952char *owl_command_delete(int argc, char **argv, char *buff)
1953{
1954  int move_after = 1;
1955
1956  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1957    move_after = 0;
1958    argc--; 
1959    argv++;
1960  }
1961
1962  if (argc==1) {
1963    owl_function_deletecur(move_after);
1964    return NULL;
1965  }
1966
1967  if (argc==2 && !strcmp(argv[1], "view")) {
1968    owl_function_delete_curview_msgs(1);
1969    return NULL;
1970  }
1971
1972  if (argc==2 && !strcmp(argv[1], "trash")) {
1973    owl_function_delete_automsgs();
1974    return NULL;
1975  }
1976
1977  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1978    owl_function_delete_by_id(atoi(argv[2]), 1);
1979    return NULL;
1980  }
1981
1982  owl_function_makemsg("Unknown arguments to delete command");
1983  return NULL;
1984}
1985
1986char *owl_command_undelete(int argc, char **argv, char *buff)
1987{
1988  int move_after = 1;
1989
1990  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1991    move_after = 0;
1992    argc--; 
1993    argv++;
1994  }
1995
1996  if (argc==1) {
1997    owl_function_undeletecur(move_after);
1998    return NULL;
1999  }
2000
2001  if (argc==2 && !strcmp(argv[1], "view")) {
2002    owl_function_delete_curview_msgs(0);
2003    return NULL;
2004  }
2005
2006  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2007    owl_function_delete_by_id(atoi(argv[2]), 0);
2008    return NULL;
2009  }
2010
2011  owl_function_makemsg("Unknown arguments to delete command");
2012  return NULL;
2013}
2014
2015void owl_command_beep()
2016{
2017  owl_function_beep();
2018}
2019
2020char *owl_command_colorview(int argc, char **argv, char *buff)
2021{
2022  if (argc!=2) {
2023    owl_function_makemsg("Wrong number of arguments to colorview command");
2024    return NULL;
2025  }
2026  owl_function_color_current_filter(argv[1]);
2027  return NULL;
2028}
2029
2030char *owl_command_zpunt(int argc, char **argv, char *buff)
2031{
2032  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2033  return NULL;
2034}
2035
2036char *owl_command_zunpunt(int argc, char **argv, char *buff)
2037{
2038  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2039  return NULL;
2040}
2041
2042
2043void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type)
2044{
2045  /* if type==0 then zpunt
2046   * if type==1 then zunpunt
2047   */
2048  char *class, *inst, *recip;
2049
2050  class="message";
2051  inst="";
2052  recip="*";
2053
2054  if (argc==1) {
2055    /* show current punt filters */
2056    owl_function_show_zpunts();
2057    return;
2058  } else if (argc==2) {
2059    inst=argv[1];
2060  } else if (argc==3) {
2061    class=argv[1];
2062    inst=argv[2];
2063  } else if (argc==4) {
2064    class=argv[1];
2065    inst=argv[2];
2066    recip=argv[3];
2067  } else {
2068    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2069    return;
2070  }
2071
2072  owl_function_zpunt(class, inst, recip, type);
2073  if (type==0) {
2074    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2075  } else if (type==1) {
2076    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2077  }
2078}
2079
2080char *owl_command_smartzpunt(int argc, char **argv, char *buff)
2081{
2082  if (argc == 1) {
2083    owl_function_smartzpunt(0);
2084  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2085    owl_function_smartzpunt(1);
2086  } else {
2087    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2088  }
2089  return NULL;
2090}
2091
2092char *owl_command_getview(int argc, char **argv, char *buff)
2093{
2094  char *filtname;
2095  if (argc != 1) {
2096    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2097    return NULL;
2098  }
2099  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2100  if (filtname) filtname = owl_strdup(filtname);
2101  return filtname;
2102}
2103
2104char *owl_command_getvar(int argc, char **argv, char *buff)
2105{
2106  char tmpbuff[1024];
2107  if (argc != 2) {
2108    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2109    return NULL;
2110  }
2111  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
2112                                argv[1], tmpbuff, 1024)) {
2113    return NULL;
2114  }
2115  return owl_strdup(tmpbuff); 
2116}
2117
2118char *owl_command_search(int argc, char **argv, char *buff)
2119{
2120  int direction;
2121  char *buffstart;
2122
2123  direction=OWL_DIRECTION_DOWNWARDS;
2124  buffstart=skiptokens(buff, 1);
2125  if (argc>1 && !strcmp(argv[1], "-r")) {
2126    direction=OWL_DIRECTION_UPWARDS;
2127    buffstart=skiptokens(buff, 2);
2128  }
2129   
2130  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2131    owl_function_search_continue(direction);
2132  } else {
2133    owl_function_search_start(buffstart, direction);
2134  }
2135 
2136  return(NULL);
2137}
2138
2139char *owl_command_aimlogin(int argc, char **argv, char *buff)
2140{
2141  int ret;
2142 
2143  if ((argc<2) || (argc>3)) {
2144    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2145    return(NULL);
2146  }
2147
2148  /* if we get two arguments, ask for the password */
2149  if (argc==2) {
2150    owl_global_set_buffercommand(&g, buff);
2151    owl_function_start_password("AIM Password: ");
2152    return(NULL);
2153  }
2154
2155  /* clear the buddylist */
2156  owl_buddylist_clear(owl_global_get_buddylist(&g));
2157
2158  /* try to login */
2159  ret=owl_aim_login(argv[1], argv[2]);
2160  if (ret) owl_function_makemsg("Warning: login for %s failed.\n");
2161
2162  /* this is a test */
2163  return(NULL);
2164}
2165
2166char *owl_command_aimlogout(int argc, char **argv, char *buff)
2167{
2168  /* clear the buddylist */
2169  owl_buddylist_clear(owl_global_get_buddylist(&g));
2170
2171  owl_aim_logout();
2172  return(NULL);
2173}
2174
2175/*********************************************************************/
2176/************************** EDIT SPECIFIC ****************************/
2177/*********************************************************************/
2178
2179void owl_command_edit_cancel(owl_editwin *e)
2180{
2181  owl_history *hist;
2182
2183  owl_function_makemsg("Command cancelled.");
2184
2185  hist=owl_editwin_get_history(e);
2186  owl_history_store(hist, owl_editwin_get_text(e));
2187  owl_history_reset(hist);
2188
2189  owl_editwin_fullclear(e);
2190  owl_global_set_needrefresh(&g);
2191  wnoutrefresh(owl_editwin_get_curswin(e));
2192  owl_global_set_typwin_inactive(&g);
2193  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2194
2195  owl_function_activate_keymap("recv");
2196}
2197
2198void owl_command_edit_history_prev(owl_editwin *e)
2199{
2200  owl_history *hist;
2201  char *ptr;
2202
2203  hist=owl_editwin_get_history(e);
2204  if (!owl_history_is_touched(hist)) {
2205    owl_history_store(hist, owl_editwin_get_text(e));
2206    owl_history_set_partial(hist);
2207  }
2208  ptr=owl_history_get_prev(hist);
2209  if (ptr) {
2210    owl_editwin_clear(e);
2211    owl_editwin_insert_string(e, ptr);
2212    owl_editwin_redisplay(e, 0);
2213    owl_global_set_needrefresh(&g);
2214  } else {
2215    owl_function_beep();
2216  }
2217}
2218
2219void owl_command_edit_history_next(owl_editwin *e)
2220{
2221  owl_history *hist;
2222  char *ptr;
2223
2224  hist=owl_editwin_get_history(e);
2225  ptr=owl_history_get_next(hist);
2226  if (ptr) {
2227    owl_editwin_clear(e);
2228    owl_editwin_insert_string(e, ptr);
2229    owl_editwin_redisplay(e, 0);
2230    owl_global_set_needrefresh(&g);
2231  } else {
2232    owl_function_beep();
2233  }
2234}
2235
2236char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff)
2237{
2238  buff = skiptokens(buff, 1);
2239  owl_editwin_insert_string(e, buff);
2240  owl_editwin_redisplay(e, 0);
2241  owl_global_set_needrefresh(&g); 
2242  return NULL;
2243}
2244
2245void owl_command_editline_done(owl_editwin *e)
2246{
2247  owl_history *hist=owl_editwin_get_history(e);
2248  char *rv, *cmd;
2249
2250  owl_history_store(hist, owl_editwin_get_text(e));
2251  owl_history_reset(hist);
2252  owl_global_set_typwin_inactive(&g);
2253  cmd = owl_strdup(owl_editwin_get_text(e));
2254  owl_editwin_fullclear(e);
2255  rv = owl_function_command(cmd);
2256  owl_free(cmd);
2257
2258  wnoutrefresh(owl_editwin_get_curswin(e));
2259  owl_global_set_needrefresh(&g);
2260
2261  if (rv) {
2262    owl_function_makemsg("%s", rv);
2263    owl_free(rv);
2264  }
2265}
2266
2267
2268void owl_command_editresponse_done(owl_editwin *e)
2269{
2270  owl_global_set_response(&g, owl_editwin_get_text(e));
2271
2272  owl_global_set_typwin_inactive(&g);
2273  owl_editwin_fullclear(e);
2274  wnoutrefresh(owl_editwin_get_curswin(e));
2275  owl_global_set_needrefresh(&g);
2276
2277  owl_function_run_buffercommand();
2278}
2279
2280
2281void owl_command_editmulti_done(owl_editwin *e)
2282{
2283  owl_history *hist=owl_editwin_get_history(e);
2284
2285  owl_history_store(hist, owl_editwin_get_text(e));
2286  owl_history_reset(hist);
2287
2288  owl_function_run_buffercommand();
2289  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2290  owl_editwin_fullclear(e);
2291  owl_global_set_typwin_inactive(&g);
2292  owl_global_set_needrefresh(&g);
2293  wnoutrefresh(owl_editwin_get_curswin(e));
2294}
2295
2296void owl_command_editmulti_done_or_delete(owl_editwin *e)
2297{
2298  if (owl_editwin_is_at_end(e)) {
2299    owl_command_editmulti_done(e);
2300  } else {
2301    owl_editwin_delete_char(e);
2302  }
2303}
2304
2305
2306/*********************************************************************/
2307/*********************** POPLESS SPECIFIC ****************************/
2308/*********************************************************************/
2309
2310void owl_command_popless_quit(owl_viewwin *vw)
2311{
2312  owl_popwin_close(owl_global_get_popwin(&g));
2313  owl_viewwin_free(vw);
2314  owl_global_set_needrefresh(&g);
2315}
Note: See TracBrowser for help on using the repository browser.