source: commands.c @ aac889a

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