source: commands.c @ e54a746

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