source: commands.c @ 425c013

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