source: commands.c @ f36222f

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