source: commands.c @ 7f0c26f

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