source: commands.c @ fa4f9c3

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