source: commands.c @ 15b87cc

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