source: commands.c @ c65d81e

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