source: commands.c @ 32eed98

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