source: commands.c @ 9e596f5

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