source: commands.c @ b814715

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