source: commands.c @ c6adf17

release-1.10release-1.7release-1.8release-1.9
Last change on this file since c6adf17 was c6adf17, checked in by David Benjamin <davidben@mit.edu>, 14 years ago
Track names along with timers, add :show timers This will help people with BarnOwls eating CPU to diagnose timer leaks.
  • Property mode set to 100644
File size: 83.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 timers\n"
657              "show variables\n"
658              "show variable <variable>\n"
659              "show version\n"
660              "show view [<view>]\n"
661              "show zpunts\n",
662
663              "Show colors will display a list of valid colors for the\n"
664              "     terminal."
665              "Show filters will list the names of all filters.\n"
666              "Show filter <filter> will show the definition of a particular\n"
667              "     filter.\n\n"
668              "Show startup will display the custom startup config\n\n"
669              "Show zpunts will show the active zpunt filters.\n\n"
670              "Show keymaps will list the names of all keymaps.\n"
671              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
672              "Show commands will list the names of all keymaps.\n"
673              "Show command <command> will provide information about a command.\n\n"
674              "Show styles will list the names of all styles available\n"
675              "for formatting messages.\n\n"
676              "Show variables will list the names of all variables.\n\n"
677              "Show errors will show a list of errors encountered by Owl.\n\n"
678              "SEE ALSO: filter, view, alias, bindkey, help\n"),
679 
680  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
681              "mark a message for deletion",
682              "delete [ -id msgid ] [ --no-move ]\n"
683              "delete view\n"
684              "delete trash",
685              "If no message id is specified the current message is marked\n"
686              "for deletion.  Otherwise the message with the given message\n"
687              "id is marked for deletion.\n"
688              "If '--no-move' is specified, don't move after deletion.\n"
689              "If 'trash' is specified, deletes all trash/auto messages\n"
690              "in the current view.\n"
691              "If 'view' is specified, deletes all messages in the\n"
692              "current view.\n"),
693  OWLCMD_ALIAS("del", "delete"),
694
695  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
696              "unmark a message for deletion",
697              "undelete [ -id msgid ] [ --no-move ]\n"
698              "undelete view",
699              "If no message id is specified the current message is\n"
700              "unmarked for deletion.  Otherwise the message with the\n"
701              "given message id is unmarked for deletion.\n"
702              "If '--no-move' is specified, don't move after deletion.\n"
703              "If 'view' is specified, undeletes all messages\n"
704              "in the current view.\n"),
705  OWLCMD_ALIAS("undel", "undelete"),
706
707  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
708              "ring the terminal bell",
709              "beep",
710              "Beep will ring the terminal bell.\n"
711              "If the variable 'bell' has been\n"
712              "set to 'off' this command does nothing.\n"),
713
714  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
715              "prints a message into the debug log",
716              "debug <message>", ""),
717
718  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
719              "returns the name of the filter for the current view",
720              "", ""),
721
722  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
723              "returns the value of a variable",
724              "getvar <varname>", ""),
725
726  OWLCMD_ARGS("getfilter", owl_command_getfilter, OWL_CTX_INTERACTIVE,
727              "returns the definition of a filter",
728              "getfilter <filtername>", ""),
729
730  OWLCMD_ARGS("getstyle", owl_command_getstyle, OWL_CTX_INTERACTIVE,
731              "returns the name of the style for the current view",
732              "", ""),
733
734  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
735              "search messages for a particular string",
736              "search [-r] [<string>]",
737              "The search command will find messages that contain the\n"
738              "specified string and move the cursor there.  If no string\n"
739              "argument is supplied then the previous one is used.  By\n"
740              "default searches are done forwards; if -r is used the search\n"
741              "is performed backwards"),
742
743  OWLCMD_ARGS("setsearch", owl_command_setsearch, OWL_CTX_INTERACTIVE,
744              "set the search highlight string without searching",
745              "setsearch <string>",
746              "The setsearch command highlights all occurrences of its\n"
747          "argument and makes it the default argument for future\n"
748          "search commands, but does not move the cursor.  With\n"
749          "no argument, it makes search highlighting inactive."),
750
751  OWLCMD_ARGS("aimlogin", owl_command_aimlogin, OWL_CTX_ANY,
752              "login to an AIM account",
753              "aimlogin <screenname> [<password>]\n",
754              ""),
755
756  OWLCMD_ARGS("aimlogout", owl_command_aimlogout, OWL_CTX_ANY,
757              "logout from AIM",
758              "aimlogout\n",
759              ""),
760
761  OWLCMD_ARGS("error", owl_command_error, OWL_CTX_ANY,
762              "Display an error message",
763              "error <message>",
764              ""),
765
766  OWLCMD_ARGS("message", owl_command_message, OWL_CTX_ANY,
767              "Display an informative message",
768              "message <message>",
769              ""),
770
771  OWLCMD_VOID("yes", owl_command_yes, OWL_CTX_RECV,
772              "Answer yes to a question",
773              "yes",
774              ""),
775
776  OWLCMD_VOID("no", owl_command_no, OWL_CTX_RECV,
777              "Answer no to a question",
778              "no",
779              ""),
780
781  /****************************************************************/
782  /************************* EDIT-SPECIFIC ************************/
783  /****************************************************************/
784
785  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
786                  OWL_CTX_EDIT,
787                  "moves cursor forward a word",
788                  "", ""),
789
790  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
791                  OWL_CTX_EDIT,
792                  "moves cursor backwards a word",
793                  "", ""),
794
795  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
796                  OWL_CTX_EDIT,
797                  "moves cursor to the top left (start) of the buffer",
798                  "", ""),
799
800  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
801                  OWL_CTX_EDIT,
802                  "moves cursor to the bottom right (end) of the buffer",
803                  "", ""),
804
805  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
806                  OWL_CTX_EDIT,
807                  "moves cursor to the end of the line",
808                  "", ""),
809
810  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
811                  OWL_CTX_EDIT,
812                  "moves cursor to the beginning of the line",
813                  "", ""),
814
815  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
816                  OWL_CTX_EDIT,
817                  "moves the cursor left by a character",
818                  "", ""),
819
820  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
821                  OWL_CTX_EDIT,
822                  "moves the cursor right by a character",
823                  "", ""),
824
825  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
826                  OWL_CTX_EDIT,
827                  "deletes the word to the right of the cursor",
828                  "", ""),
829
830  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
831                  OWL_CTX_EDIT,
832                  "deletes the word to the left of the cursor",
833                  "", ""),
834
835  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
836                  OWL_CTX_EDIT,
837                  "deletes the character to the left of the cursor",
838                  "", ""),
839
840  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
841                  OWL_CTX_EDIT,
842                  "deletes the character to the right of the cursor",
843                  "", ""),
844
845  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
846                  OWL_CTX_EDIT,
847                  "deletes from the cursor to the end of the line",
848                  "", ""),
849
850  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
851                  OWL_CTX_EDIT,
852                  "deletes all of the contents of the buffer",
853                  "", ""),
854
855  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
856                  OWL_CTX_EDIT,
857                  "Interchange characters around point, moving forward one character.",
858                  "", ""),
859
860  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
861                  OWL_CTX_EDIT,
862                  "fills the current paragraph to line-wrap well",
863                  "", ""),
864
865  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
866                  OWL_CTX_EDIT,
867                  "recenters the buffer",
868                  "", ""),
869
870  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
871                  OWL_CTX_EDIT,
872                  "inserts text into the buffer",
873                  "edit:insert-text <text>", ""),
874
875  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
876                  OWL_CTX_EDIT,
877                  "cancels the current command",
878                  "", ""),
879
880  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
881                  OWL_CTX_EDIT,
882                  "replaces the text with the next history",
883                  "", ""),
884
885  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
886                  OWL_CTX_EDIT,
887                  "replaces the text with the previous history",
888                  "", ""),
889
890  OWLCMD_VOID_CTX("edit:set-mark", owl_editwin_set_mark,
891                  OWL_CTX_EDIT,
892                  "sets the mark",
893                  "", ""),
894
895  OWLCMD_VOID_CTX("edit:exchange-point-and-mark", owl_editwin_exchange_point_and_mark,
896                  OWL_CTX_EDIT,
897                  "exchanges the point and the mark",
898                  "", ""),
899
900  OWLCMD_VOID_CTX("edit:copy-region-as-kill", owl_editwin_copy_region_as_kill,
901                  OWL_CTX_EDIT,
902                  "copy the text between the point and the mark",
903                  "", ""),
904
905  OWLCMD_VOID_CTX("edit:kill-region", owl_editwin_kill_region,
906                  OWL_CTX_EDIT,
907                  "kill text between the point and the mark",
908                  "", ""),
909
910  OWLCMD_VOID_CTX("edit:yank", owl_editwin_yank,
911                  OWL_CTX_EDIT,
912                  "insert the current text from the kill buffer",
913                  "", ""),
914
915  OWLCMD_ALIAS   ("editline:done", "edit:done"),
916  OWLCMD_ALIAS   ("editresponse:done", "edit:done"),
917
918  OWLCMD_VOID_CTX("edit:move-up-line", owl_editwin_key_up, 
919                  OWL_CTX_EDITMULTI,
920                  "moves the cursor up one line",
921                  "", ""),
922
923  OWLCMD_VOID_CTX("edit:move-down-line", owl_editwin_key_down, 
924                  OWL_CTX_EDITMULTI,
925                  "moves the cursor down one line",
926                  "", ""),
927
928  OWLCMD_VOID_CTX("edit:done", owl_command_edit_done, 
929                  OWL_CTX_EDIT,
930                  "Finishes entering text in the editwin.",
931                  "", ""),
932
933  OWLCMD_VOID_CTX("edit:done-or-delete", owl_command_edit_done_or_delete, 
934                  OWL_CTX_EDITMULTI,
935                  "completes the command, but only if at end of message",
936                  "", 
937                  "If only whitespace is to the right of the cursor,\n"
938                  "runs 'edit:done'.\n"\
939                  "Otherwise runs 'edit:delete-next-char'\n"),
940
941  OWLCMD_VOID_CTX("edit:forward-paragraph", owl_editwin_forward_paragraph,
942                  OWL_CTX_EDITMULTI,
943                  "Move forward to end of paragraph.",
944                  "",
945                  "Move the point to the end of the current paragraph"),
946
947  OWLCMD_VOID_CTX("edit:backward-paragraph", owl_editwin_backward_paragraph,
948                  OWL_CTX_EDITMULTI,
949                  "Move backward to the start of paragraph.",
950                  "",
951                  "Move the point to the start of the current paragraph"),
952
953  /****************************************************************/
954  /********************** POPLESS-SPECIFIC ************************/
955  /****************************************************************/
956
957  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
958                  OWL_CTX_POPLESS,
959                  "scrolls down one page",
960                  "", ""),
961
962  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
963                  OWL_CTX_POPLESS,
964                  "scrolls down one line",
965                  "", ""),
966
967  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
968                  OWL_CTX_POPLESS,
969                  "scrolls up one page",
970                  "", ""),
971
972  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
973                  OWL_CTX_POPLESS,
974                  "scrolls up one line",
975                  "", ""),
976
977  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
978                  OWL_CTX_POPLESS,
979                  "scrolls to the top of the buffer",
980                  "", ""),
981
982  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
983                  OWL_CTX_POPLESS,
984                  "scrolls to the bottom of the buffer",
985                  "", ""),
986
987  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
988                  OWL_CTX_POPLESS,
989                  "scrolls right in the buffer",
990                  "popless:scroll-right <num-chars>", ""),
991
992  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
993                  OWL_CTX_POPLESS,
994                  "scrolls left in the buffer",
995                  "popless:scroll-left <num-chars>", ""),
996
997  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
998                  OWL_CTX_POPLESS,
999                  "exits the popless window",
1000                  "", ""),
1001
1002  OWLCMD_ARGS_CTX("popless:start-command", owl_viewwin_start_command,
1003                  OWL_CTX_POPLESS,
1004                  "starts a command line in the popless",
1005                  "popless:start-command [initial-value]",
1006                  "Initializes the command field to initial-value"),
1007
1008  OWLCMD_ARGS_CTX("popless:search", owl_viewwin_command_search, OWL_CTX_POPLESS,
1009                  "search lines for a particular string",
1010                  "popless:search [-r] [<string>]",
1011                  "The popless:search command will find lines that contain the\n"
1012                  "specified string and scroll the popwin there.  If no string\n"
1013                  "argument is supplied then the previous one is used.  By\n"
1014                  "default searches are done forwards; if -r is used the search\n"
1015                  "is performed backwards"),
1016
1017  OWLCMD_ARGS_CTX("popless:start-search", owl_viewwin_command_start_search, OWL_CTX_POPLESS,
1018                  "starts a command line to search for particular string",
1019                  "popless:search [-r] [inital-value]",
1020                  "Initializes the command-line to search for initial-value. If\n"
1021                  "-r is used, the search will be performed backwards."),
1022
1023  OWLCMD_ALIAS("webzephyr", "zwrite daemon.webzephyr -c webzephyr -i"),
1024
1025  /* This line MUST be last! */
1026  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1027
1028};
1029
1030void owl_command_info(void)
1031{
1032  owl_function_info();
1033}
1034
1035void owl_command_nop(void)
1036{
1037}
1038
1039char *owl_command_help(int argc, const char *const *argv, const char *buff)
1040{
1041  if (argc!=2) {
1042    owl_help();
1043    return NULL;
1044  }
1045 
1046  owl_function_help_for_command(argv[1]);
1047  return NULL;
1048}
1049
1050char *owl_command_zlist(int argc, const char *const *argv, const char *buff)
1051{
1052  const char *file=NULL;
1053
1054  argc--;
1055  argv++;
1056  while (argc) {
1057    if (!strcmp(argv[0], "-f")) {
1058      if (argc==1) {
1059        owl_function_makemsg("zlist: -f needs an argument");
1060        return(NULL);
1061      }
1062      file=argv[1];
1063      argc-=2;
1064      argv+=2;
1065    } else {
1066      owl_function_makemsg("zlist: unknown argument");
1067      return(NULL);
1068    }
1069  }
1070  owl_function_buddylist(0, 1, file);
1071  return(NULL);
1072}
1073
1074void owl_command_alist(void)
1075{
1076  owl_function_buddylist(1, 0, NULL);
1077}
1078
1079void owl_command_blist(void)
1080{
1081  owl_function_buddylist(1, 1, NULL);
1082}
1083
1084void owl_command_toggleoneline(void)
1085{
1086  owl_function_toggleoneline();
1087}
1088
1089void owl_command_about(void)
1090{
1091  owl_function_about();
1092}
1093
1094void owl_command_version(void)
1095{
1096  owl_function_makemsg("BarnOwl version %s", OWL_VERSION_STRING);
1097}
1098
1099char *owl_command_aim(int argc, const char *const *argv, const char *buff)
1100{
1101  if (argc<2) {
1102    owl_function_makemsg("not enough arguments to aim command");
1103    return(NULL);
1104  }
1105
1106  if (!strcmp(argv[1], "search")) {
1107    if (argc!=3) {
1108      owl_function_makemsg("not enough arguments to aim search command");
1109      return(NULL);
1110    }
1111    owl_aim_search(argv[2]);
1112  } else {
1113    owl_function_makemsg("unknown subcommand '%s' for aim command", argv[1]);
1114    return(NULL);
1115  }
1116  return(NULL);
1117}
1118
1119char *owl_command_addbuddy(int argc, const char *const *argv, const char *buff)
1120{
1121  if (argc!=3) {
1122    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1123    return(NULL);
1124  }
1125
1126  if (!strcasecmp(argv[1], "aim")) {
1127    if (!owl_global_is_aimloggedin(&g)) {
1128      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
1129      return(NULL);
1130    }
1131    /*
1132    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
1133    return(NULL);
1134    */
1135    owl_aim_addbuddy(argv[2]);
1136    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1137  } else if (!strcasecmp(argv[1], "zephyr")) {
1138    owl_zephyr_addbuddy(argv[2]);
1139    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1140  } else {
1141    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1142  }
1143
1144  return(NULL);
1145}
1146
1147char *owl_command_delbuddy(int argc, const char *const *argv, const char *buff)
1148{
1149  if (argc!=3) {
1150    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1151    return(NULL);
1152  }
1153
1154  if (!strcasecmp(argv[1], "aim")) {
1155    if (!owl_global_is_aimloggedin(&g)) {
1156      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
1157      return(NULL);
1158    }
1159    owl_aim_delbuddy(argv[2]);
1160    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1161  } else if (!strcasecmp(argv[1], "zephyr")) {
1162    owl_zephyr_delbuddy(argv[2]);
1163    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1164  } else {
1165    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1166  }
1167
1168  return(NULL);
1169}
1170
1171char *owl_command_join(int argc, const char *const *argv, const char *buff)
1172{
1173  if (argc!=3 && argc!=4) {
1174    owl_function_makemsg("usage: join <protocol> <buddyname> [exchange]");
1175    return(NULL);
1176  }
1177
1178  if (!strcasecmp(argv[1], "aim")) {
1179    if (!owl_global_is_aimloggedin(&g)) {
1180      owl_function_makemsg("join aim: You must be logged into aim to use this command.");
1181      return(NULL);
1182    }
1183    if (argc==3) {
1184      owl_aim_chat_join(argv[2], 4);
1185    } else {
1186      owl_aim_chat_join(argv[2], atoi(argv[3]));
1187    }
1188    /* owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g)); */
1189  } else {
1190    owl_function_makemsg("join: currently the only supported protocol is 'aim'");
1191  }
1192  return(NULL);
1193}
1194
1195char *owl_command_startup(int argc, const char *const *argv, const char *buff)
1196{
1197  const char *ptr;
1198
1199  if (argc<2) {
1200    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1201    return(NULL);
1202  }
1203
1204  ptr = skiptokens(buff, 1);
1205
1206  owl_function_command(ptr);
1207  owl_function_addstartup(ptr);
1208
1209  return(NULL);
1210}
1211
1212char *owl_command_unstartup(int argc, const char *const *argv, const char *buff)
1213{
1214  const char *ptr;
1215
1216  if (argc<2) {
1217    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1218    return(NULL);
1219  }
1220
1221  ptr = skiptokens(buff, 1);
1222
1223  owl_function_delstartup(ptr);
1224
1225  return(NULL);
1226}
1227
1228char *owl_command_dump(int argc, const char *const *argv, const char *buff)
1229{
1230  char *filename;
1231 
1232  if (argc!=2) {
1233    owl_function_makemsg("usage: dump <filename>");
1234    return(NULL);
1235  }
1236  filename=owl_util_makepath(argv[1]);
1237  owl_function_dump(filename);
1238  owl_free(filename);
1239  return(NULL);
1240}
1241
1242char *owl_command_source(int argc, const char *const *argv, const char *buff)
1243{
1244  if (argc!=2) {
1245    owl_function_makemsg("usage: source <filename>");
1246    return(NULL);
1247  }
1248
1249  owl_function_source(argv[1]);
1250  return(NULL);
1251}
1252
1253char *owl_command_next(int argc, const char *const *argv, const char *buff)
1254{
1255  char *filter=NULL;
1256  int skip_deleted=0, last_if_none=0;
1257  while (argc>1) {
1258    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1259      skip_deleted=1;
1260      argc-=1; argv+=1; 
1261    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1262      last_if_none=1;
1263      argc-=1; argv+=1; 
1264    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1265      filter = owl_strdup(argv[2]);
1266      argc-=2; argv+=2; 
1267    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1268      filter = owl_function_smartfilter(0, 0);
1269      argc-=2; argv+=2; 
1270    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1271      filter = owl_function_smartfilter(1, 0);
1272      argc-=2; argv+=2; 
1273    } else {
1274      owl_function_makemsg("Invalid arguments to command 'next'.");
1275      return(NULL);
1276    }
1277  }
1278  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1279  if (filter) owl_free(filter);
1280  return(NULL);
1281}
1282
1283char *owl_command_prev(int argc, const char *const *argv, const char *buff)
1284{
1285  char *filter=NULL;
1286  int skip_deleted=0, first_if_none=0;
1287  while (argc>1) {
1288    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1289      skip_deleted=1;
1290      argc-=1; argv+=1; 
1291    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1292      first_if_none=1;
1293      argc-=1; argv+=1; 
1294    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1295      filter = owl_strdup(argv[2]);
1296      argc-=2; argv+=2; 
1297    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1298      filter = owl_function_smartfilter(0, 0);
1299      argc-=2; argv+=2; 
1300    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1301      filter = owl_function_smartfilter(1, 0);
1302      argc-=2; argv+=2; 
1303   } else {
1304      owl_function_makemsg("Invalid arguments to command 'prev'.");
1305      return(NULL);
1306    }
1307  }
1308  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1309  if (filter) owl_free(filter);
1310  return(NULL);
1311}
1312
1313char *owl_command_smartnarrow(int argc, const char *const *argv, const char *buff)
1314{
1315  char *filtname = NULL;
1316
1317  char opt;
1318  int instance = 0, related = 0, i;
1319  const char **tmp_argv = owl_malloc(sizeof(char *) * argc);
1320
1321  for (i = 0; i < argc; i++)
1322    tmp_argv[i] = argv[i];
1323
1324  static const struct option options[] = {
1325    {"instance", 0, 0, 'i'},
1326    {"related",  0, 0, 'r'},
1327    {NULL,       0, 0, 0}};
1328
1329  optind = 0;
1330  while ((opt = getopt_long(argc, (char **)tmp_argv, "ir", options, NULL)) != -1) {
1331    switch (opt) {
1332      case 'i':
1333        instance = 1;
1334        break;
1335      case 'r':
1336        related = 1;
1337        break;
1338      default:
1339        owl_function_makemsg("Wrong number of arguments for %s (%c)", argv[0], opt);
1340        goto done;
1341    }
1342  }
1343
1344  filtname = owl_function_smartfilter(instance, related);
1345
1346  if (filtname) {
1347    owl_function_change_currentview_filter(filtname);
1348    owl_free(filtname);
1349  }
1350
1351done:
1352  owl_free(tmp_argv);
1353
1354  return NULL;
1355}
1356
1357char *owl_command_smartfilter(int argc, const char *const *argv, const char *buff)
1358{
1359  char *filtname = NULL;
1360
1361  if (argc == 1) {
1362    filtname = owl_function_smartfilter(0, 0);
1363  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1364    filtname = owl_function_smartfilter(1, 0);
1365  } else {
1366    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1367  }
1368  return filtname;
1369}
1370
1371void owl_command_expunge(void)
1372{
1373  owl_function_expunge();
1374}
1375
1376void owl_command_first(void)
1377{
1378  owl_global_set_rightshift(&g, 0);
1379  owl_function_firstmsg();
1380}
1381
1382void owl_command_last(void)
1383{
1384  owl_function_lastmsg();
1385}
1386
1387void owl_command_resize(void)
1388{
1389  owl_function_resize();
1390}
1391
1392void owl_command_redisplay(void)
1393{
1394  owl_function_full_redisplay();
1395}
1396
1397char *owl_command_get_shift(int argc, const char *const *argv, const char *buff)
1398{
1399  if(argc != 1)
1400  {
1401    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1402    return NULL;
1403  }
1404  return owl_sprintf("%d", owl_global_get_rightshift(&g));
1405}
1406
1407void owl_command_set_shift(int shift)
1408{
1409  owl_global_set_rightshift(&g, shift);
1410}
1411
1412void owl_command_unsuball(void)
1413{
1414  owl_function_unsuball();
1415}
1416
1417char *owl_command_loadsubs(int argc, const char *const *argv, const char *buff)
1418{
1419  if (argc == 2) {
1420    owl_function_loadsubs(argv[1]);
1421  } else if (argc == 1) {
1422    owl_function_loadsubs(NULL);
1423  } else {
1424    owl_function_makemsg("Wrong number of arguments for load-subs.");
1425    return(NULL);
1426  }
1427  return(NULL);
1428}
1429
1430
1431char *owl_command_loadloginsubs(int argc, const char *const *argv, const char *buff)
1432{
1433  if (argc == 2) {
1434    owl_function_loadloginsubs(argv[1]);
1435  } else if (argc == 1) {
1436    owl_function_loadloginsubs(NULL);
1437  } else {
1438    owl_function_makemsg("Wrong number of arguments for load-subs.");
1439    return(NULL);
1440  }
1441  return(NULL);
1442}
1443
1444void owl_command_suspend(void)
1445{
1446  owl_function_suspend();
1447}
1448
1449char *owl_command_start_command(int argc, const char *const *argv, const char *buff)
1450{
1451  buff = skiptokens(buff, 1);
1452  owl_function_start_command(buff);
1453  return(NULL);
1454}
1455
1456char *owl_command_zaway(int argc, const char *const *argv, const char *buff)
1457{
1458  if ((argc==1) ||
1459      ((argc==2) && !strcmp(argv[1], "on"))) {
1460    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1461    owl_function_zaway_on();
1462    return NULL;
1463  }
1464
1465  if (argc==2 && !strcmp(argv[1], "off")) {
1466    owl_function_zaway_off();
1467    return NULL;
1468  }
1469
1470  if (argc==2 && !strcmp(argv[1], "toggle")) {
1471    owl_function_zaway_toggle();
1472    return NULL;
1473  }
1474
1475  buff = skiptokens(buff, 1);
1476  owl_global_set_zaway_msg(&g, buff);
1477  owl_function_zaway_on();
1478  return NULL;
1479}
1480
1481
1482char *owl_command_aaway(int argc, const char *const *argv, const char *buff)
1483{
1484  if ((argc==1) ||
1485      ((argc==2) && !strcmp(argv[1], "on"))) {
1486    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1487    owl_function_aaway_on();
1488    return NULL;
1489  }
1490
1491  if (argc==2 && !strcmp(argv[1], "off")) {
1492    owl_function_aaway_off();
1493    return NULL;
1494  }
1495
1496  if (argc==2 && !strcmp(argv[1], "toggle")) {
1497    owl_function_aaway_toggle();
1498    return NULL;
1499  }
1500
1501  buff = skiptokens(buff, 1);
1502  owl_global_set_aaway_msg(&g, buff);
1503  owl_function_aaway_on();
1504  return NULL;
1505}
1506
1507
1508char *owl_command_away(int argc, const char *const *argv, const char *buff)
1509{
1510  if ((argc==1) ||
1511      ((argc==2) && !strcmp(argv[1], "on"))) {
1512    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1513    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1514    owl_function_aaway_on();
1515    owl_function_zaway_on();
1516    owl_function_makemsg("Away messages set.");
1517    return NULL;
1518  }
1519
1520  if (argc==2 && !strcmp(argv[1], "off")) {
1521    owl_function_aaway_off();
1522    owl_function_zaway_off();
1523    return NULL;
1524  }
1525
1526  if (argc==2 && !strcmp(argv[1], "toggle")) {
1527    /* if either one is on, turn it off, otherwise toggle both (turn
1528     *  them both on)
1529     */
1530    if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
1531      owl_function_aaway_toggle();
1532      owl_function_zaway_toggle();
1533      owl_function_makemsg("Away messages set.");
1534    } else {
1535      if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
1536      if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
1537      owl_function_makemsg("Away messages off.");
1538    }
1539    return NULL;
1540  }
1541
1542  buff = skiptokens(buff, 1);
1543  owl_global_set_aaway_msg(&g, buff);
1544  owl_global_set_zaway_msg(&g, buff);
1545  owl_function_aaway_on();
1546  owl_function_zaway_on();
1547  owl_function_makemsg("Away messages set.");
1548  return NULL;
1549}
1550
1551char *owl_command_set(int argc, const char *const *argv, const char *buff)
1552{
1553  const char *var, *val;
1554  int  silent=0;
1555  int requirebool=0;
1556
1557  if (argc == 1) {
1558    owl_function_printallvars();
1559    return NULL;
1560  } 
1561
1562  if (argc > 1 && !strcmp("-q",argv[1])) {
1563    silent = 1;
1564    argc--; argv++;
1565  }
1566
1567  if (argc == 2) {
1568    var=argv[1];
1569    val="on";
1570    requirebool=1;
1571  } else if (argc == 3) {
1572    var=argv[1];
1573    val=argv[2];
1574  } else {
1575    owl_function_makemsg("Wrong number of arguments for set command");
1576    return NULL;
1577  }
1578  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1579  return NULL;
1580}
1581
1582char *owl_command_unset(int argc, const char *const *argv, const char *buff)
1583{
1584  const char *var, *val;
1585  int  silent=0;
1586
1587  if (argc > 1 && !strcmp("-q",argv[1])) {
1588    silent = 1;
1589    argc--; argv++;
1590  }
1591  if (argc == 2) {
1592    var=argv[1];
1593    val="off";
1594  } else {
1595    owl_function_makemsg("Wrong number of arguments for unset command");
1596    return NULL;
1597  }
1598  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1599  return NULL;
1600}
1601
1602char *owl_command_print(int argc, const char *const *argv, const char *buff)
1603{
1604  const char *var;
1605  char valbuff[1024];
1606
1607  if (argc==1) {
1608    owl_function_printallvars();
1609    return NULL;
1610  } else if (argc!=2) {
1611    owl_function_makemsg("Wrong number of arguments for print command");
1612    return NULL;
1613  }
1614
1615  var=argv[1];
1616   
1617  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1618                                     var, valbuff, 1024)) {
1619    owl_function_makemsg("%s = '%s'", var, valbuff);
1620  } else {
1621    owl_function_makemsg("Unknown variable '%s'.", var);
1622  }
1623  return NULL;
1624}
1625
1626
1627char *owl_command_exec(int argc, const char *const *argv, const char *buff)
1628{
1629  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_RETURN);
1630}
1631
1632char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
1633{
1634  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_POPUP);
1635}
1636
1637char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
1638{
1639  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1640}
1641
1642char *owl_command_perl(int argc, const char *const *argv, const char *buff)
1643{
1644  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_RETURN);
1645}
1646
1647char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
1648{
1649  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_POPUP);
1650}
1651
1652char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
1653{
1654  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
1655}
1656
1657char *owl_command_multi(int argc, const char *const *argv, const char *buff)
1658{
1659  char *lastrv = NULL, *newbuff;
1660  char **commands;
1661  int  ncommands, i;
1662  if (argc < 2) {
1663    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1664    return NULL;
1665  }
1666  newbuff = owl_strdup(skiptokens(buff, 1));
1667  if (!strcmp(argv[0], "(")) {
1668    for (i=strlen(newbuff)-1; i>=0; i--) {
1669      if (newbuff[i] == ')') {
1670        newbuff[i] = '\0';
1671        break;
1672      } else if (newbuff[i] != ' ') {
1673        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1674        owl_free(newbuff);
1675        return NULL;
1676      }
1677    }
1678  }
1679  commands = atokenize(newbuff, ";", &ncommands);
1680  for (i=0; i<ncommands; i++) {
1681    if (lastrv) {
1682      owl_free(lastrv);
1683    }
1684    lastrv = owl_function_command(commands[i]);
1685  }
1686  owl_free(newbuff);
1687  atokenize_delete(commands, ncommands);
1688  return lastrv;
1689}
1690
1691
1692char *owl_command_alias(int argc, const char *const *argv, const char *buff)
1693{
1694  if (argc < 3) {
1695    owl_function_makemsg("Invalid arguments to 'alias' command.");
1696    return NULL;
1697  }
1698  buff = skiptokens(buff, 2);
1699  owl_function_command_alias(argv[1], buff);
1700  return (NULL);
1701}
1702
1703
1704char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
1705{
1706  owl_keymap *km;
1707  int ret;
1708
1709  if (argc < 5 || strcmp(argv[3], "command")) {
1710    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1711    return NULL;
1712  }
1713  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1714  if (!km) {
1715    owl_function_makemsg("No such keymap '%s'", argv[1]);
1716    return NULL;
1717  }
1718  buff = skiptokens(buff, 4);
1719  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1720  if (ret!=0) {
1721    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1722                         argv[2], argv[1], buff);
1723    return NULL;
1724  }
1725  return NULL;
1726}
1727
1728
1729char *owl_command_unbindkey(int argc, const char *const *argv, const char *buf)
1730{
1731  owl_keymap *km;
1732  int ret;
1733
1734  if (argc < 3) {
1735    owl_function_makemsg("Usage: bindkey <keymap> <binding>");
1736    return NULL;
1737  }
1738  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1739  if (!km) {
1740    owl_function_makemsg("No such keymap '%s'", argv[1]);
1741    return NULL;
1742  }
1743  ret = owl_keymap_remove_binding(km, argv[2]);
1744  if (ret == -1) {
1745    owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
1746                         argv[2], argv[1]);
1747    return NULL;
1748  } else if (ret == -2) {
1749    owl_function_makemsg("No such binding '%s' in keymap '%s'.",
1750                         argv[2], argv[1]);
1751  }
1752  return NULL;
1753}
1754
1755
1756void owl_command_quit(void)
1757{
1758  owl_function_quit();
1759}
1760
1761char *owl_command_debug(int argc, const char *const *argv, const char *buff)
1762{
1763  if (argc<2) {
1764    owl_function_makemsg("Need at least one argument to debug command");
1765    return(NULL);
1766  }
1767
1768  if (!owl_global_is_debug_fast(&g)) {
1769    owl_function_makemsg("Debugging is not turned on");
1770    return(NULL);
1771  }
1772
1773  owl_function_debugmsg("%s", argv[1]);
1774  return(NULL);
1775}
1776
1777char *owl_command_term(int argc, const char *const *argv, const char *buff)
1778{
1779  if (argc<2) {
1780    owl_function_makemsg("Need at least one argument to the term command");
1781    return(NULL);
1782  }
1783
1784  if (!strcmp(argv[1], "raise")) {
1785    owl_function_xterm_raise();
1786  } else if (!strcmp(argv[1], "deiconify")) {
1787    owl_function_xterm_deiconify();
1788  } else {
1789    owl_function_makemsg("Unknown terminal subcommand");
1790  }
1791  return(NULL);
1792}
1793
1794char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
1795{
1796  if ((argc<2) || (argc>3)) {
1797    owl_function_makemsg("Wrong number of arguments for zlog command");
1798    return(NULL);
1799  }
1800
1801  if (!strcmp(argv[1], "in")) {
1802    if (argc>2) {
1803      owl_global_set_tty(&g, argv[2]);
1804    }
1805    owl_zephyr_zlog_in();
1806  } else if (!strcmp(argv[1], "out")) {
1807    if (argc!=2) {
1808      owl_function_makemsg("Wrong number of arguments for zlog command");
1809      return(NULL);
1810    }
1811    owl_zephyr_zlog_out();
1812  } else {
1813    owl_function_makemsg("Invalid subcommand for zlog");
1814  }
1815  return(NULL);
1816}
1817
1818char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
1819{
1820  const char *class, *instance, *recip="";
1821  int temp=0;
1822  int ret=0;
1823
1824  if (argc < 2) {
1825    owl_function_makemsg("Not enough arguments to the subscribe command");
1826    return(NULL);
1827  }
1828  argc--;
1829  argv++;
1830
1831  if (!strcmp(argv[0], "-t")) {
1832    temp=1;
1833    argc--;
1834    argv++;
1835  }
1836  if (argc < 1) {
1837    owl_function_makemsg("Not enough arguments to the subscribe command");
1838    return(NULL);
1839  }
1840
1841  if (argc > 3) {
1842    owl_function_makemsg("Too many arguments to the subscribe command");
1843    return(NULL);
1844  }
1845
1846  class = argv[0];
1847
1848  if (argc == 1) {
1849    instance = "*";
1850  } else {
1851    instance = argv[1];
1852  }
1853
1854  if (argc <= 2) {
1855    recip="";
1856  } else if (argc==3) {
1857    recip=argv[2];
1858  }
1859
1860  ret = owl_function_subscribe(class, instance, recip);
1861  if (!temp && !ret) {
1862    owl_zephyr_addsub(NULL, class, instance, recip);
1863  }
1864  return(NULL);
1865}
1866
1867
1868char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
1869{
1870  const char *class, *instance, *recip="";
1871  int temp=0;
1872
1873  if (argc < 2) {
1874    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1875    return(NULL);
1876  }
1877  argc--;
1878  argv++;
1879
1880  if (!strcmp(argv[0], "-t")) {
1881    temp=1;
1882    argc--;
1883    argv++;
1884  }
1885  if (argc < 1) {
1886    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1887    return(NULL);
1888  }
1889
1890  if (argc > 3) {
1891    owl_function_makemsg("Too many arguments to the unsubscribe command");
1892    return(NULL);
1893  }
1894
1895  class = argv[0];
1896
1897  if (argc == 1) {
1898    instance = "*";
1899  } else {
1900    instance = argv[1];
1901  }
1902
1903  if (argc <= 2) {
1904    recip="";
1905  } else if (argc==3) {
1906    recip=argv[2];
1907  }
1908
1909  owl_function_unsubscribe(class, instance, recip);
1910  if (!temp) {
1911    owl_zephyr_delsub(NULL, class, instance, recip);
1912  }
1913  return(NULL);
1914}
1915
1916char *owl_command_echo(int argc, const char *const *argv, const char *buff)
1917{
1918  buff = skiptokens(buff, 1);
1919  owl_function_popless_text(buff);
1920  return NULL;
1921}
1922
1923void owl_command_getsubs(void)
1924{
1925  owl_function_getsubs();
1926}
1927
1928void owl_command_status(void)
1929{
1930  owl_function_status();
1931}
1932
1933char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
1934{
1935  owl_zwrite *z;
1936
1937  if (!owl_global_is_havezephyr(&g)) {
1938    owl_function_makemsg("Zephyr is not available");
1939    return(NULL);
1940  }
1941  /* check for a zwrite -m */
1942  z = owl_zwrite_new(buff);
1943  if (!z) {
1944    owl_function_error("Error in zwrite arguments");
1945    return NULL;
1946  }
1947
1948  if (owl_zwrite_is_message_set(z)) {
1949    owl_function_zwrite(z, NULL);
1950    owl_zwrite_delete(z);
1951    return NULL;
1952  }
1953
1954  if (argc < 2) {
1955    owl_zwrite_delete(z);
1956    owl_function_makemsg("Not enough arguments to the zwrite command.");
1957  } else {
1958    owl_function_zwrite_setup(z);
1959  }
1960  return(NULL);
1961}
1962
1963char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
1964{
1965  char *newbuff, *recip;
1966  const char *const *myargv;
1967  int i, j, myargc;
1968  owl_message *m;
1969 
1970  if (!owl_global_is_aimloggedin(&g)) {
1971    owl_function_makemsg("You are not logged in to AIM.");
1972    return(NULL);
1973  }
1974
1975  if (argc < 2) {
1976    owl_function_makemsg("Not enough arguments to the aimwrite command.");
1977    return(NULL);
1978  }
1979
1980  myargv=argv;
1981  if (argc<0) {
1982    owl_function_error("Unbalanced quotes in aimwrite");
1983    return(NULL);
1984  }
1985  myargc=argc;
1986  if (myargc && *(myargv[0])!='-') {
1987    myargc--;
1988    myargv++;
1989  }
1990  while (myargc) {
1991    if (!strcmp(myargv[0], "-m")) {
1992      if (myargc<2) {
1993        break;
1994      }
1995
1996      /* Once we have -m, gobble up everything else on the line */
1997      myargv++;
1998      myargc--;
1999      newbuff=owl_strdup("");
2000      while (myargc) {
2001        newbuff=owl_realloc(newbuff, strlen(newbuff)+strlen(myargv[0])+5);
2002        strcat(newbuff, myargv[0]);
2003        strcat(newbuff, " ");
2004        myargc--;
2005        myargv++;
2006      }
2007      if (strlen(newbuff) >= 1)
2008        newbuff[strlen(newbuff) - 1] = '\0'; /* remove last space */
2009
2010      recip=owl_strdup(argv[1]);
2011      owl_aim_send_im(recip, newbuff);
2012      m=owl_function_make_outgoing_aim(newbuff, recip);
2013      if (m) { 
2014          owl_global_messagequeue_addmsg(&g, m);
2015      } else {
2016          owl_function_error("Could not create outgoing AIM message");
2017      }
2018
2019      owl_free(recip);
2020      owl_free(newbuff);
2021      return(NULL);
2022    } else {
2023      /* we don't care */
2024      myargv++;
2025      myargc--;
2026    }
2027  }
2028
2029  /* squish arguments together to make one screenname w/o spaces for now */
2030  newbuff=owl_malloc(strlen(buff)+5);
2031  sprintf(newbuff, "%s ", argv[0]);
2032  j=argc-1;
2033  for (i=0; i<j; i++) {
2034    strcat(newbuff, argv[i+1]);
2035  }
2036   
2037  owl_function_aimwrite_setup(newbuff);
2038  owl_free(newbuff);
2039  return(NULL);
2040}
2041
2042char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
2043{
2044  owl_function_loopwrite_setup();
2045  return(NULL);
2046}
2047
2048char *owl_command_reply(int argc, const char *const *argv, const char *buff)
2049{
2050  int edit=0;
2051 
2052  if (argc>=2 && !strcmp("-e", argv[1])) {
2053    edit=1;
2054    argv++;
2055    argc--;
2056  }
2057
2058  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2059    owl_function_reply(0, !edit);
2060  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2061    owl_function_reply(1, !edit);
2062  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2063    const owl_message *m;
2064    const owl_view    *v;
2065    v = owl_global_get_current_view(&g);   
2066    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2067    if (m) owl_zephyr_zaway(m);
2068  } else {
2069    owl_function_makemsg("Invalid arguments to the reply command.");
2070  }
2071  return NULL;
2072}
2073
2074char *owl_command_filter(int argc, const char *const *argv, const char *buff)
2075{
2076  owl_function_create_filter(argc, argv);
2077  return NULL;
2078}
2079
2080char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
2081{
2082  int auth;
2083 
2084  if (argc<2) {
2085    owl_function_makemsg("Too few arguments for zlocate command");
2086    return NULL;
2087  }
2088
2089  auth=1;
2090  if (!strcmp(argv[1], "-d")) {
2091    if (argc>2) {
2092      auth=0;
2093      argc--;
2094      argv++;
2095    } else {
2096      owl_function_makemsg("Missing arguments for zlocate command");
2097      return NULL;
2098    }
2099  }
2100
2101  argc--;
2102  argv++;
2103  owl_function_zlocate(argc, argv, auth);
2104  return NULL;
2105}
2106
2107
2108/* Backwards compatability has made this kind of complicated:
2109 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2110 * view <filter>
2111 * view -d <expression>
2112 * view --home
2113 */
2114char *owl_command_view(int argc, const char *const *argv, const char *buff)
2115{
2116  /* First take the 'view --home' and 'view -r' cases */
2117  if (argc == 2) {
2118    if (!strcmp(argv[1], "--home")) {
2119      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2120      return(NULL);
2121    } else if (!strcmp(argv[1], "-r")) {
2122      char *foo;
2123      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2124      owl_function_change_currentview_filter(foo);
2125      owl_free(foo);
2126      return(NULL);
2127    }
2128  }
2129
2130  /* Now look for 'view <filter>' */
2131  if (argc==2) {
2132    owl_function_change_currentview_filter(argv[1]);
2133    return(NULL);
2134  }
2135
2136  /* Now get 'view -d <expression>' */
2137  if (argc>=3 && !strcmp(argv[1], "-d")) {
2138    const char **myargv;
2139    int i;
2140
2141    myargv=owl_malloc((argc*sizeof(const char *))+50);
2142    myargv[0]="";
2143    myargv[1]="owl-dynamic";
2144    for (i=2; i<argc; i++) {
2145      myargv[i]=argv[i];
2146    }
2147    owl_function_create_filter(argc, myargv);
2148    owl_function_change_currentview_filter("owl-dynamic");
2149    owl_free(myargv);
2150    return NULL;
2151  }
2152
2153  /* Finally handle the general case */
2154  if (argc<3) {
2155    owl_function_makemsg("Too few arguments to the view command.");
2156    return(NULL);
2157  }
2158  argc--;
2159  argv++;
2160  if (strcmp(argv[0], "-f") &&
2161      strcmp(argv[0], "-d") &&
2162      strcmp(argv[0], "--home") &&
2163      strcmp(argv[0], "-s") &&
2164      strcmp(argv[0], "-r")) {
2165    if (strcmp(argv[0], "main")) {
2166      owl_function_makemsg("No view named '%s'", argv[0]);
2167      return(NULL);
2168    }
2169    argc--;
2170    argv++;
2171  }
2172  while (argc) {
2173    if (!strcmp(argv[0], "-f")) {
2174      if (argc<2) {
2175        owl_function_makemsg("Too few argments to the view command");
2176        return(NULL);
2177      }
2178      owl_function_change_currentview_filter(argv[1]);
2179      argc-=2;
2180      argv+=2;
2181    } else if (!strcmp(argv[0], "--home")) {
2182      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2183      argc--;
2184      argv++;
2185    } else if (!strcmp(argv[0], "-s")) {
2186      if (argc<2) {
2187        owl_function_makemsg("Too few argments to the view command");
2188        return(NULL);
2189      }
2190      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2191      argc-=2;
2192      argv+=2;
2193    } else {
2194      owl_function_makemsg("Too few argments to the view command");
2195      return(NULL);
2196    }
2197   
2198  }
2199  return(NULL);
2200}
2201
2202char *owl_command_show(int argc, const char *const *argv, const char *buff)
2203{
2204  if (argc<2) {
2205    owl_function_help_for_command("show");
2206    return NULL;
2207  }
2208
2209  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2210    if (argc==2) {
2211      owl_function_show_filters();
2212    } else {
2213      owl_function_show_filter(argv[2]);
2214    }
2215  } else if (argc==2 
2216             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2217    owl_function_show_zpunts();
2218  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2219    if (argc==2) {
2220      owl_function_show_commands();
2221    } else {
2222      owl_function_show_command(argv[2]);
2223    }
2224  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2225    if (argc==2) {
2226      owl_function_show_variables();
2227    } else {
2228      owl_function_show_variable(argv[2]);
2229    }
2230  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2231    if (argc==2) {
2232      owl_function_show_keymaps();
2233    } else {
2234      owl_function_show_keymap(argv[2]);
2235    }
2236  } else if (!strcmp(argv[1], "view")) {
2237    if (argc==3) {
2238      owl_function_show_view(argv[2]);
2239    } else {
2240      owl_function_show_view(NULL);
2241    }
2242  } else if (!strcmp(argv[1], "colors")) {
2243    owl_function_show_colors();
2244  } else if (!strcmp(argv[1], "styles")) {
2245    owl_function_show_styles();
2246  } else if (!strcmp(argv[1], "timers")) {
2247    owl_function_show_timers();
2248  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2249    owl_function_getsubs();
2250  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2251    owl_function_show_term();
2252  } else if (!strcmp(argv[1], "version")) {
2253    owl_function_about();
2254  } else if (!strcmp(argv[1], "status")) {
2255    owl_function_status();
2256  } else if (!strcmp(argv[1], "license")) {
2257    owl_function_show_license();
2258  } else if (!strcmp(argv[1], "quickstart")) {
2259    owl_function_show_quickstart();
2260  } else if (!strcmp(argv[1], "startup")) {
2261    const char *filename;
2262   
2263    filename=owl_global_get_startupfile(&g);
2264    owl_function_popless_file(filename);
2265  } else if (!strcmp(argv[1], "errors")) {
2266    owl_function_showerrs();
2267  } else {
2268    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2269    return NULL;
2270  }
2271  return NULL;
2272}
2273
2274char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
2275{
2276  char *filtname;
2277  if (argc!=2) {
2278    owl_function_makemsg("Wrong number of arguments to viewclass command");
2279    return NULL;
2280  }
2281  filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2282  owl_function_change_currentview_filter(filtname);
2283  owl_free(filtname);
2284  return NULL;
2285}
2286
2287char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
2288{
2289  char *filtname;
2290  if (argc!=2) {
2291    owl_function_makemsg("Wrong number of arguments to viewuser command");
2292    return NULL;
2293  }
2294  filtname=owl_function_zuserfilt(argv[1]);
2295  owl_function_change_currentview_filter(filtname);
2296  owl_free(filtname);
2297  return NULL;
2298}
2299
2300
2301void owl_command_pop_message(void)
2302{
2303  owl_function_curmsg_to_popwin();
2304}
2305
2306char *owl_command_delete(int argc, const char *const *argv, const char *buff)
2307{
2308  int move_after = 1;
2309
2310  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2311    move_after = 0;
2312    argc--; 
2313    argv++;
2314  }
2315
2316  if (argc==1) {
2317    owl_function_deletecur(move_after);
2318    return NULL;
2319  }
2320
2321  if (argc==2 && !strcmp(argv[1], "view")) {
2322    owl_function_delete_curview_msgs(1);
2323    return NULL;
2324  }
2325
2326  if (argc==2 && !strcmp(argv[1], "trash")) {
2327    owl_function_delete_automsgs();
2328    return NULL;
2329  }
2330
2331  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2332    owl_function_delete_by_id(atoi(argv[2]), 1);
2333    return NULL;
2334  }
2335
2336  owl_function_makemsg("Unknown arguments to delete command");
2337  return NULL;
2338}
2339
2340char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
2341{
2342  int move_after = 1;
2343
2344  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2345    move_after = 0;
2346    argc--; 
2347    argv++;
2348  }
2349
2350  if (argc==1) {
2351    owl_function_undeletecur(move_after);
2352    return NULL;
2353  }
2354
2355  if (argc==2 && !strcmp(argv[1], "view")) {
2356    owl_function_delete_curview_msgs(0);
2357    return NULL;
2358  }
2359
2360  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2361    owl_function_delete_by_id(atoi(argv[2]), 0);
2362    return NULL;
2363  }
2364
2365  owl_function_makemsg("Unknown arguments to delete command");
2366  return NULL;
2367}
2368
2369void owl_command_beep(void)
2370{
2371  owl_function_beep();
2372}
2373
2374char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
2375{
2376  if (argc < 2 || argc > 3) {
2377    owl_function_makemsg("Wrong number of arguments to colorview command");
2378    return NULL;
2379  }
2380  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2381  return NULL;
2382}
2383
2384char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
2385{
2386  const char *filtname;
2387 
2388  if (argc < 3 || argc > 4) {
2389    owl_function_makemsg("Wrong number of arguments to colorclass command");
2390    return NULL;
2391  }
2392
2393  filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2394  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2395  return NULL;
2396}
2397
2398char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
2399{
2400  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2401  return NULL;
2402}
2403
2404char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
2405{
2406  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2407  return NULL;
2408}
2409
2410void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
2411{
2412  /* if type==0 then zpunt
2413   * if type==1 then zunpunt
2414   */
2415  const char *class, *inst, *recip;
2416
2417  class="message";
2418  inst="";
2419  recip="*";
2420
2421  if (argc==1) {
2422    /* show current punt filters */
2423    owl_function_show_zpunts();
2424    return;
2425  } else if (argc==2) {
2426    inst=argv[1];
2427  } else if (argc==3) {
2428    class=argv[1];
2429    inst=argv[2];
2430  } else if (argc==4) {
2431    class=argv[1];
2432    inst=argv[2];
2433    recip=argv[3];
2434  } else {
2435    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2436    return;
2437  }
2438
2439  owl_function_zpunt(class, inst, recip, type);
2440  if (type==0) {
2441    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2442  } else if (type==1) {
2443    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2444  }
2445}
2446
2447char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
2448{
2449  if (argc == 1) {
2450    owl_function_smartzpunt(0);
2451  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2452    owl_function_smartzpunt(1);
2453  } else {
2454    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2455  }
2456  return NULL;
2457}
2458
2459char *owl_command_punt(int argc, const char *const *argv, const char *buff)
2460{
2461  owl_command_punt_unpunt(argc, argv, buff, 0);
2462  return NULL;
2463}
2464
2465char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
2466{
2467  owl_command_punt_unpunt(argc, argv, buff, 1);
2468  return NULL;
2469}
2470
2471void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
2472{
2473  owl_list * fl;
2474  owl_filter * f;
2475  char * text;
2476  int i;
2477
2478  fl = owl_global_get_puntlist(&g);
2479  if(argc == 1) {
2480    owl_function_show_zpunts();
2481  }
2482
2483  if(argc == 2) {
2484    /* Handle :unpunt <number> */
2485    if(unpunt && (i=atoi(argv[1])) !=0) {
2486      i--;      /* Accept 1-based indexing */
2487      if(i < owl_list_get_size(fl)) {
2488        f = owl_list_get_element(fl, i);
2489        owl_list_remove_element(fl, i);
2490        owl_filter_delete(f);
2491        return;
2492      } else {
2493        owl_function_error("No such filter number: %d", i+1);
2494      }
2495    }
2496    text = owl_sprintf("filter %s", argv[1]);
2497    owl_function_punt(text, unpunt);
2498    owl_free(text);
2499  } else {
2500    owl_function_punt(skiptokens(buff, 1), unpunt);
2501  }
2502}
2503
2504
2505char *owl_command_getview(int argc, const char *const *argv, const char *buff)
2506{
2507  const char *filtname;
2508  if (argc != 1) {
2509    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2510    return NULL;
2511  }
2512  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2513  if (filtname) return owl_strdup(filtname);
2514  return NULL;
2515}
2516
2517char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
2518{
2519  char tmpbuff[1024];
2520  if (argc != 2) {
2521    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2522    return NULL;
2523  }
2524  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
2525                                argv[1], tmpbuff, 1024)) {
2526    return NULL;
2527  }
2528  return owl_strdup(tmpbuff); 
2529}
2530
2531char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
2532{
2533  const owl_filter *f;
2534  if (argc != 2) {
2535    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2536    return NULL;
2537  }
2538  f = owl_global_get_filter(&g, argv[1]);
2539  if (!f) {
2540    return NULL;
2541  }
2542  return owl_filter_print(f);
2543}
2544
2545char *owl_command_search(int argc, const char *const *argv, const char *buff)
2546{
2547  int direction;
2548  const char *buffstart;
2549
2550  direction=OWL_DIRECTION_DOWNWARDS;
2551  buffstart=skiptokens(buff, 1);
2552  if (argc>1 && !strcmp(argv[1], "-r")) {
2553    direction=OWL_DIRECTION_UPWARDS;
2554    buffstart=skiptokens(buff, 2);
2555  }
2556   
2557  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2558    /* When continuing a search, don't consider the current message. */
2559    owl_function_search_helper(false, direction);
2560  } else {
2561    owl_function_set_search(buffstart);
2562    owl_function_search_helper(true, direction);
2563  }
2564 
2565  return(NULL);
2566}
2567
2568char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
2569{
2570  const char *buffstart;
2571
2572  buffstart=skiptokens(buff, 1);
2573  owl_function_set_search(*buffstart ? buffstart : NULL);
2574 
2575  return(NULL);
2576}
2577
2578char *owl_command_aimlogin(int argc, const char *const *argv, const char *buff)
2579{
2580  if ((argc<2) || (argc>3)) {
2581    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2582    return(NULL);
2583  }
2584
2585  /* if we get two arguments, ask for the password */
2586  if (argc==2) {
2587    owl_editwin *e = owl_function_start_password("AIM Password: ");
2588    owl_editwin_set_cbdata(e, owl_strdup(argv[1]), owl_free);
2589    owl_editwin_set_callback(e, owl_callback_aimlogin);
2590    return(NULL);
2591  } else {
2592    owl_function_aimlogin(argv[1], argv[2]);
2593  }
2594
2595  /* this is a test */
2596  return(NULL);
2597}
2598
2599char *owl_command_aimlogout(int argc, const char *const *argv, const char *buff)
2600{
2601  /* clear the buddylist */
2602  owl_buddylist_clear(owl_global_get_buddylist(&g));
2603
2604  owl_aim_logout();
2605  return(NULL);
2606}
2607
2608char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
2609{
2610  const char *stylename;
2611  if (argc != 1) {
2612    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2613    return NULL;
2614  }
2615  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2616  if (stylename) return owl_strdup(stylename);
2617  return NULL;
2618}
2619
2620char *owl_command_error(int argc, const char *const *argv, const char *buff)
2621{
2622    buff = skiptokens(buff, 1);
2623    owl_function_error("%s", buff);
2624    return NULL;
2625}
2626
2627char *owl_command_message(int argc, const char *const *argv, const char *buff)
2628{
2629    buff = skiptokens(buff, 1);
2630    owl_function_makemsg("%s", buff);
2631    return NULL;
2632}
2633
2634void owl_command_yes(void)
2635{
2636  owl_message *m;
2637  const owl_view *v;
2638  const char *cmd;
2639
2640  v = owl_global_get_current_view(&g);
2641
2642  /* bail if there's no current message */
2643  if (owl_view_get_size(v) < 1) {
2644    owl_function_error("No current message.");
2645    return;
2646  }
2647
2648  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2649  if(!owl_message_is_question(m)) {
2650    owl_function_error("That message isn't a question.");
2651    return;
2652  }
2653  if(owl_message_is_answered(m)) {
2654    owl_function_error("You already answered that question.");
2655    return;
2656  }
2657  cmd = owl_message_get_attribute_value(m, "yescommand");
2658  if(!cmd) {
2659    owl_function_error("No 'yes' command!");
2660    return;
2661  }
2662
2663  owl_function_command_norv(cmd);
2664  owl_message_set_isanswered(m);
2665  return;
2666}
2667
2668void owl_command_no(void)
2669{
2670  owl_message *m;
2671  const owl_view *v;
2672  const char *cmd;
2673
2674  v = owl_global_get_current_view(&g);
2675
2676  /* bail if there's no current message */
2677  if (owl_view_get_size(v) < 1) {
2678    owl_function_error("No current message.");
2679    return;
2680  }
2681
2682  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2683  if(!owl_message_is_question(m)) {
2684    owl_function_error("That message isn't a question.");
2685    return;
2686  }
2687  if(owl_message_is_answered(m)) {
2688    owl_function_error("You already answered that question.");
2689    return;
2690  }
2691  cmd = owl_message_get_attribute_value(m, "nocommand");
2692  if(!cmd) {
2693    owl_function_error("No 'no' command!");
2694    return;
2695  }
2696
2697  owl_function_command_norv(cmd);
2698  owl_message_set_isanswered(m);
2699  return;
2700}
2701
2702/*********************************************************************/
2703/************************** EDIT SPECIFIC ****************************/
2704/*********************************************************************/
2705
2706void owl_command_edit_cancel(owl_editwin *e)
2707{
2708  owl_history *hist;
2709
2710  owl_function_makemsg("Command cancelled.");
2711
2712  if(owl_editwin_get_echochar(e) == 0) {
2713    hist=owl_editwin_get_history(e);
2714    owl_history_store(hist, owl_editwin_get_text(e));
2715    owl_history_reset(hist);
2716  }
2717
2718  owl_global_pop_context(&g);
2719}
2720
2721void owl_command_edit_history_prev(owl_editwin *e)
2722{
2723  owl_history *hist;
2724  const char *ptr;
2725
2726  hist=owl_editwin_get_history(e);
2727  if (!owl_history_is_touched(hist)) {
2728    owl_history_store(hist, owl_editwin_get_text(e));
2729    owl_history_set_partial(hist);
2730  }
2731  ptr=owl_history_get_prev(hist);
2732  if (ptr) {
2733    owl_editwin_clear(e);
2734    owl_editwin_insert_string(e, ptr);
2735  } else {
2736    owl_function_beep();
2737  }
2738}
2739
2740void owl_command_edit_history_next(owl_editwin *e)
2741{
2742  owl_history *hist;
2743  const char *ptr;
2744
2745  hist=owl_editwin_get_history(e);
2746  ptr=owl_history_get_next(hist);
2747  if (ptr) {
2748    owl_editwin_clear(e);
2749    owl_editwin_insert_string(e, ptr);
2750  } else {
2751    owl_function_beep();
2752  }
2753}
2754
2755char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
2756{
2757  buff = skiptokens(buff, 1);
2758  owl_editwin_insert_string(e, buff);
2759  return NULL;
2760}
2761
2762void owl_command_edit_done(owl_editwin *e)
2763{
2764  owl_history *hist=owl_editwin_get_history(e);
2765
2766  if (hist) {
2767    owl_history_store(hist, owl_editwin_get_text(e));
2768    owl_history_reset(hist);
2769  }
2770
2771  /* Take a reference to the editwin, so that it survives the pop
2772   * context. TODO: We should perhaps refcount or otherwise protect
2773   * the context so that, even if a command pops a context, the
2774   * context itself will last until the command returns. */
2775  owl_editwin_ref(e);
2776  owl_global_pop_context(&g);
2777
2778  owl_editwin_do_callback(e);
2779  owl_editwin_unref(e);
2780}
2781
2782void owl_command_edit_done_or_delete(owl_editwin *e)
2783{
2784  if (owl_editwin_is_at_end(e)) {
2785    owl_command_edit_done(e);
2786  } else {
2787    owl_editwin_delete_char(e);
2788  }
2789}
2790
2791
2792/*********************************************************************/
2793/*********************** POPLESS SPECIFIC ****************************/
2794/*********************************************************************/
2795
2796void owl_command_popless_quit(owl_viewwin *vw)
2797{
2798  owl_popwin *pw;
2799  pw = owl_global_get_popwin(&g);
2800  owl_global_set_popwin(&g, NULL);
2801  /* Kind of a hack, but you can only have one active viewwin right
2802   * now anyway. */
2803  if (vw == owl_global_get_viewwin(&g))
2804    owl_global_set_viewwin(&g, NULL);
2805  owl_viewwin_delete(vw);
2806  owl_popwin_delete(pw);
2807  owl_global_pop_context(&g);
2808}
Note: See TracBrowser for help on using the repository browser.