source: commands.c @ 799b60e

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