source: commands.c @ fe6f1d3

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