source: commands.c

Last change on this file was 4fd3c04, checked in by Anders Kaseorg <andersk@mit.edu>, 6 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
RevLine 
[7d4fbcd]1#include "owl.h"
[f271129]2#include <getopt.h>
[7d4fbcd]3
[e19eb97]4/* fn is "char *foo(int argc, const char *const *argv, const char *buff)" */
[7d4fbcd]5#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
[117c21c]6        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
[bc9020f]7          NULL, fn, NULL, NULL, NULL, NULL, NULL, NULL }
[7d4fbcd]8
9/* fn is "void foo(void)" */
10#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
[117c21c]11        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
[bc9020f]12          NULL, NULL, fn, NULL, NULL, NULL, NULL, NULL }
[7d4fbcd]13
14/* fn is "void foo(int)" */
15#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
[117c21c]16        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
[bc9020f]17          NULL, NULL, NULL, fn, NULL, NULL, NULL, NULL }
[7d4fbcd]18
19#define OWLCMD_ALIAS(name, actualname) \
[117c21c]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 }
[7d4fbcd]22
[e19eb97]23/* fn is "char *foo(void *ctx, int argc, const char *const *argv, const char *buff)" */
[7d4fbcd]24#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
[117c21c]25        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
[e19eb97]26          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,const char*const *,const char*))fn), NULL, NULL, NULL }
[7d4fbcd]27
28/* fn is "void foo(void)" */
29#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
[117c21c]30        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
[bc9020f]31          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL, NULL }
[7d4fbcd]32
33/* fn is "void foo(int)" */
34#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
[117c21c]35        { g_strdup(name), g_strdup(summary), g_strdup(usage), g_strdup(description), ctx, \
[bc9020f]36          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn), NULL }
[7d4fbcd]37
38
[d427f08]39void owl_cmd_add_defaults(owl_cmddict *cd)
[aad166a]40{
41  owl_cmd commands_to_init[] = {
42
[7d4fbcd]43  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
44              "send a login or logout notification",
[425c013]45              "zlog in [tty]\nzlog out",
[7d4fbcd]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"
[a16d7e5]48              "when BarnOwl is started and a logout notification is sent when owl\n"
[7d4fbcd]49              "is exited.  This behavior can be changed with the 'startuplogin'\n"
[451db9e]50              "and 'shutdownlogout' variables.  If a tty is specified for zlog in\n"
[a16d7e5]51              "then the BarnOwl variable 'tty' will be set to that string, causing\n"
[425c013]52              "it to be used as the zephyr location tty.\n"),
[7d4fbcd]53
54  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
[a16d7e5]55              "exit BarnOwl",
[7d4fbcd]56              "",
[a16d7e5]57              "Exit BarnOwl and run any shutdown activities."),
[7d4fbcd]58  OWLCMD_ALIAS("exit", "quit"),
[8921d3f]59  OWLCMD_ALIAS("q",    "quit"),
[ecd5dc5]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              ""),
[7d4fbcd]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>",
[49d67b1]87              "(Note: There is a literal word \"command\" between <keyseq>\n"
[a006a662]88              " and <command>.)\n"
[7d4fbcd]89              "Binds a key sequence to a command within a keymap.\n"
90              "Use 'show keymaps' to see the existing keymaps.\n"
[a006a662]91              "Key sequences may be things like M-C-t or NPAGE.\n\n"
[700dc91]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"),
[8a921b5]95
96  OWLCMD_ARGS("unbindkey", owl_command_unbindkey, OWL_CTX_ANY,
97              "removes a binding in a keymap",
[39a531d]98              "unbindkey <keymap> <keyseq>",
[8a921b5]99              "Removes a binding of a key sequence within a keymap.\n"
100              "Use 'show keymaps' to see the existing keymaps.\n"
[9ed1278]101              "Ex.: unbindkey recv H\n\n"
[8a921b5]102              "SEE ALSO: bindkey"),
[7d4fbcd]103
104  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
105              "send a zephyr",
[d544237]106              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [<user> ...] [-m <message...>]",
[7d4fbcd]107              "Zwrite send a zephyr to the one or more users specified.\n\n"
108              "The following options are available:\n\n"
[1c6c4d3]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"
[7d4fbcd]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"),
[d309eb3]123
[37eab7f]124  OWLCMD_ARGS("loopwrite", owl_command_loopwrite, OWL_CTX_INTERACTIVE,
125              "send a loopback message",
126              "loopwrite",
127              "Send a local message.\n"),
128
[987cf3f]129  OWLCMD_ARGS("zcrypt", owl_command_zwrite, OWL_CTX_INTERACTIVE,
[d309eb3]130              "send an encrypted zephyr",
[d544237]131              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [-m <message...>]\n",
[d309eb3]132              "Behaves like zwrite but uses encryption.  Not for use with\n"
133              "personal messages\n"),
[7d4fbcd]134 
135  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
136              "reply to the current message",
[e75011e]137              "reply [-e] [ sender | all | zaway ]",
[7d4fbcd]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"
[d544237]141              "If 'all' or no args are specified, reply publicly to the\n"
[7d4fbcd]142              "same class/instance for non-personal messages and to the\n"
[e75011e]143              "sender for personal messages.\n\n"
144              "If 'zaway' is specified, replies with a zaway message.\n\n"),
[7d4fbcd]145
146  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
147              "set a variable value",
[41677d2]148              "set [-q] <variable> [<value>]\n"
[7d4fbcd]149              "set",
150              "Set the named variable to the specified value.  If no\n"
[88ca489]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"),
[486688f]155
156  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
157              "unset a boolean variable value",
[73faa26]158              "unset [-q] <variable>\n"
159              "unset",
[486688f]160              "Set the named boolean variable to off.\n"
[7d4fbcd]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",
[d768834]167              "Print the value of the named variable.  If no arguments\n"
[7d4fbcd]168              "are used print the value of all variables.\n"),
169
[38cf544c]170  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
[a16d7e5]171              "run a command and set it to be run at every BarnOwl startup",
[38cf544c]172              "startup <commands> ...",
173              "Everything on the command line after the startup command\n"
[a16d7e5]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"
[38cf544c]176              "is started"),
177
178  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
[a16d7e5]179              "remove a command from the list of those to be run at BarnOwl startup",
[38cf544c]180              "unstartup <commands> ...",
181              ""),
182
[7d4fbcd]183  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
[a16d7e5]184              "print the version of the running BarnOwl", "", ""),
[7d4fbcd]185
186  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
187              "subscribe to a zephyr class, instance, recipient",
[fd472a7]188              "subscribe [-t] <class> [instance [recipient]]",
[451db9e]189              "Subscribe to the specified class and instance.  If the\n"
[f830d84]190              "instance or recipient is not listed on the command\n"
191              "line they default to * (the wildcard recipient).\n"
[fd472a7]192              "If the -t option is present the subscription will\n"
[f830d84]193              "only be temporary, i.e., it will not be written to\n"
194              "the subscription file and will therefore not be\n"
[a16d7e5]195              "present the next time BarnOwl is started.\n"),
[7d4fbcd]196  OWLCMD_ALIAS("sub", "subscribe"),
197
198  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
199              "unsubscribe from a zephyr class, instance, recipient",
[fd472a7]200              "unsubscribe [-t] <class> [instance [recipient]]",
[7d4fbcd]201              "Unsubscribe from the specified class and instance.  If the\n"
[f830d84]202              "instance or recipient is not listed on the command\n"
203              "line they default to * (the wildcard recipient).\n"
[fd472a7]204              "If the -t option is present the unsubscription will\n"
205              "only be temporary, i.e., it will not be updated in\n"
[f830d84]206              "the subscription file and will therefore not be\n"
[a16d7e5]207              "in effect the next time BarnOwl is started.\n"),
[7d4fbcd]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
[2adaf1d]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
[2404c3a]224  OWLCMD_ARGS("source", owl_command_source, OWL_CTX_ANY,
[a16d7e5]225              "execute BarnOwl commands from a file",
[2404c3a]226              "source <filename>",
[a16d7e5]227              "Execute the BarnOwl commands in <filename>.\n"),
[2404c3a]228
[fd93b41]229  OWLCMD_ARGS("addbuddy", owl_command_addbuddy, OWL_CTX_INTERACTIVE,
230              "add a buddy to a buddylist",
[fe0a16a]231              "addbuddy <protocol> <screenname>",
[4fd3c04]232              "Add the named buddy to your buddylist.  <protocol> must be zephyr\n"),
[fd93b41]233
234  OWLCMD_ARGS("delbuddy", owl_command_delbuddy, OWL_CTX_INTERACTIVE,
235              "delete a buddy from a buddylist",
[fe0a16a]236              "delbuddy <protocol> <screenname>",
[4fd3c04]237              "Delete the named buddy from your buddylist.  <protocol> must be zephyr\n"),
[8c92848]238
[d36f2cb]239  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
240              "creates a zpunt based on the current message",
[5eeea3b]241              "smartzpunt [-i | --instance]",
[d36f2cb]242              "Starts a zpunt command based on the current message's class\n"
243              "(and instance if -i is specified).\n"),
244
[7d4fbcd]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>",
[d544237]249              "The zpunt command will suppress messages to the specified\n"
[451db9e]250              "zephyr triplet.  In the second usage messages are suppressed\n"
[7d4fbcd]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>",
[451db9e]258              "The zunpunt command will allow messages that were previously\n"
[7d4fbcd]259              "suppressed to be received again.\n\n"
260              "SEE ALSO:  zpunt, show zpunts\n"),
261
[ce7b824]262  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
263              "suppress an arbitrary filter",
[2d415cc]264              "punt <filter-name>\n"
265              "punt <filter-text (multiple words)>",
[d544237]266              "The punt command will suppress messages to the specified\n"
[ce7b824]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",
[2d415cc]272              "unpunt <number>\n"
273              "unpunt <filter-name>\n"
274              "unpunt <filter-text (multiple words)>",
[ce7b824]275              "The unpunt command will remove an entry from the puntlist.\n"
[2d415cc]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"
[ce7b824]278              "the list (see :show zpunts)\n\n"
279              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
280
[7d4fbcd]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,
[a16d7e5]286              "display help on using BarnOwl",
[7d4fbcd]287              "help [command]", ""),
[42abb10]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"),
[aa5f725]293
[e60f98c]294  OWLCMD_VOID("blist", owl_command_blist, OWL_CTX_INTERACTIVE,
[aa5f725]295              "List all buddies logged in",
[25b5b4b]296              "blist",
[aa5f725]297              "Print a listing of buddies logged in, regardless of protocol."),
298
[e60f98c]299  OWLCMD_VOID("toggle-oneline", owl_command_toggleoneline, OWL_CTX_INTERACTIVE,
[c3ab155]300              "Toggle the style between oneline and the default style",
301              "toggle-oneline",
302              ""),
303
[8c97fa1]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
[7d4fbcd]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
[70110286]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,
[73ba824]323              "swap the positions of the pointer and the mark", "", ""),
[70110286]324
[7d4fbcd]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
[b950088]331  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
332              "move the pointer to the next message",
[7360fab]333              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
334              "          [ --smart-filter | --smart-filter-instance ]",
[b950088]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"
[7360fab]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"
[b950088]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"),
[7d4fbcd]344  OWLCMD_ALIAS("recv:next", "next"),
345
[b950088]346  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
347              "move the pointer to the previous message",
[7360fab]348              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
349              "          [ --smart-filter | --smart-filter-instance ]",
[b950088]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"
[7360fab]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"
[b950088]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"),
[7d4fbcd]359  OWLCMD_ALIAS("recv:prev", "prev"),
360
[b950088]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"),
[7d4fbcd]363
[b950088]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"),
[7d4fbcd]366
[b950088]367  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
[7d4fbcd]368
[b950088]369  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
[7d4fbcd]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,
[5eeea3b]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"),
[7d4fbcd]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,
[a16d7e5]394              "suspend BarnOwl", "", ""),
[7d4fbcd]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,
[4b660cc]443              "Set, enable or disable zephyr away message",
[7d4fbcd]444              "zaway [ on | off | toggle ]\n"
445              "zaway <message>",
[4b660cc]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,
[a38becd]451              "Set, enable or disable all away messages",
[4b660cc]452              "away [ on | off | toggle ]\n"
453              "away <message>",
[a38becd]454              "Turn on or off all away messages.  If\n"
[4b660cc]455              "'message' is specified turn them on with that message,\n"
456              "otherwise use the default.\n"
457              "\n"
[4fd3c04]458              "SEE ALSO: zaway"),
[7d4fbcd]459
[77beb3c]460  OWLCMD_ARGS("flush-logs", owl_command_flushlogs, OWL_CTX_ANY,
[ec36247]461              "flush the queue of messages waiting to be logged",
[4511ac3]462              "flush-logs [-f | --force] [-q | --quiet]",
[ec36247]463              "If BarnOwl failed to log a file, this command tells\n"
464              "BarnOwl to try logging the messages that have since\n"
[77beb3c]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"
[4511ac3]473              "normally.\n"
474              "\n"
475              "Unless --quiet is passed, a message is printed about\n"
476              "how many logs there are to flush."),
[ec36247]477
[7d4fbcd]478  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
479              "load subscriptions from a file",
480              "load-subs <file>\n", ""),
481
[7933748]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
[7d4fbcd]491  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
[a16d7e5]492              "print information about BarnOwl", "", ""),
[7d4fbcd]493
494  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
[a16d7e5]495              "print status information about the running BarnOwl", "", ""),
[7d4fbcd]496 
497  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
498              "locate a user",
[2527615]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"
[7d4fbcd]502              "the lookup request.\n"),
503 
504  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
505              "create a message filter",
[8fa9562]506              "filter <name> [ -c fgcolor ] [ -b bgcolor ] [ <expression> ... ]",
[7d4fbcd]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"
[0c502e9]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"
[49d467c]519              "    hostname   -  hostname of sending host\n"
[4fd3c04]520              "    type       -  message type (zephyr, admin)\n"
[0c502e9]521              "    direction  -  either 'in' 'out' or 'none'\n"
[40458b9]522              "    login      -  either 'login' 'logout' or 'none'\n"
523              "Also you may match on the validity of another filter:\n"
524              "    filter <filtername>\n"
[32eed98]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"
[0c502e9]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"
[451db9e]535              "Spaces must be present before and after parentheses.  If the\n"
[8fa9562]536              "optional color arguments are used they specifies the colors that\n"
[7d4fbcd]537              "messages matching this filter should be displayed in.\n\n"
[8fcd3e7]538              "SEE ALSO: smartfilter, smartnarrow, view, viewclass, viewuser\n"),
[7d4fbcd]539
540  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
[8fa9562]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"
[7d4fbcd]545              "of valid colors.\n\n"
546              "SEE ALSO: 'show colors'\n"),
547
[5e0b690]548  OWLCMD_ARGS("colorclass", owl_command_colorclass, OWL_CTX_INTERACTIVE,
549              "create a filter to color messages of the given class name",
[8fa9562]550              "colorclass <class> <fgcolor> [<bgcolor>]",
[5e0b690]551              "A filter will be created to color messages in <class>"
[8fa9562]552              "in <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
[5e0b690]553              "of valid colors.\n\n"
554              "SEE ALSO: 'show colors'\n"),
555
[7d4fbcd]556  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
557              "view messages matching a filter",
[3895e23]558              "view [<viewname>] [-f <filter> | --home | -r ] [-s <style>]\n"
[7d4fbcd]559              "view <filter>\n"
560              "view -d <expression>\n"
561              "view --home",
[ef56a67]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"
[7d4fbcd]570              "\n"
[d544237]571              "The other usages listed above are abbreviated forms that simply set\n"
[ef56a67]572              "the filter of the current view. The -d option allows you to write a\n"
[a16d7e5]573              "filter expression that will be dynamically created by BarnOwl and then\n"
[ef56a67]574              "applied as the view's filter\n"
[8fcd3e7]575              "SEE ALSO: filter, smartfilter, smartnarrow, viewclass, viewuser\n"),
[7d4fbcd]576
577  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
578              "view only messages similar to the current message",
[d544237]579              "smartnarrow [-i | --instance]  [-r | --related]",
[7d4fbcd]580              "If the curmsg is a personal message narrow\n"
[d768834]581              "   to the conversation with that user.\n"
[451db9e]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"
[7d4fbcd]585              "    to the class.\n"
[451db9e]586              "If the curmsg is a class message and '-i' is specified\n"
[8a5b5a1]587              "    then narrow to the class and instance.\n"
588              "If '-r' or '--related' is specified, behave as though the\n"
[8fcd3e7]589              "    'narrow-related' variable was inverted.\n\n"
590              "SEE ALSO: filter, smartfilter, view, viewclass, viewuser\n"),
[7d4fbcd]591
[7360fab]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"
[d768834]596              "   the conversation with that user.\n"
[451db9e]597              "If the curmsg is a <MESSAGE, foo, *>\n"
598              "   message, the filter is to that instance.\n"
[7360fab]599              "If the curmsg is a class message, the filter is that class.\n"
[d544237]600              "If the curmsg is a class message and '-i' is specified\n"
[8fcd3e7]601              "    the filter is to that class and instance.\n\n"
602              "SEE ALSO: filter, smartnarrow, view, viewclass, viewuser\n"),
[7360fab]603
[7d4fbcd]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"
[8fcd3e7]610              "SEE ALSO: filter, smartfilter, smartnarrow, view, viewuser\n"),
[7d4fbcd]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"
[8fcd3e7]619              "SEE ALSO: filter, smartfilter, smartnarrow, view, viewclass\n"),
[7d4fbcd]620  OWLCMD_ALIAS("vu", "viewuser"),
[14965e5]621  OWLCMD_ALIAS("viewperson", "viewuser"),
622  OWLCMD_ALIAS("vp", "viewuser"),
[7d4fbcd]623
624  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
[15283bb]625              "show information",
[f17bff98]626              "show colors\n"
627              "show commands\n"
628              "show command <command>\n"
629              "show errors\n"
[7d4fbcd]630              "show filters\n"
631              "show filter <filter>\n"
632              "show keymaps\n"
633              "show keymap <keymap>\n"
[debb15d]634              "show license\n"
[799b60e]635              "show quickstart\n"
[f17bff98]636              "show startup\n"
637              "show status\n"
[f1e629d]638              "show styles\n"
[f17bff98]639              "show subscriptions / show subs\n"
[7d4fbcd]640              "show terminal\n"
[f17bff98]641              "show variables\n"
642              "show variable <variable>\n"
[7d4fbcd]643              "show version\n"
[ef56a67]644              "show view [<view>]\n"
[f17bff98]645              "show zpunts\n",
[7d4fbcd]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"
[f17bff98]652              "Show startup will display the custom startup config\n\n"
[7d4fbcd]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"
[f1e629d]658              "Show styles will list the names of all styles available\n"
659              "for formatting messages.\n\n"
[7d4fbcd]660              "Show variables will list the names of all variables.\n\n"
[a16d7e5]661              "Show errors will show a list of errors encountered by BarnOwl.\n\n"
[7d4fbcd]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",
[b950088]666              "delete [ -id msgid ] [ --no-move ]\n"
[7d4fbcd]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"
[451db9e]671              "id is marked for deletion.\n"
[b950088]672              "If '--no-move' is specified, don't move after deletion.\n"
[7d4fbcd]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
[efeec7f]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
[7d4fbcd]688  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
689              "unmark a message for deletion",
[b950088]690              "undelete [ -id msgid ] [ --no-move ]\n"
[7d4fbcd]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"
[451db9e]694              "given message id is unmarked for deletion.\n"
[b950088]695              "If '--no-move' is specified, don't move after deletion.\n"
[7d4fbcd]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
[8ee73f8d]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
[cdc6ff1]719  OWLCMD_ARGS("getfilter", owl_command_getfilter, OWL_CTX_INTERACTIVE,
720              "returns the definition of a filter",
721              "getfilter <filtername>", ""),
722
[216c734]723  OWLCMD_ARGS("getstyle", owl_command_getstyle, OWL_CTX_INTERACTIVE,
724              "returns the name of the style for the current view",
725              "", ""),
726
[1fd0b25]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"
[451db9e]733              "default searches are done forwards; if -r is used the search\n"
[1fd0b25]734              "is performed backwards"),
735
[987ff51]736  OWLCMD_ARGS("setsearch", owl_command_setsearch, OWL_CTX_INTERACTIVE,
737              "set the search highlight string without searching",
738              "setsearch <string>",
[d544237]739              "The setsearch command highlights all occurrences of its\n"
[987ff51]740          "argument and makes it the default argument for future\n"
741          "search commands, but does not move the cursor.  With\n"
[451db9e]742          "no argument, it makes search highlighting inactive."),
[987ff51]743
[4692b70]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,
[b1fd36e]750              "Display an informative message",
[4692b70]751              "message <message>",
752              ""),
[d09e5a1]753
[35d2091]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
[f4d32cd]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
[7d4fbcd]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
[b68f9cd]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
[7d4fbcd]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
[f2e36b5]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
[7d4fbcd]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, 
[10b866d]874                  OWL_CTX_EDIT,
[5ade618]875                  "replaces the text with the next history",
[7d4fbcd]876                  "", ""),
877
878  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
[10b866d]879                  OWL_CTX_EDIT,
[7d4fbcd]880                  "replaces the text with the previous history",
881                  "", ""),
882
[7f0c26f]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
[a60edf2]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
[5934b87]908  OWLCMD_ALIAS   ("editline:done", "edit:done"),
[0d17295]909  OWLCMD_ALIAS   ("editresponse:done", "edit:done"),
[cf83b7a]910
[435d6b2]911  OWLCMD_VOID_CTX("edit:move-up-line", owl_editwin_key_up, 
[7d4fbcd]912                  OWL_CTX_EDITMULTI,
913                  "moves the cursor up one line",
914                  "", ""),
915
[435d6b2]916  OWLCMD_VOID_CTX("edit:move-down-line", owl_editwin_key_down, 
[7d4fbcd]917                  OWL_CTX_EDITMULTI,
918                  "moves the cursor down one line",
919                  "", ""),
920
[435d6b2]921  OWLCMD_VOID_CTX("edit:done", owl_command_edit_done, 
[0d17295]922                  OWL_CTX_EDIT,
923                  "Finishes entering text in the editwin.",
[7d4fbcd]924                  "", ""),
925
[435d6b2]926  OWLCMD_VOID_CTX("edit:done-or-delete", owl_command_edit_done_or_delete, 
[217a43e]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"
[435d6b2]931                  "runs 'edit:done'.\n"\
[217a43e]932                  "Otherwise runs 'edit:delete-next-char'\n"),
933
[435d6b2]934  OWLCMD_VOID_CTX("edit:forward-paragraph", owl_editwin_forward_paragraph,
[2fc8397]935                  OWL_CTX_EDITMULTI,
936                  "Move forward to end of paragraph.",
937                  "",
938                  "Move the point to the end of the current paragraph"),
939
[435d6b2]940  OWLCMD_VOID_CTX("edit:backward-paragraph", owl_editwin_backward_paragraph,
[2fc8397]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
[7d4fbcd]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
[09ceee3]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
[b6cf72f]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
[d2fd2f7]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",
[8258ea5]1012                  "popless:start-search [-r] [initial-value]",
[d2fd2f7]1013                  "Initializes the command-line to search for initial-value. If\n"
[df4ccc0]1014                  "-r is used, the search will be performed backwards.\n\n"
1015                  "SEE ALSO: popless:search"),
[d2fd2f7]1016
[1522e5d]1017  OWLCMD_ALIAS("webzephyr", "zwrite " OWL_WEBZEPHYR_PRINCIPAL " -c " OWL_WEBZEPHYR_CLASS " -i"),
[0b6b689]1018
[7d4fbcd]1019  /* This line MUST be last! */
[bc9020f]1020  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
[7d4fbcd]1021
[aad166a]1022  };
1023
[d427f08]1024  owl_cmddict_add_from_list(cd, commands_to_init);
[117c21c]1025  owl_cmd *cmd;
1026  for (cmd = commands_to_init; cmd->name != NULL; cmd++)
1027    owl_cmd_cleanup(cmd);
[aad166a]1028}
[7d4fbcd]1029
[c79a047]1030void owl_command_info(void)
[cf83b7a]1031{
[7d4fbcd]1032  owl_function_info();
1033}
1034
[c79a047]1035void owl_command_nop(void)
[cf83b7a]1036{
[ecd5dc5]1037}
1038
[e19eb97]1039char *owl_command_help(int argc, const char *const *argv, const char *buff)
[cf83b7a]1040{
[7d4fbcd]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
[e19eb97]1050char *owl_command_zlist(int argc, const char *const *argv, const char *buff)
[cf83b7a]1051{
[e19eb97]1052  const char *file=NULL;
[42abb10]1053
1054  argc--;
1055  argv++;
1056  while (argc) {
[61de085]1057    if (!strcmp(argv[0], "-f")) {
[42abb10]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  }
[4fd3c04]1070  owl_function_buddylist(1, file);
[aa5f725]1071  return(NULL);
1072}
1073
[c79a047]1074void owl_command_blist(void)
[cf83b7a]1075{
[4fd3c04]1076  owl_function_buddylist(1, NULL);
[42abb10]1077}
1078
[c79a047]1079void owl_command_toggleoneline(void)
[cf83b7a]1080{
[c3ab155]1081  owl_function_toggleoneline();
1082}
1083
[c79a047]1084void owl_command_about(void)
[cf83b7a]1085{
[7d4fbcd]1086  owl_function_about();
1087}
1088
[c79a047]1089void owl_command_version(void)
[cf83b7a]1090{
[ca1fb26a]1091  owl_function_makemsg("BarnOwl version %s", version);
[7d4fbcd]1092}
1093
[e19eb97]1094char *owl_command_addbuddy(int argc, const char *const *argv, const char *buff)
[fd93b41]1095{
1096  if (argc!=3) {
1097    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1098    return(NULL);
1099  }
1100
[4fd3c04]1101  if (!strcasecmp(argv[1], "zephyr")) {
[65ad073]1102    owl_zephyr_addbuddy(argv[2]);
1103    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1104  } else {
[4fd3c04]1105    owl_function_makemsg("addbuddy: currently the only supported protocol is 'zephyr'");
[fd93b41]1106  }
1107
1108  return(NULL);
1109}
1110
[e19eb97]1111char *owl_command_delbuddy(int argc, const char *const *argv, const char *buff)
[fd93b41]1112{
1113  if (argc!=3) {
1114    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1115    return(NULL);
1116  }
1117
[4fd3c04]1118  if (!strcasecmp(argv[1], "zephyr")) {
[65ad073]1119    owl_zephyr_delbuddy(argv[2]);
1120    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1121  } else {
[4fd3c04]1122    owl_function_makemsg("delbuddy: currently the only supported protocol is 'zephyr'");
[8c92848]1123  }
1124
[fd93b41]1125  return(NULL);
1126}
1127
[e19eb97]1128char *owl_command_startup(int argc, const char *const *argv, const char *buff)
[38cf544c]1129{
[e19eb97]1130  const char *ptr;
[38cf544c]1131
1132  if (argc<2) {
1133    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1134    return(NULL);
1135  }
1136
[3e96ff0]1137  ptr = skiptokens(buff, 1);
[38cf544c]1138
[c809f5e]1139  owl_function_command_norv(ptr);
[3e96ff0]1140  owl_function_addstartup(ptr);
[38cf544c]1141
1142  return(NULL);
1143}
1144
[e19eb97]1145char *owl_command_unstartup(int argc, const char *const *argv, const char *buff)
[38cf544c]1146{
[e19eb97]1147  const char *ptr;
[38cf544c]1148
1149  if (argc<2) {
1150    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1151    return(NULL);
1152  }
1153
[3e96ff0]1154  ptr = skiptokens(buff, 1);
[38cf544c]1155
[3e96ff0]1156  owl_function_delstartup(ptr);
[38cf544c]1157
1158  return(NULL);
1159}
1160
[e19eb97]1161char *owl_command_dump(int argc, const char *const *argv, const char *buff)
[cf83b7a]1162{
[f36222f]1163  char *filename;
1164 
[2adaf1d]1165  if (argc!=2) {
1166    owl_function_makemsg("usage: dump <filename>");
1167    return(NULL);
1168  }
[f36222f]1169  filename=owl_util_makepath(argv[1]);
1170  owl_function_dump(filename);
[ddbbcffa]1171  g_free(filename);
[2adaf1d]1172  return(NULL);
1173}
1174
[e19eb97]1175char *owl_command_source(int argc, const char *const *argv, const char *buff)
[2404c3a]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
[e19eb97]1186char *owl_command_next(int argc, const char *const *argv, const char *buff)
[cf83b7a]1187{
[b950088]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")) {
[d4927a7]1198      filter = g_strdup(argv[2]);
[7360fab]1199      argc-=2; argv+=2; 
1200    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
[8a5b5a1]1201      filter = owl_function_smartfilter(0, 0);
[7360fab]1202      argc-=2; argv+=2; 
1203    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
[8a5b5a1]1204      filter = owl_function_smartfilter(1, 0);
[b950088]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);
[3b8a563]1212  g_free(filter);
[b950088]1213  return(NULL);
[7d4fbcd]1214}
1215
[e19eb97]1216char *owl_command_prev(int argc, const char *const *argv, const char *buff)
[cf83b7a]1217{
[b950088]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")) {
[d4927a7]1228      filter = g_strdup(argv[2]);
[b950088]1229      argc-=2; argv+=2; 
[7360fab]1230    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
[8a5b5a1]1231      filter = owl_function_smartfilter(0, 0);
[7360fab]1232      argc-=2; argv+=2; 
1233    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
[8a5b5a1]1234      filter = owl_function_smartfilter(1, 0);
[7360fab]1235      argc-=2; argv+=2; 
1236   } else {
[b950088]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);
[3b8a563]1242  g_free(filter);
[b950088]1243  return(NULL);
[7d4fbcd]1244}
1245
[e19eb97]1246char *owl_command_smartnarrow(int argc, const char *const *argv, const char *buff)
[cf83b7a]1247{
[7360fab]1248  char *filtname = NULL;
1249
[8a5b5a1]1250  char opt;
1251  int instance = 0, related = 0, i;
[96828e4]1252  const char **tmp_argv = g_new(const char *, argc);
[8a5b5a1]1253
[447435a]1254  static const struct option options[] = {
[8a5b5a1]1255    {"instance", 0, 0, 'i'},
1256    {"related",  0, 0, 'r'},
1257    {NULL,       0, 0, 0}};
[e54a746]1258
[b31f1c9]1259  for (i = 0; i < argc; i++)
1260    tmp_argv[i] = argv[i];
1261
[e54a746]1262  optind = 0;
[447435a]1263  while ((opt = getopt_long(argc, (char **)tmp_argv, "ir", options, NULL)) != -1) {
[8a5b5a1]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    }
[7d4fbcd]1275  }
[8a5b5a1]1276
1277  filtname = owl_function_smartfilter(instance, related);
1278
[7360fab]1279  if (filtname) {
[3895e23]1280    owl_function_change_currentview_filter(filtname);
[ddbbcffa]1281    g_free(filtname);
[7360fab]1282  }
[8a5b5a1]1283
1284done:
[ddbbcffa]1285  g_free(tmp_argv);
[88e425f]1286
[7d4fbcd]1287  return NULL;
1288}
1289
[6829afc]1290CALLER_OWN char *owl_command_smartfilter(int argc, const char *const *argv, const char *buff)
[cf83b7a]1291{
[7360fab]1292  char *filtname = NULL;
1293
1294  if (argc == 1) {
[8a5b5a1]1295    filtname = owl_function_smartfilter(0, 0);
[7360fab]1296  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
[8a5b5a1]1297    filtname = owl_function_smartfilter(1, 0);
[7360fab]1298  } else {
1299    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1300  }
1301  return filtname;
1302}
1303
[c79a047]1304void owl_command_expunge(void)
[cf83b7a]1305{
[7d4fbcd]1306  owl_function_expunge();
1307}
1308
[c79a047]1309void owl_command_first(void)
[cf83b7a]1310{
[7d4fbcd]1311  owl_global_set_rightshift(&g, 0);
1312  owl_function_firstmsg();
1313}
1314
[c79a047]1315void owl_command_last(void)
[cf83b7a]1316{
[7d4fbcd]1317  owl_function_lastmsg();
1318}
1319
[c79a047]1320void owl_command_resize(void)
[cf83b7a]1321{
[7d4fbcd]1322  owl_function_resize();
1323}
1324
[c79a047]1325void owl_command_redisplay(void)
[cf83b7a]1326{
[7d4fbcd]1327  owl_function_full_redisplay();
1328}
1329
[6829afc]1330CALLER_OWN char *owl_command_get_shift(int argc, const char *const *argv, const char *buff)
[8c97fa1]1331{
1332  if(argc != 1)
1333  {
1334    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1335    return NULL;
1336  }
[3472845]1337  return g_strdup_printf("%d", owl_global_get_rightshift(&g));
[8c97fa1]1338}
1339
1340void owl_command_set_shift(int shift)
1341{
1342  owl_global_set_rightshift(&g, shift);
1343}
1344
[c79a047]1345void owl_command_unsuball(void)
[cf83b7a]1346{
[7d4fbcd]1347  owl_function_unsuball();
1348}
1349
[77beb3c]1350char *owl_command_flushlogs(int argc, const char *const *argv, const char *buff)
[ec36247]1351{
[4511ac3]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;
[77beb3c]1361    } else {
[4511ac3]1362      owl_function_makemsg("Invalid flag to flush-logs: %s", argv[i]);
[77beb3c]1363    }
1364  }
[4511ac3]1365  owl_log_flush_logs(force, quiet);
[77beb3c]1366  return NULL;
[ec36247]1367}
1368
[e19eb97]1369char *owl_command_loadsubs(int argc, const char *const *argv, const char *buff)
[cf83b7a]1370{
[7d4fbcd]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.");
[7933748]1377    return(NULL);
[7d4fbcd]1378  }
[7933748]1379  return(NULL);
1380}
1381
1382
[e19eb97]1383char *owl_command_loadloginsubs(int argc, const char *const *argv, const char *buff)
[cf83b7a]1384{
[7933748]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);
[7d4fbcd]1394}
1395
[c79a047]1396void owl_command_suspend(void)
[cf83b7a]1397{
[7d4fbcd]1398  owl_function_suspend();
1399}
1400
[e19eb97]1401char *owl_command_start_command(int argc, const char *const *argv, const char *buff)
[cf83b7a]1402{
[7d4fbcd]1403  buff = skiptokens(buff, 1);
1404  owl_function_start_command(buff);
[cf83b7a]1405  return(NULL);
[7d4fbcd]1406}
1407
[e19eb97]1408char *owl_command_zaway(int argc, const char *const *argv, const char *buff)
[cf83b7a]1409{
[7d4fbcd]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
[e19eb97]1434char *owl_command_away(int argc, const char *const *argv, const char *buff)
[4b660cc]1435{
[a38becd]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;
[8ba37ec]1442    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
[a38becd]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);
[8ba37ec]1450  }
1451
[a38becd]1452  if (away_off) {
[8ba37ec]1453    owl_function_zaway_off();
[a38becd]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.");
[8ba37ec]1465  }
1466
[4b660cc]1467  return NULL;
1468}
1469
[e19eb97]1470char *owl_command_set(int argc, const char *const *argv, const char *buff)
[cf83b7a]1471{
[e19eb97]1472  const char *var, *val;
[7d4fbcd]1473  int  silent=0;
[486688f]1474  int requirebool=0;
[ca54fd6]1475  owl_variable *v;
[7d4fbcd]1476
1477  if (argc == 1) {
1478    owl_function_printallvars();
1479    return NULL;
[486688f]1480  } 
1481
1482  if (argc > 1 && !strcmp("-q",argv[1])) {
[7d4fbcd]1483    silent = 1;
[486688f]1484    argc--; argv++;
1485  }
1486
1487  if (argc == 2) {
1488    var=argv[1];
1489    val="on";
1490    requirebool=1;
[7d4fbcd]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  }
[ca54fd6]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);
[3b9ca71]1502  } else if (requirebool && !v->takes_on_off) {
[ca54fd6]1503    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1504  } else {
1505    owl_variable_set_fromstring(v, val, !silent);
1506  }
[486688f]1507  return NULL;
1508}
[7d4fbcd]1509
[e19eb97]1510char *owl_command_unset(int argc, const char *const *argv, const char *buff)
[cf83b7a]1511{
[ca54fd6]1512  owl_variable *v;
[e19eb97]1513  const char *var, *val;
[486688f]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  }
[ca54fd6]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);
[3b9ca71]1531  } else if (!v->takes_on_off) {
[ca54fd6]1532    if (!silent) owl_function_error("Variable '%s' is not a boolean", var);
1533  } else {
1534    owl_variable_set_fromstring(v, val, !silent);
1535  }
[7d4fbcd]1536  return NULL;
1537}
1538
[e19eb97]1539char *owl_command_print(int argc, const char *const *argv, const char *buff)
[cf83b7a]1540{
[e19eb97]1541  const char *var;
[010a951]1542  char *value;
[ca54fd6]1543  const owl_variable *v;
[7d4fbcd]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   
[ca54fd6]1555  v = owl_variable_get_var(owl_global_get_vardict(&g), var);
1556  if (v) {
1557    value = owl_variable_get_tostring(v);
[ca749a9]1558    if (value == NULL)
1559      owl_function_makemsg("%s = <null>", var);
1560    else
1561      owl_function_makemsg("%s = '%s'", var, value);
[010a951]1562    g_free(value);
[7d4fbcd]1563  } else {
1564    owl_function_makemsg("Unknown variable '%s'.", var);
1565  }
1566  return NULL;
1567}
1568
1569
[6829afc]1570CALLER_OWN char *owl_command_exec(int argc, const char *const *argv, const char *buff)
[cf83b7a]1571{
[7ba9e0de]1572  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_RETURN);
[7d4fbcd]1573}
1574
[6829afc]1575CALLER_OWN char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
[cf83b7a]1576{
[7ba9e0de]1577  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_POPUP);
[7d4fbcd]1578}
1579
[6829afc]1580CALLER_OWN char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
[cf83b7a]1581{
[7ba9e0de]1582  return owl_function_exec(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
[7d4fbcd]1583}
1584
[6829afc]1585CALLER_OWN char *owl_command_perl(int argc, const char *const *argv, const char *buff)
[cf83b7a]1586{
[7ba9e0de]1587  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_RETURN);
[7d4fbcd]1588}
1589
[6829afc]1590CALLER_OWN char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
[cf83b7a]1591{
[7ba9e0de]1592  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_POPUP);
[7d4fbcd]1593}
1594
[6829afc]1595CALLER_OWN char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
[cf83b7a]1596{
[7ba9e0de]1597  return owl_function_perl(argc, argv, buff, OWL_OUTPUT_ADMINMSG);
[7d4fbcd]1598}
1599
[6829afc]1600CALLER_OWN char *owl_command_multi(int argc, const char *const *argv, const char *buff)
[cf83b7a]1601{
[42c2a80]1602  char *lastrv = NULL, *newbuff;
[7d4fbcd]1603  char **commands;
[d275eb2]1604  int  i;
[7d4fbcd]1605  if (argc < 2) {
1606    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1607    return NULL;
1608  }
[d4927a7]1609  newbuff = g_strdup(skiptokens(buff, 1));
[7d4fbcd]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.");   
[ddbbcffa]1617        g_free(newbuff);
[7d4fbcd]1618        return NULL;
1619      }
1620    }
1621  }
[d275eb2]1622  commands = g_strsplit_set(newbuff, ";", 0);
1623  for (i = 0; commands[i] != NULL; i++) {
[3b8a563]1624    g_free(lastrv);
[7d4fbcd]1625    lastrv = owl_function_command(commands[i]);
1626  }
[ddbbcffa]1627  g_free(newbuff);
[d275eb2]1628  g_strfreev(commands);
[7d4fbcd]1629  return lastrv;
1630}
1631
1632
[e19eb97]1633char *owl_command_alias(int argc, const char *const *argv, const char *buff)
[cf83b7a]1634{
[7d4fbcd]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
[e19eb97]1645char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
[cf83b7a]1646{
[7d4fbcd]1647  owl_keymap *km;
1648  int ret;
1649
1650  if (argc < 5 || strcmp(argv[3], "command")) {
[f1e629d]1651    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
[7d4fbcd]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
[8a921b5]1669
[b4a95fc]1670char *owl_command_unbindkey(int argc, const char *const *argv, const char *buf)
[8a921b5]1671{
1672  owl_keymap *km;
1673  int ret;
1674
1675  if (argc < 3) {
[39a531d]1676    owl_function_makemsg("Usage: unbindkey <keymap> <binding>");
[8a921b5]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
[c79a047]1697void owl_command_quit(void)
[cf83b7a]1698{
[7d4fbcd]1699  owl_function_quit();
1700}
1701
[e19eb97]1702char *owl_command_debug(int argc, const char *const *argv, const char *buff)
[cf83b7a]1703{
[7d4fbcd]1704  if (argc<2) {
1705    owl_function_makemsg("Need at least one argument to debug command");
[ecd5dc5]1706    return(NULL);
[7d4fbcd]1707  }
1708
1709  if (!owl_global_is_debug_fast(&g)) {
1710    owl_function_makemsg("Debugging is not turned on");
[ecd5dc5]1711    return(NULL);
[7d4fbcd]1712  }
1713
[554a2b8]1714  owl_function_debugmsg("%s", argv[1]);
[ecd5dc5]1715  return(NULL);
[7d4fbcd]1716}
1717
[e19eb97]1718char *owl_command_term(int argc, const char *const *argv, const char *buff)
[cf83b7a]1719{
[ecd5dc5]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 {
[d09e5a1]1730    owl_function_makemsg("Unknown terminal subcommand");
[ecd5dc5]1731  }
1732  return(NULL);
[7d4fbcd]1733}
1734
[e19eb97]1735char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
[cf83b7a]1736{
[425c013]1737  if ((argc<2) || (argc>3)) {
[7d4fbcd]1738    owl_function_makemsg("Wrong number of arguments for zlog command");
[425c013]1739    return(NULL);
[7d4fbcd]1740  }
1741
1742  if (!strcmp(argv[1], "in")) {
[425c013]1743    if (argc>2) {
1744      owl_global_set_tty(&g, argv[2]);
1745    }
[31e48a3]1746    owl_zephyr_zlog_in();
[7d4fbcd]1747  } else if (!strcmp(argv[1], "out")) {
[425c013]1748    if (argc!=2) {
1749      owl_function_makemsg("Wrong number of arguments for zlog command");
1750      return(NULL);
1751    }
[31e48a3]1752    owl_zephyr_zlog_out();
[7d4fbcd]1753  } else {
1754    owl_function_makemsg("Invalid subcommand for zlog");
1755  }
[425c013]1756  return(NULL);
[7d4fbcd]1757}
1758
[e19eb97]1759char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
[cf83b7a]1760{
[e19eb97]1761  const char *class, *instance, *recip="";
[bde7714]1762  int temp=0;
[3617286]1763  int ret=0;
[f830d84]1764
1765  if (argc < 2) {
[7d4fbcd]1766    owl_function_makemsg("Not enough arguments to the subscribe command");
[bde7714]1767    return(NULL);
1768  }
1769  argc--;
1770  argv++;
1771
1772  if (!strcmp(argv[0], "-t")) {
1773    temp=1;
1774    argc--;
1775    argv++;
1776  }
[f830d84]1777  if (argc < 1) {
[bde7714]1778    owl_function_makemsg("Not enough arguments to the subscribe command");
1779    return(NULL);
1780  }
1781
[f830d84]1782  if (argc > 3) {
[7d4fbcd]1783    owl_function_makemsg("Too many arguments to the subscribe command");
[bde7714]1784    return(NULL);
[7d4fbcd]1785  }
1786
[f830d84]1787  class = argv[0];
1788
1789  if (argc == 1) {
1790    instance = "*";
1791  } else {
1792    instance = argv[1];
1793  }
1794
1795  if (argc <= 2) {
[7d4fbcd]1796    recip="";
[bde7714]1797  } else if (argc==3) {
1798    recip=argv[2];
[7d4fbcd]1799  }
1800
[f830d84]1801  ret = owl_function_subscribe(class, instance, recip);
[3617286]1802  if (!temp && !ret) {
[f830d84]1803    owl_zephyr_addsub(NULL, class, instance, recip);
[bde7714]1804  }
1805  return(NULL);
[7d4fbcd]1806}
1807
1808
[e19eb97]1809char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
[cf83b7a]1810{
[e19eb97]1811  const char *class, *instance, *recip="";
[bde7714]1812  int temp=0;
[7d4fbcd]1813
[f830d84]1814  if (argc < 2) {
[7d4fbcd]1815    owl_function_makemsg("Not enough arguments to the unsubscribe command");
[bde7714]1816    return(NULL);
1817  }
1818  argc--;
1819  argv++;
1820
1821  if (!strcmp(argv[0], "-t")) {
1822    temp=1;
1823    argc--;
1824    argv++;
1825  }
[f830d84]1826  if (argc < 1) {
1827    owl_function_makemsg("Not enough arguments to the unsubscribe command");
[bde7714]1828    return(NULL);
1829  }
1830
[f830d84]1831  if (argc > 3) {
[7d4fbcd]1832    owl_function_makemsg("Too many arguments to the unsubscribe command");
[bde7714]1833    return(NULL);
[7d4fbcd]1834  }
1835
[f830d84]1836  class = argv[0];
1837
1838  if (argc == 1) {
1839    instance = "*";
1840  } else {
1841    instance = argv[1];
1842  }
1843
1844  if (argc <= 2) {
[7d4fbcd]1845    recip="";
[bde7714]1846  } else if (argc==3) {
1847    recip=argv[2];
[7d4fbcd]1848  }
1849
[f830d84]1850  owl_function_unsubscribe(class, instance, recip);
[bde7714]1851  if (!temp) {
[f830d84]1852    owl_zephyr_delsub(NULL, class, instance, recip);
[bde7714]1853  }
1854  return(NULL);
[7d4fbcd]1855}
1856
[e19eb97]1857char *owl_command_echo(int argc, const char *const *argv, const char *buff)
[cf83b7a]1858{
[7d4fbcd]1859  buff = skiptokens(buff, 1);
1860  owl_function_popless_text(buff);
1861  return NULL;
1862}
1863
[cf83b7a]1864void owl_command_getsubs(void)
1865{
[7d4fbcd]1866  owl_function_getsubs();
1867}
1868
[cf83b7a]1869void owl_command_status(void)
1870{
[7d4fbcd]1871  owl_function_status();
1872}
1873
[e19eb97]1874char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
[cf83b7a]1875{
[987cf3f]1876  owl_zwrite *z;
[1c6c4d3]1877
[5b85d19]1878  if (!owl_global_is_havezephyr(&g)) {
1879    owl_function_makemsg("Zephyr is not available");
1880    return(NULL);
1881  }
[1c6c4d3]1882  /* check for a zwrite -m */
[f89cc6f]1883  z = owl_zwrite_new(argc, argv);
[987cf3f]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;
[1c6c4d3]1893  }
1894
[7d4fbcd]1895  if (argc < 2) {
[987cf3f]1896    owl_zwrite_delete(z);
[7d4fbcd]1897    owl_function_makemsg("Not enough arguments to the zwrite command.");
1898  } else {
[987cf3f]1899    owl_function_zwrite_setup(z);
[7d4fbcd]1900  }
[ce7db4d]1901  return(NULL);
[7d4fbcd]1902}
1903
[e19eb97]1904char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
[37eab7f]1905{
1906  owl_function_loopwrite_setup();
1907  return(NULL);
1908}
1909
[e19eb97]1910char *owl_command_reply(int argc, const char *const *argv, const char *buff)
[cf83b7a]1911{
[7d4fbcd]1912  int edit=0;
1913 
[8df36cc]1914  if (argc>=2 && !strcmp("-e", argv[1])) {
[7d4fbcd]1915    edit=1;
1916    argv++;
[217a43e]1917    argc--;
[7d4fbcd]1918  }
1919
1920  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1921    owl_function_reply(0, !edit);
[e75011e]1922  } else if (argc==2 && !strcmp(argv[1], "sender")) {
[7d4fbcd]1923    owl_function_reply(1, !edit);
[e75011e]1924  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
[c08c70a]1925    const owl_message *m;
[9e5c9f3]1926    const owl_view    *v;
[e75011e]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);
[7d4fbcd]1930  } else {
1931    owl_function_makemsg("Invalid arguments to the reply command.");
1932  }
1933  return NULL;
1934}
1935
[e19eb97]1936char *owl_command_filter(int argc, const char *const *argv, const char *buff)
[cf83b7a]1937{
[7d4fbcd]1938  owl_function_create_filter(argc, argv);
1939  return NULL;
1940}
1941
[e19eb97]1942char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
[cf83b7a]1943{
[2527615]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++;
[7d4fbcd]1957    } else {
[2527615]1958      owl_function_makemsg("Missing arguments for zlocate command");
[7d4fbcd]1959      return NULL;
1960    }
1961  }
[2527615]1962
1963  argc--;
1964  argv++;
1965  owl_function_zlocate(argc, argv, auth);
[7d4fbcd]1966  return NULL;
1967}
1968
[3895e23]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 */
[e19eb97]1976char *owl_command_view(int argc, const char *const *argv, const char *buff)
[cf83b7a]1977{
[3895e23]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);
[ddbbcffa]1987      g_free(foo);
[3895e23]1988      return(NULL);
1989    }
[7d4fbcd]1990  }
1991
[ef56a67]1992  /* Now look for 'view <filter>' */
1993  if (argc==2) {
[3895e23]1994    owl_function_change_currentview_filter(argv[1]);
[ef56a67]1995    return(NULL);
1996  }
1997
1998  /* Now get 'view -d <expression>' */
[94e4899]1999  if (argc>=3 && !strcmp(argv[1], "-d")) {
[e19eb97]2000    const char **myargv;
[7d4fbcd]2001    int i;
2002
[dfe5829]2003    /* Allocate one more than argc for the trailing NULL. */
2004    myargv = g_new0(const char*, argc+1);
[7d4fbcd]2005    myargv[0]="";
2006    myargv[1]="owl-dynamic";
2007    for (i=2; i<argc; i++) {
2008      myargv[i]=argv[i];
2009    }
[287c634]2010    if (owl_function_create_filter(argc, myargv)) {
2011      owl_function_change_currentview_filter("owl-dynamic");
2012    }
[ddbbcffa]2013    g_free(myargv);
[7d4fbcd]2014    return NULL;
2015  }
2016
[ef56a67]2017  /* Finally handle the general case */
2018  if (argc<3) {
2019    owl_function_makemsg("Too few arguments to the view command.");
2020    return(NULL);
[7d4fbcd]2021  }
[ef56a67]2022  argc--;
2023  argv++;
[3895e23]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")) {
[ef56a67]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) {
[8258ea5]2039        owl_function_makemsg("Too few arguments to the view command");
[ef56a67]2040        return(NULL);
2041      }
[3895e23]2042      owl_function_change_currentview_filter(argv[1]);
[ef56a67]2043      argc-=2;
2044      argv+=2;
2045    } else if (!strcmp(argv[0], "--home")) {
[3895e23]2046      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
[ef56a67]2047      argc--;
2048      argv++;
2049    } else if (!strcmp(argv[0], "-s")) {
2050      if (argc<2) {
[8258ea5]2051        owl_function_makemsg("Too few arguments to the view command");
[ef56a67]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 {
[8258ea5]2058      owl_function_makemsg("Too few arguments to the view command");
[ef56a67]2059      return(NULL);
2060    }
2061   
2062  }
2063  return(NULL);
[7d4fbcd]2064}
2065
[e19eb97]2066char *owl_command_show(int argc, const char *const *argv, const char *buff)
[cf83b7a]2067{
[7d4fbcd]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    }
[ef56a67]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    }
[7d4fbcd]2106  } else if (!strcmp(argv[1], "colors")) {
2107    owl_function_show_colors();
[f1e629d]2108  } else if (!strcmp(argv[1], "styles")) {
2109    owl_function_show_styles();
[7d4fbcd]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();
[debb15d]2118  } else if (!strcmp(argv[1], "license")) {
2119    owl_function_show_license();
[799b60e]2120  } else if (!strcmp(argv[1], "quickstart")) {
2121    owl_function_show_quickstart();
[f17bff98]2122  } else if (!strcmp(argv[1], "startup")) {
[e19eb97]2123    const char *filename;
[f17bff98]2124   
[b363d83]2125    filename=owl_global_get_startupfile(&g);
[f17bff98]2126    owl_function_popless_file(filename);
[ec6ff52]2127  } else if (!strcmp(argv[1], "errors")) {
2128    owl_function_showerrs();
[7d4fbcd]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
[e19eb97]2136char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
[cf83b7a]2137{
[7360fab]2138  char *filtname;
[7d4fbcd]2139  if (argc!=2) {
2140    owl_function_makemsg("Wrong number of arguments to viewclass command");
2141    return NULL;
2142  }
[66e409c]2143  filtname = owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
[c7fe23e]2144  if (filtname) {
2145    owl_function_change_currentview_filter(filtname);
[ddbbcffa]2146    g_free(filtname);
[c7fe23e]2147  }
[7d4fbcd]2148  return NULL;
2149}
2150
[e19eb97]2151char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
[cf83b7a]2152{
[7360fab]2153  char *filtname;
[e06f413]2154  char *longuser;
[7d4fbcd]2155  if (argc!=2) {
2156    owl_function_makemsg("Wrong number of arguments to viewuser command");
2157    return NULL;
2158  }
[e06f413]2159  longuser = long_zuser(argv[1]);
2160  filtname = owl_function_zuserfilt(longuser);
[ddbbcffa]2161  g_free(longuser);
[c7fe23e]2162  if (filtname) {
2163    owl_function_change_currentview_filter(filtname);
[ddbbcffa]2164    g_free(filtname);
[c7fe23e]2165  }
[7d4fbcd]2166  return NULL;
2167}
2168
2169
[cf83b7a]2170void owl_command_pop_message(void)
2171{
[7d4fbcd]2172  owl_function_curmsg_to_popwin();
2173}
2174
[e19eb97]2175char *owl_command_delete(int argc, const char *const *argv, const char *buff)
[cf83b7a]2176{
[b950088]2177  int move_after = 1;
2178
[8ee73f8d]2179  if (argc>1 && !strcmp(argv[1], "--no-move")) {
[b950088]2180    move_after = 0;
2181    argc--; 
2182    argv++;
2183  }
2184
[7d4fbcd]2185  if (argc==1) {
[b950088]2186    owl_function_deletecur(move_after);
[7d4fbcd]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
[7360fab]2200  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
[7d4fbcd]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
[efeec7f]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
[e19eb97]2236char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
[cf83b7a]2237{
[b950088]2238  int move_after = 1;
2239
[8ee73f8d]2240  if (argc>1 && !strcmp(argv[1], "--no-move")) {
[b950088]2241    move_after = 0;
2242    argc--; 
2243    argv++;
2244  }
2245
[7d4fbcd]2246  if (argc==1) {
[b950088]2247    owl_function_undeletecur(move_after);
[7d4fbcd]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
[7360fab]2256  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
[7d4fbcd]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
[c79a047]2265void owl_command_beep(void)
[cf83b7a]2266{
[7d4fbcd]2267  owl_function_beep();
2268}
2269
[e19eb97]2270char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
[cf83b7a]2271{
[8fa9562]2272  if (argc < 2 || argc > 3) {
[7d4fbcd]2273    owl_function_makemsg("Wrong number of arguments to colorview command");
2274    return NULL;
2275  }
[8fa9562]2276  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
[7d4fbcd]2277  return NULL;
2278}
2279
[e19eb97]2280char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
[5e0b690]2281{
[c7fe23e]2282  char *filtname;
[5e0b690]2283 
[8fa9562]2284  if (argc < 3 || argc > 4) {
[5e0b690]2285    owl_function_makemsg("Wrong number of arguments to colorclass command");
2286    return NULL;
2287  }
2288
[66e409c]2289  filtname=owl_function_classinstfilt(argv[1], NULL, owl_global_is_narrow_related(&g));
[c7fe23e]2290  if (filtname) {
2291    (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
[ddbbcffa]2292    g_free(filtname);
[c7fe23e]2293  }
[5e0b690]2294  return NULL;
2295}
2296
[e19eb97]2297char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
[cf83b7a]2298{
[7d4fbcd]2299  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2300  return NULL;
2301}
2302
[e19eb97]2303char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
[cf83b7a]2304{
[7d4fbcd]2305  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2306  return NULL;
2307}
2308
[e19eb97]2309void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
[cf83b7a]2310{
[7d4fbcd]2311  /* if type==0 then zpunt
2312   * if type==1 then zunpunt
2313   */
[e19eb97]2314  const char *class, *inst, *recip;
[7d4fbcd]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
[e19eb97]2346char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
[cf83b7a]2347{
[d36f2cb]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
[e19eb97]2358char *owl_command_punt(int argc, const char *const *argv, const char *buff)
[ce7b824]2359{
2360  owl_command_punt_unpunt(argc, argv, buff, 0);
2361  return NULL;
2362}
2363
[e19eb97]2364char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
[ce7b824]2365{
2366  owl_command_punt_unpunt(argc, argv, buff, 1);
2367  return NULL;
2368}
2369
[e19eb97]2370void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
[ce7b824]2371{
[e6d7e4e]2372  GPtrArray * fl;
[ce7b824]2373  int i;
2374
2375  fl = owl_global_get_puntlist(&g);
2376  if(argc == 1) {
2377    owl_function_show_zpunts();
[2c68a93]2378  } else if(argc == 2) {
[ce7b824]2379    /* Handle :unpunt <number> */
[901cee9]2380    if (unpunt && (i = atoi(argv[1])) > 0) {
[ce7b824]2381      i--;      /* Accept 1-based indexing */
[e6d7e4e]2382      if (i < fl->len) {
2383        owl_filter_delete(g_ptr_array_remove_index(fl, i));
[ce7b824]2384        return;
2385      } else {
[697221f]2386        owl_function_makemsg("No such filter number: %d.", i+1);
[ce7b824]2387      }
2388    }
[78f6c35]2389    const char *filter[] = {"filter", argv[1]};
2390    owl_function_punt(2, filter, unpunt);
[ce7b824]2391  } else {
[78f6c35]2392    /* Pass in argv[1]..argv[argc-1]. */
2393    owl_function_punt(argc - 1, argv + 1, unpunt);
[ce7b824]2394  }
2395}
2396
2397
[e19eb97]2398char *owl_command_getview(int argc, const char *const *argv, const char *buff)
[cf83b7a]2399{
[e19eb97]2400  const char *filtname;
[8ee73f8d]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));
[d4927a7]2406  if (filtname) return g_strdup(filtname);
[fa4562c]2407  return NULL;
[8ee73f8d]2408}
[d36f2cb]2409
[ca54fd6]2410CALLER_OWN char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
[cf83b7a]2411{
[ca54fd6]2412  const owl_variable *v;
[8ee73f8d]2413  if (argc != 2) {
2414    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2415    return NULL;
2416  }
[ca54fd6]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);
[8ee73f8d]2420}
[7d4fbcd]2421
[e19eb97]2422char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
[cdc6ff1]2423{
[4542047]2424  const owl_filter *f;
[cdc6ff1]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
[e19eb97]2436char *owl_command_search(int argc, const char *const *argv, const char *buff)
[cf83b7a]2437{
[1fd0b25]2438  int direction;
[e19eb97]2439  const char *buffstart;
[1fd0b25]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"))) {
[118c919]2449    /* When continuing a search, don't consider the current message. */
2450    owl_function_search_helper(false, direction);
[1fd0b25]2451  } else {
[a728387]2452    owl_function_set_search(buffstart);
[118c919]2453    owl_function_search_helper(true, direction);
[1fd0b25]2454  }
2455 
2456  return(NULL);
2457}
2458
[e19eb97]2459char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
[987ff51]2460{
[e19eb97]2461  const char *buffstart;
[987ff51]2462
2463  buffstart=skiptokens(buff, 1);
[2ec737f]2464  owl_function_set_search(*buffstart ? buffstart : NULL);
[987ff51]2465 
2466  return(NULL);
2467}
2468
[6829afc]2469CALLER_OWN char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
[216c734]2470{
[e19eb97]2471  const char *stylename;
[216c734]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));
[d4927a7]2477  if (stylename) return g_strdup(stylename);
[fa4562c]2478  return NULL;
[216c734]2479}
2480
[e19eb97]2481char *owl_command_error(int argc, const char *const *argv, const char *buff)
[4692b70]2482{
2483    buff = skiptokens(buff, 1);
[554a2b8]2484    owl_function_error("%s", buff);
[4692b70]2485    return NULL;
2486}
2487
[e19eb97]2488char *owl_command_message(int argc, const char *const *argv, const char *buff)
[4692b70]2489{
2490    buff = skiptokens(buff, 1);
[554a2b8]2491    owl_function_makemsg("%s", buff);
[4692b70]2492    return NULL;
2493}
2494
[35d2091]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);
[b470451]2507  owl_history_store(hist, ptr, false);
[35d2091]2508  /* owl_function_makemsg("History '%s' stored successfully", ptr+1); */
2509  return NULL;
2510}
2511
[6829afc]2512CALLER_OWN char *owl_command_with_history(int argc, const char *const *argv, const char *buff)
[35d2091]2513{
2514  owl_history *hist;
2515  const char *ptr;
2516
2517  if (argc < 2) {
[7473e38b]2518    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
[35d2091]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);
[b470451]2529  owl_history_store(hist, ptr, false);
[35d2091]2530  return owl_function_command(ptr);
2531}
2532
[12e5f17]2533void owl_command_yes(void)
[f4d32cd]2534{
[cba04e0]2535  owl_message *m;
[9e5c9f3]2536  const owl_view *v;
[e19eb97]2537  const char *cmd;
[cba04e0]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.");
[12e5f17]2544    return;
[cba04e0]2545  }
2546
2547  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
[f4d32cd]2548  if(!owl_message_is_question(m)) {
2549    owl_function_error("That message isn't a question.");
[12e5f17]2550    return;
[f4d32cd]2551  }
2552  if(owl_message_is_answered(m)) {
2553    owl_function_error("You already answered that question.");
[12e5f17]2554    return;
[f4d32cd]2555  }
[ad15610]2556  cmd = owl_message_get_attribute_value(m, "yescommand");
[f4d32cd]2557  if(!cmd) {
[451db9e]2558    owl_function_error("No 'yes' command!");
[12e5f17]2559    return;
[f4d32cd]2560  }
2561
2562  owl_function_command_norv(cmd);
2563  owl_message_set_isanswered(m);
[12e5f17]2564  return;
[f4d32cd]2565}
2566
[12e5f17]2567void owl_command_no(void)
[f4d32cd]2568{
[cba04e0]2569  owl_message *m;
[9e5c9f3]2570  const owl_view *v;
[e19eb97]2571  const char *cmd;
[cba04e0]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.");
[12e5f17]2578    return;
[cba04e0]2579  }
2580
2581  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
[f4d32cd]2582  if(!owl_message_is_question(m)) {
2583    owl_function_error("That message isn't a question.");
[12e5f17]2584    return;
[f4d32cd]2585  }
2586  if(owl_message_is_answered(m)) {
2587    owl_function_error("You already answered that question.");
[12e5f17]2588    return;
[f4d32cd]2589  }
[ad15610]2590  cmd = owl_message_get_attribute_value(m, "nocommand");
[f4d32cd]2591  if(!cmd) {
[451db9e]2592    owl_function_error("No 'no' command!");
[12e5f17]2593    return;
[f4d32cd]2594  }
2595
2596  owl_function_command_norv(cmd);
2597  owl_message_set_isanswered(m);
[12e5f17]2598  return;
[f4d32cd]2599}
2600
[7d4fbcd]2601/*********************************************************************/
2602/************************** EDIT SPECIFIC ****************************/
2603/*********************************************************************/
2604
[cf83b7a]2605void owl_command_edit_cancel(owl_editwin *e)
2606{
[10b866d]2607  owl_history *hist;
2608
[7d4fbcd]2609  owl_function_makemsg("Command cancelled.");
[10b866d]2610
[13e2096]2611  hist = owl_editwin_get_history(e);
[83a079a]2612  if (hist)
[b470451]2613    owl_history_store(hist, owl_editwin_get_text(e), false);
[10b866d]2614
[7803326]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);
[2a17b63]2620  owl_global_pop_context(&g);
[7803326]2621
2622  owl_editwin_do_callback(e, false);
2623  owl_editwin_unref(e);
[7d4fbcd]2624}
2625
[cf83b7a]2626void owl_command_edit_history_prev(owl_editwin *e)
2627{
[7d4fbcd]2628  owl_history *hist;
[e19eb97]2629  const char *ptr;
[7d4fbcd]2630
[10b866d]2631  hist=owl_editwin_get_history(e);
[13e2096]2632  if (!hist)
2633    return;
[b470451]2634  if (!owl_history_is_touched(hist))
2635    owl_history_store(hist, owl_editwin_get_text(e), true);
[7d4fbcd]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
[cf83b7a]2645void owl_command_edit_history_next(owl_editwin *e)
2646{
[7d4fbcd]2647  owl_history *hist;
[e19eb97]2648  const char *ptr;
[7d4fbcd]2649
[10b866d]2650  hist=owl_editwin_get_history(e);
[13e2096]2651  if (!hist)
2652    return;
[7d4fbcd]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
[e19eb97]2662char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
[cf83b7a]2663{
[7d4fbcd]2664  buff = skiptokens(buff, 1);
2665  owl_editwin_insert_string(e, buff);
2666  return NULL;
2667}
2668
[435d6b2]2669void owl_command_edit_done(owl_editwin *e)
[cf83b7a]2670{
[10b866d]2671  owl_history *hist=owl_editwin_get_history(e);
2672
[83a079a]2673  if (hist)
[b470451]2674    owl_history_store(hist, owl_editwin_get_text(e), false);
[10b866d]2675
[c394de8]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);
[2a17b63]2681  owl_global_pop_context(&g);
[d83621c4]2682
[7803326]2683  owl_editwin_do_callback(e, true);
[9190285]2684  owl_editwin_unref(e);
[7d4fbcd]2685}
2686
[435d6b2]2687void owl_command_edit_done_or_delete(owl_editwin *e)
[cf83b7a]2688{
[217a43e]2689  if (owl_editwin_is_at_end(e)) {
[435d6b2]2690    owl_command_edit_done(e);
[217a43e]2691  } else {
2692    owl_editwin_delete_char(e);
2693  }
2694}
2695
[7d4fbcd]2696
2697/*********************************************************************/
2698/*********************** POPLESS SPECIFIC ****************************/
2699/*********************************************************************/
2700
[cf83b7a]2701void owl_command_popless_quit(owl_viewwin *vw)
2702{
[8ee712e0]2703  owl_popwin *pw;
2704  pw = owl_global_get_popwin(&g);
2705  owl_global_set_popwin(&g, NULL);
[9eb38bb]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);
[8ee712e0]2711  owl_popwin_delete(pw);
[2a17b63]2712  owl_global_pop_context(&g);
[7d4fbcd]2713}
Note: See TracBrowser for help on using the repository browser.