source: commands.c @ 15283bb

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