source: commands.c @ f809cad

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