source: commands.c @ 27f6487

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