source: commands.c @ f1645da

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f1645da was 12c35df, checked in by James M. Kretchmar <kretch@mit.edu>, 21 years ago
Fixed replies to loopback messages Fixed smartnarrow on classes/instances with spaces Don't allow duplicates in command history Added the 'loggingdirection' variable All loopback messages log to 'loopback' now Print an error message if trying an invalid color for a filter Fixed bug causing > not to go to end of editwin every time
  • Property mode set to 100644
File size: 68.8 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include "owl.h"
6
7static const char fileIdent[] = "$Id$";
8
9/* fn is "char *foo(int argc, char **argv, char *buff)" */
10#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
11        { name, summary, usage, description, ctx, \
12          NULL, fn, NULL, NULL, NULL, NULL, NULL }
13
14/* fn is "void foo(void)" */
15#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
16        { name, summary, usage, description, ctx, \
17          NULL, NULL, fn, NULL, NULL, NULL, NULL }
18
19/* fn is "void foo(int)" */
20#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
21        { name, summary, usage, description, ctx, \
22          NULL, NULL, NULL, fn, NULL, NULL, NULL }
23
24#define OWLCMD_ALIAS(name, actualname) \
25        { name, OWL_CMD_ALIAS_SUMMARY_PREFIX actualname, "", "", OWL_CTX_ANY, \
26          actualname, NULL, NULL, NULL, NULL, NULL, NULL }
27
28/* fn is "char *foo(void *ctx, int argc, char **argv, char *buff)" */
29#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
30        { name, summary, usage, description, ctx, \
31          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,char**,char*))fn), NULL, NULL }
32
33/* fn is "void foo(void)" */
34#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
35        { name, summary, usage, description, ctx, \
36          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL }
37
38/* fn is "void foo(int)" */
39#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
40        { name, summary, usage, description, ctx, \
41          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn) }
42
43
44owl_cmd commands_to_init[]
45  = {
46  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
47              "send a login or logout notification",
48              "zlog in [tty]\nzlog out",
49              "zlog in will send a login notification, zlog out will send a\n"
50              "logout notification.  By default a login notification is sent\n"
51              "when owl is started and a logout notification is sent when owl\n"
52              "is exited.  This behavior can be changed with the 'startuplogin'\n"
53              "and 'shudownlogout' variables.  If a tty is specified for zlog in\n"
54              "then the owl variable 'tty' will be set to that string, causing\n"
55              "it to be used as the zephyr location tty.\n"),
56
57  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
58              "exit owl",
59              "",
60              "Exit owl and run any shutdown activities."),
61  OWLCMD_ALIAS("exit", "quit"),
62  OWLCMD_ALIAS("q",    "quit"),
63
64  OWLCMD_ARGS("term", owl_command_term, OWL_CTX_ANY,
65              "control the terminal",
66              "term raise\n"
67              "term deiconify\n",
68              ""),
69
70  OWLCMD_VOID("nop", owl_command_nop, OWL_CTX_ANY,
71              "do nothing",
72              "",
73              ""),
74 
75  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
76              "prompts the user to enter a command",
77              "start-command [initial-value]",
78              "Initializes the command field to initial-value."),
79
80  OWLCMD_ARGS("start-question", owl_command_start_question, OWL_CTX_INTERACTIVE,
81              "prompts the user to enter a response to some question",
82              "start-command <question>",
83              ""),
84
85  OWLCMD_ARGS("start-password", owl_command_start_password, OWL_CTX_INTERACTIVE,
86              "prompts the user to enter a password",
87              "start-password <question>",
88              ""),
89
90  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
91              "creates a command alias",
92              "alias <new_command> <old_command>",
93              "Creates a command alias from new_command to old_command.\n"
94              "Any arguments passed to <new_command> will be appended to\n"
95              "<old_command> before it is executed.\n"),
96
97  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
98              "creates a binding in a keymap",
99              "bindkey <keymap> <keyseq> command <command>",
100              "Binds a key sequence to a command within a keymap.\n"
101              "Use 'show keymaps' to see the existing keymaps.\n"
102              "Key sequences may be things like M-C-t or NPAGE.\n"),
103
104  OWLCMD_ARGS("style", owl_command_style, OWL_CTX_ANY,
105              "creates a new style",
106              "style <name> perl <function_name>",
107              "Creates a new style for formatting messages.\n"
108              "A style named <name> will be created that will\n"
109              "format messages using the perl function <function_name>.\n\n"
110              "SEE ALSO: show styles, view -s, filter -s\n"),
111
112  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
113              "send a zephyr",
114              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
115              "Zwrite send a zephyr to the one or more users specified.\n\n"
116              "The following options are available:\n\n"
117              "-m    Specifies a message to send without prompting.\n"
118              "      Note that this does not yet log an outgoing message.\n"
119              "      This must be the last argument.\n\n"
120              "-n    Do not send a ping message.\n\n"
121              "-C    If the message is sent to more than one user include a\n"
122              "      \"cc:\" line in the text\n\n"
123              "-c class\n"
124              "      Send to the specified zephyr class\n\n"
125              "-i instance\n"
126              "      Send to the specified zephyr instance\n\n"
127              "-r realm\n"
128              "      Send to a foreign realm\n"
129              "-O opcode\n"
130              "      Send to the specified opcode\n"),
131
132  OWLCMD_ARGS("aimwrite", owl_command_aimwrite, OWL_CTX_INTERACTIVE,
133              "send an AIM message",
134              "aimzwrite <user>",
135              "Send an aim message to a user.\n"),
136
137  OWLCMD_ARGS("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  if (argc!=2) {
1086    owl_function_makemsg("usage: dump <filename>");
1087    return(NULL);
1088  }
1089
1090  owl_function_dump(argv[1]);
1091  return(NULL);
1092}
1093
1094char *owl_command_source(int argc, char **argv, char *buff)
1095{
1096  if (argc!=2) {
1097    owl_function_makemsg("usage: source <filename>");
1098    return(NULL);
1099  }
1100
1101  owl_function_source(argv[1]);
1102  return(NULL);
1103}
1104
1105char *owl_command_next(int argc, char **argv, char *buff)
1106{
1107  char *filter=NULL;
1108  int skip_deleted=0, last_if_none=0;
1109  while (argc>1) {
1110    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1111      skip_deleted=1;
1112      argc-=1; argv+=1; 
1113    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1114      last_if_none=1;
1115      argc-=1; argv+=1; 
1116    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1117      filter = owl_strdup(argv[2]);
1118      argc-=2; argv+=2; 
1119    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1120      filter = owl_function_smartfilter(0);
1121      argc-=2; argv+=2; 
1122    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1123      filter = owl_function_smartfilter(1);
1124      argc-=2; argv+=2; 
1125    } else {
1126      owl_function_makemsg("Invalid arguments to command 'next'.");
1127      return(NULL);
1128    }
1129  }
1130  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1131  if (filter) owl_free(filter);
1132  return(NULL);
1133}
1134
1135char *owl_command_prev(int argc, char **argv, char *buff)
1136{
1137  char *filter=NULL;
1138  int skip_deleted=0, first_if_none=0;
1139  while (argc>1) {
1140    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1141      skip_deleted=1;
1142      argc-=1; argv+=1; 
1143    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1144      first_if_none=1;
1145      argc-=1; argv+=1; 
1146    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1147      filter = owl_strdup(argv[2]);
1148      argc-=2; argv+=2; 
1149    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1150      filter = owl_function_smartfilter(0);
1151      argc-=2; argv+=2; 
1152    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1153      filter = owl_function_smartfilter(1);
1154      argc-=2; argv+=2; 
1155   } else {
1156      owl_function_makemsg("Invalid arguments to command 'prev'.");
1157      return(NULL);
1158    }
1159  }
1160  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1161  if (filter) owl_free(filter);
1162  return(NULL);
1163}
1164
1165char *owl_command_smartnarrow(int argc, char **argv, char *buff)
1166{
1167  char *filtname = NULL;
1168
1169  if (argc == 1) {
1170    filtname = owl_function_smartfilter(0);
1171  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1172    filtname = owl_function_smartfilter(1);
1173  } else {
1174    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1175  }
1176  if (filtname) {
1177    owl_function_change_view(filtname);
1178    owl_free(filtname);
1179  }
1180  return NULL;
1181}
1182
1183char *owl_command_smartfilter(int argc, char **argv, char *buff)
1184{
1185  char *filtname = NULL;
1186
1187  if (argc == 1) {
1188    filtname = owl_function_smartfilter(0);
1189  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1190    filtname = owl_function_smartfilter(1);
1191  } else {
1192    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1193  }
1194  return filtname;
1195}
1196
1197void owl_command_expunge()
1198{
1199  owl_function_expunge();
1200}
1201
1202void owl_command_first()
1203{
1204  owl_global_set_rightshift(&g, 0);
1205  owl_function_firstmsg();
1206}
1207
1208void owl_command_last()
1209{
1210  owl_function_lastmsg();
1211}
1212
1213void owl_command_resize()
1214{
1215  owl_function_resize();
1216}
1217
1218void owl_command_redisplay()
1219{
1220  owl_function_full_redisplay();
1221  owl_global_set_needrefresh(&g);
1222}
1223
1224void owl_command_shift_right()
1225{
1226  owl_function_shift_right();
1227}
1228
1229void owl_command_shift_left()
1230{
1231  owl_function_shift_left();
1232}
1233
1234void owl_command_unsuball()
1235{
1236  owl_function_unsuball();
1237}
1238
1239char *owl_command_loadsubs(int argc, char **argv, char *buff)
1240{
1241  if (argc == 2) {
1242    owl_function_loadsubs(argv[1]);
1243  } else if (argc == 1) {
1244    owl_function_loadsubs(NULL);
1245  } else {
1246    owl_function_makemsg("Wrong number of arguments for load-subs.");
1247    return(NULL);
1248  }
1249  return(NULL);
1250}
1251
1252
1253char *owl_command_loadloginsubs(int argc, char **argv, char *buff)
1254{
1255  if (argc == 2) {
1256    owl_function_loadloginsubs(argv[1]);
1257  } else if (argc == 1) {
1258    owl_function_loadloginsubs(NULL);
1259  } else {
1260    owl_function_makemsg("Wrong number of arguments for load-subs.");
1261    return(NULL);
1262  }
1263  return(NULL);
1264}
1265
1266void owl_command_suspend()
1267{
1268  owl_function_suspend();
1269}
1270
1271char *owl_command_start_command(int argc, char **argv, char *buff)
1272{
1273  buff = skiptokens(buff, 1);
1274  owl_function_start_command(buff);
1275  return(NULL);
1276}
1277
1278char *owl_command_start_question(int argc, char **argv, char *buff)
1279{
1280  buff = skiptokens(buff, 1);
1281  owl_function_start_question(buff);
1282  return(NULL);
1283}
1284
1285char *owl_command_start_password(int argc, char **argv, char *buff)
1286{
1287  buff = skiptokens(buff, 1);
1288  owl_function_start_password(buff);
1289  return(NULL);
1290}
1291
1292char *owl_command_zaway(int argc, char **argv, char *buff)
1293{
1294  if ((argc==1) ||
1295      ((argc==2) && !strcmp(argv[1], "on"))) {
1296    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1297    owl_function_zaway_on();
1298    return NULL;
1299  }
1300
1301  if (argc==2 && !strcmp(argv[1], "off")) {
1302    owl_function_zaway_off();
1303    return NULL;
1304  }
1305
1306  if (argc==2 && !strcmp(argv[1], "toggle")) {
1307    owl_function_zaway_toggle();
1308    return NULL;
1309  }
1310
1311  buff = skiptokens(buff, 1);
1312  owl_global_set_zaway_msg(&g, buff);
1313  owl_function_zaway_on();
1314  return NULL;
1315}
1316
1317
1318char *owl_command_set(int argc, char **argv, char *buff)
1319{
1320  char *var, *val;
1321  int  silent=0;
1322  int requirebool=0;
1323
1324  if (argc == 1) {
1325    owl_function_printallvars();
1326    return NULL;
1327  } 
1328
1329  if (argc > 1 && !strcmp("-q",argv[1])) {
1330    silent = 1;
1331    argc--; argv++;
1332  }
1333
1334  if (argc == 2) {
1335    var=argv[1];
1336    val="on";
1337    requirebool=1;
1338  } else if (argc == 3) {
1339    var=argv[1];
1340    val=argv[2];
1341  } else {
1342    owl_function_makemsg("Wrong number of arguments for set command");
1343    return NULL;
1344  }
1345  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1346  return NULL;
1347}
1348
1349char *owl_command_unset(int argc, char **argv, char *buff)
1350{
1351  char *var, *val;
1352  int  silent=0;
1353
1354  if (argc > 1 && !strcmp("-q",argv[1])) {
1355    silent = 1;
1356    argc--; argv++;
1357  }
1358  if (argc == 2) {
1359    var=argv[1];
1360    val="off";
1361  } else {
1362    owl_function_makemsg("Wrong number of arguments for unset command");
1363    return NULL;
1364  }
1365  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1366  return NULL;
1367}
1368
1369char *owl_command_print(int argc, char **argv, char *buff)
1370{
1371  char *var;
1372  char valbuff[1024];
1373
1374  if (argc==1) {
1375    owl_function_printallvars();
1376    return NULL;
1377  } else if (argc!=2) {
1378    owl_function_makemsg("Wrong number of arguments for print command");
1379    return NULL;
1380  }
1381
1382  var=argv[1];
1383   
1384  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1385                                     var, valbuff, 1024)) {
1386    owl_function_makemsg("%s = '%s'", var, valbuff);
1387  } else {
1388    owl_function_makemsg("Unknown variable '%s'.", var);
1389  }
1390  return NULL;
1391}
1392
1393
1394char *owl_command_exec(int argc, char **argv, char *buff)
1395{
1396  return owl_function_exec(argc, argv, buff, 0);
1397}
1398
1399char *owl_command_pexec(int argc, char **argv, char *buff)
1400{
1401  return owl_function_exec(argc, argv, buff, 1);
1402}
1403
1404char *owl_command_aexec(int argc, char **argv, char *buff)
1405{
1406  return owl_function_exec(argc, argv, buff, 2);
1407}
1408
1409char *owl_command_perl(int argc, char **argv, char *buff)
1410{
1411  return owl_function_perl(argc, argv, buff, 0);
1412}
1413
1414char *owl_command_pperl(int argc, char **argv, char *buff)
1415{
1416  return owl_function_perl(argc, argv, buff, 1);
1417}
1418
1419char *owl_command_aperl(int argc, char **argv, char *buff)
1420{
1421  return owl_function_perl(argc, argv, buff, 2);
1422}
1423
1424char *owl_command_multi(int argc, char **argv, char *buff)
1425{
1426  char *lastrv = NULL, *newbuff;
1427  char **commands;
1428  int  ncommands, i;
1429  if (argc < 2) {
1430    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1431    return NULL;
1432  }
1433  newbuff = owl_strdup(buff);
1434  newbuff = skiptokens(newbuff, 1);
1435  if (!strcmp(argv[0], "(")) {
1436    for (i=strlen(newbuff)-1; i>=0; i--) {
1437      if (newbuff[i] == ')') {
1438        newbuff[i] = '\0';
1439        break;
1440      } else if (newbuff[i] != ' ') {
1441        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1442        owl_free(newbuff);
1443        return NULL;
1444      }
1445    }
1446  }
1447  commands = atokenize(newbuff, ";", &ncommands);
1448  for (i=0; i<ncommands; i++) {
1449    if (lastrv) {
1450      owl_free(lastrv);
1451    }
1452    lastrv = owl_function_command(commands[i]);
1453  }
1454  atokenize_free(commands, ncommands);
1455  return lastrv;
1456}
1457
1458
1459char *owl_command_alias(int argc, char **argv, char *buff)
1460{
1461  if (argc < 3) {
1462    owl_function_makemsg("Invalid arguments to 'alias' command.");
1463    return NULL;
1464  }
1465  buff = skiptokens(buff, 2);
1466  owl_function_command_alias(argv[1], buff);
1467  return (NULL);
1468}
1469
1470
1471char *owl_command_bindkey(int argc, char **argv, char *buff)
1472{
1473  owl_keymap *km;
1474  int ret;
1475
1476  if (argc < 5 || strcmp(argv[3], "command")) {
1477    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1478    return NULL;
1479  }
1480  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1481  if (!km) {
1482    owl_function_makemsg("No such keymap '%s'", argv[1]);
1483    return NULL;
1484  }
1485  buff = skiptokens(buff, 4);
1486  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1487  if (ret!=0) {
1488    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1489                         argv[2], argv[1], buff);
1490    return NULL;
1491  }
1492  return NULL;
1493}
1494
1495char *owl_command_style(int argc, char **argv, char *buff) {
1496  owl_style *s;
1497
1498  /* Usage: style <name> perl <function> */
1499  if (argc != 4 || strcmp(argv[2], "perl")) {
1500    owl_function_makemsg("Usage: style <name> perl <function>");
1501    return NULL;
1502  }
1503  if (!owl_perlconfig_is_function(argv[3])) {
1504    owl_function_makemsg("Unable to create style '%s': no perl function '%s'",
1505                         argv[1], argv[3]);
1506    return NULL;
1507  }
1508  s=owl_malloc(sizeof(owl_style));
1509  owl_style_create_perl(s, argv[1], argv[3], NULL);
1510  owl_global_add_style(&g, s);
1511
1512  return NULL;
1513}
1514
1515
1516void owl_command_quit()
1517{
1518  owl_function_quit();
1519}
1520
1521char *owl_command_debug(int argc, char **argv, char *buff)
1522{
1523  if (argc<2) {
1524    owl_function_makemsg("Need at least one argument to debug command");
1525    return(NULL);
1526  }
1527
1528  if (!owl_global_is_debug_fast(&g)) {
1529    owl_function_makemsg("Debugging is not turned on");
1530    return(NULL);
1531  }
1532
1533  owl_function_debugmsg(argv[1]);
1534  return(NULL);
1535}
1536
1537char *owl_command_term(int argc, char **argv, char *buff)
1538{
1539  if (argc<2) {
1540    owl_function_makemsg("Need at least one argument to the term command");
1541    return(NULL);
1542  }
1543
1544  if (!strcmp(argv[1], "raise")) {
1545    owl_function_xterm_raise();
1546  } else if (!strcmp(argv[1], "deiconify")) {
1547    owl_function_xterm_deiconify();
1548  } else {
1549    owl_function_makemsg("Unknown terminal subcommand");
1550  }
1551  return(NULL);
1552}
1553
1554char *owl_command_zlog(int argc, char **argv, char *buff)
1555{
1556  if ((argc<2) || (argc>3)) {
1557    owl_function_makemsg("Wrong number of arguments for zlog command");
1558    return(NULL);
1559  }
1560
1561  if (!strcmp(argv[1], "in")) {
1562    if (argc>2) {
1563      owl_global_set_tty(&g, argv[2]);
1564    }
1565    owl_zephyr_zlog_in();
1566  } else if (!strcmp(argv[1], "out")) {
1567    if (argc!=2) {
1568      owl_function_makemsg("Wrong number of arguments for zlog command");
1569      return(NULL);
1570    }
1571    owl_zephyr_zlog_out();
1572  } else {
1573    owl_function_makemsg("Invalid subcommand for zlog");
1574  }
1575  return(NULL);
1576}
1577
1578
1579void owl_command_zlog_out(void)
1580{
1581  owl_zephyr_zlog_out();
1582}
1583
1584
1585char *owl_command_subscribe(int argc, char **argv, char *buff)
1586{
1587  char *recip="";
1588  int temp=0;
1589 
1590  if (argc<3) {
1591    owl_function_makemsg("Not enough arguments to the subscribe command");
1592    return(NULL);
1593  }
1594  argc--;
1595  argv++;
1596
1597  if (!strcmp(argv[0], "-t")) {
1598    temp=1;
1599    argc--;
1600    argv++;
1601  }
1602  if (argc<2) {
1603    owl_function_makemsg("Not enough arguments to the subscribe command");
1604    return(NULL);
1605  }
1606
1607  if (argc>3) {
1608    owl_function_makemsg("Too many arguments to the subscribe command");
1609    return(NULL);
1610  }
1611
1612  if (argc==2) {
1613    recip="";
1614  } else if (argc==3) {
1615    recip=argv[2];
1616  }
1617
1618  owl_function_subscribe(argv[0], argv[1], recip);
1619  if (!temp) {
1620    owl_zephyr_addsub(NULL, argv[0], argv[1], recip);
1621  }
1622  return(NULL);
1623}
1624
1625
1626char *owl_command_unsubscribe(int argc, char **argv, char *buff)
1627{
1628  char *recip="";
1629  int temp=0;
1630
1631  if (argc<3) {
1632    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1633    return(NULL);
1634  }
1635  argc--;
1636  argv++;
1637
1638  if (!strcmp(argv[0], "-t")) {
1639    temp=1;
1640    argc--;
1641    argv++;
1642  }
1643  if (argc<2) {
1644    owl_function_makemsg("Not enough arguments to the subscribe command");
1645    return(NULL);
1646  }
1647
1648  if (argc>3) {
1649    owl_function_makemsg("Too many arguments to the unsubscribe command");
1650    return(NULL);
1651  }
1652
1653  if (argc==2) {
1654    recip="";
1655  } else if (argc==3) {
1656    recip=argv[2];
1657  }
1658
1659  owl_function_unsubscribe(argv[0], argv[1], recip);
1660  if (!temp) {
1661    owl_zephyr_delsub(NULL, argv[0], argv[1], recip);
1662  }
1663  return(NULL);
1664}
1665
1666char *owl_command_echo(int argc, char **argv, char *buff)
1667{
1668  buff = skiptokens(buff, 1);
1669  owl_function_popless_text(buff);
1670  return NULL;
1671}
1672
1673void owl_command_getsubs(void)
1674{
1675  owl_function_getsubs();
1676}
1677
1678void owl_command_status(void)
1679{
1680  owl_function_status();
1681}
1682
1683char *owl_command_zwrite(int argc, char **argv, char *buff)
1684{
1685  owl_zwrite z;
1686
1687  if (!owl_global_is_havezephyr(&g)) {
1688    owl_function_makemsg("Zephyr is not available");
1689    return(NULL);
1690  }
1691  /* check for a zwrite -m */
1692  owl_zwrite_create_from_line(&z, buff);
1693  if (owl_zwrite_is_message_set(&z)) {
1694    owl_function_zwrite(buff, NULL);
1695    owl_zwrite_free(&z);
1696    return (NULL);
1697  }
1698
1699  if (argc < 2) {
1700    owl_function_makemsg("Not enough arguments to the zwrite command.");
1701  } else {
1702    owl_function_zwrite_setup(buff);
1703  }
1704  return(NULL);
1705}
1706
1707char *owl_command_aimwrite(int argc, char **argv, char *buff)
1708{
1709  char *newbuff;
1710  int i, j;
1711 
1712  if (!owl_global_is_aimloggedin(&g)) {
1713    owl_function_makemsg("You are not logged in to AIM.");
1714    return(NULL);
1715  }
1716
1717  if (argc < 2) {
1718    owl_function_makemsg("Not enough arguments to the aimwrite command.");
1719    return(NULL);
1720  }
1721
1722  /* squish arguments together to make one screenname w/o spaces for now */
1723  newbuff=owl_malloc(strlen(buff)+5);
1724  sprintf(newbuff, "%s ", argv[0]);
1725  j=argc-1;
1726  for (i=0; i<j; i++) {
1727    strcat(newbuff, argv[i+1]);
1728  }
1729   
1730  owl_function_aimwrite_setup(newbuff);
1731  owl_free(newbuff);
1732  return(NULL);
1733}
1734
1735char *owl_command_loopwrite(int argc, char **argv, char *buff)
1736{
1737  owl_function_loopwrite_setup();
1738  return(NULL);
1739}
1740
1741char *owl_command_zcrypt(int argc, char **argv, char *buff)
1742{
1743#ifdef OWL_ENABLE_ZCRYPT
1744  owl_zwrite z;
1745
1746  if (!owl_global_is_havezephyr(&g)) {
1747    owl_function_makemsg("Zephyr is not available");
1748    return(NULL);
1749  }
1750  /* check for a zcrypt -m */
1751  owl_zwrite_create_from_line(&z, buff);
1752  if (owl_zwrite_is_message_set(&z)) {
1753    owl_function_zcrypt(buff, NULL);
1754    owl_zwrite_free(&z);
1755    return (NULL);
1756  }
1757
1758  if (argc < 2) {
1759    owl_function_makemsg("Not enough arguments to the zcrypt command.");
1760  } else {
1761    owl_function_zwrite_setup(buff);
1762  }
1763  return(NULL);
1764#else
1765  owl_function_makemsg("This Owl does not support zcrypt");
1766#endif
1767}
1768
1769char *owl_command_reply(int argc, char **argv, char *buff)
1770{
1771  int edit=0;
1772 
1773  if (argc>=2 && !strcmp("-e", argv[1])) {
1774    edit=1;
1775    argv++;
1776    argc--;
1777  }
1778
1779  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1780    owl_function_reply(0, !edit);
1781  } else if (argc==2 && !strcmp(argv[1], "sender")) {
1782    owl_function_reply(1, !edit);
1783  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
1784    owl_message *m;
1785    owl_view    *v;
1786    v = owl_global_get_current_view(&g);   
1787    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
1788    if (m) owl_zephyr_zaway(m);
1789  } else {
1790    owl_function_makemsg("Invalid arguments to the reply command.");
1791  }
1792  return NULL;
1793}
1794
1795char *owl_command_filter(int argc, char **argv, char *buff)
1796{
1797  owl_function_create_filter(argc, argv);
1798  return NULL;
1799}
1800
1801char *owl_command_zlocate(int argc, char **argv, char *buff)
1802{
1803  int auth;
1804 
1805  if (argc<2) {
1806    owl_function_makemsg("Too few arguments for zlocate command");
1807    return NULL;
1808  }
1809
1810  auth=1;
1811  if (!strcmp(argv[1], "-d")) {
1812    if (argc>2) {
1813      auth=0;
1814      argc--;
1815      argv++;
1816    } else {
1817      owl_function_makemsg("Missing arguments for zlocate command");
1818      return NULL;
1819    }
1820  }
1821
1822  argc--;
1823  argv++;
1824  owl_function_zlocate(argc, argv, auth);
1825  return NULL;
1826}
1827
1828char *owl_command_view(int argc, char **argv, char *buff)
1829{
1830
1831  /* Backwards compatability has made this kind of complicated:
1832   * view [<viewname>] [-f <filter> | -d <expression> | --home ] [-s <style>]
1833   * view <filter>
1834   * view -d <expression>
1835   * view --home
1836   */
1837
1838  /* First take the 'view --home' case */
1839  if (argc == 2 && !strcmp(argv[1], "--home")) {
1840    owl_function_change_view(owl_global_get_view_home(&g));
1841    return(NULL);
1842  }
1843
1844  /* Now look for 'view <filter>' */
1845  if (argc==2) {
1846    owl_function_change_view(argv[1]);
1847    return(NULL);
1848  }
1849
1850  /* Now get 'view -d <expression>' */
1851  if (argc>=3 && !strcmp(argv[1], "-d")) {
1852    char **myargv;
1853    int i;
1854
1855    myargv=owl_malloc((argc*sizeof(char *))+50);
1856    myargv[0]="";
1857    myargv[1]="owl-dynamic";
1858    for (i=2; i<argc; i++) {
1859      myargv[i]=argv[i];
1860    }
1861    owl_function_create_filter(argc, myargv);
1862    owl_function_change_view("owl-dynamic");
1863    owl_free(myargv);
1864    return NULL;
1865  }
1866
1867  /* Finally handle the general case */
1868  if (argc<3) {
1869    owl_function_makemsg("Too few arguments to the view command.");
1870    return(NULL);
1871  }
1872  argc--;
1873  argv++;
1874  if (strcmp(argv[0], "-f") && strcmp(argv[0], "-d") && strcmp(argv[0], "--home") && strcmp(argv[0], "-s")) {
1875    if (strcmp(argv[0], "main")) {
1876      owl_function_makemsg("No view named '%s'", argv[0]);
1877      return(NULL);
1878    }
1879    argc--;
1880    argv++;
1881  }
1882  while (argc) {
1883    if (!strcmp(argv[0], "-f")) {
1884      if (argc<2) {
1885        owl_function_makemsg("Too few argments to the view command");
1886        return(NULL);
1887      }
1888      owl_function_change_view(argv[1]);
1889      argc-=2;
1890      argv+=2;
1891    } else if (!strcmp(argv[0], "--home")) {
1892      owl_function_change_view(owl_global_get_view_home(&g));
1893      argc--;
1894      argv++;
1895    } else if (!strcmp(argv[0], "-s")) {
1896      if (argc<2) {
1897        owl_function_makemsg("Too few argments to the view command");
1898        return(NULL);
1899      }
1900      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
1901      argc-=2;
1902      argv+=2;
1903    } else {
1904      owl_function_makemsg("Too few argments to the view command");
1905      return(NULL);
1906    }
1907   
1908  }
1909  return(NULL);
1910}
1911
1912char *owl_command_show(int argc, char **argv, char *buff)
1913{
1914  if (argc<2) {
1915    owl_function_help_for_command("show");
1916    return NULL;
1917  }
1918
1919  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1920    if (argc==2) {
1921      owl_function_show_filters();
1922    } else {
1923      owl_function_show_filter(argv[2]);
1924    }
1925  } else if (argc==2 
1926             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1927    owl_function_show_zpunts();
1928  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1929    if (argc==2) {
1930      owl_function_show_commands();
1931    } else {
1932      owl_function_show_command(argv[2]);
1933    }
1934  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1935    if (argc==2) {
1936      owl_function_show_variables();
1937    } else {
1938      owl_function_show_variable(argv[2]);
1939    }
1940  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1941    if (argc==2) {
1942      owl_function_show_keymaps();
1943    } else {
1944      owl_function_show_keymap(argv[2]);
1945    }
1946  } else if (!strcmp(argv[1], "view")) {
1947    if (argc==3) {
1948      owl_function_show_view(argv[2]);
1949    } else {
1950      owl_function_show_view(NULL);
1951    }
1952  } else if (!strcmp(argv[1], "colors")) {
1953    owl_function_show_colors();
1954  } else if (!strcmp(argv[1], "styles")) {
1955    owl_function_show_styles();
1956  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1957    owl_function_getsubs();
1958  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1959    owl_function_show_term();
1960  } else if (!strcmp(argv[1], "version")) {
1961    owl_function_about();
1962  } else if (!strcmp(argv[1], "status")) {
1963    owl_function_status();
1964  } else if (!strcmp(argv[1], "startup")) {
1965    char *filename;
1966   
1967    filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE);
1968    owl_function_popless_file(filename);
1969    owl_free(filename);
1970  } else if (!strcmp(argv[1], "errors")) {
1971    owl_function_showerrs();
1972  } else {
1973    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1974    return NULL;
1975  }
1976  return NULL;
1977}
1978
1979char *owl_command_viewclass(int argc, char **argv, char *buff)
1980{
1981  char *filtname;
1982  if (argc!=2) {
1983    owl_function_makemsg("Wrong number of arguments to viewclass command");
1984    return NULL;
1985  }
1986  filtname = owl_function_classinstfilt(argv[1], NULL);
1987  owl_function_change_view(filtname);
1988  owl_free(filtname);
1989  return NULL;
1990}
1991
1992char *owl_command_viewuser(int argc, char **argv, char *buff)
1993{
1994  char *filtname;
1995  if (argc!=2) {
1996    owl_function_makemsg("Wrong number of arguments to viewuser command");
1997    return NULL;
1998  }
1999  filtname=owl_function_zuserfilt(argv[1]);
2000  owl_function_change_view(filtname);
2001  owl_free(filtname);
2002  return NULL;
2003}
2004
2005
2006void owl_command_pop_message(void)
2007{
2008  owl_function_curmsg_to_popwin();
2009}
2010
2011void owl_command_openurl(void)
2012{
2013  owl_function_openurl();
2014}
2015
2016char *owl_command_delete(int argc, char **argv, char *buff)
2017{
2018  int move_after = 1;
2019
2020  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2021    move_after = 0;
2022    argc--; 
2023    argv++;
2024  }
2025
2026  if (argc==1) {
2027    owl_function_deletecur(move_after);
2028    return NULL;
2029  }
2030
2031  if (argc==2 && !strcmp(argv[1], "view")) {
2032    owl_function_delete_curview_msgs(1);
2033    return NULL;
2034  }
2035
2036  if (argc==2 && !strcmp(argv[1], "trash")) {
2037    owl_function_delete_automsgs();
2038    return NULL;
2039  }
2040
2041  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2042    owl_function_delete_by_id(atoi(argv[2]), 1);
2043    return NULL;
2044  }
2045
2046  owl_function_makemsg("Unknown arguments to delete command");
2047  return NULL;
2048}
2049
2050char *owl_command_undelete(int argc, char **argv, char *buff)
2051{
2052  int move_after = 1;
2053
2054  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2055    move_after = 0;
2056    argc--; 
2057    argv++;
2058  }
2059
2060  if (argc==1) {
2061    owl_function_undeletecur(move_after);
2062    return NULL;
2063  }
2064
2065  if (argc==2 && !strcmp(argv[1], "view")) {
2066    owl_function_delete_curview_msgs(0);
2067    return NULL;
2068  }
2069
2070  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2071    owl_function_delete_by_id(atoi(argv[2]), 0);
2072    return NULL;
2073  }
2074
2075  owl_function_makemsg("Unknown arguments to delete command");
2076  return NULL;
2077}
2078
2079void owl_command_beep()
2080{
2081  owl_function_beep();
2082}
2083
2084char *owl_command_colorview(int argc, char **argv, char *buff)
2085{
2086  if (argc!=2) {
2087    owl_function_makemsg("Wrong number of arguments to colorview command");
2088    return NULL;
2089  }
2090  owl_function_color_current_filter(argv[1]);
2091  return NULL;
2092}
2093
2094char *owl_command_zpunt(int argc, char **argv, char *buff)
2095{
2096  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2097  return NULL;
2098}
2099
2100char *owl_command_zunpunt(int argc, char **argv, char *buff)
2101{
2102  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2103  return NULL;
2104}
2105
2106
2107void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type)
2108{
2109  /* if type==0 then zpunt
2110   * if type==1 then zunpunt
2111   */
2112  char *class, *inst, *recip;
2113
2114  class="message";
2115  inst="";
2116  recip="*";
2117
2118  if (argc==1) {
2119    /* show current punt filters */
2120    owl_function_show_zpunts();
2121    return;
2122  } else if (argc==2) {
2123    inst=argv[1];
2124  } else if (argc==3) {
2125    class=argv[1];
2126    inst=argv[2];
2127  } else if (argc==4) {
2128    class=argv[1];
2129    inst=argv[2];
2130    recip=argv[3];
2131  } else {
2132    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2133    return;
2134  }
2135
2136  owl_function_zpunt(class, inst, recip, type);
2137  if (type==0) {
2138    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2139  } else if (type==1) {
2140    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2141  }
2142}
2143
2144char *owl_command_smartzpunt(int argc, char **argv, char *buff)
2145{
2146  if (argc == 1) {
2147    owl_function_smartzpunt(0);
2148  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2149    owl_function_smartzpunt(1);
2150  } else {
2151    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2152  }
2153  return NULL;
2154}
2155
2156char *owl_command_getview(int argc, char **argv, char *buff)
2157{
2158  char *filtname;
2159  if (argc != 1) {
2160    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2161    return NULL;
2162  }
2163  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2164  if (filtname) filtname = owl_strdup(filtname);
2165  return filtname;
2166}
2167
2168char *owl_command_getvar(int argc, char **argv, char *buff)
2169{
2170  char tmpbuff[1024];
2171  if (argc != 2) {
2172    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2173    return NULL;
2174  }
2175  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
2176                                argv[1], tmpbuff, 1024)) {
2177    return NULL;
2178  }
2179  return owl_strdup(tmpbuff); 
2180}
2181
2182char *owl_command_search(int argc, char **argv, char *buff)
2183{
2184  int direction;
2185  char *buffstart;
2186
2187  direction=OWL_DIRECTION_DOWNWARDS;
2188  buffstart=skiptokens(buff, 1);
2189  if (argc>1 && !strcmp(argv[1], "-r")) {
2190    direction=OWL_DIRECTION_UPWARDS;
2191    buffstart=skiptokens(buff, 2);
2192  }
2193   
2194  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2195    owl_function_search_continue(direction);
2196  } else {
2197    owl_function_search_start(buffstart, direction);
2198  }
2199 
2200  return(NULL);
2201}
2202
2203char *owl_command_aimlogin(int argc, char **argv, char *buff)
2204{
2205  int ret;
2206 
2207  if ((argc<2) || (argc>3)) {
2208    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2209    return(NULL);
2210  }
2211
2212  /* if we get two arguments, ask for the password */
2213  if (argc==2) {
2214    owl_global_set_buffercommand(&g, buff);
2215    owl_function_start_password("AIM Password: ");
2216    return(NULL);
2217  }
2218
2219  /* clear the buddylist */
2220  owl_buddylist_clear(owl_global_get_buddylist(&g));
2221
2222  /* try to login */
2223  ret=owl_aim_login(argv[1], argv[2]);
2224  if (ret) owl_function_makemsg("Warning: login for %s failed.\n");
2225
2226  /* this is a test */
2227  return(NULL);
2228}
2229
2230char *owl_command_aimlogout(int argc, char **argv, char *buff)
2231{
2232  /* clear the buddylist */
2233  owl_buddylist_clear(owl_global_get_buddylist(&g));
2234
2235  owl_aim_logout();
2236  return(NULL);
2237}
2238
2239/*********************************************************************/
2240/************************** EDIT SPECIFIC ****************************/
2241/*********************************************************************/
2242
2243void owl_command_edit_cancel(owl_editwin *e)
2244{
2245  owl_history *hist;
2246
2247  owl_function_makemsg("Command cancelled.");
2248
2249  hist=owl_editwin_get_history(e);
2250  owl_history_store(hist, owl_editwin_get_text(e));
2251  owl_history_reset(hist);
2252
2253  owl_editwin_fullclear(e);
2254  owl_global_set_needrefresh(&g);
2255  wnoutrefresh(owl_editwin_get_curswin(e));
2256  owl_global_set_typwin_inactive(&g);
2257  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2258
2259  owl_function_activate_keymap("recv");
2260}
2261
2262void owl_command_edit_history_prev(owl_editwin *e)
2263{
2264  owl_history *hist;
2265  char *ptr;
2266
2267  hist=owl_editwin_get_history(e);
2268  if (!owl_history_is_touched(hist)) {
2269    owl_history_store(hist, owl_editwin_get_text(e));
2270    owl_history_set_partial(hist);
2271  }
2272  ptr=owl_history_get_prev(hist);
2273  if (ptr) {
2274    owl_editwin_clear(e);
2275    owl_editwin_insert_string(e, ptr);
2276    owl_editwin_redisplay(e, 0);
2277    owl_global_set_needrefresh(&g);
2278  } else {
2279    owl_function_beep();
2280  }
2281}
2282
2283void owl_command_edit_history_next(owl_editwin *e)
2284{
2285  owl_history *hist;
2286  char *ptr;
2287
2288  hist=owl_editwin_get_history(e);
2289  ptr=owl_history_get_next(hist);
2290  if (ptr) {
2291    owl_editwin_clear(e);
2292    owl_editwin_insert_string(e, ptr);
2293    owl_editwin_redisplay(e, 0);
2294    owl_global_set_needrefresh(&g);
2295  } else {
2296    owl_function_beep();
2297  }
2298}
2299
2300char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff)
2301{
2302  buff = skiptokens(buff, 1);
2303  owl_editwin_insert_string(e, buff);
2304  owl_editwin_redisplay(e, 0);
2305  owl_global_set_needrefresh(&g); 
2306  return NULL;
2307}
2308
2309void owl_command_editline_done(owl_editwin *e)
2310{
2311  owl_history *hist=owl_editwin_get_history(e);
2312  char *rv, *cmd;
2313
2314  owl_history_store(hist, owl_editwin_get_text(e));
2315  owl_history_reset(hist);
2316  owl_global_set_typwin_inactive(&g);
2317  cmd = owl_strdup(owl_editwin_get_text(e));
2318  owl_editwin_fullclear(e);
2319  rv = owl_function_command(cmd);
2320  owl_free(cmd);
2321
2322  wnoutrefresh(owl_editwin_get_curswin(e));
2323  owl_global_set_needrefresh(&g);
2324
2325  if (rv) {
2326    owl_function_makemsg("%s", rv);
2327    owl_free(rv);
2328  }
2329}
2330
2331
2332void owl_command_editresponse_done(owl_editwin *e)
2333{
2334  owl_global_set_response(&g, owl_editwin_get_text(e));
2335
2336  owl_global_set_typwin_inactive(&g);
2337  owl_editwin_fullclear(e);
2338  wnoutrefresh(owl_editwin_get_curswin(e));
2339  owl_global_set_needrefresh(&g);
2340
2341  owl_function_run_buffercommand();
2342}
2343
2344
2345void owl_command_editmulti_done(owl_editwin *e)
2346{
2347  owl_history *hist=owl_editwin_get_history(e);
2348
2349  owl_history_store(hist, owl_editwin_get_text(e));
2350  owl_history_reset(hist);
2351
2352  owl_function_run_buffercommand();
2353  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2354  owl_editwin_fullclear(e);
2355  owl_global_set_typwin_inactive(&g);
2356  owl_global_set_needrefresh(&g);
2357  wnoutrefresh(owl_editwin_get_curswin(e));
2358}
2359
2360void owl_command_editmulti_done_or_delete(owl_editwin *e)
2361{
2362  if (owl_editwin_is_at_end(e)) {
2363    owl_command_editmulti_done(e);
2364  } else {
2365    owl_editwin_delete_char(e);
2366  }
2367}
2368
2369
2370/*********************************************************************/
2371/*********************** POPLESS SPECIFIC ****************************/
2372/*********************************************************************/
2373
2374void owl_command_popless_quit(owl_viewwin *vw)
2375{
2376  owl_popwin_close(owl_global_get_popwin(&g));
2377  owl_viewwin_free(vw);
2378  owl_global_set_needrefresh(&g);
2379}
Note: See TracBrowser for help on using the repository browser.