source: commands.c @ 42abb10

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