source: commands.c @ f2e36b5

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since f2e36b5 was f2e36b5, checked in by Erik Nygren <nygren@mit.edu>, 22 years ago
* Page-down will not skip past the last message if its truncated. * Added C-t binding for transposing characters. (from jdaniel)
  • Property mode set to 100644
File size: 49.1 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  /****************************************************************/
501  /************************* EDIT-SPECIFIC ************************/
502  /****************************************************************/
503
504  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
505                  OWL_CTX_EDIT,
506                  "moves cursor forward a word",
507                  "", ""),
508
509  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
510                  OWL_CTX_EDIT,
511                  "moves cursor backwards a word",
512                  "", ""),
513
514  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
515                  OWL_CTX_EDIT,
516                  "moves cursor to the top left (start) of the buffer",
517                  "", ""),
518
519  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
520                  OWL_CTX_EDIT,
521                  "moves cursor to the bottom right (end) of the buffer",
522                  "", ""),
523
524  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
525                  OWL_CTX_EDIT,
526                  "moves cursor to the end of the line",
527                  "", ""),
528
529  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
530                  OWL_CTX_EDIT,
531                  "moves cursor to the beginning of the line",
532                  "", ""),
533
534  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
535                  OWL_CTX_EDIT,
536                  "moves the cursor left by a character",
537                  "", ""),
538
539  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
540                  OWL_CTX_EDIT,
541                  "moves the cursor right by a character",
542                  "", ""),
543
544  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
545                  OWL_CTX_EDIT,
546                  "deletes the word to the right of the cursor",
547                  "", ""),
548
549  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
550                  OWL_CTX_EDIT,
551                  "deletes the word to the left of the cursor",
552                  "", ""),
553
554  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
555                  OWL_CTX_EDIT,
556                  "deletes the character to the left of the cursor",
557                  "", ""),
558
559  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
560                  OWL_CTX_EDIT,
561                  "deletes the character to the right of the cursor",
562                  "", ""),
563
564  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
565                  OWL_CTX_EDIT,
566                  "deletes from the cursor to the end of the line",
567                  "", ""),
568
569  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
570                  OWL_CTX_EDIT,
571                  "deletes all of the contents of the buffer",
572                  "", ""),
573
574  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
575                  OWL_CTX_EDIT,
576                  "Interchange characters around point, moving forward one character.",
577                  "", ""),
578
579  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
580                  OWL_CTX_EDIT,
581                  "fills the current paragraph to line-wrap well",
582                  "", ""),
583
584  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
585                  OWL_CTX_EDIT,
586                  "recenters the buffer",
587                  "", ""),
588
589  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
590                  OWL_CTX_EDIT,
591                  "inserts text into the buffer",
592                  "edit:insert-text <text>", ""),
593
594  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
595                  OWL_CTX_EDIT,
596                  "cancels the current command",
597                  "", ""),
598
599  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
600                  OWL_CTX_EDIT,
601                  "replaces the text with the previous history",
602                  "", ""),
603
604  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
605                  OWL_CTX_EDIT,
606                  "replaces the text with the previous history",
607                  "", ""),
608
609  OWLCMD_VOID_CTX("editline:done", owl_command_editline_done, 
610                  OWL_CTX_EDITLINE,
611                  "completes the command (eg, executes command being composed)",
612                  "", ""),
613
614  OWLCMD_VOID_CTX("editmulti:move-up-line", owl_editwin_key_up, 
615                  OWL_CTX_EDITMULTI,
616                  "moves the cursor up one line",
617                  "", ""),
618
619  OWLCMD_VOID_CTX("editmulti:move-down-line", owl_editwin_key_down, 
620                  OWL_CTX_EDITMULTI,
621                  "moves the cursor down one line",
622                  "", ""),
623
624  OWLCMD_VOID_CTX("editmulti:done", owl_command_editmulti_done, 
625                  OWL_CTX_EDITMULTI,
626                  "completes the command (eg, sends message being composed)",
627                  "", ""),
628
629  OWLCMD_VOID_CTX("editmulti:done-or-delete", owl_command_editmulti_done_or_delete, 
630                  OWL_CTX_EDITMULTI,
631                  "completes the command, but only if at end of message",
632                  "", 
633                  "If only whitespace is to the right of the cursor,\n"
634                  "runs 'editmulti:done'.\n"\
635                  "Otherwise runs 'edit:delete-next-char'\n"),
636
637  /****************************************************************/
638  /********************** POPLESS-SPECIFIC ************************/
639  /****************************************************************/
640
641  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
642                  OWL_CTX_POPLESS,
643                  "scrolls down one page",
644                  "", ""),
645
646  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
647                  OWL_CTX_POPLESS,
648                  "scrolls down one line",
649                  "", ""),
650
651  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
652                  OWL_CTX_POPLESS,
653                  "scrolls up one page",
654                  "", ""),
655
656  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
657                  OWL_CTX_POPLESS,
658                  "scrolls up one line",
659                  "", ""),
660
661  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
662                  OWL_CTX_POPLESS,
663                  "scrolls to the top of the buffer",
664                  "", ""),
665
666  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
667                  OWL_CTX_POPLESS,
668                  "scrolls to the bottom of the buffer",
669                  "", ""),
670
671  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
672                  OWL_CTX_POPLESS,
673                  "scrolls right in the buffer",
674                  "popless:scroll-right <num-chars>", ""),
675
676  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
677                  OWL_CTX_POPLESS,
678                  "scrolls left in the buffer",
679                  "popless:scroll-left <num-chars>", ""),
680
681  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
682                  OWL_CTX_POPLESS,
683                  "exits the popless window",
684                  "", ""),
685
686  /* This line MUST be last! */
687  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
688
689};
690
691void owl_command_info() {
692  owl_function_info();
693}
694
695char *owl_command_help(int argc, char **argv, char *buff) {
696  if (argc!=2) {
697    owl_help();
698    return NULL;
699  }
700 
701  owl_function_help_for_command(argv[1]);
702  return NULL;
703}
704
705void owl_command_about() {
706  owl_function_about();
707}
708
709void owl_command_version() {
710  char buff[1024];
711
712  sprintf(buff, "Owl version %s", OWL_VERSION_STRING);
713  owl_function_makemsg(buff);
714}
715
716char *owl_command_next(int argc, char **argv, char *buff) {
717  char *filter=NULL;
718  int skip_deleted=0, last_if_none=0;
719  while (argc>1) {
720    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
721      skip_deleted=1;
722      argc-=1; argv+=1; 
723    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
724      last_if_none=1;
725      argc-=1; argv+=1; 
726    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
727      filter = owl_strdup(argv[2]);
728      argc-=2; argv+=2; 
729    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
730      filter = owl_function_smartfilter(0);
731      argc-=2; argv+=2; 
732    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
733      filter = owl_function_smartfilter(1);
734      argc-=2; argv+=2; 
735    } else {
736      owl_function_makemsg("Invalid arguments to command 'next'.");
737      return(NULL);
738    }
739  }
740  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
741  if (filter) owl_free(filter);
742  return(NULL);
743}
744
745char *owl_command_prev(int argc, char **argv, char *buff) {
746  char *filter=NULL;
747  int skip_deleted=0, first_if_none=0;
748  while (argc>1) {
749    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
750      skip_deleted=1;
751      argc-=1; argv+=1; 
752    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
753      first_if_none=1;
754      argc-=1; argv+=1; 
755    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
756      filter = owl_strdup(argv[2]);
757      argc-=2; argv+=2; 
758    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
759      filter = owl_function_smartfilter(0);
760      argc-=2; argv+=2; 
761    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
762      filter = owl_function_smartfilter(1);
763      argc-=2; argv+=2; 
764   } else {
765      owl_function_makemsg("Invalid arguments to command 'prev'.");
766      return(NULL);
767    }
768  }
769  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
770  if (filter) owl_free(filter);
771  return(NULL);
772}
773
774char *owl_command_smartnarrow(int argc, char **argv, char *buff) {
775  char *filtname = NULL;
776
777  if (argc == 1) {
778    filtname = owl_function_smartfilter(0);
779  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
780    filtname = owl_function_smartfilter(1);
781  } else {
782    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
783  }
784  if (filtname) {
785    owl_function_change_view(filtname);
786    owl_free(filtname);
787  }
788  return NULL;
789}
790
791char *owl_command_smartfilter(int argc, char **argv, char *buff) {
792  char *filtname = NULL;
793
794  if (argc == 1) {
795    filtname = owl_function_smartfilter(0);
796  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
797    filtname = owl_function_smartfilter(1);
798  } else {
799    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
800  }
801  return filtname;
802}
803
804void owl_command_expunge() {
805  owl_function_expunge();
806}
807
808void owl_command_first() {
809  owl_global_set_rightshift(&g, 0);
810  owl_function_firstmsg();
811}
812
813void owl_command_last() {
814  owl_function_lastmsg();
815}
816
817void owl_command_resize() {
818  owl_function_resize();
819}
820
821void owl_command_redisplay() {
822  owl_function_full_redisplay();
823  owl_global_set_needrefresh(&g);
824}
825
826void owl_command_shift_right() {
827  owl_function_shift_right();
828}
829
830void owl_command_shift_left() {
831  owl_function_shift_left();
832}
833
834void owl_command_unsuball() {
835  owl_function_unsuball();
836}
837
838char *owl_command_loadsubs(int argc, char **argv, char *buff) {
839  if (argc == 2) {
840    owl_function_loadsubs(argv[1]);
841  } else if (argc == 1) {
842    owl_function_loadsubs(NULL);
843  } else {
844    owl_function_makemsg("Wrong number of arguments for load-subs.");
845    return NULL;
846  }
847  return NULL;
848}
849
850void owl_command_suspend() {
851  owl_function_suspend();
852}
853
854char *owl_command_start_command(int argc, char **argv, char *buff) {
855  buff = skiptokens(buff, 1);
856  owl_function_start_command(buff);
857  return NULL;
858}
859
860char *owl_command_zaway(int argc, char **argv, char *buff) {
861 
862  if ((argc==1) ||
863      ((argc==2) && !strcmp(argv[1], "on"))) {
864    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
865    owl_function_zaway_on();
866    return NULL;
867  }
868
869  if (argc==2 && !strcmp(argv[1], "off")) {
870    owl_function_zaway_off();
871    return NULL;
872  }
873
874  if (argc==2 && !strcmp(argv[1], "toggle")) {
875    owl_function_zaway_toggle();
876    return NULL;
877  }
878
879  buff = skiptokens(buff, 1);
880  owl_global_set_zaway_msg(&g, buff);
881  owl_function_zaway_on();
882  return NULL;
883}
884
885
886char *owl_command_set(int argc, char **argv, char *buff) {
887  char *var, *val;
888  int  silent=0;
889
890  if (argc == 1) {
891    owl_function_printallvars();
892    return NULL;
893  } else if (argc == 4 && !strcmp("-q",argv[1])) {
894    silent = 1;
895    var=argv[2];
896    val=argv[3];
897  } else if (argc == 3) {
898    var=argv[1];
899    val=argv[2];
900  } else {
901    owl_function_makemsg("Wrong number of arguments for set command");
902    return NULL;
903  }
904
905  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent);
906  return NULL;
907}
908
909char *owl_command_print(int argc, char **argv, char *buff) {
910  char *var;
911  char valbuff[1024];
912
913  if (argc==1) {
914    owl_function_printallvars();
915    return NULL;
916  } else if (argc!=2) {
917    owl_function_makemsg("Wrong number of arguments for print command");
918    return NULL;
919  }
920
921  var=argv[1];
922   
923  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
924                                     var, valbuff, 1024)) {
925    owl_function_makemsg("%s = '%s'", var, valbuff);
926  } else {
927    owl_function_makemsg("Unknown variable '%s'.", var);
928  }
929  return NULL;
930}
931
932
933char *owl_command_exec(int argc, char **argv, char *buff) {
934  return owl_function_exec(argc, argv, buff, 0);
935}
936
937char *owl_command_pexec(int argc, char **argv, char *buff) {
938  return owl_function_exec(argc, argv, buff, 1);
939}
940
941char *owl_command_aexec(int argc, char **argv, char *buff) {
942  return owl_function_exec(argc, argv, buff, 2);
943}
944
945char *owl_command_perl(int argc, char **argv, char *buff) {
946  return owl_function_perl(argc, argv, buff, 0);
947}
948
949char *owl_command_pperl(int argc, char **argv, char *buff) {
950  return owl_function_perl(argc, argv, buff, 1);
951}
952
953char *owl_command_aperl(int argc, char **argv, char *buff) {
954  return owl_function_perl(argc, argv, buff, 2);
955}
956
957char *owl_command_multi(int argc, char **argv, char *buff) {
958  char *lastrv = NULL, *newbuff;
959  char **commands;
960  int  ncommands, i;
961  if (argc < 2) {
962    owl_function_makemsg("Invalid arguments to 'multi' command.");   
963    return NULL;
964  }
965  newbuff = owl_strdup(buff);
966  newbuff = skiptokens(newbuff, 1);
967  if (!strcmp(argv[0], "(")) {
968    for (i=strlen(newbuff)-1; i>=0; i--) {
969      if (newbuff[i] == ')') {
970        newbuff[i] = '\0';
971        break;
972      } else if (newbuff[i] != ' ') {
973        owl_function_makemsg("Invalid arguments to 'multi' command.");   
974        owl_free(newbuff);
975        return NULL;
976      }
977    }
978  }
979  commands = atokenize(newbuff, ";", &ncommands);
980  for (i=0; i<ncommands; i++) {
981    if (lastrv) {
982      owl_free(lastrv);
983    }
984    lastrv = owl_function_command(commands[i]);
985  }
986  atokenize_free(commands, ncommands);
987  return lastrv;
988}
989
990
991char *owl_command_alias(int argc, char **argv, char *buff) {
992  if (argc < 3) {
993    owl_function_makemsg("Invalid arguments to 'alias' command.");
994    return NULL;
995  }
996  buff = skiptokens(buff, 2);
997  owl_function_command_alias(argv[1], buff);
998  return (NULL);
999}
1000
1001
1002char *owl_command_bindkey(int argc, char **argv, char *buff) {
1003  owl_keymap *km;
1004  int ret;
1005
1006  if (argc < 5 || strcmp(argv[3], "command")) {
1007    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>", argv[3], argc);
1008    return NULL;
1009  }
1010  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1011  if (!km) {
1012    owl_function_makemsg("No such keymap '%s'", argv[1]);
1013    return NULL;
1014  }
1015  buff = skiptokens(buff, 4);
1016  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1017  if (ret!=0) {
1018    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1019                         argv[2], argv[1], buff);
1020    return NULL;
1021  }
1022  return NULL;
1023}
1024
1025void owl_command_quit() {
1026  owl_function_quit();
1027}
1028
1029char *owl_command_debug(int argc, char **argv, char *buff) {
1030  if (argc<2) {
1031    owl_function_makemsg("Need at least one argument to debug command");
1032    return NULL;
1033  }
1034
1035  if (!owl_global_is_debug_fast(&g)) {
1036    owl_function_makemsg("Debugging is not turned on");
1037    return NULL;
1038  }
1039
1040  owl_function_debugmsg(argv[1]);
1041  return NULL;
1042}
1043
1044char *owl_command_ktest(int argc, char **argv, char *buff) {
1045  owl_function_popless_text("foobar");
1046  return NULL;
1047}
1048
1049char *owl_command_zlog(int argc, char **argv, char *buff) {
1050  if (argc != 2) {
1051    owl_function_makemsg("Wrong number of arguments for zlog command");
1052    return NULL;
1053  }
1054
1055  if (!strcmp(argv[1], "in")) {
1056    owl_function_zlog_in();
1057  } else if (!strcmp(argv[1], "out")) {
1058    owl_function_zlog_out();
1059  } else {
1060    owl_function_makemsg("Invalid subcommand for zlog");
1061  }
1062  return NULL;
1063}
1064
1065
1066void owl_command_zlog_out() {
1067  owl_function_zlog_out();
1068}
1069
1070
1071char *owl_command_subscribe(int argc, char **argv, char *buff) {
1072  char *recip="";
1073
1074  if (argc<3) {
1075    owl_function_makemsg("Not enough arguments to the subscribe command");
1076    return NULL;
1077  } else if (argc>4) {
1078    owl_function_makemsg("Too many arguments to the subscribe command");
1079    return NULL;
1080  }
1081
1082  if (argc==3) {
1083    recip="";
1084  } else if (argc==4) {
1085    recip=argv[3];
1086  }
1087
1088  owl_function_subscribe(argv[1], argv[2], recip);
1089  return NULL;
1090}
1091
1092
1093char *owl_command_unsubscribe(int argc, char **argv, char *buff) {
1094  char *recip="";
1095
1096  if (argc<3) {
1097    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1098    return NULL;
1099  } else if (argc>4) {
1100    owl_function_makemsg("Too many arguments to the unsubscribe command");
1101    return NULL;
1102  }
1103
1104  if (argc==3) {
1105    recip="";
1106  } else if (argc==4) {
1107    recip=argv[3];
1108  }
1109
1110  owl_function_unsubscribe(argv[1], argv[2], recip);
1111  return NULL;
1112}
1113
1114char *owl_command_echo(int argc, char **argv, char *buff) {
1115  buff = skiptokens(buff, 1);
1116  owl_function_popless_text(buff);
1117  return NULL;
1118}
1119
1120void owl_command_getsubs() {
1121  owl_function_getsubs();
1122}
1123
1124void owl_command_status() {
1125  owl_function_status();
1126}
1127
1128char *owl_command_zwrite(int argc, char **argv, char *buff) {
1129  char *tmpbuff, *pos, *cmd, *msg;
1130
1131  /* check for a zwrite -m */
1132  for (pos = buff; *pos; pos = skiptokens(pos, 1)) {
1133    if (!strncmp(pos, "-m ", 3)) {
1134      cmd = owl_strdup(buff);
1135      msg = cmd+(pos-buff);
1136      *msg = '\0';
1137      msg += 3;
1138      owl_zwrite_create_and_send_from_line(cmd, msg);
1139      owl_free(cmd);
1140      return NULL;
1141    }
1142  }
1143
1144  if (argc < 2) {
1145    owl_function_makemsg("Not enough arguments to the zwrite command.");
1146  } else {
1147    tmpbuff = owl_strdup(buff);
1148    owl_function_zwrite_setup(tmpbuff);
1149    owl_global_set_buffercommand(&g, tmpbuff);
1150    owl_free(tmpbuff);
1151  }
1152  return NULL;
1153}
1154
1155char *owl_command_reply(int argc, char **argv, char *buff) {
1156  int edit=0;
1157 
1158  if (argc>=2 && !strcmp("-e", argv[1])) {
1159    edit=1;
1160    argv++;
1161    argc--;
1162  }
1163
1164  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
1165    owl_function_reply(0, !edit);
1166  } else if (argc==2 && !strcmp(argv[1], "sender")) {
1167    owl_function_reply(1, !edit);
1168  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
1169    owl_message *m;
1170    owl_view    *v;
1171    v = owl_global_get_current_view(&g);   
1172    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
1173    if (m) owl_zephyr_zaway(m);
1174  } else {
1175    owl_function_makemsg("Invalid arguments to the reply command.");
1176  }
1177  return NULL;
1178}
1179
1180char *owl_command_filter(int argc, char **argv, char *buff) {
1181  owl_function_create_filter(argc, argv);
1182  return NULL;
1183}
1184
1185char *owl_command_zlocate(int argc, char **argv, char *buff) {
1186  if (argc==2) {
1187    owl_function_zlocate(argv[1], 1);
1188  } else if (argc==3) {
1189    if (!strcmp(argv[1], "-d")) {
1190      owl_function_zlocate(argv[2], 0);
1191    } else {
1192      owl_function_makemsg("Invalid option to the zlocate command");
1193      return NULL;
1194    }
1195  } else {
1196    owl_function_makemsg("Wrong number of arguments for zlocate command");
1197    return NULL;
1198  }
1199  return NULL;
1200}
1201
1202char *owl_command_view(int argc, char **argv, char *buff) {
1203  if (argc<2) {
1204    owl_function_makemsg("Wrong number of arguments to view command");
1205    return NULL;
1206  }
1207
1208  if (argc == 2 && !strcmp(argv[1], "--home")) {
1209    owl_function_change_view(owl_global_get_view_home(&g));
1210    return NULL;
1211  }
1212
1213  /* is it a dynamic filter? */
1214  if (!strcmp(argv[1], "-d")) {
1215    char **myargv;
1216    int i;
1217
1218    myargv=owl_malloc((argc*sizeof(char *))+50);
1219    myargv[0]="";
1220    myargv[1]="owl-dynamic";
1221    for (i=2; i<argc; i++) {
1222      myargv[i]=argv[i];
1223    }
1224    owl_function_create_filter(argc, myargv);
1225    owl_function_change_view("owl-dynamic");
1226    owl_free(myargv);
1227    return NULL;
1228  }
1229
1230  /* otherwise it's a normal view command */
1231  if (argc>2) {
1232    owl_function_makemsg("Wrong number of arguments to view command");
1233    return NULL;
1234  }
1235  owl_function_change_view(argv[1]);
1236  return NULL;
1237}
1238
1239
1240char *owl_command_show(int argc, char **argv, char *buff) {
1241
1242  if (argc<2) {
1243    owl_function_help_for_command("show");
1244    return NULL;
1245  }
1246
1247  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
1248    if (argc==2) {
1249      owl_function_show_filters();
1250    } else {
1251      owl_function_show_filter(argv[2]);
1252    }
1253  } else if (argc==2 
1254             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
1255    owl_function_show_zpunts();
1256  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
1257    if (argc==2) {
1258      owl_function_show_commands();
1259    } else {
1260      owl_function_show_command(argv[2]);
1261    }
1262  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
1263    if (argc==2) {
1264      owl_function_show_variables();
1265    } else {
1266      owl_function_show_variable(argv[2]);
1267    }
1268  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
1269    if (argc==2) {
1270      owl_function_show_keymaps();
1271    } else {
1272      owl_function_show_keymap(argv[2]);
1273    }
1274  } else if (!strcmp(argv[1], "colors")) {
1275    owl_function_show_colors();
1276  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
1277    owl_function_getsubs();
1278  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
1279    owl_function_show_term();
1280  } else if (!strcmp(argv[1], "version")) {
1281    owl_function_about();
1282  } else if (!strcmp(argv[1], "status")) {
1283    owl_function_status();
1284  } else {
1285    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
1286    return NULL;
1287  }
1288  return NULL;
1289}
1290
1291char *owl_command_viewclass(int argc, char **argv, char *buff) {
1292  char *filtname;
1293  if (argc!=2) {
1294    owl_function_makemsg("Wrong number of arguments to viewclass command");
1295    return NULL;
1296  }
1297  filtname = owl_function_fastclassinstfilt(argv[1], NULL);
1298  owl_function_change_view(filtname);
1299  owl_free(filtname);
1300  return NULL;
1301}
1302
1303char *owl_command_viewuser(int argc, char **argv, char *buff) {
1304  char *filtname;
1305  if (argc!=2) {
1306    owl_function_makemsg("Wrong number of arguments to viewuser command");
1307    return NULL;
1308  }
1309  filtname = owl_function_fastuserfilt(argv[1]);
1310  owl_function_change_view(filtname);
1311  owl_free(filtname);
1312  return NULL;
1313}
1314
1315
1316void owl_command_pop_message(void) {
1317  owl_function_curmsg_to_popwin();
1318}
1319
1320void owl_command_openurl(void) {
1321  owl_function_openurl();
1322}
1323
1324char *owl_command_delete(int argc, char **argv, char *buff) {
1325  int move_after = 1;
1326
1327  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1328    move_after = 0;
1329    argc--; 
1330    argv++;
1331  }
1332
1333  if (argc==1) {
1334    owl_function_deletecur(move_after);
1335    return NULL;
1336  }
1337
1338  if (argc==2 && !strcmp(argv[1], "view")) {
1339    owl_function_delete_curview_msgs(1);
1340    return NULL;
1341  }
1342
1343  if (argc==2 && !strcmp(argv[1], "trash")) {
1344    owl_function_delete_automsgs();
1345    return NULL;
1346  }
1347
1348  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1349    owl_function_delete_by_id(atoi(argv[2]), 1);
1350    return NULL;
1351  }
1352
1353  owl_function_makemsg("Unknown arguments to delete command");
1354  return NULL;
1355}
1356
1357char *owl_command_undelete(int argc, char **argv, char *buff) {
1358  int move_after = 1;
1359
1360  if (argc>1 && !strcmp(argv[1], "--no-move")) {
1361    move_after = 0;
1362    argc--; 
1363    argv++;
1364  }
1365
1366  if (argc==1) {
1367    owl_function_undeletecur(move_after);
1368    return NULL;
1369  }
1370
1371  if (argc==2 && !strcmp(argv[1], "view")) {
1372    owl_function_delete_curview_msgs(0);
1373    return NULL;
1374  }
1375
1376  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
1377    owl_function_delete_by_id(atoi(argv[2]), 0);
1378    return NULL;
1379  }
1380
1381  owl_function_makemsg("Unknown arguments to delete command");
1382  return NULL;
1383}
1384
1385void owl_command_beep() {
1386  owl_function_beep();
1387}
1388
1389char *owl_command_colorview(int argc, char **argv, char *buff) {
1390  if (argc!=2) {
1391    owl_function_makemsg("Wrong number of arguments to colorview command");
1392    return NULL;
1393  }
1394  owl_function_color_current_filter(argv[1]);
1395  return NULL;
1396}
1397
1398char *owl_command_zpunt(int argc, char **argv, char *buff) {
1399  owl_command_zpunt_and_zunpunt(argc, argv, 0);
1400  return NULL;
1401}
1402
1403char *owl_command_zunpunt(int argc, char **argv, char *buff) {
1404  owl_command_zpunt_and_zunpunt(argc, argv, 1);
1405  return NULL;
1406}
1407
1408
1409void owl_command_zpunt_and_zunpunt(int argc, char **argv, int type) {
1410  /* if type==0 then zpunt
1411   * if type==1 then zunpunt
1412   */
1413  char *class, *inst, *recip;
1414
1415  class="message";
1416  inst="";
1417  recip="*";
1418
1419  if (argc==1) {
1420    /* show current punt filters */
1421    owl_function_show_zpunts();
1422    return;
1423  } else if (argc==2) {
1424    inst=argv[1];
1425  } else if (argc==3) {
1426    class=argv[1];
1427    inst=argv[2];
1428  } else if (argc==4) {
1429    class=argv[1];
1430    inst=argv[2];
1431    recip=argv[3];
1432  } else {
1433    owl_function_makemsg("Wrong number of arguments to the zpunt command");
1434    return;
1435  }
1436
1437  owl_function_zpunt(class, inst, recip, type);
1438  if (type==0) {
1439    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
1440  } else if (type==1) {
1441    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
1442  }
1443}
1444
1445char *owl_command_smartzpunt(int argc, char **argv, char *buff) {
1446  if (argc == 1) {
1447    owl_function_smartzpunt(0);
1448  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1449    owl_function_smartzpunt(1);
1450  } else {
1451    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1452  }
1453  return NULL;
1454}
1455
1456char *owl_command_getview(int argc, char **argv, char *buff) {
1457  char *filtname;
1458  if (argc != 1) {
1459    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1460    return NULL;
1461  }
1462  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
1463  if (filtname) filtname = owl_strdup(filtname);
1464  return filtname;
1465}
1466
1467char *owl_command_getvar(int argc, char **argv, char *buff) {
1468  char tmpbuff[1024];
1469  if (argc != 2) {
1470    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1471    return NULL;
1472  }
1473  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
1474                                argv[1], tmpbuff, 1024)) {
1475    return NULL;
1476  }
1477  return owl_strdup(tmpbuff); 
1478}
1479
1480/*********************************************************************/
1481/************************** EDIT SPECIFIC ****************************/
1482/*********************************************************************/
1483
1484void owl_command_edit_cancel(owl_editwin *e) {
1485  owl_history *hist;
1486
1487  owl_function_makemsg("Command cancelled.");
1488
1489  hist=owl_editwin_get_history(e);
1490  owl_history_store(hist, owl_editwin_get_text(e));
1491  owl_history_reset(hist);
1492
1493  owl_editwin_fullclear(e);
1494  owl_global_set_needrefresh(&g);
1495  wnoutrefresh(owl_editwin_get_curswin(e));
1496  owl_global_set_typwin_inactive(&g);
1497  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1498}
1499
1500void owl_command_edit_history_prev(owl_editwin *e) {
1501  owl_history *hist;
1502  char *ptr;
1503
1504  hist=owl_editwin_get_history(e);
1505  if (!owl_history_is_touched(hist)) {
1506    owl_history_store(hist, owl_editwin_get_text(e));
1507    owl_history_set_partial(hist);
1508  }
1509  ptr=owl_history_get_prev(hist);
1510  if (ptr) {
1511    owl_editwin_clear(e);
1512    owl_editwin_insert_string(e, ptr);
1513    owl_editwin_redisplay(e, 0);
1514    owl_global_set_needrefresh(&g);
1515  } else {
1516    owl_function_beep();
1517  }
1518}
1519
1520void owl_command_edit_history_next(owl_editwin *e) {
1521  owl_history *hist;
1522  char *ptr;
1523
1524  hist=owl_editwin_get_history(e);
1525  ptr=owl_history_get_next(hist);
1526  if (ptr) {
1527    owl_editwin_clear(e);
1528    owl_editwin_insert_string(e, ptr);
1529    owl_editwin_redisplay(e, 0);
1530    owl_global_set_needrefresh(&g);
1531  } else {
1532    owl_function_beep();
1533  }
1534}
1535
1536char *owl_command_edit_insert_text(owl_editwin *e, int argc, char **argv, char *buff) {
1537  buff = skiptokens(buff, 1);
1538  owl_editwin_insert_string(e, buff);
1539  owl_editwin_redisplay(e, 0);
1540  owl_global_set_needrefresh(&g); 
1541  return NULL;
1542}
1543
1544void owl_command_editline_done(owl_editwin *e) {
1545  owl_history *hist=owl_editwin_get_history(e);
1546  char *rv, *cmd;
1547
1548  owl_history_store(hist, owl_editwin_get_text(e));
1549  owl_history_reset(hist);
1550  owl_global_set_typwin_inactive(&g);
1551  cmd = owl_strdup(owl_editwin_get_text(e));
1552  owl_editwin_fullclear(e);
1553  rv = owl_function_command(cmd);
1554  owl_free(cmd);
1555
1556  wnoutrefresh(owl_editwin_get_curswin(e));
1557  owl_global_set_needrefresh(&g);
1558
1559  if (rv) {
1560    owl_function_makemsg("%s", rv);
1561    owl_free(rv);
1562  }
1563}
1564
1565void owl_command_editmulti_done(owl_editwin *e) {
1566  owl_history *hist=owl_editwin_get_history(e);
1567
1568  owl_history_store(hist, owl_editwin_get_text(e));
1569  owl_history_reset(hist);
1570
1571  owl_function_run_buffercommand();
1572  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
1573  owl_editwin_fullclear(e);
1574  owl_global_set_typwin_inactive(&g);
1575  owl_global_set_needrefresh(&g);
1576  wnoutrefresh(owl_editwin_get_curswin(e));
1577}
1578
1579void owl_command_editmulti_done_or_delete(owl_editwin *e) {
1580  if (owl_editwin_is_at_end(e)) {
1581    owl_command_editmulti_done(e);
1582  } else {
1583    owl_editwin_delete_char(e);
1584  }
1585}
1586
1587
1588/*********************************************************************/
1589/*********************** POPLESS SPECIFIC ****************************/
1590/*********************************************************************/
1591
1592void owl_command_popless_quit(owl_viewwin *vw) {
1593  owl_popwin_close(owl_global_get_popwin(&g));
1594  owl_viewwin_free(vw);
1595  owl_global_set_needrefresh(&g);
1596}
1597
Note: See TracBrowser for help on using the repository browser.