source: commands.c @ f7cf6c2

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