source: commands.c @ 31e48a3

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