source: commands.c @ 0ee43c8

release-1.10release-1.6release-1.7release-1.8release-1.9
Last change on this file since 0ee43c8 was e2cbbbe, checked in by Nelson Elhage <nelhage@mit.edu>, 15 years ago
Merge branch 'refactor-zcrypt'
  • Property mode set to 100644
File size: 82.7 KB
Line 
1#include <getopt.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <string.h>
5#include <unistd.h>
6#include "owl.h"
7
8/* fn is "char *foo(int argc, const char *const *argv, const char *buff)" */
9#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
10        { name, summary, usage, description, ctx, \
11          NULL, fn, NULL, NULL, NULL, NULL, NULL, NULL }
12
13/* fn is "void foo(void)" */
14#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
15        { name, summary, usage, description, ctx, \
16          NULL, NULL, fn, NULL, NULL, NULL, NULL, NULL }
17
18/* fn is "void foo(int)" */
19#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
20        { name, summary, usage, description, ctx, \
21          NULL, NULL, NULL, fn, NULL, NULL, NULL, NULL }
22
23#define OWLCMD_ALIAS(name, actualname) \
24        { name, OWL_CMD_ALIAS_SUMMARY_PREFIX actualname, "", "", OWL_CTX_ANY, \
25          actualname, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
26
27/* fn is "char *foo(void *ctx, int argc, const char *const *argv, const char *buff)" */
28#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
29        { name, summary, usage, description, ctx, \
30          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,const char*const *,const char*))fn), NULL, NULL, NULL }
31
32/* fn is "void foo(void)" */
33#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
34        { name, summary, usage, description, ctx, \
35          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL, NULL }
36
37/* fn is "void foo(int)" */
38#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
39        { name, summary, usage, description, ctx, \
40          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn), NULL }
41
42
43const owl_cmd commands_to_init[]
44  = {
45  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
46              "send a login or logout notification",
47              "zlog in [tty]\nzlog out",
48              "zlog in will send a login notification, zlog out will send a\n"
49              "logout notification.  By default a login notification is sent\n"
50              "when owl is started and a logout notification is sent when owl\n"
51              "is exited.  This behavior can be changed with the 'startuplogin'\n"
52              "and 'shutdownlogout' variables.  If a tty is specified for zlog in\n"
53              "then the owl variable 'tty' will be set to that string, causing\n"
54              "it to be used as the zephyr location tty.\n"),
55
56  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
57              "exit owl",
58              "",
59              "Exit owl and run any shutdown activities."),
60  OWLCMD_ALIAS("exit", "quit"),
61  OWLCMD_ALIAS("q",    "quit"),
62
63  OWLCMD_ARGS("term", owl_command_term, OWL_CTX_ANY,
64              "control the terminal",
65              "term raise\n"
66              "term deiconify\n",
67              ""),
68
69  OWLCMD_VOID("nop", owl_command_nop, OWL_CTX_ANY,
70              "do nothing",
71              "",
72              ""),
73 
74  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
75              "prompts the user to enter a command",
76              "start-command [initial-value]",
77              "Initializes the command field to initial-value."),
78
79  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
80              "creates a command alias",
81              "alias <new_command> <old_command>",
82              "Creates a command alias from new_command to old_command.\n"
83              "Any arguments passed to <new_command> will be appended to\n"
84              "<old_command> before it is executed.\n"),
85
86  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
87              "creates a binding in a keymap",
88              "bindkey <keymap> <keyseq> command <command>",
89              "(Note: There is a literal word \"command\" between <keyseq>\n"
90              " and <command>.)\n"
91              "Binds a key sequence to a command within a keymap.\n"
92              "Use 'show keymaps' to see the existing keymaps.\n"
93              "Key sequences may be things like M-C-t or NPAGE.\n\n"
94              "Ex.: bindkey recv C-b command zwrite -c barnowl"
95              "SEE ALSO: bindkey"),
96
97  OWLCMD_ARGS("unbindkey", owl_command_unbindkey, OWL_CTX_ANY,
98              "removes a binding in a keymap",
99              "bindkey <keymap> <keyseq>",
100              "Removes a binding of a key sequence within a keymap.\n"
101              "Use 'show keymaps' to see the existing keymaps.\n"
102              "Ex.: unbindkey recv H"
103              "SEE ALSO: bindkey"),
104
105  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
106              "send a zephyr",
107              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
108              "Zwrite send a zephyr to the one or more users specified.\n\n"
109              "The following options are available:\n\n"
110              "-m    Specifies a message to send without prompting.\n"
111              "      Note that this does not yet log an outgoing message.\n"
112              "      This must be the last argument.\n\n"
113              "-n    Do not send a ping message.\n\n"
114              "-C    If the message is sent to more than one user include a\n"
115              "      \"cc:\" line in the text\n\n"
116              "-c class\n"
117              "      Send to the specified zephyr class\n\n"
118              "-i instance\n"
119              "      Send to the specified zephyr instance\n\n"
120              "-r realm\n"
121              "      Send to a foreign realm\n"
122              "-O opcode\n"
123              "      Send to the specified opcode\n"),
124
125  OWLCMD_ARGS("aimwrite", owl_command_aimwrite, OWL_CTX_INTERACTIVE,
126              "send an AIM message",
127              "aimwrite <user> [-m <message...>]",
128              "Send an aim message to a user.\n\n" 
129              "The following options are available:\n\n"
130              "-m    Specifies a message to send without prompting.\n"),
131
132  OWLCMD_ARGS("loopwrite", owl_command_loopwrite, OWL_CTX_INTERACTIVE,
133              "send a loopback message",
134              "loopwrite",
135              "Send a local message.\n"),
136
137  OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
138              "send an encrypted zephyr",
139              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [-m <message...>]\n",
140              "Behaves like zwrite but uses encryption.  Not for use with\n"
141              "personal messages\n"),
142 
143  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
144              "reply to the current message",
145              "reply [-e] [ sender | all | zaway ]",
146              "If -e is specified, the zwrite command line is presented to\n"
147              "allow editing.\n\n"
148              "If 'sender' is specified, reply to the sender.\n\n"
149              "If 'all' or no args are specified, reply publically to the\n"
150              "same class/instance for non-personal messages and to the\n"
151              "sender for personal messages.\n\n"
152              "If 'zaway' is specified, replies with a zaway message.\n\n"),
153
154  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
155              "set a variable value",
156              "set [-q] [<variable>] [<value>]\n"
157              "set",
158              "Set the named variable to the specified value.  If no\n"
159              "arguments are given, print the value of all variables.\n"
160              "If the value is unspecified and the variable is a boolean, it will be\n"
161              "set to 'on'.  If -q is used, set is silent and does not print a\n"
162              "message.\n"),
163
164  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
165              "unset a boolean variable value",
166              "unset [-q] <variable>\n"
167              "unset",
168              "Set the named boolean variable to off.\n"
169              "If -q is specified, is silent and doesn't print a message.\n"),
170
171  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
172              "print a variable value",
173              "print <variable>\n"
174              "print",
175              "Print the value of the named variable.  If no arguments\n"
176              "are used print the value of all variables.\n"),
177
178  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
179              "run a command and set it to be run at every Owl startup",
180              "startup <commands> ...",
181              "Everything on the command line after the startup command\n"
182              "is executed as a normal owl command and is also placed in\n"
183              "a file so that the command is executed every time owl\n"
184              "is started"),
185
186  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
187              "remove a command from the list of those to be run at Owl startup",
188              "unstartup <commands> ...",
189              ""),
190
191  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
192              "print the version of the running owl", "", ""),
193
194  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
195              "subscribe to a zephyr class, instance, recipient",
196              "subscribe [-t] <class> [instance [recipient]]",
197              "Subscribe to the specified class and instance.  If the\n"
198              "instance or recipient is not listed on the command\n"
199              "line they default to * (the wildcard recipient).\n"
200              "If the -t option is present the subscription will\n"
201              "only be temporary, i.e., it will not be written to\n"
202              "the subscription file and will therefore not be\n"
203              "present the next time owl is started.\n"),
204  OWLCMD_ALIAS("sub", "subscribe"),
205
206  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
207              "unsubscribe from a zephyr class, instance, recipient",
208              "unsubscribe [-t] <class> [instance [recipient]]",
209              "Unsubscribe from the specified class and instance.  If the\n"
210              "instance or recipient is not listed on the command\n"
211              "line they default to * (the wildcard recipient).\n"
212              "If the -t option is present the unsubscription will\n"
213              "only be temporary, i.e., it will not be updated in\n"
214              "the subscription file and will therefore not be\n"
215              "in effect the next time owl is started.\n"),
216  OWLCMD_ALIAS("unsub", "unsubscribe"),
217
218  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
219              "unsubscribe from all zephyrs", "", ""),
220 
221  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
222              "print all current subscriptions",
223              "getsubs",
224              "getsubs retrieves the current subscriptions from the server\n"
225              "and displays them.\n"),
226
227  OWLCMD_ARGS("dump", owl_command_dump, OWL_CTX_ANY,
228              "dump messages to a file",
229              "dump <filename>",
230              "Dump messages in current view to the named file."),
231
232  OWLCMD_ARGS("source", owl_command_source, OWL_CTX_ANY,
233              "execute owl commands from a file",
234              "source <filename>",
235              "Execute the owl commands in <filename>.\n"),
236
237  OWLCMD_ARGS("aim", owl_command_aim, OWL_CTX_INTERACTIVE,
238              "AIM specific commands",
239              "aim search <email>",
240              ""),
241
242  OWLCMD_ARGS("addbuddy", owl_command_addbuddy, OWL_CTX_INTERACTIVE,
243              "add a buddy to a buddylist",
244              "addbuddy <protocol> <screenname>",
245              "Add the named buddy to your buddylist.  <protocol> can be aim or zephyr\n"),
246
247  OWLCMD_ARGS("delbuddy", owl_command_delbuddy, OWL_CTX_INTERACTIVE,
248              "delete a buddy from a buddylist",
249              "delbuddy <protocol> <screenname>",
250              "Delete the named buddy from your buddylist.  <protocol> can be aim or zephyr\n"),
251
252  OWLCMD_ARGS("join", owl_command_join, OWL_CTX_INTERACTIVE,
253              "join a chat group",
254              "join aim <groupname> [exchange]",
255              "Join the AIM chatroom with 'groupname'.\n"),
256
257  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
258              "creates a zpunt based on the current message",
259              "smartzpunt [-i | --instance]",
260              "Starts a zpunt command based on the current message's class\n"
261              "(and instance if -i is specified).\n"),
262
263  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
264              "suppress a given zephyr triplet",
265              "zpunt <class> <instance> [recipient]\n"
266              "zpunt <instance>",
267              "The zpunt command will supress message to the specified\n"
268              "zephyr triplet.  In the second usage messages are suppressed\n"
269              "for class MESSAGE and the named instance.\n\n"
270              "SEE ALSO:  zunpunt, show zpunts\n"),
271
272  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
273              "undo a previous zpunt",
274              "zunpunt <class> <instance> [recipient]\n"
275              "zunpunt <instance>",
276              "The zunpunt command will allow messages that were previously\n"
277              "suppressed to be received again.\n\n"
278              "SEE ALSO:  zpunt, show zpunts\n"),
279
280  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
281              "suppress an arbitrary filter",
282              "punt <filter-text>",
283              "punt <filter-text (multiple words)>\n"
284              "The punt command will supress message to the specified\n"
285              "filter\n\n"
286              "SEE ALSO:  unpunt, zpunt, show zpunts\n"),
287
288  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
289              "remove an entry from the punt list",
290              "zpunt <filter-text>\n"
291              "zpunt <filter-text>\n"
292              "zpunt <number>\n",
293              "The unpunt command will remove an entry from the puntlist.\n"
294              "The first two forms correspond to the first two forms of the :punt\n"
295              "command. The latter allows you to remove a specific entry from the\n"
296              "the list (see :show zpunts)\n\n"
297              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
298
299  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
300              "display detailed information about the current message",
301              "", ""),
302 
303  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
304              "display help on using owl",
305              "help [command]", ""),
306
307  OWLCMD_ARGS("zlist", owl_command_zlist, OWL_CTX_INTERACTIVE,
308              "List users logged in",
309              "znol [-f file]",
310              "Print a znol-style listing of users logged in"),
311
312  OWLCMD_VOID("alist", owl_command_alist, OWL_CTX_INTERACTIVE,
313              "List AIM users logged in",
314              "alist",
315              "Print a listing of AIM users logged in"),
316
317  OWLCMD_VOID("blist", owl_command_blist, OWL_CTX_INTERACTIVE,
318              "List all buddies logged in",
319              "blist",
320              "Print a listing of buddies logged in, regardless of protocol."),
321
322  OWLCMD_VOID("toggle-oneline", owl_command_toggleoneline, OWL_CTX_INTERACTIVE,
323              "Toggle the style between oneline and the default style",
324              "toggle-oneline",
325              ""),
326
327  OWLCMD_ARGS("recv:getshift", owl_command_get_shift, OWL_CTX_INTERACTIVE,
328              "gets position of receive window scrolling", "", ""),
329
330  OWLCMD_INT("recv:setshift", owl_command_set_shift, OWL_CTX_INTERACTIVE,
331              "scrolls receive window to specified position", "", ""),
332
333  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
334              OWL_CTX_INTERACTIVE,
335              "scrolls down by a page", "", ""),
336
337  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
338              "scrolls up by a page", "", ""),
339
340  OWLCMD_VOID("recv:mark", owl_function_mark_message,
341              OWL_CTX_INTERACTIVE,
342              "mark the current message", "", ""),
343
344  OWLCMD_VOID("recv:swapmark", owl_function_swap_cur_marked,
345              OWL_CTX_INTERACTIVE,
346              "swap the positions of the pointer and the mark", "", ""),
347
348  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
349              "scrolls current message up or down", 
350              "recv:scroll <numlines>", 
351              "Scrolls the current message up or down by <numlines>.\n"
352              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
353
354  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
355              "move the pointer to the next message",
356              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
357              "          [ --smart-filter | --smart-filter-instance ]",
358              "Moves the pointer to the next message in the current view.\n"
359              "If --filter is specified, will only consider messages in\n"
360              "the filter <name>.\n"
361              "If --smart-filter or --smart-filter-instance is specified,\n"
362              "goes to the next message that is similar to the current message.\n"
363              "If --skip-deleted is specified, deleted messages will\n"
364              "be skipped.\n"
365              "If --last-if-none is specified, will stop at last message\n"
366              "in the view if no other suitable messages are found.\n"),
367  OWLCMD_ALIAS("recv:next", "next"),
368
369  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
370              "move the pointer to the previous message",
371              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
372              "          [ --smart-filter | --smart-filter-instance ]",
373              "Moves the pointer to the next message in the current view.\n"
374              "If --filter is specified, will only consider messages in\n"
375              "the filter <name>.\n"
376              "If --smart-filter or --smart-filter-instance is specified,\n"
377              "goes to the previous message that is similar to the current message.\n"
378              "If --skip-deleted is specified, deleted messages will\n"
379              "be skipped.\n"
380              "If --first-if-none is specified, will stop at first message\n"
381              "in the view if no other suitable messages are found.\n"),
382  OWLCMD_ALIAS("recv:prev", "prev"),
383
384  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
385  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
386
387  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
388  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
389
390  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
391
392  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
393
394  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
395              "move the pointer to the first message", "", ""),
396  OWLCMD_ALIAS("recv:first", "first"),
397
398  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
399              "move the pointer to the last message", "", 
400              "Moves the pointer to the last message in the view.\n"
401              "If we are already at the last message in the view,\n"
402              "blanks the screen and moves just past the end of the view\n"
403              "so that new messages will appear starting at the top\n"
404              "of the screen.\n"),
405  OWLCMD_ALIAS("recv:last", "last"),
406
407  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
408              "remove all messages marked for deletion", "", ""),
409
410  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
411              "resize the window to the current screen size", "", ""),
412
413  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
414              "redraw the entire window", "", ""),
415
416  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
417              "suspend owl", "", ""),
418
419  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
420              "pops up a message in popup window",
421              "echo [args .. ]\n\n", ""),
422
423  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
424              "run a command from the shell",
425              "exec [args .. ]", ""),
426
427  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
428              "run a command from the shell and display in an admin message",
429              "aexec [args .. ]", ""),
430
431  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
432              "run a command from the shell and display in a popup window",
433              "pexec [args .. ]", ""),
434
435  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
436              "run a perl expression",
437              "perl [args .. ]", ""),
438
439  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
440              "run a perl expression and display in an admin message",
441              "aperl [args .. ]", ""),
442
443  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
444              "run a perl expression and display in a popup window",
445              "pperl [args .. ]", ""),
446
447  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
448              "runs multiple ;-separated commands",
449              "multi <command1> ( ; <command2> )*\n",
450              "Runs multiple semicolon-separated commands in order.\n"
451              "Note quoting isn't supported here yet.\n"
452              "If you want to do something fancy, use perl.\n"),
453
454  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
455              "runs multiple ;-separated commands",
456              "'(' <command1> ( ; <command2> )* ')'\n",
457              "Runs multiple semicolon-separated commands in order.\n"
458              "You must have a space before the final ')'\n"
459              "Note quoting isn't supported here yet.\n"
460              "If you want to do something fancy, use perl.\n"),
461
462  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
463              "pops up a message in a window", "", ""),
464
465  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
466              "Set, enable or disable zephyr away message",
467              "zaway [ on | off | toggle ]\n"
468              "zaway <message>",
469              "Turn on or off a zaway message.  If 'message' is\n"
470              "specified turn on zaway with that message, otherwise\n"
471              "use the default.\n"),
472
473  OWLCMD_ARGS("aaway", owl_command_aaway, OWL_CTX_INTERACTIVE,
474              "Set, enable or disable AIM away message",
475              "aaway [ on | off | toggle ]\n"
476              "aaway <message>",
477              "Turn on or off the AIM away message.  If 'message' is\n"
478              "specified turn on aaway with that message, otherwise\n"
479              "use the default.\n"),
480
481  OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
482              "Set, enable or disable both AIM and zephyr away messages",
483              "away [ on | off | toggle ]\n"
484              "away <message>",
485              "Turn on or off the AIM and zephyr away message.  If\n"
486              "'message' is specified turn them on with that message,\n"
487              "otherwise use the default.\n"
488              "\n"
489              "This command really just runs the 'aaway' and 'zaway'\n"
490              "commands together\n"
491              "\n"
492              "SEE ALSO: aaway, zaway"),
493
494  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
495              "load subscriptions from a file",
496              "load-subs <file>\n", ""),
497
498  OWLCMD_ARGS("loadsubs", owl_command_loadsubs, OWL_CTX_ANY,
499              "load subscriptions from a file",
500              "loadsubs <file>\n", ""),
501
502  OWLCMD_ARGS("loadloginsubs", owl_command_loadloginsubs, OWL_CTX_ANY,
503              "load login subscriptions from a file",
504              "loadloginsubs <file>\n",
505              "The file should contain a list of usernames, one per line."),
506
507  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
508              "print information about owl", "", ""),
509
510  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
511              "print status information about the running owl", "", ""),
512 
513  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
514              "locate a user",
515              "zlocate [-d] <user> ...", 
516              "Performs a zlocate on one ore more users and puts the result\n"
517              "int a popwin.  If -d is specified, does not authenticate\n"
518              "the lookup request.\n"),
519 
520  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
521              "create a message filter",
522              "filter <name> [ -c fgcolor ] [ -b bgcolor ] [ <expression> ... ]",
523              "The filter command creates a filter with the specified name,\n"
524              "or if one already exists it is replaced.  Example filter\n"
525              "syntax would be:\n\n"
526              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
527              "Valid matching fields are:\n"
528              "    sender     -  sender\n"
529              "    recipient  -  recipient\n"
530              "    class      -  zephyr class name\n"
531              "    instance   -  zephyr instance name\n"
532              "    opcode     -  zephyr opcode\n"
533              "    realm      -  zephyr realm\n"
534              "    body       -  message body\n"
535              "    hostname   -  hostname of sending host\n"
536              "    type       -  message type (zephyr, aim, admin)\n"
537              "    direction  -  either 'in' 'out' or 'none'\n"
538              "    login      -  either 'login' 'logout' or 'none'\n"
539              "Also you may match on the validity of another filter:\n"
540              "    filter <filtername>\n"
541              "Also you may pass the message to a perl function returning 0 or 1,\n"
542              "where 1 indicates that the function matches the filter:\n"
543              "    perl <subname>\n"
544              "Valid operators are:\n"
545              "    and\n"
546              "    or\n"
547              "    not\n"
548              "And additionally you may use the static values:\n"
549              "    true\n"
550              "    false\n"
551              "Spaces must be present before and after parentheses.  If the\n"
552              "optional color arguments are used they specifies the colors that\n"
553              "messages matching this filter should be displayed in.\n\n"
554              "SEE ALSO: view, viewclass, viewuser\n"),
555
556  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
557              "change the colors on the current filter",
558              "colorview <fgcolor> [<bgcolor>]",
559              "The colors of messages in the current filter will be changed\n"
560              "to <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
561              "of valid colors.\n\n"
562              "SEE ALSO: 'show colors'\n"),
563
564  OWLCMD_ARGS("colorclass", owl_command_colorclass, OWL_CTX_INTERACTIVE,
565              "create a filter to color messages of the given class name",
566              "colorclass <class> <fgcolor> [<bgcolor>]",
567              "A filter will be created to color messages in <class>"
568              "in <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
569              "of valid colors.\n\n"
570              "SEE ALSO: 'show colors'\n"),
571
572  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
573              "view messages matching a filter",
574              "view [<viewname>] [-f <filter> | --home | -r ] [-s <style>]\n"
575              "view <filter>\n"
576              "view -d <expression>\n"
577              "view --home",
578              "The view command sets information associated with a particular view,\n"
579              "such as view's filter or style.  In the first general usage listed\n"
580              "above <viewname> is the name of the view to be changed.  If not\n"
581              "specified the default view 'main' will be used.  A filter can be set\n"
582              "for the view by listing a named filter after the -f argument.  If\n"
583              "the --home argument is used the filter will be set to the filter named\n"
584              "by the\n 'view_home' variable.  The style can be set by listing the\n"
585              "name style after the -s argument.\n"
586              "\n"
587              "The other usages listed above are abbreivated forms that simply set\n"
588              "the filter of the current view. The -d option allows you to write a\n"
589              "filter expression that will be dynamically created by owl and then\n"
590              "applied as the view's filter\n"
591              "SEE ALSO: filter, viewclass, viewuser\n"),
592
593  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
594              "view only messages similar to the current message",
595              "smartnarrow [-i | --instance]  [-r | --relatde]",
596              "If the curmsg is a personal message narrow\n"
597              "   to the conversation with that user.\n"
598              "If the curmsg is a <MESSAGE, foo, *>\n"
599              "   message, narrow to the instance.\n"
600              "If the curmsg is a class message, narrow\n"
601              "    to the class.\n"
602              "If the curmsg is a class message and '-i' is specified\n"
603              "    then narrow to the class and instance.\n"
604              "If '-r' or '--related' is specified, behave as though the\n"
605              "    'narrow-related' variable was inverted."),
606
607  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
608              "returns the name of a filter based on the current message",
609              "smartfilter [-i | --instance]",
610              "If the curmsg is a personal message, the filter is\n"
611              "   the conversation with that user.\n"
612              "If the curmsg is a <MESSAGE, foo, *>\n"
613              "   message, the filter is to that instance.\n"
614              "If the curmsg is a class message, the filter is that class.\n"
615              "If the curmsg is a class message and '-i' is specied\n"
616              "    the filter is to that class and instance.\n"),
617
618  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
619              "view messages matching a particular class",
620              "viewclass <class>",
621              "The viewclass command will automatically create a filter\n"
622              "matching the specified class and switch the current view\n"
623              "to it.\n\n"
624              "SEE ALSO: filter, view, viewuser\n"),
625  OWLCMD_ALIAS("vc", "viewclass"),
626
627  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
628              "view messages matching a particular user",
629              "viewuser <user>",
630              "The viewuser command will automatically create a filter\n"
631              "matching the specified user and switch the current\n"
632              "view to it.\n\n"
633              "SEE ALSO: filter, view, viewclass\n"),
634  OWLCMD_ALIAS("vu", "viewuser"),
635
636  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
637              "show information",
638              "show colors\n"
639              "show commands\n"
640              "show command <command>\n"
641              "show errors\n"
642              "show filters\n"
643              "show filter <filter>\n"
644              "show keymaps\n"
645              "show keymap <keymap>\n"
646              "show license\n"
647              "show quickstart\n"
648              "show startup\n"
649              "show status\n"
650              "show styles\n"
651              "show subscriptions / show subs\n"
652              "show terminal\n"
653              "show variables\n"
654              "show variable <variable>\n"
655              "show version\n"
656              "show view [<view>]\n"
657              "show zpunts\n",
658
659              "Show colors will display a list of valid colors for the\n"
660              "     terminal."
661              "Show filters will list the names of all filters.\n"
662              "Show filter <filter> will show the definition of a particular\n"
663              "     filter.\n\n"
664              "Show startup will display the custom startup config\n\n"
665              "Show zpunts will show the active zpunt filters.\n\n"
666              "Show keymaps will list the names of all keymaps.\n"
667              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
668              "Show commands will list the names of all keymaps.\n"
669              "Show command <command> will provide information about a command.\n\n"
670              "Show styles will list the names of all styles available\n"
671              "for formatting messages.\n\n"
672              "Show variables will list the names of all variables.\n\n"
673              "Show errors will show a list of errors ecountered by Owl.\n\n"
674              "SEE ALSO: filter, view, alias, bindkey, help\n"),
675 
676  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
677              "mark a message for deletion",
678              "delete [ -id msgid ] [ --no-move ]\n"
679              "delete view\n"
680              "delete trash",
681              "If no message id is specified the current message is marked\n"
682              "for deletion.  Otherwise the message with the given message\n"
683              "id is marked for deletion.\n"
684              "If '--no-move' is specified, don't move after deletion.\n"
685              "If 'trash' is specified, deletes all trash/auto messages\n"
686              "in the current view.\n"
687              "If 'view' is specified, deletes all messages in the\n"
688              "current view.\n"),
689  OWLCMD_ALIAS("del", "delete"),
690
691  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
692              "unmark a message for deletion",
693              "undelete [ -id msgid ] [ --no-move ]\n"
694              "undelete view",
695              "If no message id is specified the current message is\n"
696              "unmarked for deletion.  Otherwise the message with the\n"
697              "given message id is unmarked for deletion.\n"
698              "If '--no-move' is specified, don't move after deletion.\n"
699              "If 'view' is specified, undeletes all messages\n"
700              "in the current view.\n"),
701  OWLCMD_ALIAS("undel", "undelete"),
702
703  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
704              "ring the terminal bell",
705              "beep",
706              "Beep will ring the terminal bell.\n"
707              "If the variable 'bell' has been\n"
708              "set to 'off' this command does nothing.\n"),
709
710  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
711              "prints a message into the debug log",
712              "debug <message>", ""),
713
714  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
715              "returns the name of the filter for the current view",
716              "", ""),
717
718  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
719              "returns the value of a variable",
720              "getvar <varname>", ""),
721
722  OWLCMD_ARGS("getfilter", owl_command_getfilter, OWL_CTX_INTERACTIVE,
723              "returns the definition of a filter",
724              "getfilter <filtername>", ""),
725
726  OWLCMD_ARGS("getstyle", owl_command_getstyle, OWL_CTX_INTERACTIVE,
727              "returns the name of the style for the current view",
728              "", ""),
729
730  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
731              "search messages for a particular string",
732              "search [-r] [<string>]",
733              "The search command will find messages that contain the\n"
734              "specified string and move the cursor there.  If no string\n"
735              "argument is supplied then the previous one is used.  By\n"
736              "default searches are done forwards; if -r is used the search\n"
737              "is performed backwards"),
738
739  OWLCMD_ARGS("setsearch", owl_command_setsearch, OWL_CTX_INTERACTIVE,
740              "set the search highlight string without searching",
741              "setsearch <string>",
742              "The setsearch command highlights all occurences of its\n"
743          "argument and makes it the default argument for future\n"
744          "search commands, but does not move the cursor.  With\n"
745          "no argument, it makes search highlighting inactive."),
746
747  OWLCMD_ARGS("aimlogin", owl_command_aimlogin, OWL_CTX_ANY,
748              "login to an AIM account",
749              "aimlogin <screenname> [<password>]\n",
750              ""),
751
752  OWLCMD_ARGS("aimlogout", owl_command_aimlogout, OWL_CTX_ANY,
753              "logout from AIM",
754              "aimlogout\n",
755              ""),
756
757  OWLCMD_ARGS("error", owl_command_error, OWL_CTX_ANY,
758              "Display an error message",
759              "error <message>",
760              ""),
761
762  OWLCMD_ARGS("message", owl_command_message, OWL_CTX_ANY,
763              "Display an informative message",
764              "message <message>",
765              ""),
766
767  OWLCMD_VOID("yes", owl_command_yes, OWL_CTX_RECV,
768              "Answer yes to a question",
769              "yes",
770              ""),
771
772  OWLCMD_VOID("no", owl_command_no, OWL_CTX_RECV,
773              "Answer no to a question",
774              "no",
775              ""),
776
777  /****************************************************************/
778  /************************* EDIT-SPECIFIC ************************/
779  /****************************************************************/
780
781  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
782                  OWL_CTX_EDIT,
783                  "moves cursor forward a word",
784                  "", ""),
785
786  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
787                  OWL_CTX_EDIT,
788                  "moves cursor backwards a word",
789                  "", ""),
790
791  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
792                  OWL_CTX_EDIT,
793                  "moves cursor to the top left (start) of the buffer",
794                  "", ""),
795
796  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
797                  OWL_CTX_EDIT,
798                  "moves cursor to the bottom right (end) of the buffer",
799                  "", ""),
800
801  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
802                  OWL_CTX_EDIT,
803                  "moves cursor to the end of the line",
804                  "", ""),
805
806  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
807                  OWL_CTX_EDIT,
808                  "moves cursor to the beginning of the line",
809                  "", ""),
810
811  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
812                  OWL_CTX_EDIT,
813                  "moves the cursor left by a character",
814                  "", ""),
815
816  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
817                  OWL_CTX_EDIT,
818                  "moves the cursor right by a character",
819                  "", ""),
820
821  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
822                  OWL_CTX_EDIT,
823                  "deletes the word to the right of the cursor",
824                  "", ""),
825
826  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
827                  OWL_CTX_EDIT,
828                  "deletes the word to the left of the cursor",
829                  "", ""),
830
831  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
832                  OWL_CTX_EDIT,
833                  "deletes the character to the left of the cursor",
834                  "", ""),
835
836  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
837                  OWL_CTX_EDIT,
838                  "deletes the character to the right of the cursor",
839                  "", ""),
840
841  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
842                  OWL_CTX_EDIT,
843                  "deletes from the cursor to the end of the line",
844                  "", ""),
845
846  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
847                  OWL_CTX_EDIT,
848                  "deletes all of the contents of the buffer",
849                  "", ""),
850
851  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
852                  OWL_CTX_EDIT,
853                  "Interchange characters around point, moving forward one character.",
854                  "", ""),
855
856  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
857                  OWL_CTX_EDIT,
858                  "fills the current paragraph to line-wrap well",
859                  "", ""),
860
861  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
862                  OWL_CTX_EDIT,
863                  "recenters the buffer",
864                  "", ""),
865
866  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
867                  OWL_CTX_EDIT,
868                  "inserts text into the buffer",
869                  "edit:insert-text <text>", ""),
870
871  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
872                  OWL_CTX_EDIT,
873                  "cancels the current command",
874                  "", ""),
875
876  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
877                  OWL_CTX_EDIT,
878                  "replaces the text with the next history",
879                  "", ""),
880
881  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
882                  OWL_CTX_EDIT,
883                  "replaces the text with the previous history",
884                  "", ""),
885
886  OWLCMD_VOID_CTX("edit:set-mark", owl_editwin_set_mark,
887                  OWL_CTX_EDIT,
888                  "sets the mark",
889                  "", ""),
890
891  OWLCMD_VOID_CTX("edit:exchange-point-and-mark", owl_editwin_exchange_point_and_mark,
892                  OWL_CTX_EDIT,
893                  "exchanges the point and the mark",
894                  "", ""),
895
896  OWLCMD_VOID_CTX("edit:copy-region-as-kill", owl_editwin_copy_region_as_kill,
897                  OWL_CTX_EDIT,
898                  "copy the text between the point and the mark",
899                  "", ""),
900
901  OWLCMD_VOID_CTX("edit:kill-region", owl_editwin_kill_region,
902                  OWL_CTX_EDIT,
903                  "kill text between the point and the mark",
904                  "", ""),
905
906  OWLCMD_VOID_CTX("edit:yank", owl_editwin_yank,
907                  OWL_CTX_EDIT,
908                  "insert the current text from the kill buffer",
909                  "", ""),
910
911  OWLCMD_ALIAS   ("editline:done", "edit:done"),
912  OWLCMD_ALIAS   ("editresponse:done", "edit:done"),
913
914  OWLCMD_VOID_CTX("edit:move-up-line", owl_editwin_key_up, 
915                  OWL_CTX_EDITMULTI,
916                  "moves the cursor up one line",
917                  "", ""),
918
919  OWLCMD_VOID_CTX("edit:move-down-line", owl_editwin_key_down, 
920                  OWL_CTX_EDITMULTI,
921                  "moves the cursor down one line",
922                  "", ""),
923
924  OWLCMD_VOID_CTX("edit:done", owl_command_edit_done, 
925                  OWL_CTX_EDIT,
926                  "Finishes entering text in the editwin.",
927                  "", ""),
928
929  OWLCMD_VOID_CTX("edit:done-or-delete", owl_command_edit_done_or_delete, 
930                  OWL_CTX_EDITMULTI,
931                  "completes the command, but only if at end of message",
932                  "", 
933                  "If only whitespace is to the right of the cursor,\n"
934                  "runs 'edit:done'.\n"\
935                  "Otherwise runs 'edit:delete-next-char'\n"),
936
937  OWLCMD_VOID_CTX("edit:forward-paragraph", owl_editwin_forward_paragraph,
938                  OWL_CTX_EDITMULTI,
939                  "Move forward to end of paragraph.",
940                  "",
941                  "Move the point to the end of the current paragraph"),
942
943  OWLCMD_VOID_CTX("edit:backward-paragraph", owl_editwin_backward_paragraph,
944                  OWL_CTX_EDITMULTI,
945                  "Move backward to the start of paragraph.",
946                  "",
947                  "Move the point to the start of the current paragraph"),
948
949  /****************************************************************/
950  /********************** POPLESS-SPECIFIC ************************/
951  /****************************************************************/
952
953  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
954                  OWL_CTX_POPLESS,
955                  "scrolls down one page",
956                  "", ""),
957
958  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
959                  OWL_CTX_POPLESS,
960                  "scrolls down one line",
961                  "", ""),
962
963  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
964                  OWL_CTX_POPLESS,
965                  "scrolls up one page",
966                  "", ""),
967
968  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
969                  OWL_CTX_POPLESS,
970                  "scrolls up one line",
971                  "", ""),
972
973  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
974                  OWL_CTX_POPLESS,
975                  "scrolls to the top of the buffer",
976                  "", ""),
977
978  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
979                  OWL_CTX_POPLESS,
980                  "scrolls to the bottom of the buffer",
981                  "", ""),
982
983  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
984                  OWL_CTX_POPLESS,
985                  "scrolls right in the buffer",
986                  "popless:scroll-right <num-chars>", ""),
987
988  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
989                  OWL_CTX_POPLESS,
990                  "scrolls left in the buffer",
991                  "popless:scroll-left <num-chars>", ""),
992
993  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
994                  OWL_CTX_POPLESS,
995                  "exits the popless window",
996                  "", ""),
997
998  OWLCMD_ALIAS("webzephyr", "zwrite daemon.webzephyr -c webzephyr -i"),
999
1000  /* This line MUST be last! */
1001  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1002
1003};
1004
1005void owl_command_info(void)
1006{
1007  owl_function_info();
1008}
1009
1010void owl_command_nop(void)
1011{
1012}
1013
1014char *owl_command_help(int argc, const char *const *argv, const char *buff)
1015{
1016  if (argc!=2) {
1017    owl_help();
1018    return NULL;
1019  }
1020 
1021  owl_function_help_for_command(argv[1]);
1022  return NULL;
1023}
1024
1025char *owl_command_zlist(int argc, const char *const *argv, const char *buff)
1026{
1027  const char *file=NULL;
1028
1029  argc--;
1030  argv++;
1031  while (argc) {
1032    if (!strcmp(argv[0], "-f")) {
1033      if (argc==1) {
1034        owl_function_makemsg("zlist: -f needs an argument");
1035        return(NULL);
1036      }
1037      file=argv[1];
1038      argc-=2;
1039      argv+=2;
1040    } else {
1041      owl_function_makemsg("zlist: unknown argument");
1042      return(NULL);
1043    }
1044  }
1045  owl_function_buddylist(0, 1, file);
1046  return(NULL);
1047}
1048
1049void owl_command_alist(void)
1050{
1051  owl_function_buddylist(1, 0, NULL);
1052}
1053
1054void owl_command_blist(void)
1055{
1056  owl_function_buddylist(1, 1, NULL);
1057}
1058
1059void owl_command_toggleoneline(void)
1060{
1061  owl_function_toggleoneline();
1062}
1063
1064void owl_command_about(void)
1065{
1066  owl_function_about();
1067}
1068
1069void owl_command_version(void)
1070{
1071  owl_function_makemsg("BarnOwl version %s", OWL_VERSION_STRING);
1072}
1073
1074char *owl_command_aim(int argc, const char *const *argv, const char *buff)
1075{
1076  if (argc<2) {
1077    owl_function_makemsg("not enough arguments to aim command");
1078    return(NULL);
1079  }
1080
1081  if (!strcmp(argv[1], "search")) {
1082    if (argc!=3) {
1083      owl_function_makemsg("not enough arguments to aim search command");
1084      return(NULL);
1085    }
1086    owl_aim_search(argv[2]);
1087  } else {
1088    owl_function_makemsg("unknown subcommand '%s' for aim command", argv[1]);
1089    return(NULL);
1090  }
1091  return(NULL);
1092}
1093
1094char *owl_command_addbuddy(int argc, const char *const *argv, const char *buff)
1095{
1096  if (argc!=3) {
1097    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1098    return(NULL);
1099  }
1100
1101  if (!strcasecmp(argv[1], "aim")) {
1102    if (!owl_global_is_aimloggedin(&g)) {
1103      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
1104      return(NULL);
1105    }
1106    /*
1107    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
1108    return(NULL);
1109    */
1110    owl_aim_addbuddy(argv[2]);
1111    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1112  } else if (!strcasecmp(argv[1], "zephyr")) {
1113    owl_zephyr_addbuddy(argv[2]);
1114    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1115  } else {
1116    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1117  }
1118
1119  return(NULL);
1120}
1121
1122char *owl_command_delbuddy(int argc, const char *const *argv, const char *buff)
1123{
1124  if (argc!=3) {
1125    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1126    return(NULL);
1127  }
1128
1129  if (!strcasecmp(argv[1], "aim")) {
1130    if (!owl_global_is_aimloggedin(&g)) {
1131      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
1132      return(NULL);
1133    }
1134    owl_aim_delbuddy(argv[2]);
1135    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1136  } else if (!strcasecmp(argv[1], "zephyr")) {
1137    owl_zephyr_delbuddy(argv[2]);
1138    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1139  } else {
1140    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1141  }
1142
1143  return(NULL);
1144}
1145
1146char *owl_command_join(int argc, const char *const *argv, const char *buff)
1147{
1148  if (argc!=3 && argc!=4) {
1149    owl_function_makemsg("usage: join <protocol> <buddyname> [exchange]");
1150    return(NULL);
1151  }
1152
1153  if (!strcasecmp(argv[1], "aim")) {
1154    if (!owl_global_is_aimloggedin(&g)) {
1155      owl_function_makemsg("join aim: You must be logged into aim to use this command.");
1156      return(NULL);
1157    }
1158    if (argc==3) {
1159      owl_aim_chat_join(argv[2], 4);
1160    } else {
1161      owl_aim_chat_join(argv[2], atoi(argv[3]));
1162    }
1163    /* owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g)); */
1164  } else {
1165    owl_function_makemsg("join: currently the only supported protocol is 'aim'");
1166  }
1167  return(NULL);
1168}
1169
1170char *owl_command_startup(int argc, const char *const *argv, const char *buff)
1171{
1172  const char *ptr;
1173
1174  if (argc<2) {
1175    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1176    return(NULL);
1177  }
1178
1179  ptr = skiptokens(buff, 1);
1180
1181  owl_function_command(ptr);
1182  owl_function_addstartup(ptr);
1183
1184  return(NULL);
1185}
1186
1187char *owl_command_unstartup(int argc, const char *const *argv, const char *buff)
1188{
1189  const char *ptr;
1190
1191  if (argc<2) {
1192    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1193    return(NULL);
1194  }
1195
1196  ptr = skiptokens(buff, 1);
1197
1198  owl_function_delstartup(ptr);
1199
1200  return(NULL);
1201}
1202
1203char *owl_command_dump(int argc, const char *const *argv, const char *buff)
1204{
1205  char *filename;
1206 
1207  if (argc!=2) {
1208    owl_function_makemsg("usage: dump <filename>");
1209    return(NULL);
1210  }
1211  filename=owl_util_makepath(argv[1]);
1212  owl_function_dump(filename);
1213  owl_free(filename);
1214  return(NULL);
1215}
1216
1217char *owl_command_source(int argc, const char *const *argv, const char *buff)
1218{
1219  if (argc!=2) {
1220    owl_function_makemsg("usage: source <filename>");
1221    return(NULL);
1222  }
1223
1224  owl_function_source(argv[1]);
1225  return(NULL);
1226}
1227
1228char *owl_command_next(int argc, const char *const *argv, const char *buff)
1229{
1230  char *filter=NULL;
1231  int skip_deleted=0, last_if_none=0;
1232  while (argc>1) {
1233    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1234      skip_deleted=1;
1235      argc-=1; argv+=1; 
1236    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1237      last_if_none=1;
1238      argc-=1; argv+=1; 
1239    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1240      filter = owl_strdup(argv[2]);
1241      argc-=2; argv+=2; 
1242    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1243      filter = owl_function_smartfilter(0, 0);
1244      argc-=2; argv+=2; 
1245    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1246      filter = owl_function_smartfilter(1, 0);
1247      argc-=2; argv+=2; 
1248    } else {
1249      owl_function_makemsg("Invalid arguments to command 'next'.");
1250      return(NULL);
1251    }
1252  }
1253  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1254  if (filter) owl_free(filter);
1255  return(NULL);
1256}
1257
1258char *owl_command_prev(int argc, const char *const *argv, const char *buff)
1259{
1260  char *filter=NULL;
1261  int skip_deleted=0, first_if_none=0;
1262  while (argc>1) {
1263    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1264      skip_deleted=1;
1265      argc-=1; argv+=1; 
1266    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1267      first_if_none=1;
1268      argc-=1; argv+=1; 
1269    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1270      filter = owl_strdup(argv[2]);
1271      argc-=2; argv+=2; 
1272    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1273      filter = owl_function_smartfilter(0, 0);
1274      argc-=2; argv+=2; 
1275    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1276      filter = owl_function_smartfilter(1, 0);
1277      argc-=2; argv+=2; 
1278   } else {
1279      owl_function_makemsg("Invalid arguments to command 'prev'.");
1280      return(NULL);
1281    }
1282  }
1283  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1284  if (filter) owl_free(filter);
1285  return(NULL);
1286}
1287
1288char *owl_command_smartnarrow(int argc, const char *const *argv, const char *buff)
1289{
1290  char *filtname = NULL;
1291
1292  char opt;
1293  int instance = 0, related = 0, i;
1294  char **tmp_argv = owl_malloc(sizeof(char *) * argc);
1295
1296  for (i = 0; i < argc; i++)
1297    tmp_argv[i] = owl_strdup(argv[i]);
1298
1299  static struct option options[] = {
1300    {"instance", 0, 0, 'i'},
1301    {"related",  0, 0, 'r'},
1302    {NULL,       0, 0, 0}};
1303  while ((opt = getopt_long(argc, tmp_argv, "ir", options, NULL)) != -1) {
1304    switch (opt) {
1305      case 'i':
1306        instance = 1;
1307        break;
1308      case 'r':
1309        related = 1;
1310        break;
1311      default:
1312        owl_function_makemsg("Wrong number of arguments for %s (%c)", argv[0], opt);
1313        goto done;
1314    }
1315  }
1316
1317  for (i = 0; i < argc; i++)
1318    owl_free(tmp_argv[i]);
1319  owl_free(tmp_argv);
1320
1321  filtname = owl_function_smartfilter(instance, related);
1322
1323  if (filtname) {
1324    owl_function_change_currentview_filter(filtname);
1325    owl_free(filtname);
1326  }
1327
1328done:
1329  optind = 0; /* reset getopt */
1330  return NULL;
1331}
1332
1333char *owl_command_smartfilter(int argc, const char *const *argv, const char *buff)
1334{
1335  char *filtname = NULL;
1336
1337  if (argc == 1) {
1338    filtname = owl_function_smartfilter(0, 0);
1339  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1340    filtname = owl_function_smartfilter(1, 0);
1341  } else {
1342    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1343  }
1344  return filtname;
1345}
1346
1347void owl_command_expunge(void)
1348{
1349  owl_function_expunge();
1350}
1351
1352void owl_command_first(void)
1353{
1354  owl_global_set_rightshift(&g, 0);
1355  owl_function_firstmsg();
1356}
1357
1358void owl_command_last(void)
1359{
1360  owl_function_lastmsg();
1361}
1362
1363void owl_command_resize(void)
1364{
1365  owl_function_resize();
1366}
1367
1368void owl_command_redisplay(void)
1369{
1370  owl_function_full_redisplay();
1371  owl_global_set_needrefresh(&g);
1372}
1373
1374char *owl_command_get_shift(int argc, const char *const *argv, const char *buff)
1375{
1376  if(argc != 1)
1377  {
1378    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1379    return NULL;
1380  }
1381  return owl_sprintf("%d", owl_global_get_rightshift(&g));
1382}
1383
1384void owl_command_set_shift(int shift)
1385{
1386  owl_global_set_rightshift(&g, shift);
1387  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1388  owl_global_set_needrefresh(&g);
1389}
1390
1391void owl_command_unsuball(void)
1392{
1393  owl_function_unsuball();
1394}
1395
1396char *owl_command_loadsubs(int argc, const char *const *argv, const char *buff)
1397{
1398  if (argc == 2) {
1399    owl_function_loadsubs(argv[1]);
1400  } else if (argc == 1) {
1401    owl_function_loadsubs(NULL);
1402  } else {
1403    owl_function_makemsg("Wrong number of arguments for load-subs.");
1404    return(NULL);
1405  }
1406  return(NULL);
1407}
1408
1409
1410char *owl_command_loadloginsubs(int argc, const char *const *argv, const char *buff)
1411{
1412  if (argc == 2) {
1413    owl_function_loadloginsubs(argv[1]);
1414  } else if (argc == 1) {
1415    owl_function_loadloginsubs(NULL);
1416  } else {
1417    owl_function_makemsg("Wrong number of arguments for load-subs.");
1418    return(NULL);
1419  }
1420  return(NULL);
1421}
1422
1423void owl_command_suspend(void)
1424{
1425  owl_function_suspend();
1426}
1427
1428char *owl_command_start_command(int argc, const char *const *argv, const char *buff)
1429{
1430  buff = skiptokens(buff, 1);
1431  owl_function_start_command(buff);
1432  return(NULL);
1433}
1434
1435char *owl_command_zaway(int argc, const char *const *argv, const char *buff)
1436{
1437  if ((argc==1) ||
1438      ((argc==2) && !strcmp(argv[1], "on"))) {
1439    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1440    owl_function_zaway_on();
1441    return NULL;
1442  }
1443
1444  if (argc==2 && !strcmp(argv[1], "off")) {
1445    owl_function_zaway_off();
1446    return NULL;
1447  }
1448
1449  if (argc==2 && !strcmp(argv[1], "toggle")) {
1450    owl_function_zaway_toggle();
1451    return NULL;
1452  }
1453
1454  buff = skiptokens(buff, 1);
1455  owl_global_set_zaway_msg(&g, buff);
1456  owl_function_zaway_on();
1457  return NULL;
1458}
1459
1460
1461char *owl_command_aaway(int argc, const char *const *argv, const char *buff)
1462{
1463  if ((argc==1) ||
1464      ((argc==2) && !strcmp(argv[1], "on"))) {
1465    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1466    owl_function_aaway_on();
1467    return NULL;
1468  }
1469
1470  if (argc==2 && !strcmp(argv[1], "off")) {
1471    owl_function_aaway_off();
1472    return NULL;
1473  }
1474
1475  if (argc==2 && !strcmp(argv[1], "toggle")) {
1476    owl_function_aaway_toggle();
1477    return NULL;
1478  }
1479
1480  buff = skiptokens(buff, 1);
1481  owl_global_set_aaway_msg(&g, buff);
1482  owl_function_aaway_on();
1483  return NULL;
1484}
1485
1486
1487char *owl_command_away(int argc, const char *const *argv, const char *buff)
1488{
1489  if ((argc==1) ||
1490      ((argc==2) && !strcmp(argv[1], "on"))) {
1491    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1492    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1493    owl_function_aaway_on();
1494    owl_function_zaway_on();
1495    owl_function_makemsg("Away messages set.");
1496    return NULL;
1497  }
1498
1499  if (argc==2 && !strcmp(argv[1], "off")) {
1500    owl_function_aaway_off();
1501    owl_function_zaway_off();
1502    return NULL;
1503  }
1504
1505  if (argc==2 && !strcmp(argv[1], "toggle")) {
1506    /* if either one is on, turn it off, otherwise toggle both (turn
1507     *  them both on)
1508     */
1509    if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
1510      owl_function_aaway_toggle();
1511      owl_function_zaway_toggle();
1512      owl_function_makemsg("Away messages set.");
1513    } else {
1514      if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
1515      if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
1516      owl_function_makemsg("Away messages off.");
1517    }
1518    return NULL;
1519  }
1520
1521  buff = skiptokens(buff, 1);
1522  owl_global_set_aaway_msg(&g, buff);
1523  owl_global_set_zaway_msg(&g, buff);
1524  owl_function_aaway_on();
1525  owl_function_zaway_on();
1526  owl_function_makemsg("Away messages set.");
1527  return NULL;
1528}
1529
1530char *owl_command_set(int argc, const char *const *argv, const char *buff)
1531{
1532  const char *var, *val;
1533  int  silent=0;
1534  int requirebool=0;
1535
1536  if (argc == 1) {
1537    owl_function_printallvars();
1538    return NULL;
1539  } 
1540
1541  if (argc > 1 && !strcmp("-q",argv[1])) {
1542    silent = 1;
1543    argc--; argv++;
1544  }
1545
1546  if (argc == 2) {
1547    var=argv[1];
1548    val="on";
1549    requirebool=1;
1550  } else if (argc == 3) {
1551    var=argv[1];
1552    val=argv[2];
1553  } else {
1554    owl_function_makemsg("Wrong number of arguments for set command");
1555    return NULL;
1556  }
1557  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1558  return NULL;
1559}
1560
1561char *owl_command_unset(int argc, const char *const *argv, const char *buff)
1562{
1563  const char *var, *val;
1564  int  silent=0;
1565
1566  if (argc > 1 && !strcmp("-q",argv[1])) {
1567    silent = 1;
1568    argc--; argv++;
1569  }
1570  if (argc == 2) {
1571    var=argv[1];
1572    val="off";
1573  } else {
1574    owl_function_makemsg("Wrong number of arguments for unset command");
1575    return NULL;
1576  }
1577  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1578  return NULL;
1579}
1580
1581char *owl_command_print(int argc, const char *const *argv, const char *buff)
1582{
1583  const char *var;
1584  char valbuff[1024];
1585
1586  if (argc==1) {
1587    owl_function_printallvars();
1588    return NULL;
1589  } else if (argc!=2) {
1590    owl_function_makemsg("Wrong number of arguments for print command");
1591    return NULL;
1592  }
1593
1594  var=argv[1];
1595   
1596  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1597                                     var, valbuff, 1024)) {
1598    owl_function_makemsg("%s = '%s'", var, valbuff);
1599  } else {
1600    owl_function_makemsg("Unknown variable '%s'.", var);
1601  }
1602  return NULL;
1603}
1604
1605
1606char *owl_command_exec(int argc, const char *const *argv, const char *buff)
1607{
1608  return owl_function_exec(argc, argv, buff, 0);
1609}
1610
1611char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
1612{
1613  return owl_function_exec(argc, argv, buff, 1);
1614}
1615
1616char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
1617{
1618  return owl_function_exec(argc, argv, buff, 2);
1619}
1620
1621char *owl_command_perl(int argc, const char *const *argv, const char *buff)
1622{
1623  return owl_function_perl(argc, argv, buff, 0);
1624}
1625
1626char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
1627{
1628  return owl_function_perl(argc, argv, buff, 1);
1629}
1630
1631char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
1632{
1633  return owl_function_perl(argc, argv, buff, 2);
1634}
1635
1636char *owl_command_multi(int argc, const char *const *argv, const char *buff)
1637{
1638  char *lastrv = NULL, *newbuff;
1639  char **commands;
1640  int  ncommands, i;
1641  if (argc < 2) {
1642    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1643    return NULL;
1644  }
1645  newbuff = owl_strdup(skiptokens(buff, 1));
1646  if (!strcmp(argv[0], "(")) {
1647    for (i=strlen(newbuff)-1; i>=0; i--) {
1648      if (newbuff[i] == ')') {
1649        newbuff[i] = '\0';
1650        break;
1651      } else if (newbuff[i] != ' ') {
1652        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1653        owl_free(newbuff);
1654        return NULL;
1655      }
1656    }
1657  }
1658  commands = atokenize(newbuff, ";", &ncommands);
1659  for (i=0; i<ncommands; i++) {
1660    if (lastrv) {
1661      owl_free(lastrv);
1662    }
1663    lastrv = owl_function_command(commands[i]);
1664  }
1665  owl_free(newbuff);
1666  atokenize_delete(commands, ncommands);
1667  return lastrv;
1668}
1669
1670
1671char *owl_command_alias(int argc, const char *const *argv, const char *buff)
1672{
1673  if (argc < 3) {
1674    owl_function_makemsg("Invalid arguments to 'alias' command.");
1675    return NULL;
1676  }
1677  buff = skiptokens(buff, 2);
1678  owl_function_command_alias(argv[1], buff);
1679  return (NULL);
1680}
1681
1682
1683char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
1684{
1685  owl_keymap *km;
1686  int ret;
1687
1688  if (argc < 5 || strcmp(argv[3], "command")) {
1689    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1690    return NULL;
1691  }
1692  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1693  if (!km) {
1694    owl_function_makemsg("No such keymap '%s'", argv[1]);
1695    return NULL;
1696  }
1697  buff = skiptokens(buff, 4);
1698  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1699  if (ret!=0) {
1700    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1701                         argv[2], argv[1], buff);
1702    return NULL;
1703  }
1704  return NULL;
1705}
1706
1707
1708char *owl_command_unbindkey(int argc, const char *const *argv, const char *buf)
1709{
1710  owl_keymap *km;
1711  int ret;
1712
1713  if (argc < 3) {
1714    owl_function_makemsg("Usage: bindkey <keymap> <binding>");
1715    return NULL;
1716  }
1717  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1718  if (!km) {
1719    owl_function_makemsg("No such keymap '%s'", argv[1]);
1720    return NULL;
1721  }
1722  ret = owl_keymap_remove_binding(km, argv[2]);
1723  if (ret == -1) {
1724    owl_function_makemsg("Unable to unbind '%s' in keymap '%s'.",
1725                         argv[2], argv[1]);
1726    return NULL;
1727  } else if (ret == -2) {
1728    owl_function_makemsg("No such binding '%s' in keymap '%s'.",
1729                         argv[2], argv[1]);
1730  }
1731  return NULL;
1732}
1733
1734
1735void owl_command_quit(void)
1736{
1737  owl_function_quit();
1738}
1739
1740char *owl_command_debug(int argc, const char *const *argv, const char *buff)
1741{
1742  if (argc<2) {
1743    owl_function_makemsg("Need at least one argument to debug command");
1744    return(NULL);
1745  }
1746
1747  if (!owl_global_is_debug_fast(&g)) {
1748    owl_function_makemsg("Debugging is not turned on");
1749    return(NULL);
1750  }
1751
1752  owl_function_debugmsg("%s", argv[1]);
1753  return(NULL);
1754}
1755
1756char *owl_command_term(int argc, const char *const *argv, const char *buff)
1757{
1758  if (argc<2) {
1759    owl_function_makemsg("Need at least one argument to the term command");
1760    return(NULL);
1761  }
1762
1763  if (!strcmp(argv[1], "raise")) {
1764    owl_function_xterm_raise();
1765  } else if (!strcmp(argv[1], "deiconify")) {
1766    owl_function_xterm_deiconify();
1767  } else {
1768    owl_function_makemsg("Unknown terminal subcommand");
1769  }
1770  return(NULL);
1771}
1772
1773char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
1774{
1775  if ((argc<2) || (argc>3)) {
1776    owl_function_makemsg("Wrong number of arguments for zlog command");
1777    return(NULL);
1778  }
1779
1780  if (!strcmp(argv[1], "in")) {
1781    if (argc>2) {
1782      owl_global_set_tty(&g, argv[2]);
1783    }
1784    owl_zephyr_zlog_in();
1785  } else if (!strcmp(argv[1], "out")) {
1786    if (argc!=2) {
1787      owl_function_makemsg("Wrong number of arguments for zlog command");
1788      return(NULL);
1789    }
1790    owl_zephyr_zlog_out();
1791  } else {
1792    owl_function_makemsg("Invalid subcommand for zlog");
1793  }
1794  return(NULL);
1795}
1796
1797char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
1798{
1799  const char *class, *instance, *recip="";
1800  int temp=0;
1801  int ret=0;
1802
1803  if (argc < 2) {
1804    owl_function_makemsg("Not enough arguments to the subscribe command");
1805    return(NULL);
1806  }
1807  argc--;
1808  argv++;
1809
1810  if (!strcmp(argv[0], "-t")) {
1811    temp=1;
1812    argc--;
1813    argv++;
1814  }
1815  if (argc < 1) {
1816    owl_function_makemsg("Not enough arguments to the subscribe command");
1817    return(NULL);
1818  }
1819
1820  if (argc > 3) {
1821    owl_function_makemsg("Too many arguments to the subscribe command");
1822    return(NULL);
1823  }
1824
1825  class = argv[0];
1826
1827  if (argc == 1) {
1828    instance = "*";
1829  } else {
1830    instance = argv[1];
1831  }
1832
1833  if (argc <= 2) {
1834    recip="";
1835  } else if (argc==3) {
1836    recip=argv[2];
1837  }
1838
1839  ret = owl_function_subscribe(class, instance, recip);
1840  if (!temp && !ret) {
1841    owl_zephyr_addsub(NULL, class, instance, recip);
1842  }
1843  return(NULL);
1844}
1845
1846
1847char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
1848{
1849  const char *class, *instance, *recip="";
1850  int temp=0;
1851
1852  if (argc < 2) {
1853    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1854    return(NULL);
1855  }
1856  argc--;
1857  argv++;
1858
1859  if (!strcmp(argv[0], "-t")) {
1860    temp=1;
1861    argc--;
1862    argv++;
1863  }
1864  if (argc < 1) {
1865    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1866    return(NULL);
1867  }
1868
1869  if (argc > 3) {
1870    owl_function_makemsg("Too many arguments to the unsubscribe command");
1871    return(NULL);
1872  }
1873
1874  class = argv[0];
1875
1876  if (argc == 1) {
1877    instance = "*";
1878  } else {
1879    instance = argv[1];
1880  }
1881
1882  if (argc <= 2) {
1883    recip="";
1884  } else if (argc==3) {
1885    recip=argv[2];
1886  }
1887
1888  owl_function_unsubscribe(class, instance, recip);
1889  if (!temp) {
1890    owl_zephyr_delsub(NULL, class, instance, recip);
1891  }
1892  return(NULL);
1893}
1894
1895char *owl_command_echo(int argc, const char *const *argv, const char *buff)
1896{
1897  buff = skiptokens(buff, 1);
1898  owl_function_popless_text(buff);
1899  return NULL;
1900}
1901
1902void owl_command_getsubs(void)
1903{
1904  owl_function_getsubs();
1905}
1906
1907void owl_command_status(void)
1908{
1909  owl_function_status();
1910}
1911
1912char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
1913{
1914  owl_zwrite z;
1915
1916  if (!owl_global_is_havezephyr(&g)) {
1917    owl_function_makemsg("Zephyr is not available");
1918    return(NULL);
1919  }
1920  /* check for a zwrite -m */
1921  owl_zwrite_create_from_line(&z, buff);
1922  if (owl_zwrite_is_message_set(&z)) {
1923    owl_function_zwrite(buff, NULL);
1924    owl_zwrite_cleanup(&z);
1925    return (NULL);
1926  }
1927  owl_zwrite_cleanup(&z);
1928
1929  if (argc < 2) {
1930    owl_function_makemsg("Not enough arguments to the zwrite command.");
1931  } else {
1932    owl_function_zwrite_setup(buff);
1933  }
1934  return(NULL);
1935}
1936
1937char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
1938{
1939  char *newbuff, *recip;
1940  const char *const *myargv;
1941  int i, j, myargc;
1942  owl_message *m;
1943 
1944  if (!owl_global_is_aimloggedin(&g)) {
1945    owl_function_makemsg("You are not logged in to AIM.");
1946    return(NULL);
1947  }
1948
1949  if (argc < 2) {
1950    owl_function_makemsg("Not enough arguments to the aimwrite command.");
1951    return(NULL);
1952  }
1953
1954  myargv=argv;
1955  if (argc<0) {
1956    owl_function_error("Unbalanced quotes in aimwrite");
1957    return(NULL);
1958  }
1959  myargc=argc;
1960  if (myargc && *(myargv[0])!='-') {
1961    myargc--;
1962    myargv++;
1963  }
1964  while (myargc) {
1965    if (!strcmp(myargv[0], "-m")) {
1966      if (myargc<2) {
1967        break;
1968      }
1969
1970      /* Once we have -m, gobble up everything else on the line */
1971      myargv++;
1972      myargc--;
1973      newbuff=owl_strdup("");
1974      while (myargc) {
1975        newbuff=owl_realloc(newbuff, strlen(newbuff)+strlen(myargv[0])+5);
1976        strcat(newbuff, myargv[0]);
1977        strcat(newbuff, " ");
1978        myargc--;
1979        myargv++;
1980      }
1981      if (strlen(newbuff) >= 1)
1982        newbuff[strlen(newbuff) - 1] = '\0'; /* remove last space */
1983
1984      recip=owl_strdup(argv[1]);
1985      owl_aim_send_im(recip, newbuff);
1986      m=owl_function_make_outgoing_aim(newbuff, recip);
1987      if (m) { 
1988          owl_global_messagequeue_addmsg(&g, m);
1989      } else {
1990          owl_function_error("Could not create outgoing AIM message");
1991      }
1992
1993      owl_free(recip);
1994      owl_free(newbuff);
1995      return(NULL);
1996    } else {
1997      /* we don't care */
1998      myargv++;
1999      myargc--;
2000    }
2001  }
2002
2003  /* squish arguments together to make one screenname w/o spaces for now */
2004  newbuff=owl_malloc(strlen(buff)+5);
2005  sprintf(newbuff, "%s ", argv[0]);
2006  j=argc-1;
2007  for (i=0; i<j; i++) {
2008    strcat(newbuff, argv[i+1]);
2009  }
2010   
2011  owl_function_aimwrite_setup(newbuff);
2012  owl_free(newbuff);
2013  return(NULL);
2014}
2015
2016char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
2017{
2018  owl_function_loopwrite_setup();
2019  return(NULL);
2020}
2021
2022char *owl_command_zcrypt(int argc, const char *const *argv, const char *buff)
2023{
2024  owl_zwrite z;
2025
2026  if (!owl_global_is_havezephyr(&g)) {
2027    owl_function_makemsg("Zephyr is not available");
2028    return(NULL);
2029  }
2030  /* check for a zcrypt -m */
2031  owl_zwrite_create_from_line(&z, buff);
2032  if (owl_zwrite_is_message_set(&z)) {
2033    owl_function_zcrypt(buff, NULL);
2034    owl_zwrite_cleanup(&z);
2035    return (NULL);
2036  }
2037  owl_zwrite_cleanup(&z);
2038
2039  if (argc < 2) {
2040    owl_function_makemsg("Not enough arguments to the zcrypt command.");
2041  } else {
2042    owl_function_zwrite_setup(buff);
2043  }
2044  return(NULL);
2045}
2046
2047char *owl_command_reply(int argc, const char *const *argv, const char *buff)
2048{
2049  int edit=0;
2050 
2051  if (argc>=2 && !strcmp("-e", argv[1])) {
2052    edit=1;
2053    argv++;
2054    argc--;
2055  }
2056
2057  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2058    owl_function_reply(0, !edit);
2059  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2060    owl_function_reply(1, !edit);
2061  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2062    const owl_message *m;
2063    const owl_view    *v;
2064    v = owl_global_get_current_view(&g);   
2065    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2066    if (m) owl_zephyr_zaway(m);
2067  } else {
2068    owl_function_makemsg("Invalid arguments to the reply command.");
2069  }
2070  return NULL;
2071}
2072
2073char *owl_command_filter(int argc, const char *const *argv, const char *buff)
2074{
2075  owl_function_create_filter(argc, argv);
2076  return NULL;
2077}
2078
2079char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
2080{
2081  int auth;
2082 
2083  if (argc<2) {
2084    owl_function_makemsg("Too few arguments for zlocate command");
2085    return NULL;
2086  }
2087
2088  auth=1;
2089  if (!strcmp(argv[1], "-d")) {
2090    if (argc>2) {
2091      auth=0;
2092      argc--;
2093      argv++;
2094    } else {
2095      owl_function_makemsg("Missing arguments for zlocate command");
2096      return NULL;
2097    }
2098  }
2099
2100  argc--;
2101  argv++;
2102  owl_function_zlocate(argc, argv, auth);
2103  return NULL;
2104}
2105
2106
2107/* Backwards compatability has made this kind of complicated:
2108 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2109 * view <filter>
2110 * view -d <expression>
2111 * view --home
2112 */
2113char *owl_command_view(int argc, const char *const *argv, const char *buff)
2114{
2115  /* First take the 'view --home' and 'view -r' cases */
2116  if (argc == 2) {
2117    if (!strcmp(argv[1], "--home")) {
2118      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2119      return(NULL);
2120    } else if (!strcmp(argv[1], "-r")) {
2121      char *foo;
2122      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2123      owl_function_change_currentview_filter(foo);
2124      owl_free(foo);
2125      return(NULL);
2126    }
2127  }
2128
2129  /* Now look for 'view <filter>' */
2130  if (argc==2) {
2131    owl_function_change_currentview_filter(argv[1]);
2132    return(NULL);
2133  }
2134
2135  /* Now get 'view -d <expression>' */
2136  if (argc>=3 && !strcmp(argv[1], "-d")) {
2137    const char **myargv;
2138    int i;
2139
2140    myargv=owl_malloc((argc*sizeof(const char *))+50);
2141    myargv[0]="";
2142    myargv[1]="owl-dynamic";
2143    for (i=2; i<argc; i++) {
2144      myargv[i]=argv[i];
2145    }
2146    owl_function_create_filter(argc, myargv);
2147    owl_function_change_currentview_filter("owl-dynamic");
2148    owl_free(myargv);
2149    return NULL;
2150  }
2151
2152  /* Finally handle the general case */
2153  if (argc<3) {
2154    owl_function_makemsg("Too few arguments to the view command.");
2155    return(NULL);
2156  }
2157  argc--;
2158  argv++;
2159  if (strcmp(argv[0], "-f") &&
2160      strcmp(argv[0], "-d") &&
2161      strcmp(argv[0], "--home") &&
2162      strcmp(argv[0], "-s") &&
2163      strcmp(argv[0], "-r")) {
2164    if (strcmp(argv[0], "main")) {
2165      owl_function_makemsg("No view named '%s'", argv[0]);
2166      return(NULL);
2167    }
2168    argc--;
2169    argv++;
2170  }
2171  while (argc) {
2172    if (!strcmp(argv[0], "-f")) {
2173      if (argc<2) {
2174        owl_function_makemsg("Too few argments to the view command");
2175        return(NULL);
2176      }
2177      owl_function_change_currentview_filter(argv[1]);
2178      argc-=2;
2179      argv+=2;
2180    } else if (!strcmp(argv[0], "--home")) {
2181      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2182      argc--;
2183      argv++;
2184    } else if (!strcmp(argv[0], "-r")) {
2185      const char *foo;
2186      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2187      owl_function_change_currentview_filter(foo);
2188    } else if (!strcmp(argv[0], "-s")) {
2189      if (argc<2) {
2190        owl_function_makemsg("Too few argments to the view command");
2191        return(NULL);
2192      }
2193      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2194      argc-=2;
2195      argv+=2;
2196    } else {
2197      owl_function_makemsg("Too few argments to the view command");
2198      return(NULL);
2199    }
2200   
2201  }
2202  return(NULL);
2203}
2204
2205char *owl_command_show(int argc, const char *const *argv, const char *buff)
2206{
2207  if (argc<2) {
2208    owl_function_help_for_command("show");
2209    return NULL;
2210  }
2211
2212  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2213    if (argc==2) {
2214      owl_function_show_filters();
2215    } else {
2216      owl_function_show_filter(argv[2]);
2217    }
2218  } else if (argc==2 
2219             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2220    owl_function_show_zpunts();
2221  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2222    if (argc==2) {
2223      owl_function_show_commands();
2224    } else {
2225      owl_function_show_command(argv[2]);
2226    }
2227  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2228    if (argc==2) {
2229      owl_function_show_variables();
2230    } else {
2231      owl_function_show_variable(argv[2]);
2232    }
2233  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2234    if (argc==2) {
2235      owl_function_show_keymaps();
2236    } else {
2237      owl_function_show_keymap(argv[2]);
2238    }
2239  } else if (!strcmp(argv[1], "view")) {
2240    if (argc==3) {
2241      owl_function_show_view(argv[2]);
2242    } else {
2243      owl_function_show_view(NULL);
2244    }
2245  } else if (!strcmp(argv[1], "colors")) {
2246    owl_function_show_colors();
2247  } else if (!strcmp(argv[1], "styles")) {
2248    owl_function_show_styles();
2249  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2250    owl_function_getsubs();
2251  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2252    owl_function_show_term();
2253  } else if (!strcmp(argv[1], "version")) {
2254    owl_function_about();
2255  } else if (!strcmp(argv[1], "status")) {
2256    owl_function_status();
2257  } else if (!strcmp(argv[1], "license")) {
2258    owl_function_show_license();
2259  } else if (!strcmp(argv[1], "quickstart")) {
2260    owl_function_show_quickstart();
2261  } else if (!strcmp(argv[1], "startup")) {
2262    const char *filename;
2263   
2264    filename=owl_global_get_startupfile(&g);
2265    owl_function_popless_file(filename);
2266  } else if (!strcmp(argv[1], "errors")) {
2267    owl_function_showerrs();
2268  } else {
2269    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2270    return NULL;
2271  }
2272  return NULL;
2273}
2274
2275char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
2276{
2277  char *filtname;
2278  if (argc!=2) {
2279    owl_function_makemsg("Wrong number of arguments to viewclass command");
2280    return NULL;
2281  }
2282  filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2283  owl_function_change_currentview_filter(filtname);
2284  owl_free(filtname);
2285  return NULL;
2286}
2287
2288char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
2289{
2290  char *filtname;
2291  if (argc!=2) {
2292    owl_function_makemsg("Wrong number of arguments to viewuser command");
2293    return NULL;
2294  }
2295  filtname=owl_function_zuserfilt(argv[1]);
2296  owl_function_change_currentview_filter(filtname);
2297  owl_free(filtname);
2298  return NULL;
2299}
2300
2301
2302void owl_command_pop_message(void)
2303{
2304  owl_function_curmsg_to_popwin();
2305}
2306
2307char *owl_command_delete(int argc, const char *const *argv, const char *buff)
2308{
2309  int move_after = 1;
2310
2311  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2312    move_after = 0;
2313    argc--; 
2314    argv++;
2315  }
2316
2317  if (argc==1) {
2318    owl_function_deletecur(move_after);
2319    return NULL;
2320  }
2321
2322  if (argc==2 && !strcmp(argv[1], "view")) {
2323    owl_function_delete_curview_msgs(1);
2324    return NULL;
2325  }
2326
2327  if (argc==2 && !strcmp(argv[1], "trash")) {
2328    owl_function_delete_automsgs();
2329    return NULL;
2330  }
2331
2332  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2333    owl_function_delete_by_id(atoi(argv[2]), 1);
2334    return NULL;
2335  }
2336
2337  owl_function_makemsg("Unknown arguments to delete command");
2338  return NULL;
2339}
2340
2341char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
2342{
2343  int move_after = 1;
2344
2345  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2346    move_after = 0;
2347    argc--; 
2348    argv++;
2349  }
2350
2351  if (argc==1) {
2352    owl_function_undeletecur(move_after);
2353    return NULL;
2354  }
2355
2356  if (argc==2 && !strcmp(argv[1], "view")) {
2357    owl_function_delete_curview_msgs(0);
2358    return NULL;
2359  }
2360
2361  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2362    owl_function_delete_by_id(atoi(argv[2]), 0);
2363    return NULL;
2364  }
2365
2366  owl_function_makemsg("Unknown arguments to delete command");
2367  return NULL;
2368}
2369
2370void owl_command_beep(void)
2371{
2372  owl_function_beep();
2373}
2374
2375char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
2376{
2377  if (argc < 2 || argc > 3) {
2378    owl_function_makemsg("Wrong number of arguments to colorview command");
2379    return NULL;
2380  }
2381  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2382  return NULL;
2383}
2384
2385char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
2386{
2387  const char *filtname;
2388 
2389  if (argc < 3 || argc > 4) {
2390    owl_function_makemsg("Wrong number of arguments to colorclass command");
2391    return NULL;
2392  }
2393
2394  filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
2395  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2396  return NULL;
2397}
2398
2399char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
2400{
2401  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2402  return NULL;
2403}
2404
2405char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
2406{
2407  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2408  return NULL;
2409}
2410
2411void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
2412{
2413  /* if type==0 then zpunt
2414   * if type==1 then zunpunt
2415   */
2416  const char *class, *inst, *recip;
2417
2418  class="message";
2419  inst="";
2420  recip="*";
2421
2422  if (argc==1) {
2423    /* show current punt filters */
2424    owl_function_show_zpunts();
2425    return;
2426  } else if (argc==2) {
2427    inst=argv[1];
2428  } else if (argc==3) {
2429    class=argv[1];
2430    inst=argv[2];
2431  } else if (argc==4) {
2432    class=argv[1];
2433    inst=argv[2];
2434    recip=argv[3];
2435  } else {
2436    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2437    return;
2438  }
2439
2440  owl_function_zpunt(class, inst, recip, type);
2441  if (type==0) {
2442    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2443  } else if (type==1) {
2444    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2445  }
2446}
2447
2448char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
2449{
2450  if (argc == 1) {
2451    owl_function_smartzpunt(0);
2452  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2453    owl_function_smartzpunt(1);
2454  } else {
2455    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2456  }
2457  return NULL;
2458}
2459
2460char *owl_command_punt(int argc, const char *const *argv, const char *buff)
2461{
2462  owl_command_punt_unpunt(argc, argv, buff, 0);
2463  return NULL;
2464}
2465
2466char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
2467{
2468  owl_command_punt_unpunt(argc, argv, buff, 1);
2469  return NULL;
2470}
2471
2472void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
2473{
2474  owl_list * fl;
2475  owl_filter * f;
2476  char * text;
2477  int i;
2478
2479  fl = owl_global_get_puntlist(&g);
2480  if(argc == 1) {
2481    owl_function_show_zpunts();
2482  }
2483
2484  if(argc == 2) {
2485    /* Handle :unpunt <number> */
2486    if(unpunt && (i=atoi(argv[1])) !=0) {
2487      i--;      /* Accept 1-based indexing */
2488      if(i < owl_list_get_size(fl)) {
2489        f = owl_list_get_element(fl, i);
2490        owl_list_remove_element(fl, i);
2491        owl_filter_delete(f);
2492        return;
2493      } else {
2494        owl_function_error("No such filter number: %d", i+1);
2495      }
2496    }
2497    text = owl_sprintf("filter %s", argv[1]);
2498    owl_function_punt(text, unpunt);
2499    owl_free(text);
2500  } else {
2501    owl_function_punt(skiptokens(buff, 1), unpunt);
2502  }
2503}
2504
2505
2506char *owl_command_getview(int argc, const char *const *argv, const char *buff)
2507{
2508  const char *filtname;
2509  if (argc != 1) {
2510    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2511    return NULL;
2512  }
2513  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2514  if (filtname) return owl_strdup(filtname);
2515  return NULL;
2516}
2517
2518char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
2519{
2520  char tmpbuff[1024];
2521  if (argc != 2) {
2522    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2523    return NULL;
2524  }
2525  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
2526                                argv[1], tmpbuff, 1024)) {
2527    return NULL;
2528  }
2529  return owl_strdup(tmpbuff); 
2530}
2531
2532char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
2533{
2534  const owl_filter *f;
2535  if (argc != 2) {
2536    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2537    return NULL;
2538  }
2539  f = owl_global_get_filter(&g, argv[1]);
2540  if (!f) {
2541    return NULL;
2542  }
2543  return owl_filter_print(f);
2544}
2545
2546char *owl_command_search(int argc, const char *const *argv, const char *buff)
2547{
2548  int direction;
2549  const char *buffstart;
2550
2551  direction=OWL_DIRECTION_DOWNWARDS;
2552  buffstart=skiptokens(buff, 1);
2553  if (argc>1 && !strcmp(argv[1], "-r")) {
2554    direction=OWL_DIRECTION_UPWARDS;
2555    buffstart=skiptokens(buff, 2);
2556  }
2557   
2558  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2559    owl_function_search_continue(direction);
2560  } else {
2561    owl_function_search_start(buffstart, direction);
2562  }
2563 
2564  return(NULL);
2565}
2566
2567char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
2568{
2569  const char *buffstart;
2570
2571  buffstart=skiptokens(buff, 1);
2572  owl_function_search_start(*buffstart ? buffstart : NULL, OWL_DIRECTION_NONE);
2573 
2574  return(NULL);
2575}
2576
2577char *owl_command_aimlogin(int argc, const char *const *argv, const char *buff)
2578{
2579  if ((argc<2) || (argc>3)) {
2580    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2581    return(NULL);
2582  }
2583
2584  /* if we get two arguments, ask for the password */
2585  if (argc==2) {
2586    owl_editwin *e = owl_function_start_password("AIM Password: ");
2587    owl_editwin_set_cbdata(e, owl_strdup(argv[1]), owl_free);
2588    owl_editwin_set_callback(e, owl_callback_aimlogin);
2589    return(NULL);
2590  } else {
2591    owl_function_aimlogin(argv[1], argv[2]);
2592  }
2593
2594  /* this is a test */
2595  return(NULL);
2596}
2597
2598char *owl_command_aimlogout(int argc, const char *const *argv, const char *buff)
2599{
2600  /* clear the buddylist */
2601  owl_buddylist_clear(owl_global_get_buddylist(&g));
2602
2603  owl_aim_logout();
2604  return(NULL);
2605}
2606
2607char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
2608{
2609  const char *stylename;
2610  if (argc != 1) {
2611    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2612    return NULL;
2613  }
2614  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2615  if (stylename) return owl_strdup(stylename);
2616  return NULL;
2617}
2618
2619char *owl_command_error(int argc, const char *const *argv, const char *buff)
2620{
2621    buff = skiptokens(buff, 1);
2622    owl_function_error("%s", buff);
2623    return NULL;
2624}
2625
2626char *owl_command_message(int argc, const char *const *argv, const char *buff)
2627{
2628    buff = skiptokens(buff, 1);
2629    owl_function_makemsg("%s", buff);
2630    return NULL;
2631}
2632
2633void owl_command_yes(void)
2634{
2635  owl_message *m;
2636  const owl_view *v;
2637  const char *cmd;
2638
2639  v = owl_global_get_current_view(&g);
2640
2641  /* bail if there's no current message */
2642  if (owl_view_get_size(v) < 1) {
2643    owl_function_error("No current message.");
2644    return;
2645  }
2646
2647  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2648  if(!owl_message_is_question(m)) {
2649    owl_function_error("That message isn't a question.");
2650    return;
2651  }
2652  if(owl_message_is_answered(m)) {
2653    owl_function_error("You already answered that question.");
2654    return;
2655  }
2656  cmd = owl_message_get_attribute_value(m, "yescommand");
2657  if(!cmd) {
2658    owl_function_error("No 'yes' command!");
2659    return;
2660  }
2661
2662  owl_function_command_norv(cmd);
2663  owl_message_set_isanswered(m);
2664  return;
2665}
2666
2667void owl_command_no(void)
2668{
2669  owl_message *m;
2670  const owl_view *v;
2671  const char *cmd;
2672
2673  v = owl_global_get_current_view(&g);
2674
2675  /* bail if there's no current message */
2676  if (owl_view_get_size(v) < 1) {
2677    owl_function_error("No current message.");
2678    return;
2679  }
2680
2681  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2682  if(!owl_message_is_question(m)) {
2683    owl_function_error("That message isn't a question.");
2684    return;
2685  }
2686  if(owl_message_is_answered(m)) {
2687    owl_function_error("You already answered that question.");
2688    return;
2689  }
2690  cmd = owl_message_get_attribute_value(m, "nocommand");
2691  if(!cmd) {
2692    owl_function_error("No 'no' command!");
2693    return;
2694  }
2695
2696  owl_function_command_norv(cmd);
2697  owl_message_set_isanswered(m);
2698  return;
2699}
2700
2701/*********************************************************************/
2702/************************** EDIT SPECIFIC ****************************/
2703/*********************************************************************/
2704
2705void owl_command_edit_cancel(owl_editwin *e)
2706{
2707  owl_history *hist;
2708
2709  owl_function_makemsg("Command cancelled.");
2710
2711  if(owl_editwin_get_echochar(e) == 0) {
2712    hist=owl_editwin_get_history(e);
2713    owl_history_store(hist, owl_editwin_get_text(e));
2714    owl_history_reset(hist);
2715  }
2716
2717  owl_global_set_needrefresh(&g);
2718  owl_global_pop_context(&g);
2719
2720  owl_global_set_typwin_inactive(&g);
2721  owl_editwin_delete(e);
2722}
2723
2724void owl_command_edit_history_prev(owl_editwin *e)
2725{
2726  owl_history *hist;
2727  const char *ptr;
2728
2729  hist=owl_editwin_get_history(e);
2730  if (!owl_history_is_touched(hist)) {
2731    owl_history_store(hist, owl_editwin_get_text(e));
2732    owl_history_set_partial(hist);
2733  }
2734  ptr=owl_history_get_prev(hist);
2735  if (ptr) {
2736    owl_editwin_clear(e);
2737    owl_editwin_insert_string(e, ptr);
2738    owl_editwin_redisplay(e);
2739    owl_global_set_needrefresh(&g);
2740  } else {
2741    owl_function_beep();
2742  }
2743}
2744
2745void owl_command_edit_history_next(owl_editwin *e)
2746{
2747  owl_history *hist;
2748  const char *ptr;
2749
2750  hist=owl_editwin_get_history(e);
2751  ptr=owl_history_get_next(hist);
2752  if (ptr) {
2753    owl_editwin_clear(e);
2754    owl_editwin_insert_string(e, ptr);
2755    owl_editwin_redisplay(e);
2756    owl_global_set_needrefresh(&g);
2757  } else {
2758    owl_function_beep();
2759  }
2760}
2761
2762char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
2763{
2764  buff = skiptokens(buff, 1);
2765  owl_editwin_insert_string(e, buff);
2766  owl_editwin_redisplay(e);
2767  owl_global_set_needrefresh(&g); 
2768  return NULL;
2769}
2770
2771void owl_command_edit_done(owl_editwin *e)
2772{
2773  owl_history *hist=owl_editwin_get_history(e);
2774
2775  if (hist) {
2776    owl_history_store(hist, owl_editwin_get_text(e));
2777    owl_history_reset(hist);
2778  }
2779
2780  owl_global_set_typwin_inactive(&g);
2781  owl_global_pop_context(&g);
2782  owl_global_set_needrefresh(&g);
2783
2784  owl_editwin_do_callback(e);
2785  owl_editwin_delete(e);
2786}
2787
2788void owl_command_edit_done_or_delete(owl_editwin *e)
2789{
2790  if (owl_editwin_is_at_end(e)) {
2791    owl_command_edit_done(e);
2792  } else {
2793    owl_editwin_delete_char(e);
2794  }
2795}
2796
2797
2798/*********************************************************************/
2799/*********************** POPLESS SPECIFIC ****************************/
2800/*********************************************************************/
2801
2802void owl_command_popless_quit(owl_viewwin *vw)
2803{
2804  owl_popwin_close(owl_global_get_popwin(&g));
2805  owl_global_pop_context(&g);
2806  owl_viewwin_cleanup(vw);
2807  owl_global_set_needrefresh(&g);
2808}
Note: See TracBrowser for help on using the repository browser.