source: commands.c @ 86840c5

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