source: commands.c @ 67103d4

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