source: commands.c @ ba4fde8

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