source: commands.c @ c15bbfb

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