source: commands.c @ 55562e1

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 55562e1 was 55562e1, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
Added 'get <variable>' command which returns the value of the variable as a string. This allows variable values to be retrieved from perl with the likes of: if ("on" eq &owl::command('get zaway')) { ... }
  • Property mode set to 100644
File size: 55.3 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include "owl.h"
6
7static const char fileIdent[] = "$Id$";
8
9/* fn is "char *foo(int argc, char **argv, char *buff)" */
10#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
11        { name, summary, usage, description, ctx, \
12          NULL, fn, NULL, NULL, NULL, NULL, NULL }
13
14/* fn is "void foo(void)" */
15#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
16        { name, summary, usage, description, ctx, \
17          NULL, NULL, fn, NULL, NULL, NULL, NULL }
18
19/* fn is "void foo(int)" */
20#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
21        { name, summary, usage, description, ctx, \
22          NULL, NULL, NULL, fn, NULL, NULL, NULL }
23
24#define OWLCMD_ALIAS(name, actualname) \
25        { name, OWL_CMD_ALIAS_SUMMARY_PREFIX actualname, "", "", OWL_CTX_ANY, \
26          actualname, NULL, NULL, NULL, NULL, NULL, NULL }
27
28/* fn is "char *foo(void *ctx, int argc, char **argv, char *buff)" */
29#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
30        { name, summary, usage, description, ctx, \
31          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,char**,char*))fn), NULL, NULL }
32
33/* fn is "void foo(void)" */
34#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
35        { name, summary, usage, description, ctx, \
36          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL }
37
38/* fn is "void foo(int)" */
39#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
40        { name, summary, usage, description, ctx, \
41          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn) }
42
43
44owl_cmd commands_to_init[]
45  = {
46  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
47              "send a login or logout notification",
48              "zlog in [tty]\nzlog out",
49              "zlog in will send a login notification, zlog out will send a\n"
50              "logout notification.  By default a login notification is sent\n"
51              "when owl is started and a logout notification is sent when owl\n"
52              "is exited.  This behavior can be changed with the 'startuplogin'\n"
53              "and 'shudownlogout' variables.  If a tty is specified for zlog in\n"
54              "then the owl variable 'tty' will be set to that string, causing\n"
55              "it to be used as the zephyr location tty.\n"),
56
57  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
58              "exit owl",
59              "",
60              "Exit owl and run any shutdown activities."),
61  OWLCMD_ALIAS("exit", "quit"),
62  OWLCMD_ALIAS("q",    "quit"),
63 
64  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
65              "prompts the user to enter a command",
66              "start-command [initial-value]",
67              "Initializes the command field to initial-value."),
68
69  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
70              "creates a command alias",
71              "alias <new_command> <old_command>",
72              "Creates a command alias from new_command to old_command.\n"
73              "Any arguments passed to <new_command> will be appended to\n"
74              "<old_command> before it is executed.\n"),
75
76  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
77              "creates a binding in a keymap",
78              "bindkey <keymap> <keyseq> command <command>",
79              "Binds a key sequence to a command within a keymap.\n"
80              "Use 'show keymaps' to see the existing keymaps.\n"
81              "Key sequences may be things like M-C-t or NPAGE.\n"),
82
83  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
84              "send a zephyr",
85              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
86              "Zwrite send a zephyr to the one or more users specified.\n\n"
87              "The following options are available:\n\n"
88              "-m    Specifies a message to send without prompting.\n"
89              "      Note that this does not yet log an outgoing message.\n"
90              "      This must be the last argument.\n\n"
91              "-n    Do not send a ping message.\n\n"
92              "-C    If the message is sent to more than one user include a\n"
93              "      \"cc:\" line in the text\n\n"
94              "-c class\n"
95              "      Send to the specified zephyr class\n\n"
96              "-i instance\n"
97              "      Send to the specified zephyr instance\n\n"
98              "-r realm\n"
99              "      Send to a foreign realm\n"
100              "-O opcode\n"
101              "      Send to the specified opcode\n"),
102
103  /*
104  OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
105              "send an encrypted zephyr",
106              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [-m <message...>]\n",
107              "Behaves like zwrite but uses encryption.  Not for use with\n"
108              "personal messages\n"),
109  */
110 
111  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
112              "reply to the current message",
113              "reply [-e] [ sender | all | zaway ]",
114              "If -e is specified, the zwrite command line is presented to\n"
115              "allow editing.\n\n"
116              "If 'sender' is specified, reply to the sender.\n\n"
117              "If 'all' or no args are specified, reply publically to the\n"
118              "same class/instance for non-personal messages and to the\n"
119              "sender for personal messages.\n\n"
120              "If 'zaway' is specified, replies with a zaway message.\n\n"),
121
122  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
123              "set a variable value",
124              "set [-q] <variable> [<value>]\n"
125              "set",
126              "Set the named variable to the specified value.  If no\n"
127              "arguments are used print the value of all variables.\n"
128              "If value is unspecified and the variable is a boolean, will set it to 'on'.\n"
129              "If -q is specified, is silent and doesn't print a message.\n"),
130
131  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
132              "unset a boolean variable value",
133              "set [-q] <variable>\n"
134              "set",
135              "Set the named boolean variable to off.\n"
136              "If -q is specified, is silent and doesn't print a message.\n"),
137
138  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
139              "print a variable value",
140              "print <variable>\n"
141              "print",
142              "Print the value of the named variable.  If no arugments\n"
143              "are used print the value of all variables.\n"),
144
145  OWLCMD_ARGS("get", owl_command_get_variable, OWL_CTX_ANY,
146              "returns a variable value",
147              "get <variable>",
148              "Returns the value of the named variable as a string.\n"),
149
150  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
151              "print the version of the running owl", "", ""),
152
153  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
154              "subscribe to a zephyr class, instance, recipient",
155              "subscribe [-t] <class> <instance> [recipient]",
156              "Subscribe the specified class and instance.  If the recipient\n"
157              "is not listed on the command line it defaults\n"
158              "to * (the wildcard recipient).  If the -t option is present\n"
159              "the subscription will only be temporary, i.e., it will not\n"
160              "be written to the subscription file and will therefore not\n"
161              "be present the next time owl is started.\n"),
162  OWLCMD_ALIAS("sub", "subscribe"),
163
164  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
165              "unsubscribe from a zephyr class, instance, recipient",
166              "unsubscribe [-t] <class> <instance> [recipient]",
167              "Unsubscribe from the specified class and instance.  If the\n"
168              "recipient is not listed on the command line it defaults\n"
169              "to * (the wildcard recipient).  If the -t option is present\n"
170              "the unsubscription will only be temporary, i.e., it will not\n"
171              "be updated in the subscription file and will therefore not\n"
172              "be in effect the next time owl is started.\n"),
173  OWLCMD_ALIAS("unsub", "unsubscribe"),
174
175  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
176              "unsubscribe from all zephyrs", "", ""),
177 
178  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
179              "print all current subscriptions",
180              "getsubs",
181              "getsubs retrieves the current subscriptions from the server\n"
182              "and displays them.\n"),
183
184  OWLCMD_ARGS("dump", owl_command_dump, OWL_CTX_ANY,
185              "dump messages to a file",
186              "dump <filename>",
187              "Dump messages in current view to the named file."),
188
189  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
190              "creates a zpunt based on the current message",
191              "smartzpunt [-i | --instance]",
192              "Starts a zpunt command based on the current message's class\n"
193              "(and instance if -i is specified).\n"),
194
195  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
196              "suppress a given zephyr triplet",
197              "zpunt <class> <instance> [recipient]\n"
198              "zpunt <instance>",
199              "The zpunt command will supress message to the specified\n"
200              "zephyr triplet.  In the second usage messages as supressed\n"
201              "for class MESSAGE and the named instance.\n\n"
202              "SEE ALSO:  zunpunt, show zpunts\n"),
203
204  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
205              "undo a previous zpunt",
206              "zunpunt <class> <instance> [recipient]\n"
207              "zunpunt <instance>",
208              "The zunpunt command will allow messages that were previosly\n"
209              "suppressed to be received again.\n\n"
210              "SEE ALSO:  zpunt, show zpunts\n"),
211
212  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
213              "display detailed information about the current message",
214              "", ""),
215 
216  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
217              "display help on using owl",
218              "help [command]", ""),
219
220  OWLCMD_ARGS("zlist", owl_command_zlist, OWL_CTX_INTERACTIVE,
221              "List users logged in",
222              "znol [-f file]",
223              "Print a znol-style listing of users logged in"),
224 
225  OWLCMD_VOID("recv:shiftleft", owl_command_shift_left, OWL_CTX_INTERACTIVE,
226              "scrolls receive window to the left", "", ""),
227
228  OWLCMD_VOID("recv:shiftright", owl_command_shift_right, OWL_CTX_INTERACTIVE,
229              "scrolls receive window to the left", "", ""),
230
231  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
232              OWL_CTX_INTERACTIVE,
233              "scrolls down by a page", "", ""),
234
235  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
236              "scrolls up by a page", "", ""),
237
238  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
239              "scrolls current message up or down", 
240              "recv:scroll <numlines>", 
241              "Scrolls the current message up or down by <numlines>.\n"
242              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
243
244  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
245              "move the pointer to the next message",
246              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
247              "          [ --smart-filter | --smart-filter-instance ]",
248              "Moves the pointer to the next message in the current view.\n"
249              "If --filter is specified, will only consider messages in\n"
250              "the filter <name>.\n"
251              "If --smart-filter or --smart-filter-instance is specified,\n"
252              "goes to the next message that is similar to the current message.\n"
253              "If --skip-deleted is specified, deleted messages will\n"
254              "be skipped.\n"
255              "If --last-if-none is specified, will stop at last message\n"
256              "in the view if no other suitable messages are found.\n"),
257  OWLCMD_ALIAS("recv:next", "next"),
258
259  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
260              "move the pointer to the previous message",
261              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
262              "          [ --smart-filter | --smart-filter-instance ]",
263              "Moves the pointer to the next message in the current view.\n"
264              "If --filter is specified, will only consider messages in\n"
265              "the filter <name>.\n"
266              "If --smart-filter or --smart-filter-instance is specified,\n"
267              "goes to the previous message that is similar to the current message.\n"
268              "If --skip-deleted is specified, deleted messages will\n"
269              "be skipped.\n"
270              "If --first-if-none is specified, will stop at first message\n"
271              "in the view if no other suitable messages are found.\n"),
272  OWLCMD_ALIAS("recv:prev", "prev"),
273
274  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
275  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
276
277  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
278  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
279
280  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
281
282  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
283
284  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
285              "move the pointer to the first message", "", ""),
286  OWLCMD_ALIAS("recv:first", "first"),
287
288  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
289              "move the pointer to the last message", "", 
290              "Moves the pointer to the last message in the view.\n"
291              "If we are already at the last message in the view,\n"
292              "blanks the screen and moves just past the end of the view\n"
293              "so that new messages will appear starting at the top\n"
294              "of the screen.\n"),
295  OWLCMD_ALIAS("recv:last", "last"),
296
297  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
298              "remove all messages marked for deletion", "", ""),
299
300  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
301              "resize the window to the current screen size", "", ""),
302
303  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
304              "redraw the entire window", "", ""),
305
306  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
307              "suspend owl", "", ""),
308
309  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
310              "pops up a message in popup window",
311              "echo [args .. ]\n\n", ""),
312
313  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
314              "run a command from the shell",
315              "exec [args .. ]", ""),
316
317  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
318              "run a command from the shell and display in an admin message",
319              "aexec [args .. ]", ""),
320
321  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
322              "run a command from the shell and display in a popup window",
323              "pexec [args .. ]", ""),
324
325  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
326              "run a perl expression",
327              "perl [args .. ]", ""),
328
329  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
330              "run a perl expression and display in an admin message",
331              "aperl [args .. ]", ""),
332
333  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
334              "run a perl expression and display in a popup window",
335              "pperl [args .. ]", ""),
336
337  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
338              "runs multiple ;-separated commands",
339              "multi <command1> ( ; <command2> )*\n",
340              "Runs multiple semicolon-separated commands in order.\n"
341              "Note quoting isn't supported here yet.\n"
342              "If you want to do something fancy, use perl.\n"),
343
344  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
345              "runs multiple ;-separated commands",
346              "'(' <command1> ( ; <command2> )* ')'\n",
347              "Runs multiple semicolon-separated commands in order.\n"
348              "You must have a space before the final ')'\n"
349              "Note quoting isn't supported here yet.\n"
350              "If you want to do something fancy, use perl.\n"),
351
352  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
353              "pops up a message in a window", "", ""),
354
355  OWLCMD_VOID("openurl", owl_command_openurl, OWL_CTX_INTERACTIVE,
356              "opens up a URL from the current message",
357              "", 
358              "Uses the 'webbrowser' variable to determine\n"
359              "which browser to use.  Currently, 'netscape'\n"
360              "and 'galeon' are supported.\n"),
361
362  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
363              "running a command from the shell",
364              "zaway [ on | off | toggle ]\n"
365              "zaway <message>",
366              "Turn on or off the default zaway message.  If a message is\n"
367              "specified turn on zaway with that message\n"),
368
369  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
370              "load subscriptions from a file",
371              "load-subs <file>\n", ""),
372
373  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
374              "print information about owl", "", ""),
375
376  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
377              "print status information about the running owl", "", ""),
378 
379  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
380              "locate a user",
381              "zlocate [-d] <user> ...", 
382              "Performs a zlocate on one ore more users and puts the result\n"
383              "int a popwin.  If -d is specified, does not authenticate\n"
384              "the lookup request.\n"),
385 
386  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
387              "create a message filter",
388              "filter <name> [ -c color ] [ <expression> ... ]",
389              "The filter command creates a filter with the specified name,\n"
390              "or if one already exists it is replaced.  Example filter\n"
391              "syntax would be:\n\n"
392              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
393              "Valid matching fields are class, instance, recipient, sender,\n"
394              "opcode and realm. Valid operations are 'and', 'or' and 'not'.\n"
395              "Spaces must be present before and after parenthesis.  If the\n"
396              "optional color argument is used it specifies the color that\n"
397              "messages matching this filter should be displayed in.\n\n"
398
399              "SEE ALSO: view, viewclass, viewuser\n"),
400
401  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
402              "change the color on the current filter",
403              "colorview <color>",
404              "The color of messages in the current filter will be changed\n"
405              "to <color>.  Use the 'show colors' command for a list\n"
406              "of valid colors.\n\n"
407              "SEE ALSO: 'show colors'\n"),
408
409  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
410              "view messages matching a filter",
411              "view <filter>\n"
412              "view -d <expression>\n"
413              "view --home",
414              "In the first usage, The view command sets the current view to\n"
415              "the specified filter.   This causes only messages matching\n"
416              "that filter to be displayed.\n"
417              "\n"
418              "In the second usage a filter expression\n"
419              "and be specified directly\n"
420              "after -d.  Owl will build an internal filter based on this\n"
421              "filter and change the current view to use it.\n\n"
422              "If --home is specified, switches to the view specified by\n"
423              "the 'view_home' variable.\n\n"
424              "SEE ALSO: filter, viewclass, viewuser\n"),
425
426  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
427              "view only messages similar to the current message",
428              "smartnarrow [-i | --instance]",
429              "If the curmsg is a personal message narrow\n"
430              "   to the converstaion with that user.\n"
431              "If the curmsg is a class message, instance foo, recip *\n"
432              "   message, narrow to the class, inst.\n"
433              "If the curmsg is a class message then narrow\n"
434              "    to the class.\n"
435              "If the curmsg is a class message and '-i' is specied\n"
436              "    then narrow to the class, instance\n"),
437
438  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
439              "returns the name of a filter based on the current message",
440              "smartfilter [-i | --instance]",
441              "If the curmsg is a personal message, the filter is\n"
442              "   the converstaion with that user.\n"
443              "If the curmsg is a class message, instance foo, recip *\n"
444              "   message, the filter is the class, inst.\n"
445              "If the curmsg is a class message, the filter is that class.\n"
446              "If the curmsg is a class message and '-i' is specied\n"
447              "    the filter is that <class,instance> pair\n"),
448
449  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
450              "view messages matching a particular class",
451              "viewclass <class>",
452              "The viewclass command will automatically create a filter\n"
453              "matching the specified class and switch the current view\n"
454              "to it.\n\n"
455              "SEE ALSO: filter, view, viewuser\n"),
456  OWLCMD_ALIAS("vc", "viewclass"),
457
458  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
459              "view messages matching a particular user",
460              "viewuser <user>",
461              "The viewuser command will automatically create a filter\n"
462              "matching the specified user and switch the current\n"
463              "view to it.\n\n"
464              "SEE ALSO: filter, view, viewclass\n"),
465  OWLCMD_ALIAS("vu", "viewuser"),
466
467  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
468              "show information",
469              "show variables\n"
470              "show variable <variable>\n"
471              "show filters\n"
472              "show filter <filter>\n"
473              "show keymaps\n"
474              "show keymap <keymap>\n"
475              "show commands\n"
476              "show command <command>\n"
477              "show subs\n"
478              "show subscriptions\n"
479              "show zpunts\n"
480              "show colors\n"
481              "show terminal\n"
482              "show version\n"
483              "show status\n",
484
485              "Show colors will display a list of valid colors for the\n"
486              "     terminal."
487              "Show filters will list the names of all filters.\n"
488              "Show filter <filter> will show the definition of a particular\n"
489              "     filter.\n\n"
490              "Show zpunts will show the active zpunt filters.\n\n"
491              "Show keymaps will list the names of all keymaps.\n"
492              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
493              "Show commands will list the names of all keymaps.\n"
494              "Show command <command> will provide information about a command.\n\n"
495              "Show variables will list the names of all variables.\n\n"
496              "SEE ALSO: filter, view, alias, bindkey, help\n"),
497 
498  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
499              "mark a message for deletion",
500              "delete [ -id msgid ] [ --no-move ]\n"
501              "delete view\n"
502              "delete trash",
503              "If no message id is specified the current message is marked\n"
504              "for deletion.  Otherwise the message with the given message\n"
505              "id is marked for deltion.\n"
506              "If '--no-move' is specified, don't move after deletion.\n"
507              "If 'trash' is specified, deletes all trash/auto messages\n"
508              "in the current view.\n"
509              "If 'view' is specified, deletes all messages in the\n"
510              "current view.\n"),
511  OWLCMD_ALIAS("del", "delete"),
512
513  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
514              "unmark a message for deletion",
515              "undelete [ -id msgid ] [ --no-move ]\n"
516              "undelete view",
517              "If no message id is specified the current message is\n"
518              "unmarked for deletion.  Otherwise the message with the\n"
519              "given message id is marked for undeltion.\n"
520              "If '--no-move' is specified, don't move after deletion.\n"
521              "If 'view' is specified, undeletes all messages\n"
522              "in the current view.\n"),
523  OWLCMD_ALIAS("undel", "undelete"),
524
525  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
526              "ring the terminal bell",
527              "beep",
528              "Beep will ring the terminal bell.\n"
529              "If the variable 'bell' has been\n"
530              "set to 'off' this command does nothing.\n"),
531
532  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
533              "prints a message into the debug log",
534              "debug <message>", ""),
535
536  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
537              "returns the name of the filter for the current view",
538              "", ""),
539
540  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
541              "returns the value of a variable",
542              "getvar <varname>", ""),
543
544  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
545              "search messages for a particular string",
546              "search [-r] [<string>]",
547              "The search command will find messages that contain the\n"
548              "specified string and move the cursor there.  If no string\n"
549              "argument is supplied then the previous one is used.  By\n"
550              "default searches are done fowards, if -r is used the search\n"
551              "is performed backwards"),
552
553  /****************************************************************/
554  /************************* EDIT-SPECIFIC ************************/
555  /****************************************************************/
556
557  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
558                  OWL_CTX_EDIT,
559                  "moves cursor forward a word",
560                  "", ""),
561
562  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
563                  OWL_CTX_EDIT,
564                  "moves cursor backwards a word",
565                  "", ""),
566
567  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
568                  OWL_CTX_EDIT,
569                  "moves cursor to the top left (start) of the buffer",
570                  "", ""),
571
572  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
573                  OWL_CTX_EDIT,
574                  "moves cursor to the bottom right (end) of the buffer",
575                  "", ""),
576
577  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
578                  OWL_CTX_EDIT,
579                  "moves cursor to the end of the line",
580                  "", ""),
581
582  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
583                  OWL_CTX_EDIT,
584                  "moves cursor to the beginning of the line",
585                  "", ""),
586
587  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
588                  OWL_CTX_EDIT,
589                  "moves the cursor left by a character",
590                  "", ""),
591
592  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
593                  OWL_CTX_EDIT,
594                  "moves the cursor right by a character",
595                  "", ""),
596
597  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
598                  OWL_CTX_EDIT,
599                  "deletes the word to the right of the cursor",
600                  "", ""),
601
602  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
603                  OWL_CTX_EDIT,
604                  "deletes the word to the left of the cursor",
605                  "", ""),
606
607  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
608                  OWL_CTX_EDIT,
609                  "deletes the character to the left of the cursor",
610                  "", ""),
611
612  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
613                  OWL_CTX_EDIT,
614                  "deletes the character to the right of the cursor",
615                  "", ""),
616
617  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
618                  OWL_CTX_EDIT,
619                  "deletes from the cursor to the end of the line",
620                  "", ""),
621
622  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
623                  OWL_CTX_EDIT,
624                  "deletes all of the contents of the buffer",
625                  "", ""),
626
627  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
628                  OWL_CTX_EDIT,
629                  "Interchange characters around point, moving forward one character.",
630                  "", ""),
631
632  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
633                  OWL_CTX_EDIT,
634                  "fills the current paragraph to line-wrap well",
635                  "", ""),
636
637  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
638                  OWL_CTX_EDIT,
639                  "recenters the buffer",
640                  "", ""),
641
642  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
643                  OWL_CTX_EDIT,
644                  "inserts text into the buffer",
645                  "edit:insert-text <text>", ""),
646
647  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
648                  OWL_CTX_EDIT,
649                  "cancels the current command",
650                  "", ""),
651
652  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
653                  OWL_CTX_EDIT,
654                  "replaces the text with the previous history",
655                  "", ""),
656
657  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
658                  OWL_CTX_EDIT,
659                  "replaces the text with the previous history",
660                  "", ""),
661
662  OWLCMD_VOID_CTX("editline:done", owl_command_editline_done, 
663                  OWL_CTX_EDITLINE,
664                  "completes the command (eg, executes command being composed)",
665                  "", ""),
666
667  OWLCMD_VOID_CTX("editmulti:move-up-line", owl_editwin_key_up, 
668                  OWL_CTX_EDITMULTI,
669                  "moves the cursor up one line",
670                  "", ""),
671
672  OWLCMD_VOID_CTX("editmulti:move-down-line", owl_editwin_key_down, 
673                  OWL_CTX_EDITMULTI,
674                  "moves the cursor down one line",
675                  "", ""),
676
677  OWLCMD_VOID_CTX("editmulti:done", owl_command_editmulti_done, 
678                  OWL_CTX_EDITMULTI,
679                  "completes the command (eg, sends message being composed)",
680                  "", ""),
681
682  OWLCMD_VOID_CTX("editmulti:done-or-delete", owl_command_editmulti_done_or_delete, 
683                  OWL_CTX_EDITMULTI,
684                  "completes the command, but only if at end of message",
685                  "", 
686                  "If only whitespace is to the right of the cursor,\n"
687                  "runs 'editmulti:done'.\n"\
688                  "Otherwise runs 'edit:delete-next-char'\n"),
689
690  /****************************************************************/
691  /********************** POPLESS-SPECIFIC ************************/
692  /****************************************************************/
693
694  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
695                  OWL_CTX_POPLESS,
696                  "scrolls down one page",
697                  "", ""),
698
699  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
700                  OWL_CTX_POPLESS,
701                  "scrolls down one line",
702                  "", ""),
703
704  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
705                  OWL_CTX_POPLESS,
706                  "scrolls up one page",
707                  "", ""),
708
709  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
710                  OWL_CTX_POPLESS,
711                  "scrolls up one line",
712                  "", ""),
713
714  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
715                  OWL_CTX_POPLESS,
716                  "scrolls to the top of the buffer",
717                  "", ""),
718
719  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
720                  OWL_CTX_POPLESS,
721                  "scrolls to the bottom of the buffer",
722                  "", ""),
723
724  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
725                  OWL_CTX_POPLESS,
726                  "scrolls right in the buffer",
727                  "popless:scroll-right <num-chars>", ""),
728
729  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
730                  OWL_CTX_POPLESS,
731                  "scrolls left in the buffer",
732                  "popless:scroll-left <num-chars>", ""),
733
734  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
735                  OWL_CTX_POPLESS,
736                  "exits the popless window",
737                  "", ""),
738
739  /* This line MUST be last! */
740  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
741
742};
743
744void owl_command_info() {
745  owl_function_info();
746}
747
748char *owl_command_help(int argc, char **argv, char *buff) {
749  if (argc!=2) {
750    owl_help();
751    return NULL;
752  }
753 
754  owl_function_help_for_command(argv[1]);
755  return NULL;
756}
757
758char *owl_command_zlist(int argc, char **argv, char *buff) {
759  int elapsed=0, timesort=0;
760  char *file=NULL;
761
762  argc--;
763  argv++;
764  while (argc) {
765    if (!strcmp(argv[0], "-e")) {
766      elapsed=1;
767      argc--;
768      argv++;
769    } else if (!strcmp(argv[0], "-t")) {
770      timesort=1;
771      argc--;
772      argv++;
773    } else if (!strcmp(argv[0], "-f")) {
774      if (argc==1) {
775        owl_function_makemsg("zlist: -f needs an argument");
776        return(NULL);
777      }
778      file=argv[1];
779      argc-=2;
780      argv+=2;
781    } else {
782      owl_function_makemsg("zlist: unknown argument");
783      return(NULL);
784    }
785  }
786  owl_function_zlist(file, elapsed, timesort);
787  return(NULL);
788}
789
790void owl_command_about() {
791  owl_function_about();
792}
793
794void owl_command_version() {
795  char buff[1024];
796
797  sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
798  owl_function_makemsg(buff);
799}
800
801char *owl_command_dump(int argc, char **argv, char *buff) {
802  if (argc!=2) {
803    owl_function_makemsg("usage: dump <filename>");
804    return(NULL);
805  }
806
807  owl_function_dump(argv[1]);
808  return(NULL);
809}
810
811char *owl_command_next(int argc, char **argv, char *buff) {
812  char *filter=NULL;
813  int skip_deleted=0, last_if_none=0;
814  while (argc>1) {
815    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
816      skip_deleted=1;
817      argc-=1; argv+=1; 
818    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
819      last_if_none=1;
820      argc-=1; argv+=1; 
821    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
822      filter = owl_strdup(argv[2]);
823      argc-=2; argv+=2; 
824    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
825      filter = owl_function_smartfilter(0);
826      argc-=2; argv+=2; 
827    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
828      filter = owl_function_smartfilter(1);
829      argc-=2; argv+=2; 
830    } else {
831      owl_function_makemsg("Invalid arguments to command 'next'.");
832      return(NULL);
833    }
834  }
835  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
836  if (filter) owl_free(filter);
837  return(NULL);
838}
839
840char *owl_command_prev(int argc, char **argv, char *buff) {
841  char *filter=NULL;
842  int skip_deleted=0, first_if_none=0;
843  while (argc>1) {
844    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
845      skip_deleted=1;
846      argc-=1; argv+=1; 
847    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
848      first_if_none=1;
849      argc-=1; argv+=1; 
850    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
851      filter = owl_strdup(argv[2]);
852      argc-=2; argv+=2; 
853    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
854      filter = owl_function_smartfilter(0);
855      argc-=2; argv+=2; 
856    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
857      filter = owl_function_smartfilter(1);
858      argc-=2; argv+=2; 
859   } else {
860      owl_function_makemsg("Invalid arguments to command 'prev'.");
861      return(NULL);
862    }
863  }
864  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
865  if (filter) owl_free(filter);
866  return(NULL);
867}
868
869char *owl_command_smartnarrow(int argc, char **argv, char *buff) {
870  char *filtname = NULL;
871
872  if (argc == 1) {
873    filtname = owl_function_smartfilter(0);
874  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
875    filtname = owl_function_smartfilter(1);
876  } else {
877    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
878  }
879  if (filtname) {
880    owl_function_change_view(filtname);
881    owl_free(filtname);
882  }
883  return NULL;
884}
885
886char *owl_command_smartfilter(int argc, char **argv, char *buff) {
887  char *filtname = NULL;
888
889  if (argc == 1) {
890    filtname = owl_function_smartfilter(0);
891  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
892    filtname = owl_function_smartfilter(1);
893  } else {
894    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
895  }
896  return filtname;
897}
898
899void owl_command_expunge() {
900  owl_function_expunge();
901}
902
903void owl_command_first() {
904  owl_global_set_rightshift(&g, 0);
905  owl_function_firstmsg();
906}
907
908void owl_command_last() {
909  owl_function_lastmsg();
910}
911
912void owl_command_resize() {
913  owl_function_resize();
914}
915
916void owl_command_redisplay() {
917  owl_function_full_redisplay();
918  owl_global_set_needrefresh(&g);
919}
920
921void owl_command_shift_right() {
922  owl_function_shift_right();
923}
924
925void owl_command_shift_left() {
926  owl_function_shift_left();
927}
928
929void owl_command_unsuball() {
930  owl_function_unsuball();
931}
932
933char *owl_command_loadsubs(int argc, char **argv, char *buff) {
934  if (argc == 2) {
935    owl_function_loadsubs(argv[1]);
936  } else if (argc == 1) {
937    owl_function_loadsubs(NULL);
938  } else {
939    owl_function_makemsg("Wrong number of arguments for load-subs.");
940    return NULL;
941  }
942  return NULL;
943}
944
945void owl_command_suspend() {
946  owl_function_suspend();
947}
948
949char *owl_command_start_command(int argc, char **argv, char *buff) {
950  buff = skiptokens(buff, 1);
951  owl_function_start_command(buff);
952  return NULL;
953}
954
955char *owl_command_zaway(int argc, char **argv, char *buff) {
956 
957  if ((argc==1) ||
958      ((argc==2) && !strcmp(argv[1], "on"))) {
959    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
960    owl_function_zaway_on();
961    return NULL;
962  }
963
964  if (argc==2 && !strcmp(argv[1], "off")) {
965    owl_function_zaway_off();
966    return NULL;
967  }
968
969  if (argc==2 && !strcmp(argv[1], "toggle")) {
970    owl_function_zaway_toggle();
971    return NULL;
972  }
973
974  buff = skiptokens(buff, 1);
975  owl_global_set_zaway_msg(&g, buff);
976  owl_function_zaway_on();
977  return NULL;
978}
979
980
981char *owl_command_set(int argc, char **argv, char *buff) {
982  char *var, *val;
983  int  silent=0;
984  int requirebool=0;
985
986  if (argc == 1) {
987    owl_function_printallvars();
988    return NULL;
989  } 
990
991  if (argc > 1 && !strcmp("-q",argv[1])) {
992    silent = 1;
993    argc--; argv++;
994  }
995
996  if (argc == 2) {
997    var=argv[1];
998    val="on";
999    requirebool=1;
1000  } else if (argc == 3) {
1001    var=argv[1];
1002    val=argv[2];
1003  } else {
1004    owl_function_makemsg("Wrong number of arguments for set command");
1005    return NULL;
1006  }
1007  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1008  return NULL;
1009}
1010
1011char *owl_command_unset(int argc, char **argv, char *buff) {
1012  char *var, *val;
1013  int  silent=0;
1014
1015  if (argc > 1 && !strcmp("-q",argv[1])) {
1016    silent = 1;
1017    argc--; argv++;
1018  }
1019  if (argc == 2) {
1020    var=argv[1];
1021    val="off";
1022  } else {
1023    owl_function_makemsg("Wrong number of arguments for unset command");
1024    return NULL;
1025  }
1026  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1027  return NULL;
1028}
1029
1030char *owl_command_print(int argc, char **argv, char *buff) {
1031  char *var;
1032  char valbuff[1024];
1033
1034  if (argc==1) {
1035    owl_function_printallvars();
1036    return NULL;
1037  } else if (argc!=2) {
1038    owl_function_makemsg("Wrong number of arguments for print command");
1039    return NULL;
1040  }
1041
1042  var=argv[1];
1043   
1044  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1045                                     var, valbuff, 1024)) {
1046    owl_function_makemsg("%s = '%s'", var, valbuff);
1047  } else {
1048    owl_function_makemsg("Unknown variable '%s'.", var);
1049  }
1050  return NULL;
1051}
1052
1053char *owl_command_get_variable(int argc, char **argv, char *buff) {
1054  char *var;
1055  char valbuff[1024];
1056
1057 if (argc!=2) {
1058    owl_function_makemsg("Wrong number of arguments for get command");
1059    return NULL;
1060  }
1061
1062  var=argv[1];
1063   
1064  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1065                                     var, valbuff, 1024)) {
1066    return owl_strdup(valbuff);
1067  } else {
1068    owl_function_makemsg("Unknown variable '%s'.", var);
1069    return NULL;
1070  }
1071}
1072
1073
1074char *owl_command_exec(int argc, char **argv, char *buff) {
1075  return owl_function_exec(argc, argv, buff, 0);
1076}
1077
1078char *owl_command_pexec(int argc, char **argv, char *buff) {
1079  return owl_function_exec(argc, argv, buff, 1);
1080}
1081
1082char *owl_command_aexec(int argc, char **argv, char *buff) {
1083  return owl_function_exec(argc, argv, buff, 2);
1084}
1085
1086char *owl_command_perl(int argc, char **argv, char *buff) {
1087  return owl_function_perl(argc, argv, buff, 0);
1088}
1089
1090char *owl_command_pperl(int argc, char **argv, char *buff) {
1091  return owl_function_perl(argc, argv, buff, 1);
1092}
1093
1094char *owl_command_aperl(int argc, char **argv, char *buff) {
1095  return owl_function_perl(argc, argv, buff, 2);
1096}
1097
1098char *owl_command_multi(int argc, char **argv, char *buff) {
1099  char *lastrv = NULL, *newbuff;
1100  char **commands;
1101  int  ncommands, i;
1102  if (argc < 2) {
1103    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1104    return NULL;
1105  }
1106  newbuff = owl_strdup(buff);
1107  newbuff = skiptokens(newbuff, 1);
1108  if (!strcmp(argv[0], "(")) {
1109    for (i=strlen(newbuff)-1; i>=0; i--) {
1110      if (newbuff[i] == ')') {
1111        newbuff[i] = '\0';
1112        break;
1113      } else if (newbuff[i] != ' ') {
1114        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1115        owl_free(newbuff);
1116        return NULL;
1117      }
1118    }
1119  }
1120  commands = atokenize(newbuff, ";", &ncommands);
1121  for (i=0; i<ncommands; i++) {
1122    if (lastrv) {
1123      owl_free(lastrv);
1124    }
1125    lastrv = owl_function_command(commands[i]);
1126  }
1127  atokenize_free(commands, ncommands);
1128  return lastrv;
1129}
1130
1131
1132char *owl_command_alias(int argc, char **argv, char *buff) {
1133  if (argc < 3) {
1134    owl_function_makemsg("Invalid arguments to 'alias' command.");
1135    return NULL;
1136  }
1137  buff = skiptokens(buff, 2);
1138  owl_function_command_alias(argv[1], buff);
1139  return (NULL);
1140}
1141
1142
1143char *owl_command_bindkey(int argc, char **argv, char *buff) {
1144  owl_keymap *km;
1145  int ret;
1146
1147  if (argc < 5 || strcmp(argv[3], "command")) {
1148    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>", argv[3], argc);
1149    return NULL;
1150  }
1151  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1152  if (!km) {
1153    owl_function_makemsg("No such keymap '%s'", argv[1]);
1154    return NULL;
1155  }
1156  buff = skiptokens(buff, 4);
1157  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1158  if (ret!=0) {
1159    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1160                         argv[2], argv[1], buff);
1161    return NULL;
1162  }
1163  return NULL;
1164}
1165
1166void owl_command_quit() {
1167  owl_function_quit();
1168}
1169
1170char *owl_command_debug(int argc, char **argv, char *buff) {
1171  if (argc<2) {
1172    owl_function_makemsg("Need at least one argument to debug command");
1173    return NULL;
1174  }
1175
1176  if (!owl_global_is_debug_fast(&g)) {
1177    owl_function_makemsg("Debugging is not turned on");
1178    return NULL;
1179  }
1180
1181  owl_function_debugmsg(argv[1]);
1182  return NULL;
1183}
1184
1185char *owl_command_ktest(int argc, char **argv, char *buff) {
1186  owl_function_popless_text("foobar");
1187  return NULL;
1188}
1189
1190char *owl_command_zlog(int argc, char **argv, char *buff) {
1191  if ((argc<2) || (argc>3)) {
1192    owl_function_makemsg("Wrong number of arguments for zlog command");
1193    return(NULL);
1194  }
1195
1196  if (!strcmp(argv[1], "in")) {
1197    if (argc>2) {
1198      owl_global_set_tty(&g, argv[2]);
1199    }
1200    owl_function_zlog_in();
1201  } else if (!strcmp(argv[1], "out")) {
1202    if (argc!=2) {
1203      owl_function_makemsg("Wrong number of arguments for zlog command");
1204      return(NULL);
1205    }
1206    owl_function_zlog_out();
1207  } else {
1208    owl_function_makemsg("Invalid subcommand for zlog");
1209  }
1210  return(NULL);
1211}
1212
1213
1214void owl_command_zlog_out() {
1215  owl_function_zlog_out();
1216}
1217
1218
1219char *owl_command_subscribe(int argc, char **argv, char *buff) {
1220  char *recip="";
1221  int temp=0;
1222 
1223  if (argc<3) {
1224    owl_function_makemsg("Not enough arguments to the subscribe command");
1225    return(NULL);
1226  }
1227  argc--;
1228  argv++;
1229
1230  if (!strcmp(argv[0], "-t")) {
1231    temp=1;
1232    argc--;
1233    argv++;
1234  }
1235  if (argc<2) {
1236    owl_function_makemsg("Not enough arguments to the subscribe command");
1237    return(NULL);
1238  }
1239
1240  if (argc>3) {
1241    owl_function_makemsg("Too many arguments to the subscribe command");
1242    return(NULL);
1243  }
1244
1245  if (argc==2) {
1246    recip="";
1247  } else if (argc==3) {
1248    recip=argv[2];
1249  }
1250
1251  owl_function_subscribe(argv[0], argv[1], recip);
1252  if (!temp) {
1253    owl_zephyr_addsub(NULL, argv[0], argv[1], recip);
1254  }
1255  return(NULL);
1256}
1257
1258
1259char *owl_command_unsubscribe(int argc, char **argv, char *buff) {
1260  char *recip="";
1261  int temp=0;
1262
1263  if (argc<3) {
1264    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1265    return(NULL);
1266  }
1267  argc--;
1268  argv++;
1269
1270  if (!strcmp(argv[0], "-t")) {
1271    temp=1;
1272    argc--;
1273    argv++;
1274  }
1275  if (argc<2) {
1276    owl_function_makemsg("Not enough arguments to the subscribe command");
1277    return(NULL);
1278  }
1279
1280  if (argc>3) {
1281    owl_function_makemsg("Too many arguments to the unsubscribe command");
1282    return(NULL);
1283  }
1284
1285  if (argc==2) {
1286    recip="";
1287  } else if (argc==3) {
1288    recip=argv[2];
1289  }
1290
1291  owl_function_unsubscribe(argv[0], argv[1], recip);
1292  if (!temp) {
1293    owl_zephyr_delsub(NULL, argv[0], argv[1], recip);
1294  }
1295  return(NULL);
1296}
1297
1298char *owl_command_echo(int argc, char **argv, char *buff) {
1299  buff = skiptokens(buff, 1);
1300  owl_function_popless_text(buff);
1301  return NULL;
1302}
1303
1304void owl_command_getsubs() {
1305  owl_function_getsubs();
1306}
1307
1308void owl_command_status() {
1309  owl_function_status();
1310}
1311
1312char *owl_command_zwrite(int argc, char **argv, char *buff) {
1313  char *tmpbuff, *pos, *cmd, *msg;
1314
1315  /* check for a zwrite -m */
1316  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
1317    if (!strncmp(pos, "-m ", 3)) {
1318      cmd = owl_strdup(buff);
1319      msg = cmd+(pos-buff);
1320      *msg = '\0';
1321      msg += 3;
1322      owl_zwrite_create_and_send_from_line(cmd, msg);
1323      owl_free(cmd);
1324      return NULL;
1325    }
1326  }
1327
1328  if (argc < 2) {
1329    owl_function_makemsg("Not enough arguments to the zwrite command.");
1330  } else {
1331    tmpbuff = owl_strdup(buff);
1332    owl_function_zwrite_setup(tmpbuff);
1333    owl_global_set_buffercommand(&g, tmpbuff);
1334    owl_free(tmpbuff);
1335  }
1336  return NULL;
1337}
1338
1339char *owl_command_zcrypt(int argc, char **argv, char *buff) {
1340  char *tmpbuff, *pos, *cmd, *msg;
1341 
1342  /* check for a zwrite -m */
1343  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
1344    if (!strncmp(pos, "-m ", 3)) {
1345      cmd = owl_strdup(buff);
1346      msg = cmd+(pos-buff);
1347      *msg = '\0';
1348      msg += 3;
1349      owl_zwrite_create_and_send_from_line(cmd, msg);
1350      owl_free(cmd);
1351      return NULL;
1352    }
1353  }
1354
1355  if (argc < 2) {
1356    owl_function_makemsg("Not enough arguments to the zcrypt command.");
1357  } else {
1358    tmpbuff = owl_strdup(buff);
1359    owl_function_zwrite_setup(tmpbuff);
1360    owl_global_set_buffercommand(&g, tmpbuff);
1361    owl_free(tmpbuff);
1362  }
1363  return(NULL);
1364}
1365
1366char *owl_command_reply(int argc, char **argv, char *buff) {
1367  int edit=0;
1368 
1369  if (argc>=2 && !strcmp("-e", argv[1])) {
1370    edit=1;
1371    argv++;
1372    argc--;
1373  }
1374
1375  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1376    owl_function_reply(0, !edit);
1377  } else if (argc==2 && !strcmp(argv[1], "sender")) {
1378    owl_function_reply(1, !edit);
1379  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
1380    owl_message *m;
1381    owl_view    *v;
1382    v = owl_global_get_current_view(&g);   
1383    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
1384    if (m) owl_zephyr_zaway(m);
1385  } else {
1386    owl_function_makemsg("Invalid arguments to the reply command.");
1387  }
1388  return NULL;
1389}
1390
1391char *owl_command_filter(int argc, char **argv, char *buff) {
1392  owl_function_create_filter(argc, argv);
1393  return NULL;
1394}
1395
1396char *owl_command_zlocate(int argc, char **argv, char *buff) {
1397  int auth;
1398 
1399  if (argc<2) {
1400    owl_function_makemsg("Too few arguments for zlocate command");
1401    return NULL;
1402  }
1403
1404  auth=1;
1405  if (!strcmp(argv[1], "-d")) {
1406    if (argc>2) {
1407      auth=0;
1408      argc--;
1409      argv++;
1410    } else {
1411      owl_function_makemsg("Missing arguments for zlocate command");
1412      return NULL;
1413    }
1414  }
1415
1416  argc--;
1417  argv++;
1418  owl_function_zlocate(argc, argv, auth);
1419  return NULL;
1420}
1421
1422char *owl_command_view(int argc, char **argv, char *buff) {
1423  if (argc<2) {
1424    owl_function_makemsg("Wrong number of arguments to view command");
1425    return NULL;
1426  }
1427
1428  if (argc == 2 && !strcmp(argv[1], "--home")) {
1429    owl_function_change_view(owl_global_get_view_home(&g));
1430    return NULL;
1431  }
1432
1433  /* is it a dynamic filter? */
1434  if (!strcmp(argv[1], "-d")) {
1435    char **myargv;
1436    int i;
1437
1438    myargv=owl_malloc((argc*sizeof(char *))+50);
1439    myargv[0]="";
1440    myargv[1]="owl-dynamic";
1441    for (i=2; i<argc; i++) {
1442      myargv[i]=argv[i];
1443    }
1444    owl_function_create_filter(argc, myargv);
1445    owl_function_change_view("owl-dynamic");
1446    owl_free(myargv);
1447    return NULL;
1448  }
1449
1450  /* otherwise it's a normal view command */
1451  if (argc>2) {
1452    owl_function_makemsg("Wrong number of arguments to view command");
1453    return NULL;
1454  }
1455  owl_function_change_view(argv[1]);
1456  return NULL;
1457}
1458
1459
1460char *owl_command_show(int argc, char **argv, char *buff) {
1461
1462  if (argc<2) {
1463    owl_function_help_for_command("show");
1464    return NULL;
1465  }
1466
1467  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1468    if (argc==2) {
1469      owl_function_show_filters();
1470    } else {
1471      owl_function_show_filter(argv[2]);
1472    }
1473  } else if (argc==2 
1474             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1475    owl_function_show_zpunts();
1476  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1477    if (argc==2) {
1478      owl_function_show_commands();
1479    } else {
1480      owl_function_show_command(argv[2]);
1481    }
1482  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1483    if (argc==2) {
1484      owl_function_show_variables();
1485    } else {
1486      owl_function_show_variable(argv[2]);
1487    }
1488  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1489    if (argc==2) {
1490      owl_function_show_keymaps();
1491    } else {
1492      owl_function_show_keymap(argv[2]);
1493    }
1494  } else if (!strcmp(argv[1], "colors")) {
1495    owl_function_show_colors();
1496  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1497    owl_function_getsubs();
1498  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1499    owl_function_show_term();
1500  } else if (!strcmp(argv[1], "version")) {
1501    owl_function_about();
1502  } else if (!strcmp(argv[1], "status")) {
1503    owl_function_status();
1504  } else {
1505    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1506    return NULL;
1507  }
1508  return NULL;
1509}
1510
1511char *owl_command_viewclass(int argc, char **argv, char *buff) {
1512  char *filtname;
1513  if (argc!=2) {
1514    owl_function_makemsg("Wrong number of arguments to viewclass command");
1515    return NULL;
1516  }
1517  filtname = owl_function_fastclassinstfilt(argv[1], NULL);
1518  owl_function_change_view(filtname);
1519  owl_free(filtname);
1520  return NULL;
1521}
1522
1523char *owl_command_viewuser(int argc, char **argv, char *buff) {
1524  char *filtname;
1525  if (argc!=2) {
1526    owl_function_makemsg("Wrong number of arguments to viewuser command");
1527    return NULL;
1528  }
1529  filtname = owl_function_fastuserfilt(argv[1]);
1530  owl_function_change_view(filtname);
1531  owl_free(filtname);
1532  return NULL;
1533}
1534
1535
1536void owl_command_pop_message(void) {
1537  owl_function_curmsg_to_popwin();
1538}
1539
1540void owl_command_openurl(void) {
1541  owl_function_openurl();
1542}
1543
1544char *owl_command_delete(int argc, char **argv, char *buff) {
1545  int move_after = 1;
1546
1547  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1548    move_after = 0;
1549    argc--; 
1550    argv++;
1551  }
1552
1553  if (argc==1) {
1554    owl_function_deletecur(move_after);
1555    return NULL;
1556  }
1557
1558  if (argc==2 && !strcmp(argv[1], "view")) {
1559    owl_function_delete_curview_msgs(1);
1560    return NULL;
1561  }
1562
1563  if (argc==2 && !strcmp(argv[1], "trash")) {
1564    owl_function_delete_automsgs();
1565    return NULL;
1566  }
1567
1568  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1569    owl_function_delete_by_id(atoi(argv[2]), 1);
1570    return NULL;
1571  }
1572
1573  owl_function_makemsg("Unknown arguments to delete command");
1574  return NULL;
1575}
1576
1577char *owl_command_undelete(int argc, char **argv, char *buff) {
1578  int move_after = 1;
1579
1580  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1581    move_after = 0;
1582    argc--; 
1583    argv++;
1584  }
1585
1586  if (argc==1) {
1587    owl_function_undeletecur(move_after);
1588    return NULL;
1589  }
1590
1591  if (argc==2 && !strcmp(argv[1], "view")) {
1592    owl_function_delete_curview_msgs(0);
1593    return NULL;
1594  }
1595
1596  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1597    owl_function_delete_by_id(atoi(argv[2]), 0);
1598    return NULL;
1599  }
1600
1601  owl_function_makemsg("Unknown arguments to delete command");
1602  return NULL;
1603}
1604
1605void owl_command_beep() {
1606  owl_function_beep();
1607}
1608
1609char *owl_command_colorview(int argc, char **argv, char *buff) {
1610  if (argc!=2) {
1611    owl_function_makemsg("Wrong number of arguments to colorview command");
1612    return NULL;
1613  }
1614  owl_function_color_current_filter(argv[1]);
1615  return NULL;
1616}
1617
1618char *owl_command_zpunt(int argc, char **argv, char *buff) {
1619  owl_command_zpunt_and_zunpunt(argc, argv, 0);
1620  return NULL;
1621}
1622
1623char *owl_command_zunpunt(int argc, char **argv, char *buff) {
1624  owl_command_zpunt_and_zunpunt(argc, argv, 1);
1625  return NULL;
1626}
1627
1628
1629void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type) {
1630  /* if type==0 then zpunt
1631   * if type==1 then zunpunt
1632   */
1633  char *class, *inst, *recip;
1634
1635  class="message";
1636  inst="";
1637  recip="*";
1638
1639  if (argc==1) {
1640    /* show current punt filters */
1641    owl_function_show_zpunts();
1642    return;
1643  } else if (argc==2) {
1644    inst=argv[1];
1645  } else if (argc==3) {
1646    class=argv[1];
1647    inst=argv[2];
1648  } else if (argc==4) {
1649    class=argv[1];
1650    inst=argv[2];
1651    recip=argv[3];
1652  } else {
1653    owl_function_makemsg("Wrong number of arguments to the zpunt command");
1654    return;
1655  }
1656
1657  owl_function_zpunt(class, inst, recip, type);
1658  if (type==0) {
1659    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
1660  } else if (type==1) {
1661    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
1662  }
1663}
1664
1665char *owl_command_smartzpunt(int argc, char **argv, char *buff) {
1666  if (argc == 1) {
1667    owl_function_smartzpunt(0);
1668  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1669    owl_function_smartzpunt(1);
1670  } else {
1671    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1672  }
1673  return NULL;
1674}
1675
1676char *owl_command_getview(int argc, char **argv, char *buff) {
1677  char *filtname;
1678  if (argc != 1) {
1679    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1680    return NULL;
1681  }
1682  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
1683  if (filtname) filtname = owl_strdup(filtname);
1684  return filtname;
1685}
1686
1687char *owl_command_getvar(int argc, char **argv, char *buff) {
1688  char tmpbuff[1024];
1689  if (argc != 2) {
1690    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1691    return NULL;
1692  }
1693  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
1694                                argv[1], tmpbuff, 1024)) {
1695    return NULL;
1696  }
1697  return owl_strdup(tmpbuff); 
1698}
1699
1700char *owl_command_search(int argc, char **argv, char *buff) {
1701  int direction;
1702  char *buffstart;
1703
1704  direction=OWL_DIRECTION_DOWNWARDS;
1705  buffstart=skiptokens(buff, 1);
1706  if (argc>1 && !strcmp(argv[1], "-r")) {
1707    direction=OWL_DIRECTION_UPWARDS;
1708    buffstart=skiptokens(buff, 2);
1709  }
1710   
1711  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
1712    owl_function_search_continue(direction);
1713  } else {
1714    owl_function_search_start(buffstart, direction);
1715  }
1716 
1717  return(NULL);
1718}
1719
1720/*********************************************************************/
1721/************************** EDIT SPECIFIC ****************************/
1722/*********************************************************************/
1723
1724void owl_command_edit_cancel(owl_editwin *e) {
1725  owl_history *hist;
1726
1727  owl_function_makemsg("Command cancelled.");
1728
1729  hist=owl_editwin_get_history(e);
1730  owl_history_store(hist, owl_editwin_get_text(e));
1731  owl_history_reset(hist);
1732
1733  owl_editwin_fullclear(e);
1734  owl_global_set_needrefresh(&g);
1735  wnoutrefresh(owl_editwin_get_curswin(e));
1736  owl_global_set_typwin_inactive(&g);
1737  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1738}
1739
1740void owl_command_edit_history_prev(owl_editwin *e) {
1741  owl_history *hist;
1742  char *ptr;
1743
1744  hist=owl_editwin_get_history(e);
1745  if (!owl_history_is_touched(hist)) {
1746    owl_history_store(hist, owl_editwin_get_text(e));
1747    owl_history_set_partial(hist);
1748  }
1749  ptr=owl_history_get_prev(hist);
1750  if (ptr) {
1751    owl_editwin_clear(e);
1752    owl_editwin_insert_string(e, ptr);
1753    owl_editwin_redisplay(e, 0);
1754    owl_global_set_needrefresh(&g);
1755  } else {
1756    owl_function_beep();
1757  }
1758}
1759
1760void owl_command_edit_history_next(owl_editwin *e) {
1761  owl_history *hist;
1762  char *ptr;
1763
1764  hist=owl_editwin_get_history(e);
1765  ptr=owl_history_get_next(hist);
1766  if (ptr) {
1767    owl_editwin_clear(e);
1768    owl_editwin_insert_string(e, ptr);
1769    owl_editwin_redisplay(e, 0);
1770    owl_global_set_needrefresh(&g);
1771  } else {
1772    owl_function_beep();
1773  }
1774}
1775
1776char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff) {
1777  buff = skiptokens(buff, 1);
1778  owl_editwin_insert_string(e, buff);
1779  owl_editwin_redisplay(e, 0);
1780  owl_global_set_needrefresh(&g); 
1781  return NULL;
1782}
1783
1784void owl_command_editline_done(owl_editwin *e) {
1785  owl_history *hist=owl_editwin_get_history(e);
1786  char *rv, *cmd;
1787
1788  owl_history_store(hist, owl_editwin_get_text(e));
1789  owl_history_reset(hist);
1790  owl_global_set_typwin_inactive(&g);
1791  cmd = owl_strdup(owl_editwin_get_text(e));
1792  owl_editwin_fullclear(e);
1793  rv = owl_function_command(cmd);
1794  owl_free(cmd);
1795
1796  wnoutrefresh(owl_editwin_get_curswin(e));
1797  owl_global_set_needrefresh(&g);
1798
1799  if (rv) {
1800    owl_function_makemsg("%s", rv);
1801    owl_free(rv);
1802  }
1803}
1804
1805void owl_command_editmulti_done(owl_editwin *e) {
1806  owl_history *hist=owl_editwin_get_history(e);
1807
1808  owl_history_store(hist, owl_editwin_get_text(e));
1809  owl_history_reset(hist);
1810
1811  owl_function_run_buffercommand();
1812  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1813  owl_editwin_fullclear(e);
1814  owl_global_set_typwin_inactive(&g);
1815  owl_global_set_needrefresh(&g);
1816  wnoutrefresh(owl_editwin_get_curswin(e));
1817}
1818
1819void owl_command_editmulti_done_or_delete(owl_editwin *e) {
1820  if (owl_editwin_is_at_end(e)) {
1821    owl_command_editmulti_done(e);
1822  } else {
1823    owl_editwin_delete_char(e);
1824  }
1825}
1826
1827
1828/*********************************************************************/
1829/*********************** POPLESS SPECIFIC ****************************/
1830/*********************************************************************/
1831
1832void owl_command_popless_quit(owl_viewwin *vw) {
1833  owl_popwin_close(owl_global_get_popwin(&g));
1834  owl_viewwin_free(vw);
1835  owl_global_set_needrefresh(&g);
1836}
Note: See TracBrowser for help on using the repository browser.