source: commands.c @ 5f3168a

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