source: commands.c @ 601a9e0

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