source: commands.c @ 453bd70

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