source: commands.c @ 2be605a

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