source: commands.c @ 685cca7

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