source: commands.c @ 2ec737f

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