source: commands.c @ ecd5dc5

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