source: commands.c @ 2cca044

release-1.10release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 2cca044 was 8c97fa1, checked in by Nelson Elhage <nelhage@mit.edu>, 15 years ago
Add recv:getshift and recv:setshift [nelhage@mit.edu: Clean up shift_left logic slightly]
  • Property mode set to 100644
File size: 82.4 KB
Line 
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <unistd.h>
5#include "owl.h"
6
7/* fn is "char *foo(int argc, const char *const *argv, const char *buff)" */
8#define OWLCMD_ARGS(name, fn, ctx, summary, usage, description) \
9        { name, summary, usage, description, ctx, \
10          NULL, fn, NULL, NULL, NULL, NULL, NULL, NULL }
11
12/* fn is "void foo(void)" */
13#define OWLCMD_VOID(name, fn, ctx, summary, usage, description) \
14        { name, summary, usage, description, ctx, \
15          NULL, NULL, fn, NULL, NULL, NULL, NULL, NULL }
16
17/* fn is "void foo(int)" */
18#define OWLCMD_INT(name, fn, ctx, summary, usage, description) \
19        { name, summary, usage, description, ctx, \
20          NULL, NULL, NULL, fn, NULL, NULL, NULL, NULL }
21
22#define OWLCMD_ALIAS(name, actualname) \
23        { name, OWL_CMD_ALIAS_SUMMARY_PREFIX actualname, "", "", OWL_CTX_ANY, \
24          actualname, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
25
26/* fn is "char *foo(void *ctx, int argc, const char *const *argv, const char *buff)" */
27#define OWLCMD_ARGS_CTX(name, fn, ctx, summary, usage, description) \
28        { name, summary, usage, description, ctx, \
29          NULL, NULL, NULL, NULL, ((char*(*)(void*,int,const char*const *,const char*))fn), NULL, NULL, NULL }
30
31/* fn is "void foo(void)" */
32#define OWLCMD_VOID_CTX(name, fn, ctx, summary, usage, description) \
33        { name, summary, usage, description, ctx, \
34          NULL, NULL, NULL, NULL, NULL, ((void(*)(void*))(fn)), NULL, NULL }
35
36/* fn is "void foo(int)" */
37#define OWLCMD_INT_CTX(name, fn, ctx, summary, usage, description) \
38        { name, summary, usage, description, ctx, \
39          NULL, NULL, NULL, NULL, NULL, NULL, ((void(*)(void*,int))fn), NULL }
40
41
42const owl_cmd commands_to_init[]
43  = {
44  OWLCMD_ARGS("zlog", owl_command_zlog, OWL_CTX_ANY,
45              "send a login or logout notification",
46              "zlog in [tty]\nzlog out",
47              "zlog in will send a login notification, zlog out will send a\n"
48              "logout notification.  By default a login notification is sent\n"
49              "when owl is started and a logout notification is sent when owl\n"
50              "is exited.  This behavior can be changed with the 'startuplogin'\n"
51              "and 'shutdownlogout' variables.  If a tty is specified for zlog in\n"
52              "then the owl variable 'tty' will be set to that string, causing\n"
53              "it to be used as the zephyr location tty.\n"),
54
55  OWLCMD_VOID("quit", owl_command_quit, OWL_CTX_ANY,
56              "exit owl",
57              "",
58              "Exit owl and run any shutdown activities."),
59  OWLCMD_ALIAS("exit", "quit"),
60  OWLCMD_ALIAS("q",    "quit"),
61
62  OWLCMD_ARGS("term", owl_command_term, OWL_CTX_ANY,
63              "control the terminal",
64              "term raise\n"
65              "term deiconify\n",
66              ""),
67
68  OWLCMD_VOID("nop", owl_command_nop, OWL_CTX_ANY,
69              "do nothing",
70              "",
71              ""),
72 
73  OWLCMD_ARGS("start-command", owl_command_start_command, OWL_CTX_INTERACTIVE,
74              "prompts the user to enter a command",
75              "start-command [initial-value]",
76              "Initializes the command field to initial-value."),
77
78  OWLCMD_ARGS("alias", owl_command_alias, OWL_CTX_ANY,
79              "creates a command alias",
80              "alias <new_command> <old_command>",
81              "Creates a command alias from new_command to old_command.\n"
82              "Any arguments passed to <new_command> will be appended to\n"
83              "<old_command> before it is executed.\n"),
84
85  OWLCMD_ARGS("bindkey", owl_command_bindkey, OWL_CTX_ANY,
86              "creates a binding in a keymap",
87              "bindkey <keymap> <keyseq> command <command>",
88              "(Note: There is a literal word \"command\" between <keyseq>\n"
89              " and <command>.)\n"
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\n"
93              "Ex.: bindkey recv C-b command zwrite -c barnowl"),
94
95  OWLCMD_ARGS("zwrite", owl_command_zwrite, OWL_CTX_INTERACTIVE,
96              "send a zephyr",
97              "zwrite [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [<user> ...] [-m <message...>]",
98              "Zwrite send a zephyr to the one or more users specified.\n\n"
99              "The following options are available:\n\n"
100              "-m    Specifies a message to send without prompting.\n"
101              "      Note that this does not yet log an outgoing message.\n"
102              "      This must be the last argument.\n\n"
103              "-n    Do not send a ping message.\n\n"
104              "-C    If the message is sent to more than one user include a\n"
105              "      \"cc:\" line in the text\n\n"
106              "-c class\n"
107              "      Send to the specified zephyr class\n\n"
108              "-i instance\n"
109              "      Send to the specified zephyr instance\n\n"
110              "-r realm\n"
111              "      Send to a foreign realm\n"
112              "-O opcode\n"
113              "      Send to the specified opcode\n"),
114
115  OWLCMD_ARGS("aimwrite", owl_command_aimwrite, OWL_CTX_INTERACTIVE,
116              "send an AIM message",
117              "aimwrite <user> [-m <message...>]",
118              "Send an aim message to a user.\n\n" 
119              "The following options are available:\n\n"
120              "-m    Specifies a message to send without prompting.\n"),
121
122  OWLCMD_ARGS("loopwrite", owl_command_loopwrite, OWL_CTX_INTERACTIVE,
123              "send a loopback message",
124              "loopwrite",
125              "Send a local message.\n"),
126
127  OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
128              "send an encrypted zephyr",
129              "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcde] [-m <message...>]\n",
130              "Behaves like zwrite but uses encryption.  Not for use with\n"
131              "personal messages\n"),
132 
133  OWLCMD_ARGS("reply", owl_command_reply,  OWL_CTX_INTERACTIVE,
134              "reply to the current message",
135              "reply [-e] [ sender | all | zaway ]",
136              "If -e is specified, the zwrite command line is presented to\n"
137              "allow editing.\n\n"
138              "If 'sender' is specified, reply to the sender.\n\n"
139              "If 'all' or no args are specified, reply publically to the\n"
140              "same class/instance for non-personal messages and to the\n"
141              "sender for personal messages.\n\n"
142              "If 'zaway' is specified, replies with a zaway message.\n\n"),
143
144  OWLCMD_ARGS("set", owl_command_set, OWL_CTX_ANY,
145              "set a variable value",
146              "set [-q] [<variable>] [<value>]\n"
147              "set",
148              "Set the named variable to the specified value.  If no\n"
149              "arguments are given, print the value of all variables.\n"
150              "If the value is unspecified and the variable is a boolean, it will be\n"
151              "set to 'on'.  If -q is used, set is silent and does not print a\n"
152              "message.\n"),
153
154  OWLCMD_ARGS("unset", owl_command_unset, OWL_CTX_ANY,
155              "unset a boolean variable value",
156              "unset [-q] <variable>\n"
157              "unset",
158              "Set the named boolean variable to off.\n"
159              "If -q is specified, is silent and doesn't print a message.\n"),
160
161  OWLCMD_ARGS("print", owl_command_print, OWL_CTX_ANY,
162              "print a variable value",
163              "print <variable>\n"
164              "print",
165              "Print the value of the named variable.  If no arguments\n"
166              "are used print the value of all variables.\n"),
167
168  OWLCMD_ARGS("startup", owl_command_startup, OWL_CTX_ANY,
169              "run a command and set it to be run at every Owl startup",
170              "startup <commands> ...",
171              "Everything on the command line after the startup command\n"
172              "is executed as a normal owl command and is also placed in\n"
173              "a file so that the command is executed every time owl\n"
174              "is started"),
175
176  OWLCMD_ARGS("unstartup", owl_command_unstartup, OWL_CTX_ANY,
177              "remove a command from the list of those to be run at Owl startup",
178              "unstartup <commands> ...",
179              ""),
180
181  OWLCMD_VOID("version", owl_command_version, OWL_CTX_ANY,
182              "print the version of the running owl", "", ""),
183
184  OWLCMD_ARGS("subscribe", owl_command_subscribe, OWL_CTX_ANY,
185              "subscribe to a zephyr class, instance, recipient",
186              "subscribe [-t] <class> [instance [recipient]]",
187              "Subscribe to the specified class and instance.  If the\n"
188              "instance or recipient is not listed on the command\n"
189              "line they default to * (the wildcard recipient).\n"
190              "If the -t option is present the subscription will\n"
191              "only be temporary, i.e., it will not be written to\n"
192              "the subscription file and will therefore not be\n"
193              "present the next time owl is started.\n"),
194  OWLCMD_ALIAS("sub", "subscribe"),
195
196  OWLCMD_ARGS("unsubscribe", owl_command_unsubscribe, OWL_CTX_ANY,
197              "unsubscribe from a zephyr class, instance, recipient",
198              "unsubscribe [-t] <class> [instance [recipient]]",
199              "Unsubscribe from the specified class and instance.  If the\n"
200              "instance or recipient is not listed on the command\n"
201              "line they default to * (the wildcard recipient).\n"
202              "If the -t option is present the unsubscription will\n"
203              "only be temporary, i.e., it will not be updated in\n"
204              "the subscription file and will therefore not be\n"
205              "in effect the next time owl is started.\n"),
206  OWLCMD_ALIAS("unsub", "unsubscribe"),
207
208  OWLCMD_VOID("unsuball", owl_command_unsuball, OWL_CTX_ANY,
209              "unsubscribe from all zephyrs", "", ""),
210 
211  OWLCMD_VOID("getsubs", owl_command_getsubs, OWL_CTX_ANY,
212              "print all current subscriptions",
213              "getsubs",
214              "getsubs retrieves the current subscriptions from the server\n"
215              "and displays them.\n"),
216
217  OWLCMD_ARGS("dump", owl_command_dump, OWL_CTX_ANY,
218              "dump messages to a file",
219              "dump <filename>",
220              "Dump messages in current view to the named file."),
221
222  OWLCMD_ARGS("source", owl_command_source, OWL_CTX_ANY,
223              "execute owl commands from a file",
224              "source <filename>",
225              "Execute the owl commands in <filename>.\n"),
226
227  OWLCMD_ARGS("aim", owl_command_aim, OWL_CTX_INTERACTIVE,
228              "AIM specific commands",
229              "aim search <email>",
230              ""),
231
232  OWLCMD_ARGS("addbuddy", owl_command_addbuddy, OWL_CTX_INTERACTIVE,
233              "add a buddy to a buddylist",
234              "addbuddy <protocol> <screenname>",
235              "Add the named buddy to your buddylist.  <protocol> can be aim or zephyr\n"),
236
237  OWLCMD_ARGS("delbuddy", owl_command_delbuddy, OWL_CTX_INTERACTIVE,
238              "delete a buddy from a buddylist",
239              "delbuddy <protocol> <screenname>",
240              "Delete the named buddy from your buddylist.  <protocol> can be aim or zephyr\n"),
241
242  OWLCMD_ARGS("join", owl_command_join, OWL_CTX_INTERACTIVE,
243              "join a chat group",
244              "join aim <groupname> [exchange]",
245              "Join the AIM chatroom with 'groupname'.\n"),
246
247  OWLCMD_ARGS("smartzpunt", owl_command_smartzpunt, OWL_CTX_INTERACTIVE,
248              "creates a zpunt based on the current message",
249              "smartzpunt [-i | --instance]",
250              "Starts a zpunt command based on the current message's class\n"
251              "(and instance if -i is specified).\n"),
252
253  OWLCMD_ARGS("zpunt", owl_command_zpunt, OWL_CTX_ANY,
254              "suppress a given zephyr triplet",
255              "zpunt <class> <instance> [recipient]\n"
256              "zpunt <instance>",
257              "The zpunt command will supress message to the specified\n"
258              "zephyr triplet.  In the second usage messages are suppressed\n"
259              "for class MESSAGE and the named instance.\n\n"
260              "SEE ALSO:  zunpunt, show zpunts\n"),
261
262  OWLCMD_ARGS("zunpunt", owl_command_zunpunt, OWL_CTX_ANY,
263              "undo a previous zpunt",
264              "zunpunt <class> <instance> [recipient]\n"
265              "zunpunt <instance>",
266              "The zunpunt command will allow messages that were previously\n"
267              "suppressed to be received again.\n\n"
268              "SEE ALSO:  zpunt, show zpunts\n"),
269
270  OWLCMD_ARGS("punt", owl_command_punt, OWL_CTX_ANY,
271              "suppress an arbitrary filter",
272              "punt <filter-text>",
273              "punt <filter-text (multiple words)>\n"
274              "The punt command will supress message to the specified\n"
275              "filter\n\n"
276              "SEE ALSO:  unpunt, zpunt, show zpunts\n"),
277
278  OWLCMD_ARGS("unpunt", owl_command_unpunt, OWL_CTX_ANY,
279              "remove an entry from the punt list",
280              "zpunt <filter-text>\n"
281              "zpunt <filter-text>\n"
282              "zpunt <number>\n",
283              "The unpunt command will remove an entry from the puntlist.\n"
284              "The first two forms correspond to the first two forms of the :punt\n"
285              "command. The latter allows you to remove a specific entry from the\n"
286              "the list (see :show zpunts)\n\n"
287              "SEE ALSO:  punt, zpunt, zunpunt, show zpunts\n"),
288
289  OWLCMD_VOID("info", owl_command_info, OWL_CTX_INTERACTIVE,
290              "display detailed information about the current message",
291              "", ""),
292 
293  OWLCMD_ARGS("help", owl_command_help, OWL_CTX_INTERACTIVE,
294              "display help on using owl",
295              "help [command]", ""),
296
297  OWLCMD_ARGS("zlist", owl_command_zlist, OWL_CTX_INTERACTIVE,
298              "List users logged in",
299              "znol [-f file]",
300              "Print a znol-style listing of users logged in"),
301
302  OWLCMD_VOID("alist", owl_command_alist, OWL_CTX_INTERACTIVE,
303              "List AIM users logged in",
304              "alist",
305              "Print a listing of AIM users logged in"),
306
307  OWLCMD_VOID("blist", owl_command_blist, OWL_CTX_INTERACTIVE,
308              "List all buddies logged in",
309              "blist",
310              "Print a listing of buddies logged in, regardless of protocol."),
311
312  OWLCMD_VOID("toggle-oneline", owl_command_toggleoneline, OWL_CTX_INTERACTIVE,
313              "Toggle the style between oneline and the default style",
314              "toggle-oneline",
315              ""),
316
317  OWLCMD_ARGS("recv:getshift", owl_command_get_shift, OWL_CTX_INTERACTIVE,
318              "gets position of receive window scrolling", "", ""),
319
320  OWLCMD_INT("recv:setshift", owl_command_set_shift, OWL_CTX_INTERACTIVE,
321              "scrolls receive window to specified position", "", ""),
322
323  OWLCMD_VOID("recv:shiftleft", owl_command_shift_left, OWL_CTX_INTERACTIVE,
324              "scrolls receive window to the left", "", ""),
325
326  OWLCMD_VOID("recv:shiftright", owl_command_shift_right, OWL_CTX_INTERACTIVE,
327              "scrolls receive window to the left", "", ""),
328
329  OWLCMD_VOID("recv:pagedown", owl_function_mainwin_pagedown, 
330              OWL_CTX_INTERACTIVE,
331              "scrolls down by a page", "", ""),
332
333  OWLCMD_VOID("recv:pageup", owl_function_mainwin_pageup, OWL_CTX_INTERACTIVE,
334              "scrolls up by a page", "", ""),
335
336  OWLCMD_VOID("recv:mark", owl_function_mark_message,
337              OWL_CTX_INTERACTIVE,
338              "mark the current message", "", ""),
339
340  OWLCMD_VOID("recv:swapmark", owl_function_swap_cur_marked,
341              OWL_CTX_INTERACTIVE,
342              "swap the positions of the pointer and the mark", "", ""),
343
344  OWLCMD_INT ("recv:scroll", owl_function_page_curmsg, OWL_CTX_INTERACTIVE,
345              "scrolls current message up or down", 
346              "recv:scroll <numlines>", 
347              "Scrolls the current message up or down by <numlines>.\n"
348              "Scrolls up if <numlines> is negative, else scrolls down.\n"),
349
350  OWLCMD_ARGS("next", owl_command_next, OWL_CTX_INTERACTIVE,
351              "move the pointer to the next message",
352              "recv:next [ --filter <name> ] [ --skip-deleted ] [ --last-if-none ]\n"
353              "          [ --smart-filter | --smart-filter-instance ]",
354              "Moves the pointer to the next message in the current view.\n"
355              "If --filter is specified, will only consider messages in\n"
356              "the filter <name>.\n"
357              "If --smart-filter or --smart-filter-instance is specified,\n"
358              "goes to the next message that is similar to the current message.\n"
359              "If --skip-deleted is specified, deleted messages will\n"
360              "be skipped.\n"
361              "If --last-if-none is specified, will stop at last message\n"
362              "in the view if no other suitable messages are found.\n"),
363  OWLCMD_ALIAS("recv:next", "next"),
364
365  OWLCMD_ARGS("prev", owl_command_prev, OWL_CTX_INTERACTIVE,
366              "move the pointer to the previous message",
367              "recv:prev [ --filter <name> ] [ --skip-deleted ] [ --first-if-none ]\n"
368              "          [ --smart-filter | --smart-filter-instance ]",
369              "Moves the pointer to the next message in the current view.\n"
370              "If --filter is specified, will only consider messages in\n"
371              "the filter <name>.\n"
372              "If --smart-filter or --smart-filter-instance is specified,\n"
373              "goes to the previous message that is similar to the current message.\n"
374              "If --skip-deleted is specified, deleted messages will\n"
375              "be skipped.\n"
376              "If --first-if-none is specified, will stop at first message\n"
377              "in the view if no other suitable messages are found.\n"),
378  OWLCMD_ALIAS("recv:prev", "prev"),
379
380  OWLCMD_ALIAS("recv:next-notdel", "recv:next --skip-deleted --last-if-none"),
381  OWLCMD_ALIAS("next-notdel",      "recv:next --skip-deleted --last-if-none"),
382
383  OWLCMD_ALIAS("recv:prev-notdel", "recv:prev --skip-deleted --first-if-none"),
384  OWLCMD_ALIAS("prev-notdel",      "recv:prev --skip-deleted --first-if-none"),
385
386  OWLCMD_ALIAS("recv:next-personal", "recv:next --filter personal"),
387
388  OWLCMD_ALIAS("recv:prev-personal", "recv:prev --filter personal"),
389
390  OWLCMD_VOID("first", owl_command_first, OWL_CTX_INTERACTIVE,
391              "move the pointer to the first message", "", ""),
392  OWLCMD_ALIAS("recv:first", "first"),
393
394  OWLCMD_VOID("last", owl_command_last, OWL_CTX_INTERACTIVE,
395              "move the pointer to the last message", "", 
396              "Moves the pointer to the last message in the view.\n"
397              "If we are already at the last message in the view,\n"
398              "blanks the screen and moves just past the end of the view\n"
399              "so that new messages will appear starting at the top\n"
400              "of the screen.\n"),
401  OWLCMD_ALIAS("recv:last", "last"),
402
403  OWLCMD_VOID("expunge", owl_command_expunge, OWL_CTX_INTERACTIVE,
404              "remove all messages marked for deletion", "", ""),
405
406  OWLCMD_VOID("resize", owl_command_resize, OWL_CTX_ANY,
407              "resize the window to the current screen size", "", ""),
408
409  OWLCMD_VOID("redisplay", owl_command_redisplay, OWL_CTX_ANY,
410              "redraw the entire window", "", ""),
411
412  OWLCMD_VOID("suspend", owl_command_suspend, OWL_CTX_ANY,
413              "suspend owl", "", ""),
414
415  OWLCMD_ARGS("echo", owl_command_echo, OWL_CTX_ANY,
416              "pops up a message in popup window",
417              "echo [args .. ]\n\n", ""),
418
419  OWLCMD_ARGS("exec", owl_command_exec, OWL_CTX_ANY,
420              "run a command from the shell",
421              "exec [args .. ]", ""),
422
423  OWLCMD_ARGS("aexec", owl_command_aexec, OWL_CTX_INTERACTIVE,
424              "run a command from the shell and display in an admin message",
425              "aexec [args .. ]", ""),
426
427  OWLCMD_ARGS("pexec", owl_command_pexec, OWL_CTX_INTERACTIVE,
428              "run a command from the shell and display in a popup window",
429              "pexec [args .. ]", ""),
430
431  OWLCMD_ARGS("perl", owl_command_perl, OWL_CTX_ANY,
432              "run a perl expression",
433              "perl [args .. ]", ""),
434
435  OWLCMD_ARGS("aperl", owl_command_aperl, OWL_CTX_INTERACTIVE,
436              "run a perl expression and display in an admin message",
437              "aperl [args .. ]", ""),
438
439  OWLCMD_ARGS("pperl", owl_command_pperl, OWL_CTX_INTERACTIVE,
440              "run a perl expression and display in a popup window",
441              "pperl [args .. ]", ""),
442
443  OWLCMD_ARGS("multi", owl_command_multi, OWL_CTX_ANY,
444              "runs multiple ;-separated commands",
445              "multi <command1> ( ; <command2> )*\n",
446              "Runs multiple semicolon-separated commands in order.\n"
447              "Note quoting isn't supported here yet.\n"
448              "If you want to do something fancy, use perl.\n"),
449
450  OWLCMD_ARGS("(", owl_command_multi, OWL_CTX_ANY,
451              "runs multiple ;-separated commands",
452              "'(' <command1> ( ; <command2> )* ')'\n",
453              "Runs multiple semicolon-separated commands in order.\n"
454              "You must have a space before the final ')'\n"
455              "Note quoting isn't supported here yet.\n"
456              "If you want to do something fancy, use perl.\n"),
457
458  OWLCMD_VOID("pop-message", owl_command_pop_message, OWL_CTX_RECWIN,
459              "pops up a message in a window", "", ""),
460
461  OWLCMD_ARGS("zaway", owl_command_zaway, OWL_CTX_INTERACTIVE,
462              "Set, enable or disable zephyr away message",
463              "zaway [ on | off | toggle ]\n"
464              "zaway <message>",
465              "Turn on or off a zaway message.  If 'message' is\n"
466              "specified turn on zaway with that message, otherwise\n"
467              "use the default.\n"),
468
469  OWLCMD_ARGS("aaway", owl_command_aaway, OWL_CTX_INTERACTIVE,
470              "Set, enable or disable AIM away message",
471              "aaway [ on | off | toggle ]\n"
472              "aaway <message>",
473              "Turn on or off the AIM away message.  If 'message' is\n"
474              "specified turn on aaway with that message, otherwise\n"
475              "use the default.\n"),
476
477  OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
478              "Set, enable or disable both AIM and zephyr away messages",
479              "away [ on | off | toggle ]\n"
480              "away <message>",
481              "Turn on or off the AIM and zephyr away message.  If\n"
482              "'message' is specified turn them on with that message,\n"
483              "otherwise use the default.\n"
484              "\n"
485              "This command really just runs the 'aaway' and 'zaway'\n"
486              "commands together\n"
487              "\n"
488              "SEE ALSO: aaway, zaway"),
489
490  OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
491              "load subscriptions from a file",
492              "load-subs <file>\n", ""),
493
494  OWLCMD_ARGS("loadsubs", owl_command_loadsubs, OWL_CTX_ANY,
495              "load subscriptions from a file",
496              "loadsubs <file>\n", ""),
497
498  OWLCMD_ARGS("loadloginsubs", owl_command_loadloginsubs, OWL_CTX_ANY,
499              "load login subscriptions from a file",
500              "loadloginsubs <file>\n",
501              "The file should contain a list of usernames, one per line."),
502
503  OWLCMD_VOID("about", owl_command_about, OWL_CTX_INTERACTIVE,
504              "print information about owl", "", ""),
505
506  OWLCMD_VOID("status", owl_command_status, OWL_CTX_ANY,
507              "print status information about the running owl", "", ""),
508 
509  OWLCMD_ARGS("zlocate", owl_command_zlocate, OWL_CTX_INTERACTIVE,
510              "locate a user",
511              "zlocate [-d] <user> ...", 
512              "Performs a zlocate on one ore more users and puts the result\n"
513              "int a popwin.  If -d is specified, does not authenticate\n"
514              "the lookup request.\n"),
515 
516  OWLCMD_ARGS("filter", owl_command_filter, OWL_CTX_ANY,
517              "create a message filter",
518              "filter <name> [ -c fgcolor ] [ -b bgcolor ] [ <expression> ... ]",
519              "The filter command creates a filter with the specified name,\n"
520              "or if one already exists it is replaced.  Example filter\n"
521              "syntax would be:\n\n"
522              "     filter myfilter -c red ( class ^foobar$ ) or ( class ^quux$ and instance ^bar$ )\n\n"
523              "Valid matching fields are:\n"
524              "    sender     -  sender\n"
525              "    recipient  -  recipient\n"
526              "    class      -  zephyr class name\n"
527              "    instance   -  zephyr instance name\n"
528              "    opcode     -  zephyr opcode\n"
529              "    realm      -  zephyr realm\n"
530              "    body       -  message body\n"
531              "    hostname   -  hostname of sending host\n"
532              "    type       -  message type (zephyr, aim, admin)\n"
533              "    direction  -  either 'in' 'out' or 'none'\n"
534              "    login      -  either 'login' 'logout' or 'none'\n"
535              "Also you may match on the validity of another filter:\n"
536              "    filter <filtername>\n"
537              "Also you may pass the message to a perl function returning 0 or 1,\n"
538              "where 1 indicates that the function matches the filter:\n"
539              "    perl <subname>\n"
540              "Valid operators are:\n"
541              "    and\n"
542              "    or\n"
543              "    not\n"
544              "And additionally you may use the static values:\n"
545              "    true\n"
546              "    false\n"
547              "Spaces must be present before and after parentheses.  If the\n"
548              "optional color arguments are used they specifies the colors that\n"
549              "messages matching this filter should be displayed in.\n\n"
550              "SEE ALSO: view, viewclass, viewuser\n"),
551
552  OWLCMD_ARGS("colorview", owl_command_colorview, OWL_CTX_INTERACTIVE,
553              "change the colors on the current filter",
554              "colorview <fgcolor> [<bgcolor>]",
555              "The colors of messages in the current filter will be changed\n"
556              "to <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
557              "of valid colors.\n\n"
558              "SEE ALSO: 'show colors'\n"),
559
560  OWLCMD_ARGS("colorclass", owl_command_colorclass, OWL_CTX_INTERACTIVE,
561              "create a filter to color messages of the given class name",
562              "colorclass <class> <fgcolor> [<bgcolor>]",
563              "A filter will be created to color messages in <class>"
564              "in <fgcolor>,<bgcolor>.  Use the 'show colors' command for a list\n"
565              "of valid colors.\n\n"
566              "SEE ALSO: 'show colors'\n"),
567
568  OWLCMD_ARGS("view", owl_command_view, OWL_CTX_INTERACTIVE,
569              "view messages matching a filter",
570              "view [<viewname>] [-f <filter> | --home | -r ] [-s <style>]\n"
571              "view <filter>\n"
572              "view -d <expression>\n"
573              "view --home",
574              "The view command sets information associated with a particular view,\n"
575              "such as view's filter or style.  In the first general usage listed\n"
576              "above <viewname> is the name of the view to be changed.  If not\n"
577              "specified the default view 'main' will be used.  A filter can be set\n"
578              "for the view by listing a named filter after the -f argument.  If\n"
579              "the --home argument is used the filter will be set to the filter named\n"
580              "by the\n 'view_home' variable.  The style can be set by listing the\n"
581              "name style after the -s argument.\n"
582              "\n"
583              "The other usages listed above are abbreivated forms that simply set\n"
584              "the filter of the current view. The -d option allows you to write a\n"
585              "filter expression that will be dynamically created by owl and then\n"
586              "applied as the view's filter\n"
587              "SEE ALSO: filter, viewclass, viewuser\n"),
588
589  OWLCMD_ARGS("smartnarrow", owl_command_smartnarrow, OWL_CTX_INTERACTIVE,
590              "view only messages similar to the current message",
591              "smartnarrow [-i | --instance]",
592              "If the curmsg is a personal message narrow\n"
593              "   to the conversation with that user.\n"
594              "If the curmsg is a <MESSAGE, foo, *>\n"
595              "   message, narrow to the instance.\n"
596              "If the curmsg is a class message, narrow\n"
597              "    to the class.\n"
598              "If the curmsg is a class message and '-i' is specified\n"
599              "    then narrow to the class and instance.\n"),
600
601  OWLCMD_ARGS("smartfilter", owl_command_smartfilter, OWL_CTX_INTERACTIVE,
602              "returns the name of a filter based on the current message",
603              "smartfilter [-i | --instance]",
604              "If the curmsg is a personal message, the filter is\n"
605              "   the conversation with that user.\n"
606              "If the curmsg is a <MESSAGE, foo, *>\n"
607              "   message, the filter is to that instance.\n"
608              "If the curmsg is a class message, the filter is that class.\n"
609              "If the curmsg is a class message and '-i' is specied\n"
610              "    the filter is to that class and instance.\n"),
611
612  OWLCMD_ARGS("viewclass", owl_command_viewclass, OWL_CTX_INTERACTIVE,
613              "view messages matching a particular class",
614              "viewclass <class>",
615              "The viewclass command will automatically create a filter\n"
616              "matching the specified class and switch the current view\n"
617              "to it.\n\n"
618              "SEE ALSO: filter, view, viewuser\n"),
619  OWLCMD_ALIAS("vc", "viewclass"),
620
621  OWLCMD_ARGS("viewuser", owl_command_viewuser, OWL_CTX_INTERACTIVE,
622              "view messages matching a particular user",
623              "viewuser <user>",
624              "The viewuser command will automatically create a filter\n"
625              "matching the specified user and switch the current\n"
626              "view to it.\n\n"
627              "SEE ALSO: filter, view, viewclass\n"),
628  OWLCMD_ALIAS("vu", "viewuser"),
629
630  OWLCMD_ARGS("show", owl_command_show, OWL_CTX_INTERACTIVE,
631              "show information",
632              "show colors\n"
633              "show commands\n"
634              "show command <command>\n"
635              "show errors\n"
636              "show filters\n"
637              "show filter <filter>\n"
638              "show keymaps\n"
639              "show keymap <keymap>\n"
640              "show license\n"
641              "show quickstart\n"
642              "show startup\n"
643              "show status\n"
644              "show styles\n"
645              "show subscriptions / show subs\n"
646              "show terminal\n"
647              "show variables\n"
648              "show variable <variable>\n"
649              "show version\n"
650              "show view [<view>]\n"
651              "show zpunts\n",
652
653              "Show colors will display a list of valid colors for the\n"
654              "     terminal."
655              "Show filters will list the names of all filters.\n"
656              "Show filter <filter> will show the definition of a particular\n"
657              "     filter.\n\n"
658              "Show startup will display the custom startup config\n\n"
659              "Show zpunts will show the active zpunt filters.\n\n"
660              "Show keymaps will list the names of all keymaps.\n"
661              "Show keymap <keymap> will show the key bindings in a keymap.\n\n"
662              "Show commands will list the names of all keymaps.\n"
663              "Show command <command> will provide information about a command.\n\n"
664              "Show styles will list the names of all styles available\n"
665              "for formatting messages.\n\n"
666              "Show variables will list the names of all variables.\n\n"
667              "Show errors will show a list of errors ecountered by Owl.\n\n"
668              "SEE ALSO: filter, view, alias, bindkey, help\n"),
669 
670  OWLCMD_ARGS("delete", owl_command_delete, OWL_CTX_INTERACTIVE,
671              "mark a message for deletion",
672              "delete [ -id msgid ] [ --no-move ]\n"
673              "delete view\n"
674              "delete trash",
675              "If no message id is specified the current message is marked\n"
676              "for deletion.  Otherwise the message with the given message\n"
677              "id is marked for deletion.\n"
678              "If '--no-move' is specified, don't move after deletion.\n"
679              "If 'trash' is specified, deletes all trash/auto messages\n"
680              "in the current view.\n"
681              "If 'view' is specified, deletes all messages in the\n"
682              "current view.\n"),
683  OWLCMD_ALIAS("del", "delete"),
684
685  OWLCMD_ARGS("undelete", owl_command_undelete, OWL_CTX_INTERACTIVE,
686              "unmark a message for deletion",
687              "undelete [ -id msgid ] [ --no-move ]\n"
688              "undelete view",
689              "If no message id is specified the current message is\n"
690              "unmarked for deletion.  Otherwise the message with the\n"
691              "given message id is unmarked for deletion.\n"
692              "If '--no-move' is specified, don't move after deletion.\n"
693              "If 'view' is specified, undeletes all messages\n"
694              "in the current view.\n"),
695  OWLCMD_ALIAS("undel", "undelete"),
696
697  OWLCMD_VOID("beep", owl_command_beep, OWL_CTX_ANY,
698              "ring the terminal bell",
699              "beep",
700              "Beep will ring the terminal bell.\n"
701              "If the variable 'bell' has been\n"
702              "set to 'off' this command does nothing.\n"),
703
704  OWLCMD_ARGS("debug", owl_command_debug, OWL_CTX_ANY,
705              "prints a message into the debug log",
706              "debug <message>", ""),
707
708  OWLCMD_ARGS("getview", owl_command_getview, OWL_CTX_INTERACTIVE,
709              "returns the name of the filter for the current view",
710              "", ""),
711
712  OWLCMD_ARGS("getvar", owl_command_getvar, OWL_CTX_INTERACTIVE,
713              "returns the value of a variable",
714              "getvar <varname>", ""),
715
716  OWLCMD_ARGS("getfilter", owl_command_getfilter, OWL_CTX_INTERACTIVE,
717              "returns the definition of a filter",
718              "getfilter <filtername>", ""),
719
720  OWLCMD_ARGS("getstyle", owl_command_getstyle, OWL_CTX_INTERACTIVE,
721              "returns the name of the style for the current view",
722              "", ""),
723
724  OWLCMD_ARGS("search", owl_command_search, OWL_CTX_INTERACTIVE,
725              "search messages for a particular string",
726              "search [-r] [<string>]",
727              "The search command will find messages that contain the\n"
728              "specified string and move the cursor there.  If no string\n"
729              "argument is supplied then the previous one is used.  By\n"
730              "default searches are done forwards; if -r is used the search\n"
731              "is performed backwards"),
732
733  OWLCMD_ARGS("setsearch", owl_command_setsearch, OWL_CTX_INTERACTIVE,
734              "set the search highlight string without searching",
735              "setsearch <string>",
736              "The setsearch command highlights all occurences of its\n"
737          "argument and makes it the default argument for future\n"
738          "search commands, but does not move the cursor.  With\n"
739          "no argument, it makes search highlighting inactive."),
740
741  OWLCMD_ARGS("aimlogin", owl_command_aimlogin, OWL_CTX_ANY,
742              "login to an AIM account",
743              "aimlogin <screenname> [<password>]\n",
744              ""),
745
746  OWLCMD_ARGS("aimlogout", owl_command_aimlogout, OWL_CTX_ANY,
747              "logout from AIM",
748              "aimlogout\n",
749              ""),
750
751  OWLCMD_ARGS("error", owl_command_error, OWL_CTX_ANY,
752              "Display an error message",
753              "error <message>",
754              ""),
755
756  OWLCMD_ARGS("message", owl_command_message, OWL_CTX_ANY,
757              "Display an informative message",
758              "message <message>",
759              ""),
760
761  OWLCMD_VOID("yes", owl_command_yes, OWL_CTX_RECV,
762              "Answer yes to a question",
763              "yes",
764              ""),
765
766  OWLCMD_VOID("no", owl_command_no, OWL_CTX_RECV,
767              "Answer no to a question",
768              "no",
769              ""),
770
771  /****************************************************************/
772  /************************* EDIT-SPECIFIC ************************/
773  /****************************************************************/
774
775  OWLCMD_VOID_CTX("edit:move-next-word", owl_editwin_move_to_nextword, 
776                  OWL_CTX_EDIT,
777                  "moves cursor forward a word",
778                  "", ""),
779
780  OWLCMD_VOID_CTX("edit:move-prev-word", owl_editwin_move_to_previousword, 
781                  OWL_CTX_EDIT,
782                  "moves cursor backwards a word",
783                  "", ""),
784
785  OWLCMD_VOID_CTX("edit:move-to-buffer-start", owl_editwin_move_to_top,
786                  OWL_CTX_EDIT,
787                  "moves cursor to the top left (start) of the buffer",
788                  "", ""),
789
790  OWLCMD_VOID_CTX("edit:move-to-buffer-end", owl_editwin_move_to_end, 
791                  OWL_CTX_EDIT,
792                  "moves cursor to the bottom right (end) of the buffer",
793                  "", ""),
794
795  OWLCMD_VOID_CTX("edit:move-to-line-end", owl_editwin_move_to_line_end, 
796                  OWL_CTX_EDIT,
797                  "moves cursor to the end of the line",
798                  "", ""),
799
800  OWLCMD_VOID_CTX("edit:move-to-line-start", owl_editwin_move_to_line_start, 
801                  OWL_CTX_EDIT,
802                  "moves cursor to the beginning of the line",
803                  "", ""),
804
805  OWLCMD_VOID_CTX("edit:move-left", owl_editwin_key_left, 
806                  OWL_CTX_EDIT,
807                  "moves the cursor left by a character",
808                  "", ""),
809
810  OWLCMD_VOID_CTX("edit:move-right", owl_editwin_key_right,
811                  OWL_CTX_EDIT,
812                  "moves the cursor right by a character",
813                  "", ""),
814
815  OWLCMD_VOID_CTX("edit:delete-next-word", owl_editwin_delete_nextword,
816                  OWL_CTX_EDIT,
817                  "deletes the word to the right of the cursor",
818                  "", ""),
819
820  OWLCMD_VOID_CTX("edit:delete-prev-word", owl_editwin_delete_previousword,
821                  OWL_CTX_EDIT,
822                  "deletes the word to the left of the cursor",
823                  "", ""),
824
825  OWLCMD_VOID_CTX("edit:delete-prev-char", owl_editwin_backspace,
826                  OWL_CTX_EDIT,
827                  "deletes the character to the left of the cursor",
828                  "", ""),
829
830  OWLCMD_VOID_CTX("edit:delete-next-char", owl_editwin_delete_char, 
831                  OWL_CTX_EDIT,
832                  "deletes the character to the right of the cursor",
833                  "", ""),
834
835  OWLCMD_VOID_CTX("edit:delete-to-line-end", owl_editwin_delete_to_endofline,
836                  OWL_CTX_EDIT,
837                  "deletes from the cursor to the end of the line",
838                  "", ""),
839
840  OWLCMD_VOID_CTX("edit:delete-all", owl_editwin_clear, 
841                  OWL_CTX_EDIT,
842                  "deletes all of the contents of the buffer",
843                  "", ""),
844
845  OWLCMD_VOID_CTX("edit:transpose-chars", owl_editwin_transpose_chars,
846                  OWL_CTX_EDIT,
847                  "Interchange characters around point, moving forward one character.",
848                  "", ""),
849
850  OWLCMD_VOID_CTX("edit:fill-paragraph", owl_editwin_fill_paragraph, 
851                  OWL_CTX_EDIT,
852                  "fills the current paragraph to line-wrap well",
853                  "", ""),
854
855  OWLCMD_VOID_CTX("edit:recenter", owl_editwin_recenter, 
856                  OWL_CTX_EDIT,
857                  "recenters the buffer",
858                  "", ""),
859
860  OWLCMD_ARGS_CTX("edit:insert-text", owl_command_edit_insert_text, 
861                  OWL_CTX_EDIT,
862                  "inserts text into the buffer",
863                  "edit:insert-text <text>", ""),
864
865  OWLCMD_VOID_CTX("edit:cancel", owl_command_edit_cancel, 
866                  OWL_CTX_EDIT,
867                  "cancels the current command",
868                  "", ""),
869
870  OWLCMD_VOID_CTX("edit:history-next", owl_command_edit_history_next, 
871                  OWL_CTX_EDIT,
872                  "replaces the text with the next history",
873                  "", ""),
874
875  OWLCMD_VOID_CTX("edit:history-prev", owl_command_edit_history_prev, 
876                  OWL_CTX_EDIT,
877                  "replaces the text with the previous history",
878                  "", ""),
879
880  OWLCMD_VOID_CTX("edit:set-mark", owl_editwin_set_mark,
881                  OWL_CTX_EDIT,
882                  "sets the mark",
883                  "", ""),
884
885  OWLCMD_VOID_CTX("edit:exchange-point-and-mark", owl_editwin_exchange_point_and_mark,
886                  OWL_CTX_EDIT,
887                  "exchanges the point and the mark",
888                  "", ""),
889
890  OWLCMD_VOID_CTX("edit:copy-region-as-kill", owl_editwin_copy_region_as_kill,
891                  OWL_CTX_EDIT,
892                  "copy the text between the point and the mark",
893                  "", ""),
894
895  OWLCMD_VOID_CTX("edit:kill-region", owl_editwin_kill_region,
896                  OWL_CTX_EDIT,
897                  "kill text between the point and the mark",
898                  "", ""),
899
900  OWLCMD_VOID_CTX("edit:yank", owl_editwin_yank,
901                  OWL_CTX_EDIT,
902                  "insert the current text from the kill buffer",
903                  "", ""),
904
905  OWLCMD_VOID_CTX("editline:done", owl_command_editline_done, 
906                  OWL_CTX_EDITLINE,
907                  "completes the command (eg, executes command being composed)",
908                  "", ""),
909
910  OWLCMD_VOID_CTX("editresponse:done", owl_command_editresponse_done, 
911                  OWL_CTX_EDITRESPONSE,
912                  "completes the response to a question",
913                  "", ""),
914
915  OWLCMD_VOID_CTX("edit:move-up-line", owl_editwin_key_up, 
916                  OWL_CTX_EDITMULTI,
917                  "moves the cursor up one line",
918                  "", ""),
919
920  OWLCMD_VOID_CTX("edit:move-down-line", owl_editwin_key_down, 
921                  OWL_CTX_EDITMULTI,
922                  "moves the cursor down one line",
923                  "", ""),
924
925  OWLCMD_VOID_CTX("edit:done", owl_command_edit_done, 
926                  OWL_CTX_EDITMULTI,
927                  "completes the command (eg, sends message being composed)",
928                  "", ""),
929
930  OWLCMD_VOID_CTX("edit:done-or-delete", owl_command_edit_done_or_delete, 
931                  OWL_CTX_EDITMULTI,
932                  "completes the command, but only if at end of message",
933                  "", 
934                  "If only whitespace is to the right of the cursor,\n"
935                  "runs 'edit:done'.\n"\
936                  "Otherwise runs 'edit:delete-next-char'\n"),
937
938  OWLCMD_VOID_CTX("edit:forward-paragraph", owl_editwin_forward_paragraph,
939                  OWL_CTX_EDITMULTI,
940                  "Move forward to end of paragraph.",
941                  "",
942                  "Move the point to the end of the current paragraph"),
943
944  OWLCMD_VOID_CTX("edit:backward-paragraph", owl_editwin_backward_paragraph,
945                  OWL_CTX_EDITMULTI,
946                  "Move backward to the start of paragraph.",
947                  "",
948                  "Move the point to the start of the current paragraph"),
949
950  /****************************************************************/
951  /********************** POPLESS-SPECIFIC ************************/
952  /****************************************************************/
953
954  OWLCMD_VOID_CTX("popless:scroll-down-page", owl_viewwin_pagedown, 
955                  OWL_CTX_POPLESS,
956                  "scrolls down one page",
957                  "", ""),
958
959  OWLCMD_VOID_CTX("popless:scroll-down-line", owl_viewwin_linedown, 
960                  OWL_CTX_POPLESS,
961                  "scrolls down one line",
962                  "", ""),
963
964  OWLCMD_VOID_CTX("popless:scroll-up-page", owl_viewwin_pageup, 
965                  OWL_CTX_POPLESS,
966                  "scrolls up one page",
967                  "", ""),
968
969  OWLCMD_VOID_CTX("popless:scroll-up-line", owl_viewwin_lineup, 
970                  OWL_CTX_POPLESS,
971                  "scrolls up one line",
972                  "", ""),
973
974  OWLCMD_VOID_CTX("popless:scroll-to-top", owl_viewwin_top, 
975                  OWL_CTX_POPLESS,
976                  "scrolls to the top of the buffer",
977                  "", ""),
978
979  OWLCMD_VOID_CTX("popless:scroll-to-bottom", owl_viewwin_bottom, 
980                  OWL_CTX_POPLESS,
981                  "scrolls to the bottom of the buffer",
982                  "", ""),
983
984  OWLCMD_INT_CTX ("popless:scroll-right", owl_viewwin_right, 
985                  OWL_CTX_POPLESS,
986                  "scrolls right in the buffer",
987                  "popless:scroll-right <num-chars>", ""),
988
989  OWLCMD_INT_CTX ("popless:scroll-left", owl_viewwin_left, 
990                  OWL_CTX_POPLESS,
991                  "scrolls left in the buffer",
992                  "popless:scroll-left <num-chars>", ""),
993
994  OWLCMD_VOID_CTX("popless:quit", owl_command_popless_quit, 
995                  OWL_CTX_POPLESS,
996                  "exits the popless window",
997                  "", ""),
998
999  OWLCMD_ALIAS("webzephyr", "zwrite daemon.webzephyr -c webzephyr -i"),
1000
1001  /* This line MUST be last! */
1002  { NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
1003
1004};
1005
1006void owl_command_info(void)
1007{
1008  owl_function_info();
1009}
1010
1011void owl_command_nop(void)
1012{
1013}
1014
1015char *owl_command_help(int argc, const char *const *argv, const char *buff)
1016{
1017  if (argc!=2) {
1018    owl_help();
1019    return NULL;
1020  }
1021 
1022  owl_function_help_for_command(argv[1]);
1023  return NULL;
1024}
1025
1026char *owl_command_zlist(int argc, const char *const *argv, const char *buff)
1027{
1028  const char *file=NULL;
1029
1030  argc--;
1031  argv++;
1032  while (argc) {
1033    if (!strcmp(argv[0], "-f")) {
1034      if (argc==1) {
1035        owl_function_makemsg("zlist: -f needs an argument");
1036        return(NULL);
1037      }
1038      file=argv[1];
1039      argc-=2;
1040      argv+=2;
1041    } else {
1042      owl_function_makemsg("zlist: unknown argument");
1043      return(NULL);
1044    }
1045  }
1046  owl_function_buddylist(0, 1, file);
1047  return(NULL);
1048}
1049
1050void owl_command_alist(void)
1051{
1052  owl_function_buddylist(1, 0, NULL);
1053}
1054
1055void owl_command_blist(void)
1056{
1057  owl_function_buddylist(1, 1, NULL);
1058}
1059
1060void owl_command_toggleoneline(void)
1061{
1062  owl_function_toggleoneline();
1063}
1064
1065void owl_command_about(void)
1066{
1067  owl_function_about();
1068}
1069
1070void owl_command_version(void)
1071{
1072  owl_function_makemsg("BarnOwl version %s", OWL_VERSION_STRING);
1073}
1074
1075char *owl_command_aim(int argc, const char *const *argv, const char *buff)
1076{
1077  if (argc<2) {
1078    owl_function_makemsg("not enough arguments to aim command");
1079    return(NULL);
1080  }
1081
1082  if (!strcmp(argv[1], "search")) {
1083    if (argc!=3) {
1084      owl_function_makemsg("not enough arguments to aim search command");
1085      return(NULL);
1086    }
1087    owl_aim_search(argv[2]);
1088  } else {
1089    owl_function_makemsg("unknown subcommand '%s' for aim command", argv[1]);
1090    return(NULL);
1091  }
1092  return(NULL);
1093}
1094
1095char *owl_command_addbuddy(int argc, const char *const *argv, const char *buff)
1096{
1097  if (argc!=3) {
1098    owl_function_makemsg("usage: addbuddy <protocol> <buddyname>");
1099    return(NULL);
1100  }
1101
1102  if (!strcasecmp(argv[1], "aim")) {
1103    if (!owl_global_is_aimloggedin(&g)) {
1104      owl_function_makemsg("addbuddy: You must be logged into aim to use this command.");
1105      return(NULL);
1106    }
1107    /*
1108    owl_function_makemsg("This function is not yet operational.  Stay tuned.");
1109    return(NULL);
1110    */
1111    owl_aim_addbuddy(argv[2]);
1112    owl_function_makemsg("%s added as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1113  } else if (!strcasecmp(argv[1], "zephyr")) {
1114    owl_zephyr_addbuddy(argv[2]);
1115    owl_function_makemsg("%s added as zephyr buddy", argv[2]);
1116  } else {
1117    owl_function_makemsg("addbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1118  }
1119
1120  return(NULL);
1121}
1122
1123char *owl_command_delbuddy(int argc, const char *const *argv, const char *buff)
1124{
1125  if (argc!=3) {
1126    owl_function_makemsg("usage: delbuddy <protocol> <buddyname>");
1127    return(NULL);
1128  }
1129
1130  if (!strcasecmp(argv[1], "aim")) {
1131    if (!owl_global_is_aimloggedin(&g)) {
1132      owl_function_makemsg("delbuddy: You must be logged into aim to use this command.");
1133      return(NULL);
1134    }
1135    owl_aim_delbuddy(argv[2]);
1136    owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g));
1137  } else if (!strcasecmp(argv[1], "zephyr")) {
1138    owl_zephyr_delbuddy(argv[2]);
1139    owl_function_makemsg("%s deleted as zephyr buddy", argv[2]);
1140  } else {
1141    owl_function_makemsg("delbuddy: currently the only supported protocols are 'zephyr' and 'aim'");
1142  }
1143
1144  return(NULL);
1145}
1146
1147char *owl_command_join(int argc, const char *const *argv, const char *buff)
1148{
1149  if (argc!=3 && argc!=4) {
1150    owl_function_makemsg("usage: join <protocol> <buddyname> [exchange]");
1151    return(NULL);
1152  }
1153
1154  if (!strcasecmp(argv[1], "aim")) {
1155    if (!owl_global_is_aimloggedin(&g)) {
1156      owl_function_makemsg("join aim: You must be logged into aim to use this command.");
1157      return(NULL);
1158    }
1159    if (argc==3) {
1160      owl_aim_chat_join(argv[2], 4);
1161    } else {
1162      owl_aim_chat_join(argv[2], atoi(argv[3]));
1163    }
1164    /* owl_function_makemsg("%s deleted as AIM buddy for %s", argv[2], owl_global_get_aim_screenname(&g)); */
1165  } else {
1166    owl_function_makemsg("join: currently the only supported protocol is 'aim'");
1167  }
1168  return(NULL);
1169}
1170
1171char *owl_command_startup(int argc, const char *const *argv, const char *buff)
1172{
1173  const char *ptr;
1174
1175  if (argc<2) {
1176    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1177    return(NULL);
1178  }
1179
1180  ptr = skiptokens(buff, 1);
1181
1182  owl_function_command(ptr);
1183  owl_function_addstartup(ptr);
1184
1185  return(NULL);
1186}
1187
1188char *owl_command_unstartup(int argc, const char *const *argv, const char *buff)
1189{
1190  const char *ptr;
1191
1192  if (argc<2) {
1193    owl_function_makemsg("usage: %s <commands> ...", argv[0]);
1194    return(NULL);
1195  }
1196
1197  ptr = skiptokens(buff, 1);
1198
1199  owl_function_delstartup(ptr);
1200
1201  return(NULL);
1202}
1203
1204char *owl_command_dump(int argc, const char *const *argv, const char *buff)
1205{
1206  char *filename;
1207 
1208  if (argc!=2) {
1209    owl_function_makemsg("usage: dump <filename>");
1210    return(NULL);
1211  }
1212  filename=owl_util_makepath(argv[1]);
1213  owl_function_dump(filename);
1214  owl_free(filename);
1215  return(NULL);
1216}
1217
1218char *owl_command_source(int argc, const char *const *argv, const char *buff)
1219{
1220  if (argc!=2) {
1221    owl_function_makemsg("usage: source <filename>");
1222    return(NULL);
1223  }
1224
1225  owl_function_source(argv[1]);
1226  return(NULL);
1227}
1228
1229char *owl_command_next(int argc, const char *const *argv, const char *buff)
1230{
1231  char *filter=NULL;
1232  int skip_deleted=0, last_if_none=0;
1233  while (argc>1) {
1234    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1235      skip_deleted=1;
1236      argc-=1; argv+=1; 
1237    } else if (argc>=1 && !strcmp(argv[1], "--last-if-none")) {
1238      last_if_none=1;
1239      argc-=1; argv+=1; 
1240    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1241      filter = owl_strdup(argv[2]);
1242      argc-=2; argv+=2; 
1243    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1244      filter = owl_function_smartfilter(0);
1245      argc-=2; argv+=2; 
1246    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1247      filter = owl_function_smartfilter(1);
1248      argc-=2; argv+=2; 
1249    } else {
1250      owl_function_makemsg("Invalid arguments to command 'next'.");
1251      return(NULL);
1252    }
1253  }
1254  owl_function_nextmsg_full(filter, skip_deleted, last_if_none);
1255  if (filter) owl_free(filter);
1256  return(NULL);
1257}
1258
1259char *owl_command_prev(int argc, const char *const *argv, const char *buff)
1260{
1261  char *filter=NULL;
1262  int skip_deleted=0, first_if_none=0;
1263  while (argc>1) {
1264    if (argc>=1 && !strcmp(argv[1], "--skip-deleted")) {
1265      skip_deleted=1;
1266      argc-=1; argv+=1; 
1267    } else if (argc>=1 && !strcmp(argv[1], "--first-if-none")) {
1268      first_if_none=1;
1269      argc-=1; argv+=1; 
1270    } else if (argc>=2 && !strcmp(argv[1], "--filter")) {
1271      filter = owl_strdup(argv[2]);
1272      argc-=2; argv+=2; 
1273    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter")) {
1274      filter = owl_function_smartfilter(0);
1275      argc-=2; argv+=2; 
1276    } else if (argc>=2 && !strcmp(argv[1], "--smart-filter-instance")) {
1277      filter = owl_function_smartfilter(1);
1278      argc-=2; argv+=2; 
1279   } else {
1280      owl_function_makemsg("Invalid arguments to command 'prev'.");
1281      return(NULL);
1282    }
1283  }
1284  owl_function_prevmsg_full(filter, skip_deleted, first_if_none);
1285  if (filter) owl_free(filter);
1286  return(NULL);
1287}
1288
1289char *owl_command_smartnarrow(int argc, const char *const *argv, const char *buff)
1290{
1291  char *filtname = NULL;
1292
1293  if (argc == 1) {
1294    filtname = owl_function_smartfilter(0);
1295  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1296    filtname = owl_function_smartfilter(1);
1297  } else {
1298    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1299  }
1300  if (filtname) {
1301    owl_function_change_currentview_filter(filtname);
1302    owl_free(filtname);
1303  }
1304  return NULL;
1305}
1306
1307char *owl_command_smartfilter(int argc, const char *const *argv, const char *buff)
1308{
1309  char *filtname = NULL;
1310
1311  if (argc == 1) {
1312    filtname = owl_function_smartfilter(0);
1313  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
1314    filtname = owl_function_smartfilter(1);
1315  } else {
1316    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
1317  }
1318  return filtname;
1319}
1320
1321void owl_command_expunge(void)
1322{
1323  owl_function_expunge();
1324}
1325
1326void owl_command_first(void)
1327{
1328  owl_global_set_rightshift(&g, 0);
1329  owl_function_firstmsg();
1330}
1331
1332void owl_command_last(void)
1333{
1334  owl_function_lastmsg();
1335}
1336
1337void owl_command_resize(void)
1338{
1339  owl_function_resize();
1340}
1341
1342void owl_command_redisplay(void)
1343{
1344  owl_function_full_redisplay();
1345  owl_global_set_needrefresh(&g);
1346}
1347
1348char *owl_command_get_shift(int argc, const char *const *argv, const char *buff)
1349{
1350  if(argc != 1)
1351  {
1352    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
1353    return NULL;
1354  }
1355  return owl_sprintf("%d", owl_global_get_rightshift(&g));
1356}
1357
1358void owl_command_set_shift(int shift)
1359{
1360  owl_global_set_rightshift(&g, shift);
1361  owl_mainwin_redisplay(owl_global_get_mainwin(&g));
1362  owl_global_set_needrefresh(&g);
1363}
1364
1365void owl_command_shift_left(void)
1366{
1367  owl_function_shift_left();
1368}
1369
1370void owl_command_shift_right(void)
1371{
1372  owl_function_shift_right();
1373}
1374
1375void owl_command_unsuball(void)
1376{
1377  owl_function_unsuball();
1378}
1379
1380char *owl_command_loadsubs(int argc, const char *const *argv, const char *buff)
1381{
1382  if (argc == 2) {
1383    owl_function_loadsubs(argv[1]);
1384  } else if (argc == 1) {
1385    owl_function_loadsubs(NULL);
1386  } else {
1387    owl_function_makemsg("Wrong number of arguments for load-subs.");
1388    return(NULL);
1389  }
1390  return(NULL);
1391}
1392
1393
1394char *owl_command_loadloginsubs(int argc, const char *const *argv, const char *buff)
1395{
1396  if (argc == 2) {
1397    owl_function_loadloginsubs(argv[1]);
1398  } else if (argc == 1) {
1399    owl_function_loadloginsubs(NULL);
1400  } else {
1401    owl_function_makemsg("Wrong number of arguments for load-subs.");
1402    return(NULL);
1403  }
1404  return(NULL);
1405}
1406
1407void owl_command_suspend(void)
1408{
1409  owl_function_suspend();
1410}
1411
1412char *owl_command_start_command(int argc, const char *const *argv, const char *buff)
1413{
1414  buff = skiptokens(buff, 1);
1415  owl_function_start_command(buff);
1416  return(NULL);
1417}
1418
1419char *owl_command_zaway(int argc, const char *const *argv, const char *buff)
1420{
1421  if ((argc==1) ||
1422      ((argc==2) && !strcmp(argv[1], "on"))) {
1423    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1424    owl_function_zaway_on();
1425    return NULL;
1426  }
1427
1428  if (argc==2 && !strcmp(argv[1], "off")) {
1429    owl_function_zaway_off();
1430    return NULL;
1431  }
1432
1433  if (argc==2 && !strcmp(argv[1], "toggle")) {
1434    owl_function_zaway_toggle();
1435    return NULL;
1436  }
1437
1438  buff = skiptokens(buff, 1);
1439  owl_global_set_zaway_msg(&g, buff);
1440  owl_function_zaway_on();
1441  return NULL;
1442}
1443
1444
1445char *owl_command_aaway(int argc, const char *const *argv, const char *buff)
1446{
1447  if ((argc==1) ||
1448      ((argc==2) && !strcmp(argv[1], "on"))) {
1449    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1450    owl_function_aaway_on();
1451    return NULL;
1452  }
1453
1454  if (argc==2 && !strcmp(argv[1], "off")) {
1455    owl_function_aaway_off();
1456    return NULL;
1457  }
1458
1459  if (argc==2 && !strcmp(argv[1], "toggle")) {
1460    owl_function_aaway_toggle();
1461    return NULL;
1462  }
1463
1464  buff = skiptokens(buff, 1);
1465  owl_global_set_aaway_msg(&g, buff);
1466  owl_function_aaway_on();
1467  return NULL;
1468}
1469
1470
1471char *owl_command_away(int argc, const char *const *argv, const char *buff)
1472{
1473  if ((argc==1) ||
1474      ((argc==2) && !strcmp(argv[1], "on"))) {
1475    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
1476    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
1477    owl_function_aaway_on();
1478    owl_function_zaway_on();
1479    owl_function_makemsg("Away messages set.");
1480    return NULL;
1481  }
1482
1483  if (argc==2 && !strcmp(argv[1], "off")) {
1484    owl_function_aaway_off();
1485    owl_function_zaway_off();
1486    return NULL;
1487  }
1488
1489  if (argc==2 && !strcmp(argv[1], "toggle")) {
1490    /* if either one is on, turn it off, otherwise toggle both (turn
1491     *  them both on)
1492     */
1493    if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
1494      owl_function_aaway_toggle();
1495      owl_function_zaway_toggle();
1496      owl_function_makemsg("Away messages set.");
1497    } else {
1498      if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
1499      if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
1500      owl_function_makemsg("Away messages off.");
1501    }
1502    return NULL;
1503  }
1504
1505  buff = skiptokens(buff, 1);
1506  owl_global_set_aaway_msg(&g, buff);
1507  owl_global_set_zaway_msg(&g, buff);
1508  owl_function_aaway_on();
1509  owl_function_zaway_on();
1510  owl_function_makemsg("Away messages set.");
1511  return NULL;
1512}
1513
1514char *owl_command_set(int argc, const char *const *argv, const char *buff)
1515{
1516  const char *var, *val;
1517  int  silent=0;
1518  int requirebool=0;
1519
1520  if (argc == 1) {
1521    owl_function_printallvars();
1522    return NULL;
1523  } 
1524
1525  if (argc > 1 && !strcmp("-q",argv[1])) {
1526    silent = 1;
1527    argc--; argv++;
1528  }
1529
1530  if (argc == 2) {
1531    var=argv[1];
1532    val="on";
1533    requirebool=1;
1534  } else if (argc == 3) {
1535    var=argv[1];
1536    val=argv[2];
1537  } else {
1538    owl_function_makemsg("Wrong number of arguments for set command");
1539    return NULL;
1540  }
1541  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, requirebool);
1542  return NULL;
1543}
1544
1545char *owl_command_unset(int argc, const char *const *argv, const char *buff)
1546{
1547  const char *var, *val;
1548  int  silent=0;
1549
1550  if (argc > 1 && !strcmp("-q",argv[1])) {
1551    silent = 1;
1552    argc--; argv++;
1553  }
1554  if (argc == 2) {
1555    var=argv[1];
1556    val="off";
1557  } else {
1558    owl_function_makemsg("Wrong number of arguments for unset command");
1559    return NULL;
1560  }
1561  owl_variable_set_fromstring(owl_global_get_vardict(&g), var, val, !silent, 1);
1562  return NULL;
1563}
1564
1565char *owl_command_print(int argc, const char *const *argv, const char *buff)
1566{
1567  const char *var;
1568  char valbuff[1024];
1569
1570  if (argc==1) {
1571    owl_function_printallvars();
1572    return NULL;
1573  } else if (argc!=2) {
1574    owl_function_makemsg("Wrong number of arguments for print command");
1575    return NULL;
1576  }
1577
1578  var=argv[1];
1579   
1580  if (0 == owl_variable_get_tostring(owl_global_get_vardict(&g), 
1581                                     var, valbuff, 1024)) {
1582    owl_function_makemsg("%s = '%s'", var, valbuff);
1583  } else {
1584    owl_function_makemsg("Unknown variable '%s'.", var);
1585  }
1586  return NULL;
1587}
1588
1589
1590char *owl_command_exec(int argc, const char *const *argv, const char *buff)
1591{
1592  return owl_function_exec(argc, argv, buff, 0);
1593}
1594
1595char *owl_command_pexec(int argc, const char *const *argv, const char *buff)
1596{
1597  return owl_function_exec(argc, argv, buff, 1);
1598}
1599
1600char *owl_command_aexec(int argc, const char *const *argv, const char *buff)
1601{
1602  return owl_function_exec(argc, argv, buff, 2);
1603}
1604
1605char *owl_command_perl(int argc, const char *const *argv, const char *buff)
1606{
1607  return owl_function_perl(argc, argv, buff, 0);
1608}
1609
1610char *owl_command_pperl(int argc, const char *const *argv, const char *buff)
1611{
1612  return owl_function_perl(argc, argv, buff, 1);
1613}
1614
1615char *owl_command_aperl(int argc, const char *const *argv, const char *buff)
1616{
1617  return owl_function_perl(argc, argv, buff, 2);
1618}
1619
1620char *owl_command_multi(int argc, const char *const *argv, const char *buff)
1621{
1622  char *lastrv = NULL, *newbuff;
1623  char **commands;
1624  int  ncommands, i;
1625  if (argc < 2) {
1626    owl_function_makemsg("Invalid arguments to 'multi' command.");   
1627    return NULL;
1628  }
1629  newbuff = owl_strdup(skiptokens(buff, 1));
1630  if (!strcmp(argv[0], "(")) {
1631    for (i=strlen(newbuff)-1; i>=0; i--) {
1632      if (newbuff[i] == ')') {
1633        newbuff[i] = '\0';
1634        break;
1635      } else if (newbuff[i] != ' ') {
1636        owl_function_makemsg("Invalid arguments to 'multi' command.");   
1637        owl_free(newbuff);
1638        return NULL;
1639      }
1640    }
1641  }
1642  commands = atokenize(newbuff, ";", &ncommands);
1643  for (i=0; i<ncommands; i++) {
1644    if (lastrv) {
1645      owl_free(lastrv);
1646    }
1647    lastrv = owl_function_command(commands[i]);
1648  }
1649  owl_free(newbuff);
1650  atokenize_free(commands, ncommands);
1651  return lastrv;
1652}
1653
1654
1655char *owl_command_alias(int argc, const char *const *argv, const char *buff)
1656{
1657  if (argc < 3) {
1658    owl_function_makemsg("Invalid arguments to 'alias' command.");
1659    return NULL;
1660  }
1661  buff = skiptokens(buff, 2);
1662  owl_function_command_alias(argv[1], buff);
1663  return (NULL);
1664}
1665
1666
1667char *owl_command_bindkey(int argc, const char *const *argv, const char *buff)
1668{
1669  owl_keymap *km;
1670  int ret;
1671
1672  if (argc < 5 || strcmp(argv[3], "command")) {
1673    owl_function_makemsg("Usage: bindkey <keymap> <binding> command <cmd>");
1674    return NULL;
1675  }
1676  km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), argv[1]);
1677  if (!km) {
1678    owl_function_makemsg("No such keymap '%s'", argv[1]);
1679    return NULL;
1680  }
1681  buff = skiptokens(buff, 4);
1682  ret = owl_keymap_create_binding(km, argv[2], buff, NULL, "*user*");
1683  if (ret!=0) {
1684    owl_function_makemsg("Unable to bind '%s' in keymap '%s' to '%s'.",
1685                         argv[2], argv[1], buff);
1686    return NULL;
1687  }
1688  return NULL;
1689}
1690
1691void owl_command_quit(void)
1692{
1693  owl_function_quit();
1694}
1695
1696char *owl_command_debug(int argc, const char *const *argv, const char *buff)
1697{
1698  if (argc<2) {
1699    owl_function_makemsg("Need at least one argument to debug command");
1700    return(NULL);
1701  }
1702
1703  if (!owl_global_is_debug_fast(&g)) {
1704    owl_function_makemsg("Debugging is not turned on");
1705    return(NULL);
1706  }
1707
1708  owl_function_debugmsg("%s", argv[1]);
1709  return(NULL);
1710}
1711
1712char *owl_command_term(int argc, const char *const *argv, const char *buff)
1713{
1714  if (argc<2) {
1715    owl_function_makemsg("Need at least one argument to the term command");
1716    return(NULL);
1717  }
1718
1719  if (!strcmp(argv[1], "raise")) {
1720    owl_function_xterm_raise();
1721  } else if (!strcmp(argv[1], "deiconify")) {
1722    owl_function_xterm_deiconify();
1723  } else {
1724    owl_function_makemsg("Unknown terminal subcommand");
1725  }
1726  return(NULL);
1727}
1728
1729char *owl_command_zlog(int argc, const char *const *argv, const char *buff)
1730{
1731  if ((argc<2) || (argc>3)) {
1732    owl_function_makemsg("Wrong number of arguments for zlog command");
1733    return(NULL);
1734  }
1735
1736  if (!strcmp(argv[1], "in")) {
1737    if (argc>2) {
1738      owl_global_set_tty(&g, argv[2]);
1739    }
1740    owl_zephyr_zlog_in();
1741  } else if (!strcmp(argv[1], "out")) {
1742    if (argc!=2) {
1743      owl_function_makemsg("Wrong number of arguments for zlog command");
1744      return(NULL);
1745    }
1746    owl_zephyr_zlog_out();
1747  } else {
1748    owl_function_makemsg("Invalid subcommand for zlog");
1749  }
1750  return(NULL);
1751}
1752
1753char *owl_command_subscribe(int argc, const char *const *argv, const char *buff)
1754{
1755  const char *class, *instance, *recip="";
1756  int temp=0;
1757  int ret=0;
1758
1759  if (argc < 2) {
1760    owl_function_makemsg("Not enough arguments to the subscribe command");
1761    return(NULL);
1762  }
1763  argc--;
1764  argv++;
1765
1766  if (!strcmp(argv[0], "-t")) {
1767    temp=1;
1768    argc--;
1769    argv++;
1770  }
1771  if (argc < 1) {
1772    owl_function_makemsg("Not enough arguments to the subscribe command");
1773    return(NULL);
1774  }
1775
1776  if (argc > 3) {
1777    owl_function_makemsg("Too many arguments to the subscribe command");
1778    return(NULL);
1779  }
1780
1781  class = argv[0];
1782
1783  if (argc == 1) {
1784    instance = "*";
1785  } else {
1786    instance = argv[1];
1787  }
1788
1789  if (argc <= 2) {
1790    recip="";
1791  } else if (argc==3) {
1792    recip=argv[2];
1793  }
1794
1795  ret = owl_function_subscribe(class, instance, recip);
1796  if (!temp && !ret) {
1797    owl_zephyr_addsub(NULL, class, instance, recip);
1798  }
1799  return(NULL);
1800}
1801
1802
1803char *owl_command_unsubscribe(int argc, const char *const *argv, const char *buff)
1804{
1805  const char *class, *instance, *recip="";
1806  int temp=0;
1807
1808  if (argc < 2) {
1809    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1810    return(NULL);
1811  }
1812  argc--;
1813  argv++;
1814
1815  if (!strcmp(argv[0], "-t")) {
1816    temp=1;
1817    argc--;
1818    argv++;
1819  }
1820  if (argc < 1) {
1821    owl_function_makemsg("Not enough arguments to the unsubscribe command");
1822    return(NULL);
1823  }
1824
1825  if (argc > 3) {
1826    owl_function_makemsg("Too many arguments to the unsubscribe command");
1827    return(NULL);
1828  }
1829
1830  class = argv[0];
1831
1832  if (argc == 1) {
1833    instance = "*";
1834  } else {
1835    instance = argv[1];
1836  }
1837
1838  if (argc <= 2) {
1839    recip="";
1840  } else if (argc==3) {
1841    recip=argv[2];
1842  }
1843
1844  owl_function_unsubscribe(class, instance, recip);
1845  if (!temp) {
1846    owl_zephyr_delsub(NULL, class, instance, recip);
1847  }
1848  return(NULL);
1849}
1850
1851char *owl_command_echo(int argc, const char *const *argv, const char *buff)
1852{
1853  buff = skiptokens(buff, 1);
1854  owl_function_popless_text(buff);
1855  return NULL;
1856}
1857
1858void owl_command_getsubs(void)
1859{
1860  owl_function_getsubs();
1861}
1862
1863void owl_command_status(void)
1864{
1865  owl_function_status();
1866}
1867
1868char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
1869{
1870  owl_zwrite z;
1871
1872  if (!owl_global_is_havezephyr(&g)) {
1873    owl_function_makemsg("Zephyr is not available");
1874    return(NULL);
1875  }
1876  /* check for a zwrite -m */
1877  owl_zwrite_create_from_line(&z, buff);
1878  if (owl_zwrite_is_message_set(&z)) {
1879    owl_function_zwrite(buff, NULL);
1880    owl_zwrite_free(&z);
1881    return (NULL);
1882  }
1883
1884  if (argc < 2) {
1885    owl_function_makemsg("Not enough arguments to the zwrite command.");
1886  } else {
1887    owl_function_zwrite_setup(buff);
1888  }
1889  return(NULL);
1890}
1891
1892char *owl_command_aimwrite(int argc, const char *const *argv, const char *buff)
1893{
1894  char *newbuff, *recip;
1895  const char *const *myargv;
1896  int i, j, myargc;
1897  owl_message *m;
1898 
1899  if (!owl_global_is_aimloggedin(&g)) {
1900    owl_function_makemsg("You are not logged in to AIM.");
1901    return(NULL);
1902  }
1903
1904  if (argc < 2) {
1905    owl_function_makemsg("Not enough arguments to the aimwrite command.");
1906    return(NULL);
1907  }
1908
1909  myargv=argv;
1910  if (argc<0) {
1911    owl_function_error("Unbalanced quotes in aimwrite");
1912    return(NULL);
1913  }
1914  myargc=argc;
1915  if (myargc && *(myargv[0])!='-') {
1916    myargc--;
1917    myargv++;
1918  }
1919  while (myargc) {
1920    if (!strcmp(myargv[0], "-m")) {
1921      if (myargc<2) {
1922        break;
1923      }
1924
1925      /* Once we have -m, gobble up everything else on the line */
1926      myargv++;
1927      myargc--;
1928      newbuff=owl_strdup("");
1929      while (myargc) {
1930        newbuff=owl_realloc(newbuff, strlen(newbuff)+strlen(myargv[0])+5);
1931        strcat(newbuff, myargv[0]);
1932        strcat(newbuff, " ");
1933        myargc--;
1934        myargv++;
1935      }
1936      if (strlen(newbuff) >= 1)
1937        newbuff[strlen(newbuff) - 1] = '\0'; /* remove last space */
1938
1939      recip=owl_malloc(strlen(argv[0])+5);
1940      sprintf(recip, "%s ", argv[1]);
1941      owl_aim_send_im(recip, newbuff);
1942      m=owl_function_make_outgoing_aim(newbuff, recip);
1943      if (m) { 
1944          owl_global_messagequeue_addmsg(&g, m);
1945      } else {
1946          owl_function_error("Could not create outgoing AIM message");
1947      }
1948
1949      owl_free(recip);
1950      owl_free(newbuff);
1951      return(NULL);
1952    } else {
1953      /* we don't care */
1954      myargv++;
1955      myargc--;
1956    }
1957  }
1958
1959  /* squish arguments together to make one screenname w/o spaces for now */
1960  newbuff=owl_malloc(strlen(buff)+5);
1961  sprintf(newbuff, "%s ", argv[0]);
1962  j=argc-1;
1963  for (i=0; i<j; i++) {
1964    strcat(newbuff, argv[i+1]);
1965  }
1966   
1967  owl_function_aimwrite_setup(newbuff);
1968  owl_free(newbuff);
1969  return(NULL);
1970}
1971
1972char *owl_command_loopwrite(int argc, const char *const *argv, const char *buff)
1973{
1974  owl_function_loopwrite_setup();
1975  return(NULL);
1976}
1977
1978char *owl_command_zcrypt(int argc, const char *const *argv, const char *buff)
1979{
1980#ifdef OWL_ENABLE_ZCRYPT
1981  owl_zwrite z;
1982
1983  if (!owl_global_is_havezephyr(&g)) {
1984    owl_function_makemsg("Zephyr is not available");
1985    return(NULL);
1986  }
1987  /* check for a zcrypt -m */
1988  owl_zwrite_create_from_line(&z, buff);
1989  if (owl_zwrite_is_message_set(&z)) {
1990    owl_function_zcrypt(buff, NULL);
1991    owl_zwrite_free(&z);
1992    return (NULL);
1993  }
1994
1995  if (argc < 2) {
1996    owl_function_makemsg("Not enough arguments to the zcrypt command.");
1997  } else {
1998    owl_function_zwrite_setup(buff);
1999  }
2000  return(NULL);
2001#else
2002  owl_function_makemsg("This Owl does not support zcrypt");
2003  return NULL;
2004#endif
2005}
2006
2007char *owl_command_reply(int argc, const char *const *argv, const char *buff)
2008{
2009  int edit=0;
2010 
2011  if (argc>=2 && !strcmp("-e", argv[1])) {
2012    edit=1;
2013    argv++;
2014    argc--;
2015  }
2016
2017  if ((argc==1) || (argc==2 && !strcmp(argv[1], "all"))) {   
2018    owl_function_reply(0, !edit);
2019  } else if (argc==2 && !strcmp(argv[1], "sender")) {
2020    owl_function_reply(1, !edit);
2021  } else if (argc==2 && !strcmp(argv[1], "zaway")) {
2022    const owl_message *m;
2023    const owl_view    *v;
2024    v = owl_global_get_current_view(&g);   
2025    m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2026    if (m) owl_zephyr_zaway(m);
2027  } else {
2028    owl_function_makemsg("Invalid arguments to the reply command.");
2029  }
2030  return NULL;
2031}
2032
2033char *owl_command_filter(int argc, const char *const *argv, const char *buff)
2034{
2035  owl_function_create_filter(argc, argv);
2036  return NULL;
2037}
2038
2039char *owl_command_zlocate(int argc, const char *const *argv, const char *buff)
2040{
2041  int auth;
2042 
2043  if (argc<2) {
2044    owl_function_makemsg("Too few arguments for zlocate command");
2045    return NULL;
2046  }
2047
2048  auth=1;
2049  if (!strcmp(argv[1], "-d")) {
2050    if (argc>2) {
2051      auth=0;
2052      argc--;
2053      argv++;
2054    } else {
2055      owl_function_makemsg("Missing arguments for zlocate command");
2056      return NULL;
2057    }
2058  }
2059
2060  argc--;
2061  argv++;
2062  owl_function_zlocate(argc, argv, auth);
2063  return NULL;
2064}
2065
2066
2067/* Backwards compatability has made this kind of complicated:
2068 * view [<viewname>] [-f <filter> | -d <expression> | --home | -r ] [-s <style>]
2069 * view <filter>
2070 * view -d <expression>
2071 * view --home
2072 */
2073char *owl_command_view(int argc, const char *const *argv, const char *buff)
2074{
2075  /* First take the 'view --home' and 'view -r' cases */
2076  if (argc == 2) {
2077    if (!strcmp(argv[1], "--home")) {
2078      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2079      return(NULL);
2080    } else if (!strcmp(argv[1], "-r")) {
2081      char *foo;
2082      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2083      owl_function_change_currentview_filter(foo);
2084      owl_free(foo);
2085      return(NULL);
2086    }
2087  }
2088
2089  /* Now look for 'view <filter>' */
2090  if (argc==2) {
2091    owl_function_change_currentview_filter(argv[1]);
2092    return(NULL);
2093  }
2094
2095  /* Now get 'view -d <expression>' */
2096  if (argc>=3 && !strcmp(argv[1], "-d")) {
2097    const char **myargv;
2098    int i;
2099
2100    myargv=owl_malloc((argc*sizeof(const char *))+50);
2101    myargv[0]="";
2102    myargv[1]="owl-dynamic";
2103    for (i=2; i<argc; i++) {
2104      myargv[i]=argv[i];
2105    }
2106    owl_function_create_filter(argc, myargv);
2107    owl_function_change_currentview_filter("owl-dynamic");
2108    owl_free(myargv);
2109    return NULL;
2110  }
2111
2112  /* Finally handle the general case */
2113  if (argc<3) {
2114    owl_function_makemsg("Too few arguments to the view command.");
2115    return(NULL);
2116  }
2117  argc--;
2118  argv++;
2119  if (strcmp(argv[0], "-f") &&
2120      strcmp(argv[0], "-d") &&
2121      strcmp(argv[0], "--home") &&
2122      strcmp(argv[0], "-s") &&
2123      strcmp(argv[0], "-r")) {
2124    if (strcmp(argv[0], "main")) {
2125      owl_function_makemsg("No view named '%s'", argv[0]);
2126      return(NULL);
2127    }
2128    argc--;
2129    argv++;
2130  }
2131  while (argc) {
2132    if (!strcmp(argv[0], "-f")) {
2133      if (argc<2) {
2134        owl_function_makemsg("Too few argments to the view command");
2135        return(NULL);
2136      }
2137      owl_function_change_currentview_filter(argv[1]);
2138      argc-=2;
2139      argv+=2;
2140    } else if (!strcmp(argv[0], "--home")) {
2141      owl_function_change_currentview_filter(owl_global_get_view_home(&g));
2142      argc--;
2143      argv++;
2144    } else if (!strcmp(argv[0], "-r")) {
2145      const char *foo;
2146      foo=owl_function_create_negative_filter(owl_view_get_filtname(owl_global_get_current_view(&g)));
2147      owl_function_change_currentview_filter(foo);
2148    } else if (!strcmp(argv[0], "-s")) {
2149      if (argc<2) {
2150        owl_function_makemsg("Too few argments to the view command");
2151        return(NULL);
2152      }
2153      owl_function_change_style(owl_global_get_current_view(&g), argv[1]);
2154      argc-=2;
2155      argv+=2;
2156    } else {
2157      owl_function_makemsg("Too few argments to the view command");
2158      return(NULL);
2159    }
2160   
2161  }
2162  return(NULL);
2163}
2164
2165char *owl_command_show(int argc, const char *const *argv, const char *buff)
2166{
2167  if (argc<2) {
2168    owl_function_help_for_command("show");
2169    return NULL;
2170  }
2171
2172  if (!strcmp(argv[1], "filter") || !strcmp(argv[1], "filters")) {
2173    if (argc==2) {
2174      owl_function_show_filters();
2175    } else {
2176      owl_function_show_filter(argv[2]);
2177    }
2178  } else if (argc==2 
2179             && (!strcmp(argv[1], "zpunts") || !strcmp(argv[1], "zpunted"))) {
2180    owl_function_show_zpunts();
2181  } else if (!strcmp(argv[1], "command") || !strcmp(argv[1], "commands")) {
2182    if (argc==2) {
2183      owl_function_show_commands();
2184    } else {
2185      owl_function_show_command(argv[2]);
2186    }
2187  } else if (!strcmp(argv[1], "variable") || !strcmp(argv[1], "variables")) {
2188    if (argc==2) {
2189      owl_function_show_variables();
2190    } else {
2191      owl_function_show_variable(argv[2]);
2192    }
2193  } else if (!strcmp(argv[1], "keymap") || !strcmp(argv[1], "keymaps")) {
2194    if (argc==2) {
2195      owl_function_show_keymaps();
2196    } else {
2197      owl_function_show_keymap(argv[2]);
2198    }
2199  } else if (!strcmp(argv[1], "view")) {
2200    if (argc==3) {
2201      owl_function_show_view(argv[2]);
2202    } else {
2203      owl_function_show_view(NULL);
2204    }
2205  } else if (!strcmp(argv[1], "colors")) {
2206    owl_function_show_colors();
2207  } else if (!strcmp(argv[1], "styles")) {
2208    owl_function_show_styles();
2209  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
2210    owl_function_getsubs();
2211  } else if (!strcmp(argv[1], "terminal") || !strcmp(argv[1], "term")) {
2212    owl_function_show_term();
2213  } else if (!strcmp(argv[1], "version")) {
2214    owl_function_about();
2215  } else if (!strcmp(argv[1], "status")) {
2216    owl_function_status();
2217  } else if (!strcmp(argv[1], "license")) {
2218    owl_function_show_license();
2219  } else if (!strcmp(argv[1], "quickstart")) {
2220    owl_function_show_quickstart();
2221  } else if (!strcmp(argv[1], "startup")) {
2222    const char *filename;
2223   
2224    filename=owl_global_get_startupfile(&g);
2225    owl_function_popless_file(filename);
2226  } else if (!strcmp(argv[1], "errors")) {
2227    owl_function_showerrs();
2228  } else {
2229    owl_function_makemsg("Unknown subcommand for 'show' command (see 'help show' for allowed args)");
2230    return NULL;
2231  }
2232  return NULL;
2233}
2234
2235char *owl_command_viewclass(int argc, const char *const *argv, const char *buff)
2236{
2237  char *filtname;
2238  if (argc!=2) {
2239    owl_function_makemsg("Wrong number of arguments to viewclass command");
2240    return NULL;
2241  }
2242  filtname = owl_function_classinstfilt(argv[1], NULL);
2243  owl_function_change_currentview_filter(filtname);
2244  owl_free(filtname);
2245  return NULL;
2246}
2247
2248char *owl_command_viewuser(int argc, const char *const *argv, const char *buff)
2249{
2250  char *filtname;
2251  if (argc!=2) {
2252    owl_function_makemsg("Wrong number of arguments to viewuser command");
2253    return NULL;
2254  }
2255  filtname=owl_function_zuserfilt(argv[1]);
2256  owl_function_change_currentview_filter(filtname);
2257  owl_free(filtname);
2258  return NULL;
2259}
2260
2261
2262void owl_command_pop_message(void)
2263{
2264  owl_function_curmsg_to_popwin();
2265}
2266
2267char *owl_command_delete(int argc, const char *const *argv, const char *buff)
2268{
2269  int move_after = 1;
2270
2271  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2272    move_after = 0;
2273    argc--; 
2274    argv++;
2275  }
2276
2277  if (argc==1) {
2278    owl_function_deletecur(move_after);
2279    return NULL;
2280  }
2281
2282  if (argc==2 && !strcmp(argv[1], "view")) {
2283    owl_function_delete_curview_msgs(1);
2284    return NULL;
2285  }
2286
2287  if (argc==2 && !strcmp(argv[1], "trash")) {
2288    owl_function_delete_automsgs();
2289    return NULL;
2290  }
2291
2292  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2293    owl_function_delete_by_id(atoi(argv[2]), 1);
2294    return NULL;
2295  }
2296
2297  owl_function_makemsg("Unknown arguments to delete command");
2298  return NULL;
2299}
2300
2301char *owl_command_undelete(int argc, const char *const *argv, const char *buff)
2302{
2303  int move_after = 1;
2304
2305  if (argc>1 && !strcmp(argv[1], "--no-move")) {
2306    move_after = 0;
2307    argc--; 
2308    argv++;
2309  }
2310
2311  if (argc==1) {
2312    owl_function_undeletecur(move_after);
2313    return NULL;
2314  }
2315
2316  if (argc==2 && !strcmp(argv[1], "view")) {
2317    owl_function_delete_curview_msgs(0);
2318    return NULL;
2319  }
2320
2321  if (argc==3 && (!strcmp(argv[1], "-id") || !strcmp(argv[1], "--id"))) {
2322    owl_function_delete_by_id(atoi(argv[2]), 0);
2323    return NULL;
2324  }
2325
2326  owl_function_makemsg("Unknown arguments to delete command");
2327  return NULL;
2328}
2329
2330void owl_command_beep(void)
2331{
2332  owl_function_beep();
2333}
2334
2335char *owl_command_colorview(int argc, const char *const *argv, const char *buff)
2336{
2337  if (argc < 2 || argc > 3) {
2338    owl_function_makemsg("Wrong number of arguments to colorview command");
2339    return NULL;
2340  }
2341  owl_function_color_current_filter(argv[1], (argc == 3 ? argv[2] : NULL));
2342  return NULL;
2343}
2344
2345char *owl_command_colorclass(int argc, const char *const *argv, const char *buff)
2346{
2347  const char *filtname;
2348 
2349  if (argc < 3 || argc > 4) {
2350    owl_function_makemsg("Wrong number of arguments to colorclass command");
2351    return NULL;
2352  }
2353
2354  filtname=owl_function_classinstfilt(argv[1], NULL);
2355  (void) owl_function_color_filter(filtname, argv[2], (argc == 4 ? argv[3] : NULL));
2356  return NULL;
2357}
2358
2359char *owl_command_zpunt(int argc, const char *const *argv, const char *buff)
2360{
2361  owl_command_zpunt_and_zunpunt(argc, argv, 0);
2362  return NULL;
2363}
2364
2365char *owl_command_zunpunt(int argc, const char *const *argv, const char *buff)
2366{
2367  owl_command_zpunt_and_zunpunt(argc, argv, 1);
2368  return NULL;
2369}
2370
2371void owl_command_zpunt_and_zunpunt(int argc, const char *const *argv, int type)
2372{
2373  /* if type==0 then zpunt
2374   * if type==1 then zunpunt
2375   */
2376  const char *class, *inst, *recip;
2377
2378  class="message";
2379  inst="";
2380  recip="*";
2381
2382  if (argc==1) {
2383    /* show current punt filters */
2384    owl_function_show_zpunts();
2385    return;
2386  } else if (argc==2) {
2387    inst=argv[1];
2388  } else if (argc==3) {
2389    class=argv[1];
2390    inst=argv[2];
2391  } else if (argc==4) {
2392    class=argv[1];
2393    inst=argv[2];
2394    recip=argv[3];
2395  } else {
2396    owl_function_makemsg("Wrong number of arguments to the zpunt command");
2397    return;
2398  }
2399
2400  owl_function_zpunt(class, inst, recip, type);
2401  if (type==0) {
2402    owl_function_makemsg("<%s, %s, %s> added to punt list.", class, inst, recip);
2403  } else if (type==1) {
2404    owl_function_makemsg("<%s, %s, %s> removed from punt list.", class, inst, recip);
2405  }
2406}
2407
2408char *owl_command_smartzpunt(int argc, const char *const *argv, const char *buff)
2409{
2410  if (argc == 1) {
2411    owl_function_smartzpunt(0);
2412  } else if (argc == 2 && (!strcmp(argv[1], "-i") || !strcmp(argv[1], "--instance"))) {
2413    owl_function_smartzpunt(1);
2414  } else {
2415    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);   
2416  }
2417  return NULL;
2418}
2419
2420char *owl_command_punt(int argc, const char *const *argv, const char *buff)
2421{
2422  owl_command_punt_unpunt(argc, argv, buff, 0);
2423  return NULL;
2424}
2425
2426char *owl_command_unpunt(int argc, const char *const *argv, const char *buff)
2427{
2428  owl_command_punt_unpunt(argc, argv, buff, 1);
2429  return NULL;
2430}
2431
2432void owl_command_punt_unpunt(int argc, const char *const * argv, const char *buff, int unpunt)
2433{
2434  owl_list * fl;
2435  owl_filter * f;
2436  char * text;
2437  int i;
2438
2439  fl = owl_global_get_puntlist(&g);
2440  if(argc == 1) {
2441    owl_function_show_zpunts();
2442  }
2443
2444  if(argc == 2) {
2445    /* Handle :unpunt <number> */
2446    if(unpunt && (i=atoi(argv[1])) !=0) {
2447      i--;      /* Accept 1-based indexing */
2448      if(i < owl_list_get_size(fl)) {
2449        f = owl_list_get_element(fl, i);
2450        owl_list_remove_element(fl, i);
2451        owl_filter_delete(f);
2452        return;
2453      } else {
2454        owl_function_error("No such filter number: %d", i+1);
2455      }
2456    }
2457    text = owl_sprintf("filter %s", argv[1]);
2458    owl_function_punt(text, unpunt);
2459    owl_free(text);
2460  } else {
2461    owl_function_punt(skiptokens(buff, 1), unpunt);
2462  }
2463}
2464
2465
2466char *owl_command_getview(int argc, const char *const *argv, const char *buff)
2467{
2468  const char *filtname;
2469  if (argc != 1) {
2470    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2471    return NULL;
2472  }
2473  filtname = owl_view_get_filtname(owl_global_get_current_view(&g));
2474  if (filtname) return owl_strdup(filtname);
2475  return NULL;
2476}
2477
2478char *owl_command_getvar(int argc, const char *const *argv, const char *buff)
2479{
2480  char tmpbuff[1024];
2481  if (argc != 2) {
2482    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2483    return NULL;
2484  }
2485  if (owl_variable_get_tostring(owl_global_get_vardict(&g), 
2486                                argv[1], tmpbuff, 1024)) {
2487    return NULL;
2488  }
2489  return owl_strdup(tmpbuff); 
2490}
2491
2492char *owl_command_getfilter(int argc, const char *const *argv, const char *buf)
2493{
2494  const owl_filter *f;
2495  if (argc != 2) {
2496    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2497    return NULL;
2498  }
2499  f = owl_global_get_filter(&g, argv[1]);
2500  if (!f) {
2501    return NULL;
2502  }
2503  return owl_filter_print(f);
2504}
2505
2506char *owl_command_search(int argc, const char *const *argv, const char *buff)
2507{
2508  int direction;
2509  const char *buffstart;
2510
2511  direction=OWL_DIRECTION_DOWNWARDS;
2512  buffstart=skiptokens(buff, 1);
2513  if (argc>1 && !strcmp(argv[1], "-r")) {
2514    direction=OWL_DIRECTION_UPWARDS;
2515    buffstart=skiptokens(buff, 2);
2516  }
2517   
2518  if (argc==1 || (argc==2 && !strcmp(argv[1], "-r"))) {
2519    owl_function_search_continue(direction);
2520  } else {
2521    owl_function_search_start(buffstart, direction);
2522  }
2523 
2524  return(NULL);
2525}
2526
2527char *owl_command_setsearch(int argc, const char *const *argv, const char *buff)
2528{
2529  const char *buffstart;
2530
2531  buffstart=skiptokens(buff, 1);
2532  owl_function_search_start(*buffstart ? buffstart : NULL, OWL_DIRECTION_NONE);
2533 
2534  return(NULL);
2535}
2536
2537char *owl_command_aimlogin(int argc, const char *const *argv, const char *buff)
2538{
2539  if ((argc<2) || (argc>3)) {
2540    owl_function_makemsg("Wrong number of arguments to aimlogin command");
2541    return(NULL);
2542  }
2543
2544  /* if we get two arguments, ask for the password */
2545  if (argc==2) {
2546    owl_global_set_buffercommand(&g, argv[1]);
2547    owl_global_set_buffercallback(&g, &owl_callback_aimlogin);
2548    owl_function_start_password("AIM Password: ");
2549    return(NULL);
2550  } else {
2551    owl_function_aimlogin(argv[1], argv[2]);
2552  }
2553
2554  /* this is a test */
2555  return(NULL);
2556}
2557
2558char *owl_command_aimlogout(int argc, const char *const *argv, const char *buff)
2559{
2560  /* clear the buddylist */
2561  owl_buddylist_clear(owl_global_get_buddylist(&g));
2562
2563  owl_aim_logout();
2564  return(NULL);
2565}
2566
2567char *owl_command_getstyle(int argc, const char *const *argv, const char *buff)
2568{
2569  const char *stylename;
2570  if (argc != 1) {
2571    owl_function_makemsg("Wrong number of arguments for %s", argv[0]);
2572    return NULL;
2573  }
2574  stylename = owl_view_get_style_name(owl_global_get_current_view(&g));
2575  if (stylename) return owl_strdup(stylename);
2576  return NULL;
2577}
2578
2579char *owl_command_error(int argc, const char *const *argv, const char *buff)
2580{
2581    buff = skiptokens(buff, 1);
2582    owl_function_error("%s", buff);
2583    return NULL;
2584}
2585
2586char *owl_command_message(int argc, const char *const *argv, const char *buff)
2587{
2588    buff = skiptokens(buff, 1);
2589    owl_function_makemsg("%s", buff);
2590    return NULL;
2591}
2592
2593void owl_command_yes(void)
2594{
2595  owl_message *m;
2596  const owl_view *v;
2597  const char *cmd;
2598
2599  v = owl_global_get_current_view(&g);
2600
2601  /* bail if there's no current message */
2602  if (owl_view_get_size(v) < 1) {
2603    owl_function_error("No current message.");
2604    return;
2605  }
2606
2607  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2608  if(!owl_message_is_question(m)) {
2609    owl_function_error("That message isn't a question.");
2610    return;
2611  }
2612  if(owl_message_is_answered(m)) {
2613    owl_function_error("You already answered that question.");
2614    return;
2615  }
2616  cmd = owl_message_get_attribute_value(m, "yescommand");
2617  if(!cmd) {
2618    owl_function_error("No 'yes' command!");
2619    return;
2620  }
2621
2622  owl_function_command_norv(cmd);
2623  owl_message_set_isanswered(m);
2624  return;
2625}
2626
2627void owl_command_no(void)
2628{
2629  owl_message *m;
2630  const owl_view *v;
2631  const char *cmd;
2632
2633  v = owl_global_get_current_view(&g);
2634
2635  /* bail if there's no current message */
2636  if (owl_view_get_size(v) < 1) {
2637    owl_function_error("No current message.");
2638    return;
2639  }
2640
2641  m = owl_view_get_element(v, owl_global_get_curmsg(&g));
2642  if(!owl_message_is_question(m)) {
2643    owl_function_error("That message isn't a question.");
2644    return;
2645  }
2646  if(owl_message_is_answered(m)) {
2647    owl_function_error("You already answered that question.");
2648    return;
2649  }
2650  cmd = owl_message_get_attribute_value(m, "nocommand");
2651  if(!cmd) {
2652    owl_function_error("No 'no' command!");
2653    return;
2654  }
2655
2656  owl_function_command_norv(cmd);
2657  owl_message_set_isanswered(m);
2658  return;
2659}
2660
2661/*********************************************************************/
2662/************************** EDIT SPECIFIC ****************************/
2663/*********************************************************************/
2664
2665void owl_command_edit_cancel(owl_editwin *e)
2666{
2667  owl_history *hist;
2668
2669  owl_function_makemsg("Command cancelled.");
2670
2671  if(owl_editwin_get_echochar(e) == 0) {
2672    hist=owl_editwin_get_history(e);
2673    owl_history_store(hist, owl_editwin_get_text(e));
2674    owl_history_reset(hist);
2675  }
2676
2677  owl_editwin_fullclear(e);
2678  owl_global_set_needrefresh(&g);
2679  wnoutrefresh(owl_editwin_get_curswin(e));
2680  owl_global_set_typwin_inactive(&g);
2681  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2682
2683  owl_function_activate_keymap("recv");
2684}
2685
2686void owl_command_edit_history_prev(owl_editwin *e)
2687{
2688  owl_history *hist;
2689  const char *ptr;
2690
2691  hist=owl_editwin_get_history(e);
2692  if (!owl_history_is_touched(hist)) {
2693    owl_history_store(hist, owl_editwin_get_text(e));
2694    owl_history_set_partial(hist);
2695  }
2696  ptr=owl_history_get_prev(hist);
2697  if (ptr) {
2698    owl_editwin_clear(e);
2699    owl_editwin_insert_string(e, ptr);
2700    owl_editwin_redisplay(e, 0);
2701    owl_global_set_needrefresh(&g);
2702  } else {
2703    owl_function_beep();
2704  }
2705}
2706
2707void owl_command_edit_history_next(owl_editwin *e)
2708{
2709  owl_history *hist;
2710  const char *ptr;
2711
2712  hist=owl_editwin_get_history(e);
2713  ptr=owl_history_get_next(hist);
2714  if (ptr) {
2715    owl_editwin_clear(e);
2716    owl_editwin_insert_string(e, ptr);
2717    owl_editwin_redisplay(e, 0);
2718    owl_global_set_needrefresh(&g);
2719  } else {
2720    owl_function_beep();
2721  }
2722}
2723
2724char *owl_command_edit_insert_text(owl_editwin *e, int argc, const char *const *argv, const char *buff)
2725{
2726  buff = skiptokens(buff, 1);
2727  owl_editwin_insert_string(e, buff);
2728  owl_editwin_redisplay(e, 0);
2729  owl_global_set_needrefresh(&g); 
2730  return NULL;
2731}
2732
2733void owl_command_editline_done(owl_editwin *e)
2734{
2735  owl_history *hist=owl_editwin_get_history(e);
2736  char *rv, *cmd;
2737
2738  owl_history_store(hist, owl_editwin_get_text(e));
2739  owl_history_reset(hist);
2740  owl_global_set_typwin_inactive(&g);
2741  cmd = owl_strdup(owl_editwin_get_text(e));
2742  owl_editwin_fullclear(e);
2743  rv = owl_function_command(cmd);
2744  owl_free(cmd);
2745
2746  wnoutrefresh(owl_editwin_get_curswin(e));
2747  owl_global_set_needrefresh(&g);
2748
2749  if (rv) {
2750    owl_function_makemsg("%s", rv);
2751    owl_free(rv);
2752  }
2753}
2754
2755
2756void owl_command_editresponse_done(owl_editwin *e)
2757{
2758  owl_function_run_buffercommand();
2759
2760  owl_global_set_typwin_inactive(&g);
2761  owl_editwin_fullclear(e);
2762  wnoutrefresh(owl_editwin_get_curswin(e));
2763  owl_global_set_needrefresh(&g);
2764}
2765
2766
2767void owl_command_edit_done(owl_editwin *e)
2768{
2769  owl_history *hist=owl_editwin_get_history(e);
2770
2771  owl_history_store(hist, owl_editwin_get_text(e));
2772  owl_history_reset(hist);
2773
2774  owl_function_run_buffercommand();
2775  owl_editwin_new_style(e, OWL_EDITWIN_STYLE_ONELINE, NULL);
2776  owl_editwin_fullclear(e);
2777  owl_global_set_typwin_inactive(&g);
2778  owl_global_set_needrefresh(&g);
2779  wnoutrefresh(owl_editwin_get_curswin(e));
2780}
2781
2782void owl_command_edit_done_or_delete(owl_editwin *e)
2783{
2784  if (owl_editwin_is_at_end(e)) {
2785    owl_command_edit_done(e);
2786  } else {
2787    owl_editwin_delete_char(e);
2788  }
2789}
2790
2791
2792/*********************************************************************/
2793/*********************** POPLESS SPECIFIC ****************************/
2794/*********************************************************************/
2795
2796void owl_command_popless_quit(owl_viewwin *vw)
2797{
2798  owl_popwin_close(owl_global_get_popwin(&g));
2799  owl_viewwin_free(vw);
2800  owl_global_set_needrefresh(&g);
2801}
Note: See TracBrowser for help on using the repository browser.