source: commands.c @ a60edf2

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