source: commands.c @ cf83b7a

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