source: commands.c @ f17bff98

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