source: commands.c @ 38cc669

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