source: commands.c @ b4a95fc

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