source: commands.c @ 2674412

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