source: commands.c @ c0c4449c

barnowl_perlaimdebianrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since c0c4449c was 0b6b689, checked in by Geoffrey Thomas <geofft@mit.edu>, 16 years ago
Added :webzephyr command with keybinding W.
  • Property mode set to 100644
File size: 80.3 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  OWLCMD_ALIAS("webzephyr", "zwrite daemon.webzephyr -c webzephyr -i"),
966
967  /* This line MUST be last! */
968  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
969
970};
971
972void owl_command_info()
973{
974  owl_function_info();
975}
976
977void owl_command_nop()
978{
979}
980
981char *owl_command_help(int argc, char **argv, char *buff)
982{
983  if (argc!=2) {
984    owl_help();
985    return NULL;
986  }
987 
988  owl_function_help_for_command(argv[1]);
989  return NULL;
990}
991
992char *owl_command_zlist(int argc, char **argv, char *buff)
993{
994  int elapsed=0, timesort=0;
995  char *file=NULL;
996
997  argc--;
998  argv++;
999  while (argc) {
1000    if (!strcmp(argv[0], "-e")) {
1001      elapsed=1;
1002      argc--;
1003      argv++;
1004    } else if (!strcmp(argv[0], "-t")) {
1005      timesort=1;
1006      argc--;
1007      argv++;
1008    } else if (!strcmp(argv[0], "-f")) {
1009      if (argc==1) {
1010        owl_function_makemsg("zlist: -f needs an argument");
1011        return(NULL);
1012      }
1013      file=argv[1];
1014      argc-=2;
1015      argv+=2;
1016    } else {
1017      owl_function_makemsg("zlist: unknown argument");
1018      return(NULL);
1019    }
1020  }
1021  owl_function_buddylist(0, 1, file);
1022  return(NULL);
1023}
1024
1025char *owl_command_alist()
1026{
1027  owl_function_buddylist(1, 0, NULL);
1028  return(NULL);
1029}
1030
1031char *owl_command_blist()
1032{
1033  owl_function_buddylist(1, 1, NULL);
1034  return(NULL);
1035}
1036
1037char *owl_command_toggleoneline()
1038{
1039  owl_function_toggleoneline();
1040  return(NULL);
1041}
1042
1043void owl_command_about()
1044{
1045  owl_function_about();
1046}
1047
1048void owl_command_version()
1049{
1050  char buff[1024];
1051
1052  sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
1053  owl_function_makemsg(buff);
1054}
1055
1056char *owl_command_aim(int argc, char **argv, char *buff)
1057{
1058  if (argc<2) {
1059    owl_function_makemsg("not enough arguments to aim command");
1060    return(NULL);
1061  }
1062
1063  if (!strcmp(argv[1], "search")) {
1064    if (argc!=3) {
1065      owl_function_makemsg("not enough arguments to aim search command");
1066      return(NULL);
1067    }
1068    owl_aim_search(argv[2]);
1069  } else {
1070    owl_function_makemsg("unknown subcommand '%s' for aim command", argv[1]);
1071    return(NULL);
1072  }
1073  return(NULL);
1074}
1075
1076char *owl_command_addbuddy(int argc, char **argv, char *buff)
1077{
1078  if (argc!=3) {
1079    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1080    return(NULL);
1081  }
1082
1083  if (!strcasecmp(argv[1], "aim")) {
1084    if (!owl_global_is_aimloggedin(&g)) {
1085      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
1086      return(NULL);
1087    }
1088    /*
1089    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
1090    return(NULL);
1091    */
1092    owl_aim_addbuddy(argv[2]);
1093    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1094  } else if (!strcasecmp(argv[1], "zephyr")) {
1095    owl_zephyr_addbuddy(argv[2]);
1096    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1097  } else {
1098    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1099  }
1100
1101  return(NULL);
1102}
1103
1104char *owl_command_delbuddy(int argc, char **argv, char *buff)
1105{
1106  if (argc!=3) {
1107    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1108    return(NULL);
1109  }
1110
1111  if (!strcasecmp(argv[1], "aim")) {
1112    if (!owl_global_is_aimloggedin(&g)) {
1113      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
1114      return(NULL);
1115    }
1116    owl_aim_delbuddy(argv[2]);
1117    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1118  } else if (!strcasecmp(argv[1], "zephyr")) {
1119    owl_zephyr_delbuddy(argv[2]);
1120    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1121  } else {
1122    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1123  }
1124
1125  return(NULL);
1126}
1127
1128char *owl_command_join(int argc, char **argv, char *buff)
1129{
1130  if (argc!=3 && argc!=4) {
1131    owl_function_makemsg("usage: join <protocol> <buddyname> [exchange]");
1132    return(NULL);
1133  }
1134
1135  if (!strcasecmp(argv[1], "aim")) {
1136    if (!owl_global_is_aimloggedin(&g)) {
1137      owl_function_makemsg("join aim: You must be logged into aim to use this command.");
1138      return(NULL);
1139    }
1140    if (argc==3) {
1141      owl_aim_chat_join(argv[2], 4);
1142    } else {
1143      owl_aim_chat_join(argv[2], atoi(argv[3]));
1144    }
1145    /* owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g)); */
1146  } else {
1147    owl_function_makemsg("join: currently the only supported protocol is 'aim'");
1148  }
1149  return(NULL);
1150}
1151
1152char *owl_command_startup(int argc, char **argv, char *buff)
1153{
1154  char *ptr;
1155
1156  if (argc<2) {
1157    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1158    return(NULL);
1159  }
1160
1161  ptr=strchr(buff, ' ');
1162  if (!ptr) {
1163    owl_function_makemsg("Parse error finding command for startup");
1164    return(NULL);
1165  }
1166
1167  owl_function_command(ptr+1);
1168  owl_function_addstartup(ptr+1);
1169
1170  return(NULL);
1171}
1172
1173char *owl_command_unstartup(int argc, char **argv, char *buff)
1174{
1175  char *ptr;
1176
1177  if (argc<2) {
1178    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1179    return(NULL);
1180  }
1181
1182  ptr=strchr(buff, ' ');
1183  if (!ptr) {
1184    owl_function_makemsg("Parse error finding command for unstartup");
1185    return(NULL);
1186  }
1187
1188  owl_function_delstartup(ptr+1);
1189
1190  return(NULL);
1191}
1192
1193char *owl_command_dump(int argc, char **argv, char *buff)
1194{
1195  char *filename;
1196 
1197  if (argc!=2) {
1198    owl_function_makemsg("usage: dump <filename>");
1199    return(NULL);
1200  }
1201  filename=owl_util_makepath(argv[1]);
1202  owl_function_dump(filename);
1203  owl_free(filename);
1204  return(NULL);
1205}
1206
1207char *owl_command_source(int argc, char **argv, char *buff)
1208{
1209  if (argc!=2) {
1210    owl_function_makemsg("usage: source <filename>");
1211    return(NULL);
1212  }
1213
1214  owl_function_source(argv[1]);
1215  return(NULL);
1216}
1217
1218char *owl_command_next(int argc, char **argv, char *buff)
1219{
1220  char *filter=NULL;
1221  int skip_deleted=0, last_if_none=0;
1222  while (argc>1) {
1223    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1224      skip_deleted=1;
1225      argc-=1; argv+=1; 
1226    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1227      last_if_none=1;
1228      argc-=1; argv+=1; 
1229    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1230      filter = owl_strdup(argv[2]);
1231      argc-=2; argv+=2; 
1232    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1233      filter = owl_function_smartfilter(0);
1234      argc-=2; argv+=2; 
1235    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1236      filter = owl_function_smartfilter(1);
1237      argc-=2; argv+=2; 
1238    } else {
1239      owl_function_makemsg("Invalid arguments to command 'next'.");
1240      return(NULL);
1241    }
1242  }
1243  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1244  if (filter) owl_free(filter);
1245  return(NULL);
1246}
1247
1248char *owl_command_prev(int argc, char **argv, char *buff)
1249{
1250  char *filter=NULL;
1251  int skip_deleted=0, first_if_none=0;
1252  while (argc>1) {
1253    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1254      skip_deleted=1;
1255      argc-=1; argv+=1; 
1256    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1257      first_if_none=1;
1258      argc-=1; argv+=1; 
1259    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1260      filter = owl_strdup(argv[2]);
1261      argc-=2; argv+=2; 
1262    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1263      filter = owl_function_smartfilter(0);
1264      argc-=2; argv+=2; 
1265    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1266      filter = owl_function_smartfilter(1);
1267      argc-=2; argv+=2; 
1268   } else {
1269      owl_function_makemsg("Invalid arguments to command 'prev'.");
1270      return(NULL);
1271    }
1272  }
1273  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1274  if (filter) owl_free(filter);
1275  return(NULL);
1276}
1277
1278char *owl_command_smartnarrow(int argc, char **argv, char *buff)
1279{
1280  char *filtname = NULL;
1281
1282  if (argc == 1) {
1283    filtname = owl_function_smartfilter(0);
1284  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1285    filtname = owl_function_smartfilter(1);
1286  } else {
1287    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1288  }
1289  if (filtname) {
1290    owl_function_change_currentview_filter(filtname);
1291    owl_free(filtname);
1292  }
1293  return NULL;
1294}
1295
1296char *owl_command_smartfilter(int argc, char **argv, char *buff)
1297{
1298  char *filtname = NULL;
1299
1300  if (argc == 1) {
1301    filtname = owl_function_smartfilter(0);
1302  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1303    filtname = owl_function_smartfilter(1);
1304  } else {
1305    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1306  }
1307  return filtname;
1308}
1309
1310void owl_command_expunge()
1311{
1312  owl_function_expunge();
1313}
1314
1315void owl_command_first()
1316{
1317  owl_global_set_rightshift(&g, 0);
1318  owl_function_firstmsg();
1319}
1320
1321void owl_command_last()
1322{
1323  owl_function_lastmsg();
1324}
1325
1326void owl_command_resize()
1327{
1328  owl_function_resize();
1329}
1330
1331void owl_command_redisplay()
1332{
1333  owl_function_full_redisplay();
1334  owl_global_set_needrefresh(&g);
1335}
1336
1337void owl_command_shift_right()
1338{
1339  owl_function_shift_right();
1340}
1341
1342void owl_command_shift_left()
1343{
1344  owl_function_shift_left();
1345}
1346
1347void owl_command_unsuball()
1348{
1349  owl_function_unsuball();
1350}
1351
1352char *owl_command_loadsubs(int argc, char **argv, char *buff)
1353{
1354  if (argc == 2) {
1355    owl_function_loadsubs(argv[1]);
1356  } else if (argc == 1) {
1357    owl_function_loadsubs(NULL);
1358  } else {
1359    owl_function_makemsg("Wrong number of arguments for load-subs.");
1360    return(NULL);
1361  }
1362  return(NULL);
1363}
1364
1365
1366char *owl_command_loadloginsubs(int argc, char **argv, char *buff)
1367{
1368  if (argc == 2) {
1369    owl_function_loadloginsubs(argv[1]);
1370  } else if (argc == 1) {
1371    owl_function_loadloginsubs(NULL);
1372  } else {
1373    owl_function_makemsg("Wrong number of arguments for load-subs.");
1374    return(NULL);
1375  }
1376  return(NULL);
1377}
1378
1379void owl_command_suspend()
1380{
1381  owl_function_suspend();
1382}
1383
1384char *owl_command_start_command(int argc, char **argv, char *buff)
1385{
1386  buff = skiptokens(buff, 1);
1387  owl_function_start_command(buff);
1388  return(NULL);
1389}
1390
1391char *owl_command_start_question(int argc, char **argv, char *buff)
1392{
1393  buff = skiptokens(buff, 1);
1394  owl_function_start_question(buff);
1395  return(NULL);
1396}
1397
1398char *owl_command_start_password(int argc, char **argv, char *buff)
1399{
1400  buff = skiptokens(buff, 1);
1401  owl_function_start_password(buff);
1402  return(NULL);
1403}
1404
1405char *owl_command_zaway(int argc, char **argv, char *buff)
1406{
1407  if ((argc==1) ||
1408      ((argc==2) && !strcmp(argv[1], "on"))) {
1409    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1410    owl_function_zaway_on();
1411    return NULL;
1412  }
1413
1414  if (argc==2 && !strcmp(argv[1], "off")) {
1415    owl_function_zaway_off();
1416    return NULL;
1417  }
1418
1419  if (argc==2 && !strcmp(argv[1], "toggle")) {
1420    owl_function_zaway_toggle();
1421    return NULL;
1422  }
1423
1424  buff = skiptokens(buff, 1);
1425  owl_global_set_zaway_msg(&g, buff);
1426  owl_function_zaway_on();
1427  return NULL;
1428}
1429
1430
1431char *owl_command_aaway(int argc, char **argv, char *buff)
1432{
1433  if ((argc==1) ||
1434      ((argc==2) && !strcmp(argv[1], "on"))) {
1435    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1436    owl_function_aaway_on();
1437    return NULL;
1438  }
1439
1440  if (argc==2 && !strcmp(argv[1], "off")) {
1441    owl_function_aaway_off();
1442    return NULL;
1443  }
1444
1445  if (argc==2 && !strcmp(argv[1], "toggle")) {
1446    owl_function_aaway_toggle();
1447    return NULL;
1448  }
1449
1450  buff = skiptokens(buff, 1);
1451  owl_global_set_aaway_msg(&g, buff);
1452  owl_function_aaway_on();
1453  return NULL;
1454}
1455
1456
1457char *owl_command_away(int argc, char **argv, char *buff)
1458{
1459  if ((argc==1) ||
1460      ((argc==2) && !strcmp(argv[1], "on"))) {
1461    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1462    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1463    owl_function_aaway_on();
1464    owl_function_zaway_on();
1465    owl_function_makemsg("Away messages set.", owl_global_get_aaway_msg_default(&g));
1466    return NULL;
1467  }
1468
1469  if (argc==2 && !strcmp(argv[1], "off")) {
1470    owl_function_aaway_off();
1471    owl_function_zaway_off();
1472    return NULL;
1473  }
1474
1475  if (argc==2 && !strcmp(argv[1], "toggle")) {
1476    /* if either one is on, turn it off, otherwise toggle both (turn
1477     *  them both on)
1478     */
1479    if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
1480      owl_function_aaway_toggle();
1481      owl_function_zaway_toggle();
1482      owl_function_makemsg("Away messages set.");
1483    } else {
1484      if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
1485      if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
1486      owl_function_makemsg("Away messages off.");
1487    }
1488    return NULL;
1489  }
1490
1491  buff = skiptokens(buff, 1);
1492  owl_global_set_aaway_msg(&g, buff);
1493  owl_global_set_zaway_msg(&g, buff);
1494  owl_function_aaway_on();
1495  owl_function_zaway_on();
1496  owl_function_makemsg("Away messages set.");
1497  return NULL;
1498}
1499
1500char *owl_command_set(int argc, char **argv, char *buff)
1501{
1502  char *var, *val;
1503  int  silent=0;
1504  int requirebool=0;
1505
1506  if (argc == 1) {
1507    owl_function_printallvars();
1508    return NULL;
1509  } 
1510
1511  if (argc > 1 && !strcmp("-q",argv[1])) {
1512    silent = 1;
1513    argc--; argv++;
1514  }
1515
1516  if (argc == 2) {
1517    var=argv[1];
1518    val="on";
1519    requirebool=1;
1520  } else if (argc == 3) {
1521    var=argv[1];
1522    val=argv[2];
1523  } else {
1524    owl_function_makemsg("Wrong number of arguments for set command");
1525    return NULL;
1526  }
1527  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1528  return NULL;
1529}
1530
1531char *owl_command_unset(int argc, char **argv, char *buff)
1532{
1533  char *var, *val;
1534  int  silent=0;
1535
1536  if (argc > 1 && !strcmp("-q",argv[1])) {
1537    silent = 1;
1538    argc--; argv++;
1539  }
1540  if (argc == 2) {
1541    var=argv[1];
1542    val="off";
1543  } else {
1544    owl_function_makemsg("Wrong number of arguments for unset command");
1545    return NULL;
1546  }
1547  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1548  return NULL;
1549}
1550
1551char *owl_command_print(int argc, char **argv, char *buff)
1552{
1553  char *var;
1554  char valbuff[1024];
1555
1556  if (argc==1) {
1557    owl_function_printallvars();
1558    return NULL;
1559  } else if (argc!=2) {
1560    owl_function_makemsg("Wrong number of arguments for print command");
1561    return NULL;
1562  }
1563
1564  var=argv[1];
1565   
1566  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1567                                     var, valbuff, 1024)) {
1568    owl_function_makemsg("%s = '%s'", var, valbuff);
1569  } else {
1570    owl_function_makemsg("Unknown variable '%s'.", var);
1571  }
1572  return NULL;
1573}
1574
1575
1576char *owl_command_exec(int argc, char **argv, char *buff)
1577{
1578  return owl_function_exec(argc, argv, buff, 0);
1579}
1580
1581char *owl_command_pexec(int argc, char **argv, char *buff)
1582{
1583  return owl_function_exec(argc, argv, buff, 1);
1584}
1585
1586char *owl_command_aexec(int argc, char **argv, char *buff)
1587{
1588  return owl_function_exec(argc, argv, buff, 2);
1589}
1590
1591char *owl_command_perl(int argc, char **argv, char *buff)
1592{
1593  return owl_function_perl(argc, argv, buff, 0);
1594}
1595
1596char *owl_command_pperl(int argc, char **argv, char *buff)
1597{
1598  return owl_function_perl(argc, argv, buff, 1);
1599}
1600
1601char *owl_command_aperl(int argc, char **argv, char *buff)
1602{
1603  return owl_function_perl(argc, argv, buff, 2);
1604}
1605
1606char *owl_command_multi(int argc, char **argv, char *buff)
1607{
1608  char *lastrv = NULL, *dupbuff, *newbuff;
1609  char **commands;
1610  int  ncommands, i;
1611  if (argc < 2) {
1612    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1613    return NULL;
1614  }
1615  dupbuff = owl_strdup(buff);
1616  newbuff = skiptokens(dupbuff, 1);
1617  if (!strcmp(argv[0], "(")) {
1618    for (i=strlen(newbuff)-1; i>=0; i--) {
1619      if (newbuff[i] == ')') {
1620        newbuff[i] = '\0';
1621        break;
1622      } else if (newbuff[i] != ' ') {
1623        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1624        owl_free(newbuff);
1625        return NULL;
1626      }
1627    }
1628  }
1629  commands = atokenize(newbuff, ";", &ncommands);
1630  for (i=0; i<ncommands; i++) {
1631    if (lastrv) {
1632      owl_free(lastrv);
1633    }
1634    lastrv = owl_function_command(commands[i]);
1635  }
1636  owl_free(dupbuff);
1637  atokenize_free(commands, ncommands);
1638  return lastrv;
1639}
1640
1641
1642char *owl_command_alias(int argc, char **argv, char *buff)
1643{
1644  if (argc < 3) {
1645    owl_function_makemsg("Invalid arguments to 'alias' command.");
1646    return NULL;
1647  }
1648  buff = skiptokens(buff, 2);
1649  owl_function_command_alias(argv[1], buff);
1650  return (NULL);
1651}
1652
1653
1654char *owl_command_bindkey(int argc, char **argv, char *buff)
1655{
1656  owl_keymap *km;
1657  int ret;
1658
1659  if (argc < 5 || strcmp(argv[3], "command")) {
1660    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1661    return NULL;
1662  }
1663  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1664  if (!km) {
1665    owl_function_makemsg("No such keymap '%s'", argv[1]);
1666    return NULL;
1667  }
1668  buff = skiptokens(buff, 4);
1669  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1670  if (ret!=0) {
1671    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1672                         argv[2], argv[1], buff);
1673    return NULL;
1674  }
1675  return NULL;
1676}
1677
1678char *owl_command_style(int argc, char **argv, char *buff) {
1679  owl_style *s;
1680
1681  /* Usage: style <name> perl <function> */
1682  if (argc != 4 || strcmp(argv[2], "perl")) {
1683    owl_function_makemsg("Usage: style <name> perl <function>");
1684    return NULL;
1685  }
1686  if (!owl_perlconfig_is_function(argv[3])) {
1687    owl_function_makemsg("Unable to create style '%s': no perl function '%s'",
1688                         argv[1], argv[3]);
1689    return NULL;
1690  }
1691  s=owl_malloc(sizeof(owl_style));
1692  owl_style_create_perl(s, argv[1], argv[3], NULL);
1693  owl_global_add_style(&g, s);
1694
1695  return NULL;
1696}
1697
1698
1699void owl_command_quit()
1700{
1701  owl_function_quit();
1702}
1703
1704char *owl_command_debug(int argc, char **argv, char *buff)
1705{
1706  if (argc<2) {
1707    owl_function_makemsg("Need at least one argument to debug command");
1708    return(NULL);
1709  }
1710
1711  if (!owl_global_is_debug_fast(&g)) {
1712    owl_function_makemsg("Debugging is not turned on");
1713    return(NULL);
1714  }
1715
1716  owl_function_debugmsg(argv[1]);
1717  return(NULL);
1718}
1719
1720char *owl_command_term(int argc, char **argv, char *buff)
1721{
1722  if (argc<2) {
1723    owl_function_makemsg("Need at least one argument to the term command");
1724    return(NULL);
1725  }
1726
1727  if (!strcmp(argv[1], "raise")) {
1728    owl_function_xterm_raise();
1729  } else if (!strcmp(argv[1], "deiconify")) {
1730    owl_function_xterm_deiconify();
1731  } else {
1732    owl_function_makemsg("Unknown terminal subcommand");
1733  }
1734  return(NULL);
1735}
1736
1737char *owl_command_zlog(int argc, char **argv, char *buff)
1738{
1739  if ((argc<2) || (argc>3)) {
1740    owl_function_makemsg("Wrong number of arguments for zlog command");
1741    return(NULL);
1742  }
1743
1744  if (!strcmp(argv[1], "in")) {
1745    if (argc>2) {
1746      owl_global_set_tty(&g, argv[2]);
1747    }
1748    owl_zephyr_zlog_in();
1749  } else if (!strcmp(argv[1], "out")) {
1750    if (argc!=2) {
1751      owl_function_makemsg("Wrong number of arguments for zlog command");
1752      return(NULL);
1753    }
1754    owl_zephyr_zlog_out();
1755  } else {
1756    owl_function_makemsg("Invalid subcommand for zlog");
1757  }
1758  return(NULL);
1759}
1760
1761
1762void owl_command_zlog_out(void)
1763{
1764  owl_zephyr_zlog_out();
1765}
1766
1767
1768char *owl_command_subscribe(int argc, char **argv, char *buff)
1769{
1770  char *recip="";
1771  int temp=0;
1772  int ret=0;
1773 
1774  if (argc<3) {
1775    owl_function_makemsg("Not enough arguments to the subscribe command");
1776    return(NULL);
1777  }
1778  argc--;
1779  argv++;
1780
1781  if (!strcmp(argv[0], "-t")) {
1782    temp=1;
1783    argc--;
1784    argv++;
1785  }
1786  if (argc<2) {
1787    owl_function_makemsg("Not enough arguments to the subscribe command");
1788    return(NULL);
1789  }
1790
1791  if (argc>3) {
1792    owl_function_makemsg("Too many arguments to the subscribe command");
1793    return(NULL);
1794  }
1795
1796  if (argc==2) {
1797    recip="";
1798  } else if (argc==3) {
1799    recip=argv[2];
1800  }
1801
1802  ret = owl_function_subscribe(argv[0], argv[1], recip);
1803  if (!temp && !ret) {
1804    owl_zephyr_addsub(NULL, argv[0], argv[1], recip);
1805  }
1806  return(NULL);
1807}
1808
1809
1810char *owl_command_unsubscribe(int argc, char **argv, char *buff)
1811{
1812  char *recip="";
1813  int temp=0;
1814
1815  if (argc<3) {
1816    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1817    return(NULL);
1818  }
1819  argc--;
1820  argv++;
1821
1822  if (!strcmp(argv[0], "-t")) {
1823    temp=1;
1824    argc--;
1825    argv++;
1826  }
1827  if (argc<2) {
1828    owl_function_makemsg("Not enough arguments to the subscribe command");
1829    return(NULL);
1830  }
1831
1832  if (argc>3) {
1833    owl_function_makemsg("Too many arguments to the unsubscribe command");
1834    return(NULL);
1835  }
1836
1837  if (argc==2) {
1838    recip="";
1839  } else if (argc==3) {
1840    recip=argv[2];
1841  }
1842
1843  owl_function_unsubscribe(argv[0], argv[1], recip);
1844  if (!temp) {
1845    owl_zephyr_delsub(NULL, argv[0], argv[1], recip);
1846  }
1847  return(NULL);
1848}
1849
1850char *owl_command_echo(int argc, char **argv, char *buff)
1851{
1852  buff = skiptokens(buff, 1);
1853  owl_function_popless_text(buff);
1854  return NULL;
1855}
1856
1857void owl_command_getsubs(void)
1858{
1859  owl_function_getsubs();
1860}
1861
1862void owl_command_status(void)
1863{
1864  owl_function_status();
1865}
1866
1867char *owl_command_zwrite(int argc, char **argv, char *buff)
1868{
1869  owl_zwrite z;
1870
1871  if (!owl_global_is_havezephyr(&g)) {
1872    owl_function_makemsg("Zephyr is not available");
1873    return(NULL);
1874  }
1875  /* check for a zwrite -m */
1876  owl_zwrite_create_from_line(&z, buff);
1877  if (owl_zwrite_is_message_set(&z)) {
1878    owl_function_zwrite(buff, NULL);
1879    owl_zwrite_free(&z);
1880    return (NULL);
1881  }
1882
1883  if (argc < 2) {
1884    owl_function_makemsg("Not enough arguments to the zwrite command.");
1885  } else {
1886    owl_function_zwrite_setup(buff);
1887  }
1888  return(NULL);
1889}
1890
1891char *owl_command_aimwrite(int argc, char **argv, char *buff)
1892{
1893  char *newbuff, *recip, **myargv;
1894  int i, j, myargc;
1895  owl_message *m;
1896 
1897  if (!owl_global_is_aimloggedin(&g)) {
1898    owl_function_makemsg("You are not logged in to AIM.");
1899    return(NULL);
1900  }
1901
1902  if (argc < 2) {
1903    owl_function_makemsg("Not enough arguments to the aimwrite command.");
1904    return(NULL);
1905  }
1906
1907  myargv=argv;
1908  if (argc<0) {
1909    owl_function_error("Unbalanced quotes in aimwrite");
1910    return(NULL);
1911  }
1912  myargc=argc;
1913  if (myargc && *(myargv[0])!='-') {
1914    myargc--;
1915    myargv++;
1916  }
1917  while (myargc) {
1918    if (!strcmp(myargv[0], "-m")) {
1919      if (myargc<2) {
1920        break;
1921      }
1922
1923      /* Once we have -m, gobble up everything else on the line */
1924      myargv++;
1925      myargc--;
1926      newbuff=owl_malloc(1);
1927      newbuff=owl_strdup("");
1928      while (myargc) {
1929        newbuff=realloc(newbuff, strlen(newbuff)+strlen(myargv[0])+5);
1930        strcat(newbuff, myargv[0]);
1931        strcat(newbuff, " ");
1932        myargc--;
1933        myargv++;
1934      }
1935      newbuff[strlen(newbuff)-1]='\0'; /* remove last space */
1936
1937      recip=owl_malloc(strlen(argv[0])+5);
1938      sprintf(recip, "%s ", argv[1]);
1939      owl_aim_send_im(recip, newbuff);
1940      m=owl_function_make_outgoing_aim(newbuff, recip);
1941      if (m) { 
1942          owl_global_messagequeue_addmsg(&g, m);
1943      } else {
1944          owl_function_error("Could not create outgoing AIM message");
1945      }
1946
1947      owl_free(recip);
1948      owl_free(newbuff);
1949      return(NULL);
1950    } else {
1951      /* we don't care */
1952      myargv++;
1953      myargc--;
1954    }
1955  }
1956
1957  /* squish arguments together to make one screenname w/o spaces for now */
1958  newbuff=owl_malloc(strlen(buff)+5);
1959  sprintf(newbuff, "%s ", argv[0]);
1960  j=argc-1;
1961  for (i=0; i<j; i++) {
1962    strcat(newbuff, argv[i+1]);
1963  }
1964   
1965  owl_function_aimwrite_setup(newbuff);
1966  owl_free(newbuff);
1967  return(NULL);
1968}
1969
1970char *owl_command_loopwrite(int argc, char **argv, char *buff)
1971{
1972  owl_function_loopwrite_setup();
1973  return(NULL);
1974}
1975
1976char *owl_command_zcrypt(int argc, char **argv, char *buff)
1977{
1978#ifdef OWL_ENABLE_ZCRYPT
1979  owl_zwrite z;
1980
1981  if (!owl_global_is_havezephyr(&g)) {
1982    owl_function_makemsg("Zephyr is not available");
1983    return(NULL);
1984  }
1985  /* check for a zcrypt -m */
1986  owl_zwrite_create_from_line(&z, buff);
1987  if (owl_zwrite_is_message_set(&z)) {
1988    owl_function_zcrypt(buff, NULL);
1989    owl_zwrite_free(&z);
1990    return (NULL);
1991  }
1992
1993  if (argc < 2) {
1994    owl_function_makemsg("Not enough arguments to the zcrypt command.");
1995  } else {
1996    owl_function_zwrite_setup(buff);
1997  }
1998  return(NULL);
1999#else
2000  owl_function_makemsg("This Owl does not support zcrypt");
2001#endif
2002}
2003
2004char *owl_command_reply(int argc, char **argv, char *buff)
2005{
2006  int edit=0;
2007 
2008  if (argc>=2 && !strcmp("-e", argv[1])) {
2009    edit=1;
2010    argv++;
2011    argc--;
2012  }
2013
2014  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2015    owl_function_reply(0, !edit);
2016  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2017    owl_function_reply(1, !edit);
2018  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2019    owl_message *m;
2020    owl_view    *v;
2021    v = owl_global_get_current_view(&g);   
2022    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2023    if (m) owl_zephyr_zaway(m);
2024  } else {
2025    owl_function_makemsg("Invalid arguments to the reply command.");
2026  }
2027  return NULL;
2028}
2029
2030char *owl_command_filter(int argc, char **argv, char *buff)
2031{
2032  owl_function_create_filter(argc, argv);
2033  return NULL;
2034}
2035
2036char *owl_command_zlocate(int argc, char **argv, char *buff)
2037{
2038  int auth;
2039 
2040  if (argc<2) {
2041    owl_function_makemsg("Too few arguments for zlocate command");
2042    return NULL;
2043  }
2044
2045  auth=1;
2046  if (!strcmp(argv[1], "-d")) {
2047    if (argc>2) {
2048      auth=0;
2049      argc--;
2050      argv++;
2051    } else {
2052      owl_function_makemsg("Missing arguments for zlocate command");
2053      return NULL;
2054    }
2055  }
2056
2057  argc--;
2058  argv++;
2059  owl_function_zlocate(argc, argv, auth);
2060  return NULL;
2061}
2062
2063
2064/* Backwards compatability has made this kind of complicated:
2065 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2066 * view <filter>
2067 * view -d <expression>
2068 * view --home
2069 */
2070char *owl_command_view(int argc, char **argv, char *buff)
2071{
2072  /* First take the 'view --home' and 'view -r' cases */
2073  if (argc == 2) {
2074    if (!strcmp(argv[1], "--home")) {
2075      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2076      return(NULL);
2077    } else if (!strcmp(argv[1], "-r")) {
2078      char *foo;
2079      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2080      owl_function_change_currentview_filter(foo);
2081      owl_free(foo);
2082      return(NULL);
2083    }
2084  }
2085
2086  /* Now look for 'view <filter>' */
2087  if (argc==2) {
2088    owl_function_change_currentview_filter(argv[1]);
2089    return(NULL);
2090  }
2091
2092  /* Now get 'view -d <expression>' */
2093  if (argc>=3 && !strcmp(argv[1], "-d")) {
2094    char **myargv;
2095    int i;
2096
2097    myargv=owl_malloc((argc*sizeof(char *))+50);
2098    myargv[0]="";
2099    myargv[1]="owl-dynamic";
2100    for (i=2; i<argc; i++) {
2101      myargv[i]=argv[i];
2102    }
2103    owl_function_create_filter(argc, myargv);
2104    owl_function_change_currentview_filter("owl-dynamic");
2105    owl_free(myargv);
2106    return NULL;
2107  }
2108
2109  /* Finally handle the general case */
2110  if (argc<3) {
2111    owl_function_makemsg("Too few arguments to the view command.");
2112    return(NULL);
2113  }
2114  argc--;
2115  argv++;
2116  if (strcmp(argv[0], "-f") &&
2117      strcmp(argv[0], "-d") &&
2118      strcmp(argv[0], "--home") &&
2119      strcmp(argv[0], "-s") &&
2120      strcmp(argv[0], "-r")) {
2121    if (strcmp(argv[0], "main")) {
2122      owl_function_makemsg("No view named '%s'", argv[0]);
2123      return(NULL);
2124    }
2125    argc--;
2126    argv++;
2127  }
2128  while (argc) {
2129    if (!strcmp(argv[0], "-f")) {
2130      if (argc<2) {
2131        owl_function_makemsg("Too few argments to the view command");
2132        return(NULL);
2133      }
2134      owl_function_change_currentview_filter(argv[1]);
2135      argc-=2;
2136      argv+=2;
2137    } else if (!strcmp(argv[0], "--home")) {
2138      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2139      argc--;
2140      argv++;
2141    } else if (!strcmp(argv[0], "-r")) {
2142      char *foo;
2143      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2144      owl_function_change_currentview_filter(foo);
2145    } else if (!strcmp(argv[0], "-s")) {
2146      if (argc<2) {
2147        owl_function_makemsg("Too few argments to the view command");
2148        return(NULL);
2149      }
2150      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2151      argc-=2;
2152      argv+=2;
2153    } else {
2154      owl_function_makemsg("Too few argments to the view command");
2155      return(NULL);
2156    }
2157   
2158  }
2159  return(NULL);
2160}
2161
2162char *owl_command_show(int argc, char **argv, char *buff)
2163{
2164  if (argc<2) {
2165    owl_function_help_for_command("show");
2166    return NULL;
2167  }
2168
2169  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2170    if (argc==2) {
2171      owl_function_show_filters();
2172    } else {
2173      owl_function_show_filter(argv[2]);
2174    }
2175  } else if (argc==2 
2176             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2177    owl_function_show_zpunts();
2178  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2179    if (argc==2) {
2180      owl_function_show_commands();
2181    } else {
2182      owl_function_show_command(argv[2]);
2183    }
2184  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2185    if (argc==2) {
2186      owl_function_show_variables();
2187    } else {
2188      owl_function_show_variable(argv[2]);
2189    }
2190  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2191    if (argc==2) {
2192      owl_function_show_keymaps();
2193    } else {
2194      owl_function_show_keymap(argv[2]);
2195    }
2196  } else if (!strcmp(argv[1], "view")) {
2197    if (argc==3) {
2198      owl_function_show_view(argv[2]);
2199    } else {
2200      owl_function_show_view(NULL);
2201    }
2202  } else if (!strcmp(argv[1], "colors")) {
2203    owl_function_show_colors();
2204  } else if (!strcmp(argv[1], "styles")) {
2205    owl_function_show_styles();
2206  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2207    owl_function_getsubs();
2208  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2209    owl_function_show_term();
2210  } else if (!strcmp(argv[1], "version")) {
2211    owl_function_about();
2212  } else if (!strcmp(argv[1], "status")) {
2213    owl_function_status();
2214  } else if (!strcmp(argv[1], "license")) {
2215    owl_function_show_license();
2216  } else if (!strcmp(argv[1], "startup")) {
2217    char *filename;
2218   
2219    filename=owl_global_get_startupfile(&g);
2220    owl_function_popless_file(filename);
2221  } else if (!strcmp(argv[1], "errors")) {
2222    owl_function_showerrs();
2223  } else {
2224    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2225    return NULL;
2226  }
2227  return NULL;
2228}
2229
2230char *owl_command_viewclass(int argc, char **argv, char *buff)
2231{
2232  char *filtname;
2233  if (argc!=2) {
2234    owl_function_makemsg("Wrong number of arguments to viewclass command");
2235    return NULL;
2236  }
2237  filtname = owl_function_classinstfilt(argv[1], NULL);
2238  owl_function_change_currentview_filter(filtname);
2239  owl_free(filtname);
2240  return NULL;
2241}
2242
2243char *owl_command_viewuser(int argc, char **argv, char *buff)
2244{
2245  char *filtname;
2246  if (argc!=2) {
2247    owl_function_makemsg("Wrong number of arguments to viewuser command");
2248    return NULL;
2249  }
2250  filtname=owl_function_zuserfilt(argv[1]);
2251  owl_function_change_currentview_filter(filtname);
2252  owl_free(filtname);
2253  return NULL;
2254}
2255
2256
2257void owl_command_pop_message(void)
2258{
2259  owl_function_curmsg_to_popwin();
2260}
2261
2262void owl_command_openurl(void)
2263{
2264  owl_function_openurl();
2265}
2266
2267char *owl_command_delete(int argc, char **argv, char *buff)
2268{
2269  int move_after = 1;
2270
2271  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2272    move_after = 0;
2273    argc--; 
2274    argv++;
2275  }
2276
2277  if (argc==1) {
2278    owl_function_deletecur(move_after);
2279    return NULL;
2280  }
2281
2282  if (argc==2 && !strcmp(argv[1], "view")) {
2283    owl_function_delete_curview_msgs(1);
2284    return NULL;
2285  }
2286
2287  if (argc==2 && !strcmp(argv[1], "trash")) {
2288    owl_function_delete_automsgs();
2289    return NULL;
2290  }
2291
2292  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2293    owl_function_delete_by_id(atoi(argv[2]), 1);
2294    return NULL;
2295  }
2296
2297  owl_function_makemsg("Unknown arguments to delete command");
2298  return NULL;
2299}
2300
2301char *owl_command_undelete(int argc, char **argv, char *buff)
2302{
2303  int move_after = 1;
2304
2305  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2306    move_after = 0;
2307    argc--; 
2308    argv++;
2309  }
2310
2311  if (argc==1) {
2312    owl_function_undeletecur(move_after);
2313    return NULL;
2314  }
2315
2316  if (argc==2 && !strcmp(argv[1], "view")) {
2317    owl_function_delete_curview_msgs(0);
2318    return NULL;
2319  }
2320
2321  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2322    owl_function_delete_by_id(atoi(argv[2]), 0);
2323    return NULL;
2324  }
2325
2326  owl_function_makemsg("Unknown arguments to delete command");
2327  return NULL;
2328}
2329
2330void owl_command_beep()
2331{
2332  owl_function_beep();
2333}
2334
2335char *owl_command_colorview(int argc, char **argv, char *buff)
2336{
2337  if (argc < 2 || argc > 3) {
2338    owl_function_makemsg("Wrong number of arguments to colorview command");
2339    return NULL;
2340  }
2341  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2342  return NULL;
2343}
2344
2345char *owl_command_colorclass(int argc, char **argv, char *buff)
2346{
2347  char *filtname;
2348 
2349  if (argc < 3 || argc > 4) {
2350    owl_function_makemsg("Wrong number of arguments to colorclass command");
2351    return NULL;
2352  }
2353
2354  filtname=owl_function_classinstfilt(argv[1], NULL);
2355  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2356  return NULL;
2357}
2358
2359char *owl_command_zpunt(int argc, char **argv, char *buff)
2360{
2361  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2362  return NULL;
2363}
2364
2365char *owl_command_zunpunt(int argc, char **argv, char *buff)
2366{
2367  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2368  return NULL;
2369}
2370
2371void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type)
2372{
2373  /* if type==0 then zpunt
2374   * if type==1 then zunpunt
2375   */
2376  char *class, *inst, *recip;
2377
2378  class="message";
2379  inst="";
2380  recip="*";
2381
2382  if (argc==1) {
2383    /* show current punt filters */
2384    owl_function_show_zpunts();
2385    return;
2386  } else if (argc==2) {
2387    inst=argv[1];
2388  } else if (argc==3) {
2389    class=argv[1];
2390    inst=argv[2];
2391  } else if (argc==4) {
2392    class=argv[1];
2393    inst=argv[2];
2394    recip=argv[3];
2395  } else {
2396    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2397    return;
2398  }
2399
2400  owl_function_zpunt(class, inst, recip, type);
2401  if (type==0) {
2402    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2403  } else if (type==1) {
2404    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2405  }
2406}
2407
2408char *owl_command_smartzpunt(int argc, char **argv, char *buff)
2409{
2410  if (argc == 1) {
2411    owl_function_smartzpunt(0);
2412  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2413    owl_function_smartzpunt(1);
2414  } else {
2415    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2416  }
2417  return NULL;
2418}
2419
2420char *owl_command_punt(int argc, char **argv, char *buff)
2421{
2422  owl_command_punt_unpunt(argc, argv, buff, 0);
2423  return NULL;
2424}
2425
2426char *owl_command_unpunt(int argc, char **argv, char *buff)
2427{
2428  owl_command_punt_unpunt(argc, argv, buff, 1);
2429  return NULL;
2430}
2431
2432void owl_command_punt_unpunt(int argc, char ** argv, char *buff, int unpunt)
2433{
2434  owl_list * fl;
2435  owl_filter * f;
2436  char * text;
2437  int i;
2438
2439  fl = owl_global_get_puntlist(&g);
2440  if(argc == 1) {
2441    owl_function_show_zpunts();
2442  }
2443
2444  if(argc == 2) {
2445    /* Handle :unpunt <number> */
2446    if(unpunt && (i=atoi(argv[1])) !=0) {
2447      i--;      /* Accept 1-based indexing */
2448      if(i < owl_list_get_size(fl)) {
2449        f = (owl_filter*)owl_list_get_element(fl, i);
2450        owl_list_remove_element(fl, i);
2451        owl_filter_free(f);
2452        return;
2453      } else {
2454        owl_function_error("No such filter number: %d", i+1);
2455      }
2456    }
2457    text = owl_sprintf("filter %s", argv[1]);
2458  } else {
2459    text = skiptokens(buff, 1);
2460  }
2461
2462  owl_function_punt(text, unpunt);
2463}
2464
2465
2466char *owl_command_getview(int argc, char **argv, char *buff)
2467{
2468  char *filtname;
2469  if (argc != 1) {
2470    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2471    return NULL;
2472  }
2473  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2474  if (filtname) filtname = owl_strdup(filtname);
2475  return filtname;
2476}
2477
2478char *owl_command_getvar(int argc, char **argv, char *buff)
2479{
2480  char tmpbuff[1024];
2481  if (argc != 2) {
2482    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2483    return NULL;
2484  }
2485  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
2486                                argv[1], tmpbuff, 1024)) {
2487    return NULL;
2488  }
2489  return owl_strdup(tmpbuff); 
2490}
2491
2492char *owl_command_search(int argc, char **argv, char *buff)
2493{
2494  int direction;
2495  char *buffstart;
2496
2497  direction=OWL_DIRECTION_DOWNWARDS;
2498  buffstart=skiptokens(buff, 1);
2499  if (argc>1 && !strcmp(argv[1], "-r")) {
2500    direction=OWL_DIRECTION_UPWARDS;
2501    buffstart=skiptokens(buff, 2);
2502  }
2503   
2504  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2505    owl_function_search_continue(direction);
2506  } else {
2507    owl_function_search_start(buffstart, direction);
2508  }
2509 
2510  return(NULL);
2511}
2512
2513char *owl_command_setsearch(int argc, char **argv, char *buff)
2514{
2515  char *buffstart;
2516
2517  buffstart=skiptokens(buff, 1);
2518
2519  owl_global_set_search_active(&g, buffstart);
2520
2521  if (!*buffstart) {
2522    owl_global_set_search_inactive(&g);
2523  }
2524
2525  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
2526 
2527  return(NULL);
2528}
2529
2530char *owl_command_aimlogin(int argc, char **argv, char *buff)
2531{
2532  if ((argc<2) || (argc>3)) {
2533    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2534    return(NULL);
2535  }
2536
2537  /* if we get two arguments, ask for the password */
2538  if (argc==2) {
2539    owl_global_set_buffercommand(&g, argv[1]);
2540    owl_global_set_buffercallback(&g, &owl_callback_aimlogin);
2541    owl_function_start_password("AIM Password: ");
2542    return(NULL);
2543  } else {
2544    owl_function_aimlogin(argv[1], argv[2]);
2545  }
2546
2547  /* this is a test */
2548  return(NULL);
2549}
2550
2551char *owl_command_aimlogout(int argc, char **argv, char *buff)
2552{
2553  /* clear the buddylist */
2554  owl_buddylist_clear(owl_global_get_buddylist(&g));
2555
2556  owl_aim_logout();
2557  return(NULL);
2558}
2559
2560char *owl_command_getstyle(int argc, char **argv, char *buff)
2561{
2562  char *stylename;
2563  if (argc != 1) {
2564    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2565    return NULL;
2566  }
2567  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2568  if (stylename) stylename = owl_strdup(stylename);
2569  return stylename;
2570}
2571
2572char *owl_command_error(int argc, char **argv, char *buff)
2573{
2574    buff = skiptokens(buff, 1);
2575    owl_function_error(buff);
2576    return NULL;
2577}
2578
2579char *owl_command_message(int argc, char **argv, char *buff)
2580{
2581    buff = skiptokens(buff, 1);
2582    owl_function_makemsg(buff);
2583    return NULL;
2584}
2585
2586void owl_command_yes(void)
2587{
2588  owl_message *m;
2589  owl_view *v;
2590  char *cmd;
2591
2592  v = owl_global_get_current_view(&g);
2593
2594  /* bail if there's no current message */
2595  if (owl_view_get_size(v) < 1) {
2596    owl_function_error("No current message.");
2597    return;
2598  }
2599
2600  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2601  if(!owl_message_is_question(m)) {
2602    owl_function_error("That message isn't a question.");
2603    return;
2604  }
2605  if(owl_message_is_answered(m)) {
2606    owl_function_error("You already answered that question.");
2607    return;
2608  }
2609  cmd = owl_message_get_attribute_value(m, "yescommand");
2610  if(!cmd) {
2611    owl_function_error("No yes command!");
2612    return;
2613  }
2614
2615  owl_function_command_norv(cmd);
2616  owl_message_set_isanswered(m);
2617  return;
2618}
2619
2620void owl_command_no(void)
2621{
2622  owl_message *m;
2623  owl_view *v;
2624  char *cmd;
2625
2626  v = owl_global_get_current_view(&g);
2627
2628  /* bail if there's no current message */
2629  if (owl_view_get_size(v) < 1) {
2630    owl_function_error("No current message.");
2631    return;
2632  }
2633
2634  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2635  if(!owl_message_is_question(m)) {
2636    owl_function_error("That message isn't a question.");
2637    return;
2638  }
2639  if(owl_message_is_answered(m)) {
2640    owl_function_error("You already answered that question.");
2641    return;
2642  }
2643  cmd = owl_message_get_attribute_value(m, "nocommand");
2644  if(!cmd) {
2645    owl_function_error("No no command!");
2646    return;
2647  }
2648
2649  owl_function_command_norv(cmd);
2650  owl_message_set_isanswered(m);
2651  return;
2652}
2653
2654/*********************************************************************/
2655/************************** EDIT SPECIFIC ****************************/
2656/*********************************************************************/
2657
2658void owl_command_edit_cancel(owl_editwin *e)
2659{
2660  owl_history *hist;
2661
2662  owl_function_makemsg("Command cancelled.");
2663
2664  hist=owl_editwin_get_history(e);
2665  owl_history_store(hist, owl_editwin_get_text(e));
2666  owl_history_reset(hist);
2667
2668  owl_editwin_fullclear(e);
2669  owl_global_set_needrefresh(&g);
2670  wnoutrefresh(owl_editwin_get_curswin(e));
2671  owl_global_set_typwin_inactive(&g);
2672  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2673
2674  owl_function_activate_keymap("recv");
2675}
2676
2677void owl_command_edit_history_prev(owl_editwin *e)
2678{
2679  owl_history *hist;
2680  char *ptr;
2681
2682  hist=owl_editwin_get_history(e);
2683  if (!owl_history_is_touched(hist)) {
2684    owl_history_store(hist, owl_editwin_get_text(e));
2685    owl_history_set_partial(hist);
2686  }
2687  ptr=owl_history_get_prev(hist);
2688  if (ptr) {
2689    owl_editwin_clear(e);
2690    owl_editwin_insert_string(e, ptr);
2691    owl_editwin_redisplay(e, 0);
2692    owl_global_set_needrefresh(&g);
2693  } else {
2694    owl_function_beep();
2695  }
2696}
2697
2698void owl_command_edit_history_next(owl_editwin *e)
2699{
2700  owl_history *hist;
2701  char *ptr;
2702
2703  hist=owl_editwin_get_history(e);
2704  ptr=owl_history_get_next(hist);
2705  if (ptr) {
2706    owl_editwin_clear(e);
2707    owl_editwin_insert_string(e, ptr);
2708    owl_editwin_redisplay(e, 0);
2709    owl_global_set_needrefresh(&g);
2710  } else {
2711    owl_function_beep();
2712  }
2713}
2714
2715char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff)
2716{
2717  buff = skiptokens(buff, 1);
2718  owl_editwin_insert_string(e, buff);
2719  owl_editwin_redisplay(e, 0);
2720  owl_global_set_needrefresh(&g); 
2721  return NULL;
2722}
2723
2724void owl_command_editline_done(owl_editwin *e)
2725{
2726  owl_history *hist=owl_editwin_get_history(e);
2727  char *rv, *cmd;
2728
2729  owl_history_store(hist, owl_editwin_get_text(e));
2730  owl_history_reset(hist);
2731  owl_global_set_typwin_inactive(&g);
2732  cmd = owl_strdup(owl_editwin_get_text(e));
2733  owl_editwin_fullclear(e);
2734  rv = owl_function_command(cmd);
2735  owl_free(cmd);
2736
2737  wnoutrefresh(owl_editwin_get_curswin(e));
2738  owl_global_set_needrefresh(&g);
2739
2740  if (rv) {
2741    owl_function_makemsg("%s", rv);
2742    owl_free(rv);
2743  }
2744}
2745
2746
2747void owl_command_editresponse_done(owl_editwin *e)
2748{
2749  owl_function_run_buffercommand();
2750
2751  owl_global_set_typwin_inactive(&g);
2752  owl_editwin_fullclear(e);
2753  wnoutrefresh(owl_editwin_get_curswin(e));
2754  owl_global_set_needrefresh(&g);
2755}
2756
2757
2758void owl_command_editmulti_done(owl_editwin *e)
2759{
2760  owl_history *hist=owl_editwin_get_history(e);
2761
2762  owl_history_store(hist, owl_editwin_get_text(e));
2763  owl_history_reset(hist);
2764
2765  owl_function_run_buffercommand();
2766  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2767  owl_editwin_fullclear(e);
2768  owl_global_set_typwin_inactive(&g);
2769  owl_global_set_needrefresh(&g);
2770  wnoutrefresh(owl_editwin_get_curswin(e));
2771}
2772
2773void owl_command_editmulti_done_or_delete(owl_editwin *e)
2774{
2775  if (owl_editwin_is_at_end(e)) {
2776    owl_command_editmulti_done(e);
2777  } else {
2778    owl_editwin_delete_char(e);
2779  }
2780}
2781
2782
2783/*********************************************************************/
2784/*********************** POPLESS SPECIFIC ****************************/
2785/*********************************************************************/
2786
2787void owl_command_popless_quit(owl_viewwin *vw)
2788{
2789  owl_popwin_close(owl_global_get_popwin(&g));
2790  owl_viewwin_free(vw);
2791  owl_global_set_needrefresh(&g);
2792}
Note: See TracBrowser for help on using the repository browser.