1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <unistd.h> |
---|
4 | #include <signal.h> |
---|
5 | #include <netinet/in.h> |
---|
6 | #include <string.h> |
---|
7 | #include <time.h> |
---|
8 | #include <sys/types.h> |
---|
9 | #include <sys/stat.h> |
---|
10 | #include <sys/wait.h> |
---|
11 | #include <errno.h> |
---|
12 | #include <signal.h> |
---|
13 | #include "owl.h" |
---|
14 | #include "filterproc.h" |
---|
15 | |
---|
16 | char *owl_function_command(const char *cmdbuff) |
---|
17 | { |
---|
18 | owl_function_debugmsg("executing command: %s", cmdbuff); |
---|
19 | return owl_cmddict_execute(owl_global_get_cmddict(&g), |
---|
20 | owl_global_get_context(&g), cmdbuff); |
---|
21 | } |
---|
22 | |
---|
23 | char *owl_function_command_argv(const char *const *argv, int argc) |
---|
24 | { |
---|
25 | return owl_cmddict_execute_argv(owl_global_get_cmddict(&g), |
---|
26 | owl_global_get_context(&g), |
---|
27 | argv, argc); |
---|
28 | } |
---|
29 | |
---|
30 | void owl_function_command_norv(const char *cmdbuff) |
---|
31 | { |
---|
32 | char *rv; |
---|
33 | rv=owl_function_command(cmdbuff); |
---|
34 | if (rv) owl_free(rv); |
---|
35 | } |
---|
36 | |
---|
37 | void owl_function_command_alias(const char *alias_from, const char *alias_to) |
---|
38 | { |
---|
39 | owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to); |
---|
40 | } |
---|
41 | |
---|
42 | const owl_cmd *owl_function_get_cmd(const char *name) |
---|
43 | { |
---|
44 | return owl_cmddict_find(owl_global_get_cmddict(&g), name); |
---|
45 | } |
---|
46 | |
---|
47 | void owl_function_show_commands(void) |
---|
48 | { |
---|
49 | owl_list l; |
---|
50 | owl_fmtext fm; |
---|
51 | |
---|
52 | owl_fmtext_init_null(&fm); |
---|
53 | owl_fmtext_append_bold(&fm, "Commands: "); |
---|
54 | owl_fmtext_append_normal(&fm, "(use 'show command <name>' for details)\n"); |
---|
55 | owl_cmddict_get_names(owl_global_get_cmddict(&g), &l); |
---|
56 | owl_fmtext_append_list(&fm, &l, "\n", owl_function_cmd_describe); |
---|
57 | owl_fmtext_append_normal(&fm, "\n"); |
---|
58 | owl_function_popless_fmtext(&fm); |
---|
59 | owl_cmddict_namelist_cleanup(&l); |
---|
60 | owl_fmtext_cleanup(&fm); |
---|
61 | } |
---|
62 | |
---|
63 | void owl_function_show_view(const char *viewname) |
---|
64 | { |
---|
65 | const owl_view *v; |
---|
66 | owl_fmtext fm; |
---|
67 | |
---|
68 | /* we only have the one view right now */ |
---|
69 | v=owl_global_get_current_view(&g); |
---|
70 | if (viewname && strcmp(viewname, owl_view_get_name(v))) { |
---|
71 | owl_function_error("No view named '%s'", viewname); |
---|
72 | return; |
---|
73 | } |
---|
74 | |
---|
75 | owl_fmtext_init_null(&fm); |
---|
76 | owl_view_to_fmtext(v, &fm); |
---|
77 | owl_function_popless_fmtext(&fm); |
---|
78 | owl_fmtext_cleanup(&fm); |
---|
79 | } |
---|
80 | |
---|
81 | void owl_function_show_styles(void) { |
---|
82 | owl_list l; |
---|
83 | owl_fmtext fm; |
---|
84 | |
---|
85 | owl_fmtext_init_null(&fm); |
---|
86 | owl_fmtext_append_bold(&fm, "Styles:\n"); |
---|
87 | owl_global_get_style_names(&g, &l); |
---|
88 | owl_fmtext_append_list(&fm, &l, "\n", owl_function_style_describe); |
---|
89 | owl_fmtext_append_normal(&fm, "\n"); |
---|
90 | owl_function_popless_fmtext(&fm); |
---|
91 | owl_list_cleanup(&l, owl_free); |
---|
92 | owl_fmtext_cleanup(&fm); |
---|
93 | } |
---|
94 | |
---|
95 | char *owl_function_style_describe(const char *name) { |
---|
96 | const char *desc; |
---|
97 | char *s; |
---|
98 | const owl_style *style; |
---|
99 | style = owl_global_get_style_by_name(&g, name); |
---|
100 | if (style) { |
---|
101 | desc = owl_style_get_description(style); |
---|
102 | } else { |
---|
103 | desc = "???"; |
---|
104 | } |
---|
105 | s = owl_sprintf("%-20s - %s%s", name, |
---|
106 | 0==owl_style_validate(style)?"":"[INVALID] ", |
---|
107 | desc); |
---|
108 | return s; |
---|
109 | } |
---|
110 | |
---|
111 | char *owl_function_cmd_describe(const char *name) |
---|
112 | { |
---|
113 | const owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name); |
---|
114 | if (cmd) return owl_cmd_describe(cmd); |
---|
115 | else return(NULL); |
---|
116 | } |
---|
117 | |
---|
118 | void owl_function_show_command(const char *name) |
---|
119 | { |
---|
120 | owl_function_help_for_command(name); |
---|
121 | } |
---|
122 | |
---|
123 | void owl_function_show_license(void) |
---|
124 | { |
---|
125 | const char *text; |
---|
126 | |
---|
127 | text="" |
---|
128 | "barnowl version " OWL_VERSION_STRING "\n" |
---|
129 | "Copyright (c) 2006-2010 The BarnOwl Developers. All rights reserved.\n" |
---|
130 | "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" |
---|
131 | "\n" |
---|
132 | "Redistribution and use in source and binary forms, with or without\n" |
---|
133 | "modification, are permitted provided that the following conditions are\n" |
---|
134 | "met:\n" |
---|
135 | "\n" |
---|
136 | " * Redistributions of source code must retain the above copyright\n" |
---|
137 | " notice, this list of conditions and the following disclaimer.\n" |
---|
138 | "\n" |
---|
139 | " * Redistributions in binary form must reproduce the above copyright\n" |
---|
140 | " notice, this list of conditions and the following disclaimer in\n" |
---|
141 | " the documentation and/or other materials provided with the\n" |
---|
142 | " distribution.\n" |
---|
143 | "\n" |
---|
144 | " * Redistributions in any form must be accompanied by information on\n" |
---|
145 | " how to obtain complete source code for the Owl software and any\n" |
---|
146 | " accompanying software that uses the Owl software. The source code\n" |
---|
147 | " must either be included in the distribution or be available for no\n" |
---|
148 | " more than the cost of distribution plus a nominal fee, and must be\n" |
---|
149 | " freely redistributable under reasonable conditions. For an\n" |
---|
150 | " executable file, complete source code means the source code for\n" |
---|
151 | " all modules it contains. It does not include source code for\n" |
---|
152 | " modules or files that typically accompany the major components of\n" |
---|
153 | " the operating system on which the executable file runs.\n" |
---|
154 | "\n" |
---|
155 | "THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n" |
---|
156 | "IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n" |
---|
157 | "WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR\n" |
---|
158 | "NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE\n" |
---|
159 | "LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n" |
---|
160 | "CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n" |
---|
161 | "SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR\n" |
---|
162 | "BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,\n" |
---|
163 | "WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\n" |
---|
164 | "OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\n" |
---|
165 | "IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"; |
---|
166 | owl_function_popless_text(text); |
---|
167 | } |
---|
168 | |
---|
169 | void owl_function_show_quickstart(void) |
---|
170 | { |
---|
171 | const char *message = |
---|
172 | "Move between messages with the arrow keys, and press 'r' to reply.\n" |
---|
173 | "For more info, press 'h' or visit http://barnowl.mit.edu/\n\n" |
---|
174 | #ifdef HAVE_LIBZEPHYR |
---|
175 | "@b(Zephyr:)\n" |
---|
176 | "To send a message to a user, type ':zwrite @b(username)'. You can also\n" |
---|
177 | "press 'z' and then type the username. To subscribe to a class, type\n" |
---|
178 | "':sub @b(class)', and then type ':zwrite -c @b(class)' to send.\n\n" |
---|
179 | #endif |
---|
180 | "@b(AIM:)\n" |
---|
181 | "Log in to AIM with ':aimlogin @b(screenname)'. Use ':aimwrite @b(screenname)',\n" |
---|
182 | "or 'a' and then the screen name, to send someone a message.\n\n" |
---|
183 | ; |
---|
184 | |
---|
185 | if (owl_perlconfig_is_function("BarnOwl::Hooks::_get_quickstart")) { |
---|
186 | char *perlquickstart = owl_perlconfig_execute("BarnOwl::Hooks::_get_quickstart()"); |
---|
187 | if (perlquickstart) { |
---|
188 | char *result = owl_sprintf("%s%s", message, perlquickstart); |
---|
189 | owl_function_adminmsg("BarnOwl Quickstart", result); |
---|
190 | owl_free(result); |
---|
191 | owl_free(perlquickstart); |
---|
192 | return; |
---|
193 | } |
---|
194 | } |
---|
195 | owl_function_adminmsg("BarnOwl Quickstart", message); |
---|
196 | } |
---|
197 | |
---|
198 | |
---|
199 | /* Create an admin message, append it to the global list of messages |
---|
200 | * and redisplay if necessary. |
---|
201 | */ |
---|
202 | void owl_function_adminmsg(const char *header, const char *body) |
---|
203 | { |
---|
204 | owl_message *m; |
---|
205 | |
---|
206 | m=owl_malloc(sizeof(owl_message)); |
---|
207 | owl_message_create_admin(m, header, body); |
---|
208 | |
---|
209 | /* add it to the global list and current view */ |
---|
210 | owl_messagelist_append_element(owl_global_get_msglist(&g), m); |
---|
211 | owl_view_consider_message(owl_global_get_current_view(&g), m); |
---|
212 | |
---|
213 | /* do followlast if necessary */ |
---|
214 | if (owl_global_should_followlast(&g)) owl_function_lastmsg_noredisplay(); |
---|
215 | |
---|
216 | /* redisplay etc. */ |
---|
217 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
218 | owl_global_set_needrefresh(&g); |
---|
219 | } |
---|
220 | |
---|
221 | /* Create an outgoing zephyr message and return a pointer to it. Does |
---|
222 | * not put it on the global queue, use owl_global_messagequeue_addmsg() for |
---|
223 | * that. |
---|
224 | */ |
---|
225 | owl_message *owl_function_make_outgoing_zephyr(const char *body, const char *zwriteline, const char *zsig) |
---|
226 | { |
---|
227 | owl_message *m; |
---|
228 | owl_zwrite zw; |
---|
229 | |
---|
230 | owl_zwrite_create_from_line(&zw, zwriteline); |
---|
231 | owl_zwrite_set_zsig(&zw, zsig); |
---|
232 | |
---|
233 | /* create the message */ |
---|
234 | m=owl_malloc(sizeof(owl_message)); |
---|
235 | |
---|
236 | owl_message_create_from_zwrite(m, &zw, body); |
---|
237 | owl_zwrite_cleanup(&zw); |
---|
238 | |
---|
239 | return(m); |
---|
240 | } |
---|
241 | |
---|
242 | /* Create an outgoing AIM message, returns a pointer to the created |
---|
243 | * message or NULL if we're not logged into AIM (and thus unable to |
---|
244 | * create the message). Does not put it on the global queue. Use |
---|
245 | * owl_global_messagequeue_addmsg() for that . |
---|
246 | */ |
---|
247 | owl_message *owl_function_make_outgoing_aim(const char *body, const char *to) |
---|
248 | { |
---|
249 | owl_message *m; |
---|
250 | |
---|
251 | /* error if we're not logged into aim */ |
---|
252 | if (!owl_global_is_aimloggedin(&g)) return(NULL); |
---|
253 | |
---|
254 | m=owl_malloc(sizeof(owl_message)); |
---|
255 | owl_message_create_aim(m, |
---|
256 | owl_global_get_aim_screenname(&g), |
---|
257 | to, |
---|
258 | body, |
---|
259 | OWL_MESSAGE_DIRECTION_OUT, |
---|
260 | 0); |
---|
261 | return(m); |
---|
262 | } |
---|
263 | |
---|
264 | /* Create an outgoing loopback message and return a pointer to it. |
---|
265 | * Does not append it to the global queue, use |
---|
266 | * owl_global_messagequeue_addmsg() for that. |
---|
267 | */ |
---|
268 | owl_message *owl_function_make_outgoing_loopback(const char *body) |
---|
269 | { |
---|
270 | owl_message *m; |
---|
271 | |
---|
272 | /* create the message */ |
---|
273 | m=owl_malloc(sizeof(owl_message)); |
---|
274 | owl_message_create_loopback(m, body); |
---|
275 | owl_message_set_direction_out(m); |
---|
276 | |
---|
277 | return(m); |
---|
278 | } |
---|
279 | |
---|
280 | void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *)) |
---|
281 | { |
---|
282 | owl_editwin *e; |
---|
283 | char *s; |
---|
284 | |
---|
285 | /* create and setup the editwin */ |
---|
286 | e = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_MULTILINE, |
---|
287 | owl_global_get_msg_history(&g)); |
---|
288 | owl_editwin_set_dotsend(e); |
---|
289 | s = owl_sprintf("----> %s\n", line); |
---|
290 | owl_editwin_set_locktext(e, s); |
---|
291 | owl_free(s); |
---|
292 | |
---|
293 | owl_editwin_set_cbdata(e, data, cleanup); |
---|
294 | owl_editwin_set_callback(e, callback); |
---|
295 | owl_global_push_context(&g, OWL_CTX_EDITMULTI, e, "editmulti"); |
---|
296 | } |
---|
297 | |
---|
298 | static void owl_function_write_setup(const char *line, const char *noun, void (*callback)(owl_editwin *)) |
---|
299 | { |
---|
300 | |
---|
301 | if (!owl_global_get_lockout_ctrld(&g)) |
---|
302 | owl_function_makemsg("Type your %s below. " |
---|
303 | "End with ^D or a dot on a line by itself." |
---|
304 | " ^C will quit.", noun); |
---|
305 | else |
---|
306 | owl_function_makemsg("Type your %s below. " |
---|
307 | "End with a dot on a line by itself. ^C will quit.", |
---|
308 | noun); |
---|
309 | |
---|
310 | owl_function_start_edit_win(line, callback, |
---|
311 | owl_strdup(line), |
---|
312 | owl_free); |
---|
313 | } |
---|
314 | |
---|
315 | void owl_function_zwrite_setup(const char *line) |
---|
316 | { |
---|
317 | owl_zwrite z; |
---|
318 | int ret; |
---|
319 | |
---|
320 | /* check the arguments */ |
---|
321 | ret=owl_zwrite_create_from_line(&z, line); |
---|
322 | if (ret) { |
---|
323 | owl_function_error("Error in zwrite arguments"); |
---|
324 | owl_zwrite_cleanup(&z); |
---|
325 | return; |
---|
326 | } |
---|
327 | |
---|
328 | /* send a ping if necessary */ |
---|
329 | if (owl_global_is_txping(&g)) { |
---|
330 | owl_zwrite_send_ping(&z); |
---|
331 | } |
---|
332 | owl_zwrite_cleanup(&z); |
---|
333 | |
---|
334 | owl_function_write_setup(line, "zephyr", &owl_callback_zwrite); |
---|
335 | } |
---|
336 | |
---|
337 | void owl_function_aimwrite_setup(const char *line) |
---|
338 | { |
---|
339 | owl_function_write_setup(line, "message", &owl_callback_aimwrite); |
---|
340 | } |
---|
341 | |
---|
342 | void owl_function_loopwrite_setup(void) |
---|
343 | { |
---|
344 | owl_function_write_setup("loopwrite", "message", owl_callback_loopwrite); |
---|
345 | } |
---|
346 | |
---|
347 | void owl_callback_zwrite(owl_editwin *e) { |
---|
348 | char *command = owl_editwin_get_cbdata(e); |
---|
349 | owl_function_zwrite(command, |
---|
350 | owl_editwin_get_text(e)); |
---|
351 | } |
---|
352 | |
---|
353 | /* send, log and display an outgoing zephyr. If 'msg' is NULL |
---|
354 | * the message is expected to be set from the zwrite line itself |
---|
355 | */ |
---|
356 | void owl_function_zwrite(const char *line, const char *msg) |
---|
357 | { |
---|
358 | owl_zwrite z; |
---|
359 | const char *mymsg; |
---|
360 | owl_message *m; |
---|
361 | |
---|
362 | if(!strncmp(line, "zcrypt", strlen("zcrypt"))) { |
---|
363 | owl_function_zcrypt(line, msg); |
---|
364 | return; |
---|
365 | } |
---|
366 | |
---|
367 | /* create the zwrite and send the message */ |
---|
368 | owl_zwrite_create_from_line(&z, line); |
---|
369 | owl_zwrite_populate_zsig(&z); |
---|
370 | if (msg) { |
---|
371 | owl_zwrite_set_message(&z, msg); |
---|
372 | } |
---|
373 | owl_zwrite_send_message(&z); |
---|
374 | owl_function_makemsg("Waiting for ack..."); |
---|
375 | |
---|
376 | /* If it's personal */ |
---|
377 | if (owl_zwrite_is_personal(&z)) { |
---|
378 | /* create the outgoing message */ |
---|
379 | mymsg=owl_zwrite_get_message(&z); |
---|
380 | m=owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z)); |
---|
381 | |
---|
382 | if (m) { |
---|
383 | owl_global_messagequeue_addmsg(&g, m); |
---|
384 | } else { |
---|
385 | owl_function_error("Could not create outgoing zephyr message"); |
---|
386 | } |
---|
387 | } |
---|
388 | |
---|
389 | /* free the zwrite */ |
---|
390 | owl_zwrite_cleanup(&z); |
---|
391 | } |
---|
392 | |
---|
393 | /* send, log and display an outgoing zcrypt zephyr. If 'msg' is NULL |
---|
394 | * the message is expected to be set from the zwrite line itself |
---|
395 | */ |
---|
396 | void owl_function_zcrypt(const char *line, const char *msg) |
---|
397 | { |
---|
398 | owl_zwrite z; |
---|
399 | const char *mymsg; |
---|
400 | char *cryptmsg; |
---|
401 | owl_message *m; |
---|
402 | const char *argv[7]; |
---|
403 | char *zcrypt; |
---|
404 | int rv, status; |
---|
405 | |
---|
406 | /* create the zwrite and send the message */ |
---|
407 | owl_zwrite_create_from_line(&z, line); |
---|
408 | owl_zwrite_populate_zsig(&z); |
---|
409 | if (msg) { |
---|
410 | owl_zwrite_set_message(&z, msg); |
---|
411 | } |
---|
412 | |
---|
413 | mymsg=owl_zwrite_get_message(&z); |
---|
414 | |
---|
415 | zcrypt = owl_sprintf("%s/zcrypt", owl_get_bindir()); |
---|
416 | argv[0] = "zcrypt"; |
---|
417 | argv[1] = "-E"; |
---|
418 | argv[2] = "-c"; argv[3] = owl_zwrite_get_class(&z); |
---|
419 | argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(&z); |
---|
420 | argv[6] = NULL; |
---|
421 | |
---|
422 | rv = call_filter(zcrypt, argv, mymsg, &cryptmsg, &status); |
---|
423 | |
---|
424 | owl_free(zcrypt); |
---|
425 | |
---|
426 | if (rv || status) { |
---|
427 | if(cryptmsg) owl_free(cryptmsg); |
---|
428 | owl_function_error("Error in zcrypt, possibly no key found. Message not sent."); |
---|
429 | owl_function_beep(); |
---|
430 | owl_zwrite_cleanup(&z); |
---|
431 | return; |
---|
432 | } |
---|
433 | |
---|
434 | owl_zwrite_set_message(&z, cryptmsg); |
---|
435 | owl_zwrite_set_opcode(&z, "crypt"); |
---|
436 | |
---|
437 | owl_zwrite_send_message(&z); |
---|
438 | owl_function_makemsg("Waiting for ack..."); |
---|
439 | |
---|
440 | /* If it's personal */ |
---|
441 | if (owl_zwrite_is_personal(&z)) { |
---|
442 | /* create the outgoing message */ |
---|
443 | mymsg=owl_zwrite_get_message(&z); |
---|
444 | m=owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z)); |
---|
445 | if (m) { |
---|
446 | owl_global_messagequeue_addmsg(&g, m); |
---|
447 | } else { |
---|
448 | owl_function_error("Could not create outgoing zephyr message"); |
---|
449 | } |
---|
450 | } |
---|
451 | |
---|
452 | /* free the zwrite */ |
---|
453 | owl_free(cryptmsg); |
---|
454 | owl_zwrite_cleanup(&z); |
---|
455 | } |
---|
456 | |
---|
457 | void owl_callback_aimwrite(owl_editwin *e) { |
---|
458 | char *command = owl_editwin_get_cbdata(e); |
---|
459 | owl_function_aimwrite(command, |
---|
460 | owl_editwin_get_text(e)); |
---|
461 | } |
---|
462 | |
---|
463 | void owl_function_aimwrite(const char *line, const char *msg) |
---|
464 | { |
---|
465 | int ret; |
---|
466 | const char *to; |
---|
467 | char *format_msg; |
---|
468 | owl_message *m; |
---|
469 | |
---|
470 | to = line + 9; |
---|
471 | |
---|
472 | /* make a formatted copy of the message */ |
---|
473 | format_msg=owl_strdup(msg); |
---|
474 | owl_text_wordunwrap(format_msg); |
---|
475 | |
---|
476 | /* send the message */ |
---|
477 | ret=owl_aim_send_im(to, format_msg); |
---|
478 | if (!ret) { |
---|
479 | owl_function_makemsg("AIM message sent."); |
---|
480 | } else { |
---|
481 | owl_function_error("Could not send AIM message."); |
---|
482 | } |
---|
483 | |
---|
484 | /* create the outgoing message */ |
---|
485 | m=owl_function_make_outgoing_aim(msg, to); |
---|
486 | |
---|
487 | if (m) { |
---|
488 | owl_global_messagequeue_addmsg(&g, m); |
---|
489 | } else { |
---|
490 | owl_function_error("Could not create outgoing AIM message"); |
---|
491 | } |
---|
492 | |
---|
493 | owl_free(format_msg); |
---|
494 | } |
---|
495 | |
---|
496 | void owl_function_send_aimawymsg(const char *to, const char *msg) |
---|
497 | { |
---|
498 | int ret; |
---|
499 | char *format_msg; |
---|
500 | owl_message *m; |
---|
501 | |
---|
502 | /* make a formatted copy of the message */ |
---|
503 | format_msg=owl_strdup(msg); |
---|
504 | owl_text_wordunwrap(format_msg); |
---|
505 | |
---|
506 | /* send the message */ |
---|
507 | ret=owl_aim_send_awaymsg(to, format_msg); |
---|
508 | if (!ret) { |
---|
509 | /* owl_function_makemsg("AIM message sent."); */ |
---|
510 | } else { |
---|
511 | owl_function_error("Could not send AIM message."); |
---|
512 | } |
---|
513 | |
---|
514 | /* create the message */ |
---|
515 | m=owl_function_make_outgoing_aim(msg, to); |
---|
516 | if (m) { |
---|
517 | owl_global_messagequeue_addmsg(&g, m); |
---|
518 | } else { |
---|
519 | owl_function_error("Could not create AIM message"); |
---|
520 | } |
---|
521 | owl_free(format_msg); |
---|
522 | } |
---|
523 | |
---|
524 | void owl_callback_loopwrite(owl_editwin *e) { |
---|
525 | owl_function_loopwrite(owl_editwin_get_text(e)); |
---|
526 | } |
---|
527 | |
---|
528 | void owl_function_loopwrite(const char *msg) |
---|
529 | { |
---|
530 | owl_message *min, *mout; |
---|
531 | |
---|
532 | /* create a message and put it on the message queue. This simulates |
---|
533 | * an incoming message */ |
---|
534 | min=owl_malloc(sizeof(owl_message)); |
---|
535 | mout=owl_function_make_outgoing_loopback(msg); |
---|
536 | |
---|
537 | if (owl_global_is_displayoutgoing(&g)) { |
---|
538 | owl_global_messagequeue_addmsg(&g, mout); |
---|
539 | } else { |
---|
540 | owl_message_delete(mout); |
---|
541 | } |
---|
542 | |
---|
543 | owl_message_create_loopback(min, msg); |
---|
544 | owl_message_set_direction_in(min); |
---|
545 | owl_global_messagequeue_addmsg(&g, min); |
---|
546 | |
---|
547 | /* fake a makemsg */ |
---|
548 | owl_function_makemsg("loopback message sent"); |
---|
549 | } |
---|
550 | |
---|
551 | /* If filter is non-null, looks for the next message matching |
---|
552 | * that filter. If skip_deleted, skips any deleted messages. |
---|
553 | * If last_if_none, will stop at the last message in the view |
---|
554 | * if no matching messages are found. */ |
---|
555 | void owl_function_nextmsg_full(const char *filter, int skip_deleted, int last_if_none) |
---|
556 | { |
---|
557 | int curmsg, i, viewsize, found; |
---|
558 | const owl_view *v; |
---|
559 | const owl_filter *f = NULL; |
---|
560 | const owl_message *m; |
---|
561 | |
---|
562 | v=owl_global_get_current_view(&g); |
---|
563 | |
---|
564 | if (filter) { |
---|
565 | f=owl_global_get_filter(&g, filter); |
---|
566 | if (!f) { |
---|
567 | owl_function_error("No %s filter defined", filter); |
---|
568 | return; |
---|
569 | } |
---|
570 | } |
---|
571 | |
---|
572 | curmsg=owl_global_get_curmsg(&g); |
---|
573 | viewsize=owl_view_get_size(v); |
---|
574 | found=0; |
---|
575 | |
---|
576 | /* just check to make sure we're in bounds... */ |
---|
577 | if (curmsg>viewsize-1) curmsg=viewsize-1; |
---|
578 | if (curmsg<0) curmsg=0; |
---|
579 | |
---|
580 | for (i=curmsg+1; i<viewsize; i++) { |
---|
581 | m=owl_view_get_element(v, i); |
---|
582 | if (skip_deleted && owl_message_is_delete(m)) continue; |
---|
583 | if (f && !owl_filter_message_match(f, m)) continue; |
---|
584 | found = 1; |
---|
585 | break; |
---|
586 | } |
---|
587 | |
---|
588 | if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1; |
---|
589 | if (i<0) i=0; |
---|
590 | |
---|
591 | if (!found) { |
---|
592 | owl_function_makemsg("already at last%s message%s%s%s", |
---|
593 | skip_deleted?" non-deleted":"", |
---|
594 | filter?" in ":"", filter?filter:"", |
---|
595 | owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g)) ? |
---|
596 | ", press Enter to scroll" : ""); |
---|
597 | /* if (!skip_deleted) owl_function_beep(); */ |
---|
598 | } |
---|
599 | |
---|
600 | if (last_if_none || found) { |
---|
601 | owl_global_set_curmsg(&g, i); |
---|
602 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
603 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
604 | owl_global_set_direction_downwards(&g); |
---|
605 | } |
---|
606 | } |
---|
607 | |
---|
608 | void owl_function_prevmsg_full(const char *filter, int skip_deleted, int first_if_none) |
---|
609 | { |
---|
610 | int curmsg, i, found; |
---|
611 | const owl_view *v; |
---|
612 | const owl_filter *f = NULL; |
---|
613 | const owl_message *m; |
---|
614 | |
---|
615 | v=owl_global_get_current_view(&g); |
---|
616 | |
---|
617 | if (filter) { |
---|
618 | f=owl_global_get_filter(&g, filter); |
---|
619 | if (!f) { |
---|
620 | owl_function_error("No %s filter defined", filter); |
---|
621 | return; |
---|
622 | } |
---|
623 | } |
---|
624 | |
---|
625 | curmsg=owl_global_get_curmsg(&g); |
---|
626 | found=0; |
---|
627 | |
---|
628 | /* just check to make sure we're in bounds... */ |
---|
629 | if (curmsg<0) curmsg=0; |
---|
630 | |
---|
631 | for (i=curmsg-1; i>=0; i--) { |
---|
632 | m=owl_view_get_element(v, i); |
---|
633 | if (skip_deleted && owl_message_is_delete(m)) continue; |
---|
634 | if (f && !owl_filter_message_match(f, m)) continue; |
---|
635 | found = 1; |
---|
636 | break; |
---|
637 | } |
---|
638 | |
---|
639 | if (i<0) i=0; |
---|
640 | |
---|
641 | if (!found) { |
---|
642 | owl_function_makemsg("already at first%s message%s%s", |
---|
643 | skip_deleted?" non-deleted":"", |
---|
644 | filter?" in ":"", filter?filter:""); |
---|
645 | /* if (!skip_deleted) owl_function_beep(); */ |
---|
646 | } |
---|
647 | |
---|
648 | if (first_if_none || found) { |
---|
649 | owl_global_set_curmsg(&g, i); |
---|
650 | owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS); |
---|
651 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
652 | owl_global_set_direction_upwards(&g); |
---|
653 | } |
---|
654 | } |
---|
655 | |
---|
656 | void owl_function_nextmsg(void) |
---|
657 | { |
---|
658 | owl_function_nextmsg_full(NULL, 0, 1); |
---|
659 | } |
---|
660 | |
---|
661 | void owl_function_prevmsg(void) |
---|
662 | { |
---|
663 | owl_function_prevmsg_full(NULL, 0, 1); |
---|
664 | } |
---|
665 | |
---|
666 | void owl_function_nextmsg_notdeleted(void) |
---|
667 | { |
---|
668 | owl_function_nextmsg_full(NULL, 1, 1); |
---|
669 | } |
---|
670 | |
---|
671 | void owl_function_prevmsg_notdeleted(void) |
---|
672 | { |
---|
673 | owl_function_prevmsg_full(NULL, 1, 1); |
---|
674 | } |
---|
675 | |
---|
676 | /* if move_after is 1, moves after the delete */ |
---|
677 | void owl_function_deletecur(int move_after) |
---|
678 | { |
---|
679 | int curmsg; |
---|
680 | owl_view *v; |
---|
681 | |
---|
682 | v=owl_global_get_current_view(&g); |
---|
683 | |
---|
684 | /* bail if there's no current message */ |
---|
685 | if (owl_view_get_size(v) < 1) { |
---|
686 | owl_function_error("No current message to delete"); |
---|
687 | return; |
---|
688 | } |
---|
689 | |
---|
690 | /* mark the message for deletion */ |
---|
691 | curmsg=owl_global_get_curmsg(&g); |
---|
692 | owl_view_delete_element(v, curmsg); |
---|
693 | |
---|
694 | if (move_after) { |
---|
695 | /* move the poiner in the appropriate direction |
---|
696 | * to the next undeleted msg */ |
---|
697 | if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { |
---|
698 | owl_function_prevmsg_notdeleted(); |
---|
699 | } else { |
---|
700 | owl_function_nextmsg_notdeleted(); |
---|
701 | } |
---|
702 | } |
---|
703 | } |
---|
704 | |
---|
705 | void owl_function_undeletecur(int move_after) |
---|
706 | { |
---|
707 | int curmsg; |
---|
708 | owl_view *v; |
---|
709 | |
---|
710 | v=owl_global_get_current_view(&g); |
---|
711 | |
---|
712 | if (owl_view_get_size(v) < 1) { |
---|
713 | owl_function_error("No current message to undelete"); |
---|
714 | return; |
---|
715 | } |
---|
716 | curmsg=owl_global_get_curmsg(&g); |
---|
717 | |
---|
718 | owl_view_undelete_element(v, curmsg); |
---|
719 | |
---|
720 | if (move_after) { |
---|
721 | if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { |
---|
722 | if (curmsg>0) { |
---|
723 | owl_function_prevmsg(); |
---|
724 | } else { |
---|
725 | owl_function_nextmsg(); |
---|
726 | } |
---|
727 | } else { |
---|
728 | owl_function_nextmsg(); |
---|
729 | } |
---|
730 | } |
---|
731 | |
---|
732 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
733 | } |
---|
734 | |
---|
735 | void owl_function_expunge(void) |
---|
736 | { |
---|
737 | int curmsg; |
---|
738 | const owl_message *m; |
---|
739 | owl_messagelist *ml; |
---|
740 | owl_view *v; |
---|
741 | int lastmsgid=0; |
---|
742 | |
---|
743 | curmsg=owl_global_get_curmsg(&g); |
---|
744 | v=owl_global_get_current_view(&g); |
---|
745 | ml=owl_global_get_msglist(&g); |
---|
746 | |
---|
747 | m=owl_view_get_element(v, curmsg); |
---|
748 | if (m) lastmsgid = owl_message_get_id(m); |
---|
749 | |
---|
750 | /* expunge the message list */ |
---|
751 | owl_messagelist_expunge(ml); |
---|
752 | |
---|
753 | /* update all views (we only have one right now) */ |
---|
754 | owl_view_recalculate(v); |
---|
755 | |
---|
756 | /* find where the new position should be |
---|
757 | (as close as possible to where we last where) */ |
---|
758 | curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid); |
---|
759 | if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1; |
---|
760 | if (curmsg<0) curmsg = 0; |
---|
761 | owl_global_set_curmsg(&g, curmsg); |
---|
762 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
763 | /* if there are no messages set the direction to down in case we |
---|
764 | delete everything upwards */ |
---|
765 | owl_global_set_direction_downwards(&g); |
---|
766 | |
---|
767 | owl_function_makemsg("Messages expunged"); |
---|
768 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
769 | } |
---|
770 | |
---|
771 | void owl_function_firstmsg(void) |
---|
772 | { |
---|
773 | owl_global_set_curmsg(&g, 0); |
---|
774 | owl_global_set_topmsg(&g, 0); |
---|
775 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
776 | owl_global_set_direction_downwards(&g); |
---|
777 | } |
---|
778 | |
---|
779 | void owl_function_lastmsg_noredisplay(void) |
---|
780 | { |
---|
781 | int oldcurmsg, curmsg; |
---|
782 | const owl_view *v; |
---|
783 | |
---|
784 | v=owl_global_get_current_view(&g); |
---|
785 | oldcurmsg=owl_global_get_curmsg(&g); |
---|
786 | curmsg=owl_view_get_size(v)-1; |
---|
787 | if (curmsg<0) curmsg=0; |
---|
788 | owl_global_set_curmsg(&g, curmsg); |
---|
789 | if (oldcurmsg < curmsg) { |
---|
790 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
791 | } else if (curmsg<owl_view_get_size(v)) { |
---|
792 | /* If already at the end, blank the screen and move curmsg |
---|
793 | * past the end of the messages. */ |
---|
794 | owl_global_set_topmsg(&g, curmsg+1); |
---|
795 | owl_global_set_curmsg(&g, curmsg+1); |
---|
796 | } |
---|
797 | /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */ |
---|
798 | owl_global_set_direction_downwards(&g); |
---|
799 | } |
---|
800 | |
---|
801 | void owl_function_lastmsg(void) |
---|
802 | { |
---|
803 | owl_function_lastmsg_noredisplay(); |
---|
804 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
805 | } |
---|
806 | |
---|
807 | void owl_function_shift_right(void) |
---|
808 | { |
---|
809 | owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10); |
---|
810 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
811 | owl_global_set_needrefresh(&g); |
---|
812 | } |
---|
813 | |
---|
814 | void owl_function_shift_left(void) |
---|
815 | { |
---|
816 | int shift; |
---|
817 | |
---|
818 | shift=owl_global_get_rightshift(&g); |
---|
819 | if (shift > 0) { |
---|
820 | owl_global_set_rightshift(&g, MAX(shift - 10, 0)); |
---|
821 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
822 | owl_global_set_needrefresh(&g); |
---|
823 | } else { |
---|
824 | owl_function_beep(); |
---|
825 | owl_function_makemsg("Already full left"); |
---|
826 | } |
---|
827 | } |
---|
828 | |
---|
829 | void owl_function_unsuball(void) |
---|
830 | { |
---|
831 | unsuball(); |
---|
832 | owl_function_makemsg("Unsubscribed from all messages."); |
---|
833 | } |
---|
834 | |
---|
835 | |
---|
836 | /* Load zephyr subscriptions from the named 'file' and load zephyr's |
---|
837 | * default subscriptions as well. An error message is printed if |
---|
838 | * 'file' can't be opened or if zephyr reports an error in |
---|
839 | * subscribing. |
---|
840 | * |
---|
841 | * If 'file' is NULL, this look for the default filename |
---|
842 | * $HOME/.zephyr.subs. If the file can not be opened in this case |
---|
843 | * only, no error message is printed. |
---|
844 | */ |
---|
845 | void owl_function_loadsubs(const char *file) |
---|
846 | { |
---|
847 | int ret, ret2; |
---|
848 | const char *foo; |
---|
849 | char *path; |
---|
850 | |
---|
851 | if (file==NULL) { |
---|
852 | ret=owl_zephyr_loadsubs(NULL, 0); |
---|
853 | } else { |
---|
854 | path = owl_util_makepath(file); |
---|
855 | ret=owl_zephyr_loadsubs(path, 1); |
---|
856 | owl_free(path); |
---|
857 | } |
---|
858 | |
---|
859 | /* for backwards compatibility for now */ |
---|
860 | ret2=owl_zephyr_loaddefaultsubs(); |
---|
861 | |
---|
862 | if (!owl_context_is_interactive(owl_global_get_context(&g))) return; |
---|
863 | |
---|
864 | foo=file?file:"file"; |
---|
865 | if (ret==0 && ret2==0) { |
---|
866 | if (!file) { |
---|
867 | owl_function_makemsg("Subscribed to messages."); |
---|
868 | } else { |
---|
869 | owl_function_makemsg("Subscribed to messages from %s", file); |
---|
870 | } |
---|
871 | } else if (ret==-1) { |
---|
872 | owl_function_error("Could not read %s", foo); |
---|
873 | } else { |
---|
874 | owl_function_error("Error subscribing to messages"); |
---|
875 | } |
---|
876 | } |
---|
877 | |
---|
878 | void owl_function_loadloginsubs(const char *file) |
---|
879 | { |
---|
880 | int ret; |
---|
881 | |
---|
882 | ret=owl_zephyr_loadloginsubs(file); |
---|
883 | |
---|
884 | if (!owl_context_is_interactive(owl_global_get_context(&g))) return; |
---|
885 | if (ret==0) { |
---|
886 | } else if (ret==-1) { |
---|
887 | owl_function_error("Could not open file for login subscriptions."); |
---|
888 | } else { |
---|
889 | owl_function_error("Error subscribing to login messages from file."); |
---|
890 | } |
---|
891 | } |
---|
892 | |
---|
893 | void owl_callback_aimlogin(owl_editwin *e) { |
---|
894 | char *user = owl_editwin_get_cbdata(e); |
---|
895 | owl_function_aimlogin(user, |
---|
896 | owl_editwin_get_text(e)); |
---|
897 | } |
---|
898 | |
---|
899 | void owl_function_aimlogin(const char *user, const char *passwd) { |
---|
900 | int ret; |
---|
901 | |
---|
902 | /* clear the buddylist */ |
---|
903 | owl_buddylist_clear(owl_global_get_buddylist(&g)); |
---|
904 | |
---|
905 | /* try to login */ |
---|
906 | ret=owl_aim_login(user, passwd); |
---|
907 | if (ret) owl_function_makemsg("Warning: login for %s failed.\n", user); |
---|
908 | } |
---|
909 | |
---|
910 | void owl_function_suspend(void) |
---|
911 | { |
---|
912 | endwin(); |
---|
913 | printf("\n"); |
---|
914 | kill(getpid(), SIGSTOP); |
---|
915 | |
---|
916 | /* resize to reinitialize all the windows when we come back */ |
---|
917 | owl_command_resize(); |
---|
918 | } |
---|
919 | |
---|
920 | void owl_function_zaway_toggle(void) |
---|
921 | { |
---|
922 | if (!owl_global_is_zaway(&g)) { |
---|
923 | owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g)); |
---|
924 | owl_function_zaway_on(); |
---|
925 | } else { |
---|
926 | owl_function_zaway_off(); |
---|
927 | } |
---|
928 | } |
---|
929 | |
---|
930 | void owl_function_zaway_on(void) |
---|
931 | { |
---|
932 | owl_global_set_zaway_on(&g); |
---|
933 | owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g)); |
---|
934 | } |
---|
935 | |
---|
936 | void owl_function_zaway_off(void) |
---|
937 | { |
---|
938 | owl_global_set_zaway_off(&g); |
---|
939 | owl_function_makemsg("zaway off"); |
---|
940 | } |
---|
941 | |
---|
942 | void owl_function_aaway_toggle(void) |
---|
943 | { |
---|
944 | if (!owl_global_is_aaway(&g)) { |
---|
945 | owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g)); |
---|
946 | owl_function_aaway_on(); |
---|
947 | } else { |
---|
948 | owl_function_aaway_off(); |
---|
949 | } |
---|
950 | } |
---|
951 | |
---|
952 | void owl_function_aaway_on(void) |
---|
953 | { |
---|
954 | owl_global_set_aaway_on(&g); |
---|
955 | /* owl_aim_set_awaymsg(owl_global_get_zaway_msg(&g)); */ |
---|
956 | owl_function_makemsg("AIM away set (%s)", owl_global_get_aaway_msg(&g)); |
---|
957 | } |
---|
958 | |
---|
959 | void owl_function_aaway_off(void) |
---|
960 | { |
---|
961 | owl_global_set_aaway_off(&g); |
---|
962 | /* owl_aim_set_awaymsg(""); */ |
---|
963 | owl_function_makemsg("AIM away off"); |
---|
964 | } |
---|
965 | |
---|
966 | void owl_function_quit(void) |
---|
967 | { |
---|
968 | char *ret; |
---|
969 | |
---|
970 | /* zlog out if we need to */ |
---|
971 | if (owl_global_is_havezephyr(&g) && |
---|
972 | owl_global_is_shutdownlogout(&g)) { |
---|
973 | owl_zephyr_zlog_out(); |
---|
974 | } |
---|
975 | |
---|
976 | /* execute the commands in shutdown */ |
---|
977 | ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();"); |
---|
978 | if (ret) owl_free(ret); |
---|
979 | |
---|
980 | /* signal our child process, if any */ |
---|
981 | if (owl_global_get_newmsgproc_pid(&g)) { |
---|
982 | kill(owl_global_get_newmsgproc_pid(&g), SIGHUP); |
---|
983 | } |
---|
984 | |
---|
985 | /* Quit zephyr */ |
---|
986 | owl_zephyr_shutdown(); |
---|
987 | |
---|
988 | /* Quit AIM */ |
---|
989 | if (owl_global_is_aimloggedin(&g)) { |
---|
990 | owl_aim_logout(); |
---|
991 | } |
---|
992 | |
---|
993 | /* done with curses */ |
---|
994 | endwin(); |
---|
995 | |
---|
996 | /* restore terminal settings */ |
---|
997 | tcsetattr(0, TCSAFLUSH, owl_global_get_startup_tio(&g)); |
---|
998 | |
---|
999 | owl_function_debugmsg("Quitting Owl"); |
---|
1000 | exit(0); |
---|
1001 | } |
---|
1002 | |
---|
1003 | void owl_function_calculate_topmsg(int direction) |
---|
1004 | { |
---|
1005 | int recwinlines, topmsg, curmsg; |
---|
1006 | const owl_view *v; |
---|
1007 | |
---|
1008 | v=owl_global_get_current_view(&g); |
---|
1009 | curmsg=owl_global_get_curmsg(&g); |
---|
1010 | topmsg=owl_global_get_topmsg(&g); |
---|
1011 | recwinlines=owl_global_get_recwin_lines(&g); |
---|
1012 | |
---|
1013 | /* |
---|
1014 | if (owl_view_get_size(v) < 1) { |
---|
1015 | return; |
---|
1016 | } |
---|
1017 | */ |
---|
1018 | |
---|
1019 | switch (owl_global_get_scrollmode(&g)) { |
---|
1020 | case OWL_SCROLLMODE_TOP: |
---|
1021 | topmsg = owl_function_calculate_topmsg_top(direction, v, curmsg, topmsg, recwinlines); |
---|
1022 | break; |
---|
1023 | case OWL_SCROLLMODE_NEARTOP: |
---|
1024 | topmsg = owl_function_calculate_topmsg_neartop(direction, v, curmsg, topmsg, recwinlines); |
---|
1025 | break; |
---|
1026 | case OWL_SCROLLMODE_CENTER: |
---|
1027 | topmsg = owl_function_calculate_topmsg_center(direction, v, curmsg, topmsg, recwinlines); |
---|
1028 | break; |
---|
1029 | case OWL_SCROLLMODE_PAGED: |
---|
1030 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 0); |
---|
1031 | break; |
---|
1032 | case OWL_SCROLLMODE_PAGEDCENTER: |
---|
1033 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 1); |
---|
1034 | break; |
---|
1035 | case OWL_SCROLLMODE_NORMAL: |
---|
1036 | default: |
---|
1037 | topmsg = owl_function_calculate_topmsg_normal(direction, v, curmsg, topmsg, recwinlines); |
---|
1038 | } |
---|
1039 | owl_function_debugmsg("Calculated a topmsg of %i", topmsg); |
---|
1040 | owl_global_set_topmsg(&g, topmsg); |
---|
1041 | } |
---|
1042 | |
---|
1043 | /* Returns what the new topmsg should be. |
---|
1044 | * Passed the last direction of movement, |
---|
1045 | * the current view, |
---|
1046 | * the current message number in the view, |
---|
1047 | * the top message currently being displayed, |
---|
1048 | * and the number of lines in the recwin. |
---|
1049 | */ |
---|
1050 | int owl_function_calculate_topmsg_top(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
1051 | { |
---|
1052 | return(curmsg); |
---|
1053 | } |
---|
1054 | |
---|
1055 | int owl_function_calculate_topmsg_neartop(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
1056 | { |
---|
1057 | if (curmsg>0 |
---|
1058 | && (owl_message_get_numlines(owl_view_get_element(v, curmsg-1)) |
---|
1059 | < recwinlines/2)) { |
---|
1060 | return(curmsg-1); |
---|
1061 | } else { |
---|
1062 | return(curmsg); |
---|
1063 | } |
---|
1064 | } |
---|
1065 | |
---|
1066 | int owl_function_calculate_topmsg_center(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
1067 | { |
---|
1068 | int i, last, lines; |
---|
1069 | |
---|
1070 | last = curmsg; |
---|
1071 | lines = 0; |
---|
1072 | for (i=curmsg-1; i>=0; i--) { |
---|
1073 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
1074 | if (lines > recwinlines/2) break; |
---|
1075 | last = i; |
---|
1076 | } |
---|
1077 | return(last); |
---|
1078 | } |
---|
1079 | |
---|
1080 | int owl_function_calculate_topmsg_paged(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines, int center_on_page) |
---|
1081 | { |
---|
1082 | int i, last, lines, savey; |
---|
1083 | |
---|
1084 | /* If we're off the top of the screen, scroll up such that the |
---|
1085 | * curmsg is near the botton of the screen. */ |
---|
1086 | if (curmsg < topmsg) { |
---|
1087 | last = curmsg; |
---|
1088 | lines = 0; |
---|
1089 | for (i=curmsg; i>=0; i--) { |
---|
1090 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
1091 | if (lines > recwinlines) break; |
---|
1092 | last = i; |
---|
1093 | } |
---|
1094 | if (center_on_page) { |
---|
1095 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
1096 | } else { |
---|
1097 | return(last); |
---|
1098 | } |
---|
1099 | } |
---|
1100 | |
---|
1101 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
1102 | savey=0; |
---|
1103 | for (i=topmsg; i<=curmsg; i++) { |
---|
1104 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
1105 | } |
---|
1106 | |
---|
1107 | /* if we're off the bottom of the screen, scroll down */ |
---|
1108 | if (savey > recwinlines) { |
---|
1109 | if (center_on_page) { |
---|
1110 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
1111 | } else { |
---|
1112 | return(curmsg); |
---|
1113 | } |
---|
1114 | } |
---|
1115 | |
---|
1116 | /* else just stay as we are... */ |
---|
1117 | return(topmsg); |
---|
1118 | } |
---|
1119 | |
---|
1120 | int owl_function_calculate_topmsg_normal(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
1121 | { |
---|
1122 | int savey, i, foo, y; |
---|
1123 | |
---|
1124 | if (curmsg<0) return(topmsg); |
---|
1125 | |
---|
1126 | /* If we're off the top of the screen then center */ |
---|
1127 | if (curmsg<topmsg) { |
---|
1128 | topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines); |
---|
1129 | } |
---|
1130 | |
---|
1131 | /* If curmsg is so far past topmsg that there are more messages than |
---|
1132 | lines, skip the line counting that follows because we're |
---|
1133 | certainly off screen. */ |
---|
1134 | savey=curmsg-topmsg; |
---|
1135 | if (savey <= recwinlines) { |
---|
1136 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
1137 | savey = 0; |
---|
1138 | for (i=topmsg; i<=curmsg; i++) { |
---|
1139 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
1140 | } |
---|
1141 | } |
---|
1142 | |
---|
1143 | /* If we're off the bottom of the screen, set the topmsg to curmsg |
---|
1144 | * and scroll upwards */ |
---|
1145 | if (savey > recwinlines) { |
---|
1146 | topmsg=curmsg; |
---|
1147 | savey=owl_message_get_numlines(owl_view_get_element(v, curmsg)); |
---|
1148 | direction=OWL_DIRECTION_UPWARDS; |
---|
1149 | } |
---|
1150 | |
---|
1151 | /* If our bottom line is less than 1/4 down the screen then scroll up */ |
---|
1152 | if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) { |
---|
1153 | if (savey < (recwinlines / 4)) { |
---|
1154 | y=0; |
---|
1155 | for (i=curmsg; i>=0; i--) { |
---|
1156 | foo=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
1157 | /* will we run the curmsg off the screen? */ |
---|
1158 | if ((foo+y) >= recwinlines) { |
---|
1159 | i++; |
---|
1160 | if (i>curmsg) i=curmsg; |
---|
1161 | break; |
---|
1162 | } |
---|
1163 | /* have saved 1/2 the screen space? */ |
---|
1164 | y+=foo; |
---|
1165 | if (y > (recwinlines / 2)) break; |
---|
1166 | } |
---|
1167 | if (i<0) i=0; |
---|
1168 | return(i); |
---|
1169 | } |
---|
1170 | } |
---|
1171 | |
---|
1172 | if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) { |
---|
1173 | /* If curmsg bottom line is more than 3/4 down the screen then scroll down */ |
---|
1174 | if (savey > ((recwinlines * 3)/4)) { |
---|
1175 | y=0; |
---|
1176 | /* count lines from the top until we can save 1/2 the screen size */ |
---|
1177 | for (i=topmsg; i<curmsg; i++) { |
---|
1178 | y+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
1179 | if (y > (recwinlines / 2)) break; |
---|
1180 | } |
---|
1181 | if (i==curmsg) { |
---|
1182 | i--; |
---|
1183 | } |
---|
1184 | return(i+1); |
---|
1185 | } |
---|
1186 | } |
---|
1187 | |
---|
1188 | return(topmsg); |
---|
1189 | } |
---|
1190 | |
---|
1191 | void owl_function_resize(void) |
---|
1192 | { |
---|
1193 | owl_global_set_resize_pending(&g); |
---|
1194 | } |
---|
1195 | |
---|
1196 | void owl_function_debugmsg(const char *fmt, ...) |
---|
1197 | { |
---|
1198 | FILE *file; |
---|
1199 | time_t now; |
---|
1200 | va_list ap; |
---|
1201 | va_start(ap, fmt); |
---|
1202 | |
---|
1203 | if (!owl_global_is_debug_fast(&g)) |
---|
1204 | return; |
---|
1205 | |
---|
1206 | file = fopen(owl_global_get_debug_file(&g), "a"); |
---|
1207 | if (!file) /* XXX should report this */ |
---|
1208 | return; |
---|
1209 | |
---|
1210 | now = time(NULL); |
---|
1211 | |
---|
1212 | fprintf(file, "[%d - %.24s - %lds]: ", |
---|
1213 | (int) getpid(), ctime(&now), now - owl_global_get_starttime(&g)); |
---|
1214 | vfprintf(file, fmt, ap); |
---|
1215 | putc('\n', file); |
---|
1216 | fclose(file); |
---|
1217 | |
---|
1218 | va_end(ap); |
---|
1219 | } |
---|
1220 | |
---|
1221 | void owl_function_beep(void) |
---|
1222 | { |
---|
1223 | if (owl_global_is_bell(&g)) { |
---|
1224 | beep(); |
---|
1225 | owl_global_set_needrefresh(&g); /* do we really need this? */ |
---|
1226 | } |
---|
1227 | } |
---|
1228 | |
---|
1229 | int owl_function_subscribe(const char *class, const char *inst, const char *recip) |
---|
1230 | { |
---|
1231 | int ret; |
---|
1232 | |
---|
1233 | ret=owl_zephyr_sub(class, inst, recip); |
---|
1234 | if (ret) { |
---|
1235 | owl_function_error("Error subscribing."); |
---|
1236 | } else { |
---|
1237 | owl_function_makemsg("Subscribed."); |
---|
1238 | } |
---|
1239 | return(ret); |
---|
1240 | } |
---|
1241 | |
---|
1242 | void owl_function_unsubscribe(const char *class, const char *inst, const char *recip) |
---|
1243 | { |
---|
1244 | int ret; |
---|
1245 | |
---|
1246 | ret=owl_zephyr_unsub(class, inst, recip); |
---|
1247 | if (ret) { |
---|
1248 | owl_function_error("Error subscribing."); |
---|
1249 | } else { |
---|
1250 | owl_function_makemsg("Unsubscribed."); |
---|
1251 | } |
---|
1252 | } |
---|
1253 | |
---|
1254 | void owl_function_set_cursor(WINDOW *win) |
---|
1255 | { |
---|
1256 | /* Be careful that this window is actually empty, otherwise panels get confused */ |
---|
1257 | if (is_wintouched(win)) { |
---|
1258 | owl_function_debugmsg("Warning: owl_function_set_cursor called on dirty window"); |
---|
1259 | update_panels(); |
---|
1260 | } |
---|
1261 | wnoutrefresh(win); |
---|
1262 | } |
---|
1263 | |
---|
1264 | void owl_function_full_redisplay(void) |
---|
1265 | { |
---|
1266 | touchwin(owl_global_get_curs_recwin(&g)); |
---|
1267 | touchwin(owl_global_get_curs_sepwin(&g)); |
---|
1268 | touchwin(owl_global_get_curs_typwin(&g)); |
---|
1269 | touchwin(owl_global_get_curs_msgwin(&g)); |
---|
1270 | |
---|
1271 | sepbar(""); |
---|
1272 | owl_function_makemsg(""); |
---|
1273 | |
---|
1274 | owl_global_set_needrefresh(&g); |
---|
1275 | } |
---|
1276 | |
---|
1277 | void owl_function_popless_text(const char *text) |
---|
1278 | { |
---|
1279 | owl_popwin *pw; |
---|
1280 | owl_viewwin *v; |
---|
1281 | |
---|
1282 | pw=owl_global_get_popwin(&g); |
---|
1283 | v=owl_global_get_viewwin(&g); |
---|
1284 | |
---|
1285 | owl_popwin_up(pw); |
---|
1286 | owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless"); |
---|
1287 | owl_viewwin_init_text(v, owl_popwin_get_curswin(pw), |
---|
1288 | owl_popwin_get_lines(pw), owl_popwin_get_cols(pw), |
---|
1289 | text); |
---|
1290 | owl_viewwin_redisplay(v); |
---|
1291 | owl_global_set_needrefresh(&g); |
---|
1292 | } |
---|
1293 | |
---|
1294 | void owl_function_popless_fmtext(const owl_fmtext *fm) |
---|
1295 | { |
---|
1296 | owl_popwin *pw; |
---|
1297 | owl_viewwin *v; |
---|
1298 | |
---|
1299 | pw=owl_global_get_popwin(&g); |
---|
1300 | v=owl_global_get_viewwin(&g); |
---|
1301 | |
---|
1302 | owl_popwin_up(pw); |
---|
1303 | owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless"); |
---|
1304 | owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw), |
---|
1305 | owl_popwin_get_lines(pw), owl_popwin_get_cols(pw), |
---|
1306 | fm); |
---|
1307 | owl_viewwin_redisplay(v); |
---|
1308 | owl_global_set_needrefresh(&g); |
---|
1309 | } |
---|
1310 | |
---|
1311 | void owl_function_popless_file(const char *filename) |
---|
1312 | { |
---|
1313 | owl_fmtext fm; |
---|
1314 | FILE *file; |
---|
1315 | char *s = NULL; |
---|
1316 | |
---|
1317 | file=fopen(filename, "r"); |
---|
1318 | if (!file) { |
---|
1319 | owl_function_error("Could not open file: %s", filename); |
---|
1320 | return; |
---|
1321 | } |
---|
1322 | |
---|
1323 | owl_fmtext_init_null(&fm); |
---|
1324 | while (owl_getline(&s, file)) |
---|
1325 | owl_fmtext_append_normal(&fm, s); |
---|
1326 | owl_free(s); |
---|
1327 | |
---|
1328 | owl_function_popless_fmtext(&fm); |
---|
1329 | owl_fmtext_cleanup(&fm); |
---|
1330 | fclose(file); |
---|
1331 | } |
---|
1332 | |
---|
1333 | void owl_function_about(void) |
---|
1334 | { |
---|
1335 | owl_function_popless_text( |
---|
1336 | "This is barnowl version " OWL_VERSION_STRING ".\n\n" |
---|
1337 | "barnowl is a fork of the Owl zephyr client, written and\n" |
---|
1338 | "maintained by Alejandro Sedeno and Nelson Elhage at the\n" |
---|
1339 | "Massachusetts Institute of Technology. \n" |
---|
1340 | "\n" |
---|
1341 | "Owl was written by James Kretchmar. The first version, 0.5, was\n" |
---|
1342 | "released in March 2002.\n" |
---|
1343 | "\n" |
---|
1344 | "The name 'owl' was chosen in reference to the owls in the\n" |
---|
1345 | "Harry Potter novels, who are tasked with carrying messages\n" |
---|
1346 | "between Witches and Wizards. The name 'barnowl' was chosen\n" |
---|
1347 | "because we feel our owls should live closer to our ponies.\n" |
---|
1348 | "\n" |
---|
1349 | "Copyright (c) 2006-2010 The BarnOwl Developers. All rights reserved.\n" |
---|
1350 | "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" |
---|
1351 | "Copyright 2002 Massachusetts Institute of Technology\n" |
---|
1352 | "\n" |
---|
1353 | "This program is free software. You can redistribute it and/or\n" |
---|
1354 | "modify under the terms of the Sleepycat License. Use the \n" |
---|
1355 | "':show license' command to display the full license\n" |
---|
1356 | ); |
---|
1357 | } |
---|
1358 | |
---|
1359 | void owl_function_info(void) |
---|
1360 | { |
---|
1361 | const owl_message *m; |
---|
1362 | owl_fmtext fm, attrfm; |
---|
1363 | const owl_view *v; |
---|
1364 | #ifdef HAVE_LIBZEPHYR |
---|
1365 | const ZNotice_t *n; |
---|
1366 | #endif |
---|
1367 | |
---|
1368 | owl_fmtext_init_null(&fm); |
---|
1369 | |
---|
1370 | v=owl_global_get_current_view(&g); |
---|
1371 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
1372 | if (!m || owl_view_get_size(v)==0) { |
---|
1373 | owl_function_error("No message selected\n"); |
---|
1374 | return; |
---|
1375 | } |
---|
1376 | |
---|
1377 | owl_fmtext_append_bold(&fm, "General Information:\n"); |
---|
1378 | owl_fmtext_appendf_normal(&fm, " Msg Id : %i\n", owl_message_get_id(m)); |
---|
1379 | |
---|
1380 | owl_fmtext_append_normal(&fm, " Type : "); |
---|
1381 | owl_fmtext_append_bold(&fm, owl_message_get_type(m)); |
---|
1382 | owl_fmtext_append_normal(&fm, "\n"); |
---|
1383 | |
---|
1384 | if (owl_message_is_direction_in(m)) { |
---|
1385 | owl_fmtext_append_normal(&fm, " Direction : in\n"); |
---|
1386 | } else if (owl_message_is_direction_out(m)) { |
---|
1387 | owl_fmtext_append_normal(&fm, " Direction : out\n"); |
---|
1388 | } else if (owl_message_is_direction_none(m)) { |
---|
1389 | owl_fmtext_append_normal(&fm, " Direction : none\n"); |
---|
1390 | } else { |
---|
1391 | owl_fmtext_append_normal(&fm, " Direction : unknown\n"); |
---|
1392 | } |
---|
1393 | |
---|
1394 | owl_fmtext_appendf_normal(&fm, " Time : %s\n", owl_message_get_timestr(m)); |
---|
1395 | |
---|
1396 | if (!owl_message_is_type_admin(m)) { |
---|
1397 | owl_fmtext_appendf_normal(&fm, " Sender : %s\n", owl_message_get_sender(m)); |
---|
1398 | owl_fmtext_appendf_normal(&fm, " Recipient : %s\n", owl_message_get_recipient(m)); |
---|
1399 | } |
---|
1400 | |
---|
1401 | if (owl_message_is_type_zephyr(m)) { |
---|
1402 | owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n"); |
---|
1403 | |
---|
1404 | owl_fmtext_appendf_normal(&fm, " Class : %s\n", owl_message_get_class(m)); |
---|
1405 | owl_fmtext_appendf_normal(&fm, " Instance : %s\n", owl_message_get_instance(m)); |
---|
1406 | owl_fmtext_appendf_normal(&fm, " Opcode : %s\n", owl_message_get_opcode(m)); |
---|
1407 | #ifdef HAVE_LIBZEPHYR |
---|
1408 | if (owl_message_is_direction_in(m)) { |
---|
1409 | char *ptr, tmpbuff[1024]; |
---|
1410 | int i, j, fields, len; |
---|
1411 | |
---|
1412 | n=owl_message_get_notice(m); |
---|
1413 | |
---|
1414 | if (!owl_message_is_pseudo(m)) { |
---|
1415 | owl_fmtext_append_normal(&fm, " Kind : "); |
---|
1416 | if (n->z_kind==UNSAFE) { |
---|
1417 | owl_fmtext_append_normal(&fm, "UNSAFE\n"); |
---|
1418 | } else if (n->z_kind==UNACKED) { |
---|
1419 | owl_fmtext_append_normal(&fm, "UNACKED\n"); |
---|
1420 | } else if (n->z_kind==ACKED) { |
---|
1421 | owl_fmtext_append_normal(&fm, "ACKED\n"); |
---|
1422 | } else if (n->z_kind==HMACK) { |
---|
1423 | owl_fmtext_append_normal(&fm, "HMACK\n"); |
---|
1424 | } else if (n->z_kind==HMCTL) { |
---|
1425 | owl_fmtext_append_normal(&fm, "HMCTL\n"); |
---|
1426 | } else if (n->z_kind==SERVACK) { |
---|
1427 | owl_fmtext_append_normal(&fm, "SERVACK\n"); |
---|
1428 | } else if (n->z_kind==SERVNAK) { |
---|
1429 | owl_fmtext_append_normal(&fm, "SERVNACK\n"); |
---|
1430 | } else if (n->z_kind==CLIENTACK) { |
---|
1431 | owl_fmtext_append_normal(&fm, "CLIENTACK\n"); |
---|
1432 | } else if (n->z_kind==STAT) { |
---|
1433 | owl_fmtext_append_normal(&fm, "STAT\n"); |
---|
1434 | } else { |
---|
1435 | owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n"); |
---|
1436 | } |
---|
1437 | } |
---|
1438 | owl_fmtext_appendf_normal(&fm, " Host : %s\n", owl_message_get_hostname(m)); |
---|
1439 | |
---|
1440 | if (!owl_message_is_pseudo(m)) { |
---|
1441 | owl_fmtext_append_normal(&fm, "\n"); |
---|
1442 | owl_fmtext_appendf_normal(&fm, " Port : %i\n", ntohs(n->z_port)); |
---|
1443 | owl_fmtext_appendf_normal(&fm, " Auth : %s\n", owl_zephyr_get_authstr(n)); |
---|
1444 | |
---|
1445 | /* FIXME make these more descriptive */ |
---|
1446 | owl_fmtext_appendf_normal(&fm, " Checkd Ath: %i\n", n->z_checked_auth); |
---|
1447 | owl_fmtext_appendf_normal(&fm, " Multi notc: %s\n", n->z_multinotice); |
---|
1448 | owl_fmtext_appendf_normal(&fm, " Num other : %i\n", n->z_num_other_fields); |
---|
1449 | owl_fmtext_appendf_normal(&fm, " Msg Len : %i\n", n->z_message_len); |
---|
1450 | |
---|
1451 | fields=owl_zephyr_get_num_fields(n); |
---|
1452 | owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); |
---|
1453 | |
---|
1454 | for (i=0; i<fields; i++) { |
---|
1455 | ptr=owl_zephyr_get_field_as_utf8(n, i+1); |
---|
1456 | len=strlen(ptr); |
---|
1457 | if (len<30) { |
---|
1458 | strncpy(tmpbuff, ptr, len); |
---|
1459 | tmpbuff[len]='\0'; |
---|
1460 | } else { |
---|
1461 | strncpy(tmpbuff, ptr, 30); |
---|
1462 | tmpbuff[30]='\0'; |
---|
1463 | strcat(tmpbuff, "..."); |
---|
1464 | } |
---|
1465 | owl_free(ptr); |
---|
1466 | |
---|
1467 | for (j=0; j<strlen(tmpbuff); j++) { |
---|
1468 | if (tmpbuff[j]=='\n') tmpbuff[j]='~'; |
---|
1469 | if (tmpbuff[j]=='\r') tmpbuff[j]='!'; |
---|
1470 | } |
---|
1471 | |
---|
1472 | owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i+1, tmpbuff); |
---|
1473 | } |
---|
1474 | owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", n->z_default_format); |
---|
1475 | } |
---|
1476 | |
---|
1477 | } |
---|
1478 | #endif |
---|
1479 | } |
---|
1480 | |
---|
1481 | owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n"); |
---|
1482 | owl_message_attributes_tofmtext(m, &attrfm); |
---|
1483 | owl_fmtext_append_fmtext(&fm, &attrfm); |
---|
1484 | |
---|
1485 | owl_function_popless_fmtext(&fm); |
---|
1486 | owl_fmtext_cleanup(&fm); |
---|
1487 | owl_fmtext_cleanup(&attrfm); |
---|
1488 | } |
---|
1489 | |
---|
1490 | /* print the current message in a popup window. |
---|
1491 | * Use the 'default' style regardless of whatever |
---|
1492 | * style the user may be using |
---|
1493 | */ |
---|
1494 | void owl_function_curmsg_to_popwin(void) |
---|
1495 | { |
---|
1496 | const owl_view *v; |
---|
1497 | const owl_message *m; |
---|
1498 | const owl_style *s; |
---|
1499 | owl_fmtext fm; |
---|
1500 | |
---|
1501 | v=owl_global_get_current_view(&g); |
---|
1502 | s=owl_global_get_style_by_name(&g, "default"); |
---|
1503 | |
---|
1504 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
1505 | |
---|
1506 | if (!m || owl_view_get_size(v)==0) { |
---|
1507 | owl_function_error("No current message"); |
---|
1508 | return; |
---|
1509 | } |
---|
1510 | |
---|
1511 | owl_fmtext_init_null(&fm); |
---|
1512 | owl_style_get_formattext(s, &fm, m); |
---|
1513 | |
---|
1514 | owl_function_popless_fmtext(&fm); |
---|
1515 | owl_fmtext_cleanup(&fm); |
---|
1516 | } |
---|
1517 | |
---|
1518 | void owl_function_page_curmsg(int step) |
---|
1519 | { |
---|
1520 | /* scroll down or up within the current message IF the message is truncated */ |
---|
1521 | |
---|
1522 | int offset, curmsg, lines; |
---|
1523 | const owl_view *v; |
---|
1524 | owl_message *m; |
---|
1525 | |
---|
1526 | offset=owl_global_get_curmsg_vert_offset(&g); |
---|
1527 | v=owl_global_get_current_view(&g); |
---|
1528 | curmsg=owl_global_get_curmsg(&g); |
---|
1529 | m=owl_view_get_element(v, curmsg); |
---|
1530 | if (!m || owl_view_get_size(v)==0) return; |
---|
1531 | lines=owl_message_get_numlines(m); |
---|
1532 | |
---|
1533 | if (offset==0) { |
---|
1534 | /* Bail if the curmsg isn't the last one displayed */ |
---|
1535 | if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) { |
---|
1536 | owl_function_makemsg("The entire message is already displayed"); |
---|
1537 | return; |
---|
1538 | } |
---|
1539 | |
---|
1540 | /* Bail if we're not truncated */ |
---|
1541 | if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) { |
---|
1542 | owl_function_makemsg("The entire message is already displayed"); |
---|
1543 | return; |
---|
1544 | } |
---|
1545 | } |
---|
1546 | |
---|
1547 | |
---|
1548 | /* don't scroll past the last line */ |
---|
1549 | if (step>0) { |
---|
1550 | if (offset+step > lines-1) { |
---|
1551 | owl_global_set_curmsg_vert_offset(&g, lines-1); |
---|
1552 | } else { |
---|
1553 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
1554 | } |
---|
1555 | } |
---|
1556 | |
---|
1557 | /* would we be before the beginning of the message? */ |
---|
1558 | if (step<0) { |
---|
1559 | if (offset+step<0) { |
---|
1560 | owl_global_set_curmsg_vert_offset(&g, 0); |
---|
1561 | } else { |
---|
1562 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
1563 | } |
---|
1564 | } |
---|
1565 | |
---|
1566 | /* redisplay */ |
---|
1567 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
1568 | owl_global_set_needrefresh(&g); |
---|
1569 | } |
---|
1570 | |
---|
1571 | void owl_function_resize_typwin(int newsize) |
---|
1572 | { |
---|
1573 | owl_global_set_typwin_lines(&g, newsize); |
---|
1574 | owl_global_set_relayout_pending(&g); |
---|
1575 | } |
---|
1576 | |
---|
1577 | void owl_function_mainwin_pagedown(void) |
---|
1578 | { |
---|
1579 | int i; |
---|
1580 | |
---|
1581 | i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g)); |
---|
1582 | if (i<0) return; |
---|
1583 | if (owl_mainwin_is_last_msg_truncated(owl_global_get_mainwin(&g)) |
---|
1584 | && (owl_global_get_curmsg(&g) < i) |
---|
1585 | && (i>0)) { |
---|
1586 | i--; |
---|
1587 | } |
---|
1588 | owl_global_set_curmsg(&g, i); |
---|
1589 | owl_function_nextmsg(); |
---|
1590 | } |
---|
1591 | |
---|
1592 | void owl_function_mainwin_pageup(void) |
---|
1593 | { |
---|
1594 | owl_global_set_curmsg(&g, owl_global_get_topmsg(&g)); |
---|
1595 | owl_function_prevmsg(); |
---|
1596 | } |
---|
1597 | |
---|
1598 | void owl_function_getsubs(void) |
---|
1599 | { |
---|
1600 | char *buff; |
---|
1601 | |
---|
1602 | buff=owl_zephyr_getsubs(); |
---|
1603 | |
---|
1604 | if (buff) { |
---|
1605 | owl_function_popless_text(buff); |
---|
1606 | } else { |
---|
1607 | owl_function_popless_text("Error getting subscriptions"); |
---|
1608 | } |
---|
1609 | |
---|
1610 | owl_free(buff); |
---|
1611 | } |
---|
1612 | |
---|
1613 | void owl_function_printallvars(void) |
---|
1614 | { |
---|
1615 | const char *name; |
---|
1616 | char var[LINE]; |
---|
1617 | owl_list varnames; |
---|
1618 | int i, numvarnames; |
---|
1619 | GString *str = g_string_new(""); |
---|
1620 | |
---|
1621 | g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); |
---|
1622 | g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); |
---|
1623 | owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); |
---|
1624 | numvarnames = owl_list_get_size(&varnames); |
---|
1625 | for (i=0; i<numvarnames; i++) { |
---|
1626 | name = owl_list_get_element(&varnames, i); |
---|
1627 | if (name && name[0]!='_') { |
---|
1628 | g_string_append_printf(str, "\n%-20s = ", name); |
---|
1629 | owl_variable_get_tostring(owl_global_get_vardict(&g), name, var, LINE); |
---|
1630 | g_string_append(str, var); |
---|
1631 | } |
---|
1632 | } |
---|
1633 | g_string_append(str, "\n"); |
---|
1634 | owl_variable_dict_namelist_cleanup(&varnames); |
---|
1635 | |
---|
1636 | owl_function_popless_text(str->str); |
---|
1637 | g_string_free(str, TRUE); |
---|
1638 | } |
---|
1639 | |
---|
1640 | void owl_function_show_variables(void) |
---|
1641 | { |
---|
1642 | owl_list varnames; |
---|
1643 | owl_fmtext fm; |
---|
1644 | int i, numvarnames; |
---|
1645 | const char *varname; |
---|
1646 | |
---|
1647 | owl_fmtext_init_null(&fm); |
---|
1648 | owl_fmtext_append_bold(&fm, |
---|
1649 | "Variables: (use 'show variable <name>' for details)\n"); |
---|
1650 | owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); |
---|
1651 | numvarnames = owl_list_get_size(&varnames); |
---|
1652 | for (i=0; i<numvarnames; i++) { |
---|
1653 | varname = owl_list_get_element(&varnames, i); |
---|
1654 | if (varname && varname[0]!='_') { |
---|
1655 | owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); |
---|
1656 | } |
---|
1657 | } |
---|
1658 | owl_variable_dict_namelist_cleanup(&varnames); |
---|
1659 | owl_function_popless_fmtext(&fm); |
---|
1660 | owl_fmtext_cleanup(&fm); |
---|
1661 | } |
---|
1662 | |
---|
1663 | void owl_function_show_variable(const char *name) |
---|
1664 | { |
---|
1665 | owl_fmtext fm; |
---|
1666 | |
---|
1667 | owl_fmtext_init_null(&fm); |
---|
1668 | owl_variable_get_help(owl_global_get_vardict(&g), name, &fm); |
---|
1669 | owl_function_popless_fmtext(&fm); |
---|
1670 | owl_fmtext_cleanup(&fm); |
---|
1671 | } |
---|
1672 | |
---|
1673 | /* note: this applies to global message list, not to view. |
---|
1674 | * If flag is 1, deletes. If flag is 0, undeletes. */ |
---|
1675 | void owl_function_delete_by_id(int id, int flag) |
---|
1676 | { |
---|
1677 | const owl_messagelist *ml; |
---|
1678 | owl_message *m; |
---|
1679 | ml = owl_global_get_msglist(&g); |
---|
1680 | m = owl_messagelist_get_by_id(ml, id); |
---|
1681 | if (m) { |
---|
1682 | if (flag == 1) { |
---|
1683 | owl_message_mark_delete(m); |
---|
1684 | } else if (flag == 0) { |
---|
1685 | owl_message_unmark_delete(m); |
---|
1686 | } |
---|
1687 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
1688 | owl_global_set_needrefresh(&g); |
---|
1689 | } else { |
---|
1690 | owl_function_error("No message with id %d: unable to mark for (un)delete",id); |
---|
1691 | } |
---|
1692 | } |
---|
1693 | |
---|
1694 | void owl_function_delete_automsgs(void) |
---|
1695 | { |
---|
1696 | /* mark for deletion all messages in the current view that match the |
---|
1697 | * 'trash' filter */ |
---|
1698 | |
---|
1699 | int i, j, count; |
---|
1700 | owl_message *m; |
---|
1701 | const owl_view *v; |
---|
1702 | const owl_filter *f; |
---|
1703 | |
---|
1704 | /* get the trash filter */ |
---|
1705 | f=owl_global_get_filter(&g, "trash"); |
---|
1706 | if (!f) { |
---|
1707 | owl_function_error("No trash filter defined"); |
---|
1708 | return; |
---|
1709 | } |
---|
1710 | |
---|
1711 | v=owl_global_get_current_view(&g); |
---|
1712 | |
---|
1713 | count=0; |
---|
1714 | j=owl_view_get_size(v); |
---|
1715 | for (i=0; i<j; i++) { |
---|
1716 | m=owl_view_get_element(v, i); |
---|
1717 | if (owl_filter_message_match(f, m)) { |
---|
1718 | count++; |
---|
1719 | owl_message_mark_delete(m); |
---|
1720 | } |
---|
1721 | } |
---|
1722 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
1723 | owl_function_makemsg("%i messages marked for deletion", count); |
---|
1724 | owl_global_set_needrefresh(&g); |
---|
1725 | } |
---|
1726 | |
---|
1727 | void owl_function_status(void) |
---|
1728 | { |
---|
1729 | char buff[MAXPATHLEN+1]; |
---|
1730 | time_t start; |
---|
1731 | int up, days, hours, minutes; |
---|
1732 | owl_fmtext fm; |
---|
1733 | |
---|
1734 | owl_fmtext_init_null(&fm); |
---|
1735 | |
---|
1736 | start=owl_global_get_starttime(&g); |
---|
1737 | |
---|
1738 | owl_fmtext_append_normal(&fm, "General Information:\n"); |
---|
1739 | |
---|
1740 | owl_fmtext_append_normal(&fm, " Version: "); |
---|
1741 | owl_fmtext_append_normal(&fm, OWL_VERSION_STRING); |
---|
1742 | owl_fmtext_append_normal(&fm, "\n"); |
---|
1743 | |
---|
1744 | owl_fmtext_append_normal(&fm, " Startup Arguments: "); |
---|
1745 | owl_fmtext_append_normal(&fm, owl_global_get_startupargs(&g)); |
---|
1746 | owl_fmtext_append_normal(&fm, "\n"); |
---|
1747 | |
---|
1748 | owl_fmtext_append_normal(&fm, " Current Directory: "); |
---|
1749 | if(getcwd(buff, MAXPATHLEN) == NULL) { |
---|
1750 | owl_fmtext_append_normal(&fm, "<Error in getcwd>"); |
---|
1751 | } else { |
---|
1752 | owl_fmtext_append_normal(&fm, buff); |
---|
1753 | } |
---|
1754 | owl_fmtext_append_normal(&fm, "\n"); |
---|
1755 | |
---|
1756 | owl_fmtext_appendf_normal(&fm, " Startup Time: %s", ctime(&start)); |
---|
1757 | |
---|
1758 | up=owl_global_get_runtime(&g); |
---|
1759 | days=up/86400; |
---|
1760 | up-=days*86400; |
---|
1761 | hours=up/3600; |
---|
1762 | up-=hours*3600; |
---|
1763 | minutes=up/60; |
---|
1764 | up-=minutes*60; |
---|
1765 | owl_fmtext_appendf_normal(&fm, " Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up); |
---|
1766 | |
---|
1767 | owl_fmtext_append_normal(&fm, "\nProtocol Options:\n"); |
---|
1768 | owl_fmtext_append_normal(&fm, " Zephyr included : "); |
---|
1769 | if (owl_global_is_havezephyr(&g)) { |
---|
1770 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
1771 | } else { |
---|
1772 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
1773 | } |
---|
1774 | owl_fmtext_append_normal(&fm, " AIM included : yes\n"); |
---|
1775 | owl_fmtext_append_normal(&fm, " Loopback included : yes\n"); |
---|
1776 | |
---|
1777 | |
---|
1778 | owl_fmtext_append_normal(&fm, "\nBuild Options:\n"); |
---|
1779 | owl_fmtext_append_normal(&fm, " Stderr redirection : "); |
---|
1780 | #if OWL_STDERR_REDIR |
---|
1781 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
1782 | #else |
---|
1783 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
1784 | #endif |
---|
1785 | |
---|
1786 | |
---|
1787 | owl_fmtext_append_normal(&fm, "\nAIM Status:\n"); |
---|
1788 | owl_fmtext_append_normal(&fm, " Logged in: "); |
---|
1789 | if (owl_global_is_aimloggedin(&g)) { |
---|
1790 | owl_fmtext_append_normal(&fm, owl_global_get_aim_screenname(&g)); |
---|
1791 | owl_fmtext_append_normal(&fm, "\n"); |
---|
1792 | } else { |
---|
1793 | owl_fmtext_append_normal(&fm, "(not logged in)\n"); |
---|
1794 | } |
---|
1795 | |
---|
1796 | owl_fmtext_append_normal(&fm, " Processing events: "); |
---|
1797 | if (owl_global_is_doaimevents(&g)) { |
---|
1798 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
1799 | } else { |
---|
1800 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
1801 | } |
---|
1802 | |
---|
1803 | owl_function_popless_fmtext(&fm); |
---|
1804 | owl_fmtext_cleanup(&fm); |
---|
1805 | } |
---|
1806 | |
---|
1807 | void owl_function_show_term(void) |
---|
1808 | { |
---|
1809 | owl_fmtext fm; |
---|
1810 | |
---|
1811 | owl_fmtext_init_null(&fm); |
---|
1812 | owl_fmtext_appendf_normal(&fm, "Terminal Lines: %i\nTerminal Columns: %i\n", |
---|
1813 | owl_global_get_lines(&g), |
---|
1814 | owl_global_get_cols(&g)); |
---|
1815 | |
---|
1816 | if (owl_global_get_hascolors(&g)) { |
---|
1817 | owl_fmtext_append_normal(&fm, "Color: Yes\n"); |
---|
1818 | owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g)); |
---|
1819 | owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); |
---|
1820 | } else { |
---|
1821 | owl_fmtext_append_normal(&fm, "Color: No\n"); |
---|
1822 | } |
---|
1823 | |
---|
1824 | owl_function_popless_fmtext(&fm); |
---|
1825 | owl_fmtext_cleanup(&fm); |
---|
1826 | } |
---|
1827 | |
---|
1828 | /* if type = 0 then normal reply. |
---|
1829 | * if type = 1 then it's a reply to sender |
---|
1830 | * if enter = 0 then allow the command to be edited |
---|
1831 | * if enter = 1 then don't wait for editing |
---|
1832 | */ |
---|
1833 | void owl_function_reply(int type, int enter) |
---|
1834 | { |
---|
1835 | char *buff=NULL; |
---|
1836 | const owl_message *m; |
---|
1837 | const owl_filter *f; |
---|
1838 | |
---|
1839 | if (owl_view_get_size(owl_global_get_current_view(&g))==0) { |
---|
1840 | owl_function_error("No message selected"); |
---|
1841 | } else { |
---|
1842 | char *cmd; |
---|
1843 | |
---|
1844 | m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g)); |
---|
1845 | if (!m) { |
---|
1846 | owl_function_error("No message selected"); |
---|
1847 | return; |
---|
1848 | } |
---|
1849 | |
---|
1850 | /* first check if we catch the reply-lockout filter */ |
---|
1851 | f=owl_global_get_filter(&g, "reply-lockout"); |
---|
1852 | if (f) { |
---|
1853 | if (owl_filter_message_match(f, m)) { |
---|
1854 | owl_function_error("Sorry, replies to this message have been disabled by the reply-lockout filter"); |
---|
1855 | return; |
---|
1856 | } |
---|
1857 | } |
---|
1858 | |
---|
1859 | /* then check if it's a question and just bring up the command prompt */ |
---|
1860 | if (owl_message_is_question(m)) { |
---|
1861 | owl_function_start_command(""); |
---|
1862 | return; |
---|
1863 | } |
---|
1864 | |
---|
1865 | if((type == 0 && |
---|
1866 | (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) || |
---|
1867 | (type == 1 && |
---|
1868 | (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) { |
---|
1869 | buff = cmd; |
---|
1870 | } |
---|
1871 | |
---|
1872 | if(!buff) { |
---|
1873 | owl_function_error("I don't know how to reply to that message."); |
---|
1874 | return; |
---|
1875 | } |
---|
1876 | |
---|
1877 | if (enter) { |
---|
1878 | owl_history *hist = owl_global_get_cmd_history(&g); |
---|
1879 | owl_history_store(hist, buff); |
---|
1880 | owl_history_reset(hist); |
---|
1881 | owl_function_command_norv(buff); |
---|
1882 | } else { |
---|
1883 | owl_function_start_command(buff); |
---|
1884 | } |
---|
1885 | owl_free(buff); |
---|
1886 | } |
---|
1887 | } |
---|
1888 | |
---|
1889 | void owl_function_zlocate(int argc, const char *const *argv, int auth) |
---|
1890 | { |
---|
1891 | owl_fmtext fm; |
---|
1892 | char *ptr; |
---|
1893 | char *result; |
---|
1894 | int i; |
---|
1895 | |
---|
1896 | owl_fmtext_init_null(&fm); |
---|
1897 | |
---|
1898 | for (i=0; i<argc; i++) { |
---|
1899 | ptr = long_zuser(argv[i]); |
---|
1900 | result = owl_zephyr_zlocate(ptr, auth); |
---|
1901 | owl_fmtext_append_normal(&fm, result); |
---|
1902 | owl_free(result); |
---|
1903 | owl_free(ptr); |
---|
1904 | } |
---|
1905 | |
---|
1906 | owl_function_popless_fmtext(&fm); |
---|
1907 | owl_fmtext_cleanup(&fm); |
---|
1908 | } |
---|
1909 | |
---|
1910 | void owl_callback_command(owl_editwin *e) |
---|
1911 | { |
---|
1912 | char *rv; |
---|
1913 | const char *line = owl_editwin_get_text(e); |
---|
1914 | |
---|
1915 | rv = owl_function_command(line); |
---|
1916 | if (rv) { |
---|
1917 | owl_function_makemsg("%s", rv); |
---|
1918 | owl_free(rv); |
---|
1919 | } |
---|
1920 | } |
---|
1921 | |
---|
1922 | void owl_function_start_command(const char *line) |
---|
1923 | { |
---|
1924 | owl_editwin *tw; |
---|
1925 | |
---|
1926 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
1927 | |
---|
1928 | owl_editwin_set_locktext(tw, "command: "); |
---|
1929 | owl_global_set_needrefresh(&g); |
---|
1930 | |
---|
1931 | owl_editwin_insert_string(tw, line); |
---|
1932 | owl_editwin_redisplay(tw); |
---|
1933 | |
---|
1934 | owl_global_push_context(&g, OWL_CTX_EDITLINE, tw, "editline"); |
---|
1935 | owl_editwin_set_callback(tw, owl_callback_command); |
---|
1936 | } |
---|
1937 | |
---|
1938 | owl_editwin *owl_function_start_question(const char *line) |
---|
1939 | { |
---|
1940 | owl_editwin *tw; |
---|
1941 | |
---|
1942 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
1943 | |
---|
1944 | owl_editwin_set_locktext(tw, line); |
---|
1945 | owl_global_set_needrefresh(&g); |
---|
1946 | |
---|
1947 | owl_editwin_redisplay(tw); |
---|
1948 | |
---|
1949 | owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse"); |
---|
1950 | return tw; |
---|
1951 | } |
---|
1952 | |
---|
1953 | owl_editwin *owl_function_start_password(const char *line) |
---|
1954 | { |
---|
1955 | owl_editwin *tw; |
---|
1956 | |
---|
1957 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, NULL); |
---|
1958 | |
---|
1959 | owl_editwin_set_echochar(tw, '*'); |
---|
1960 | |
---|
1961 | owl_editwin_set_locktext(tw, line); |
---|
1962 | owl_global_set_needrefresh(&g); |
---|
1963 | |
---|
1964 | owl_editwin_redisplay(tw); |
---|
1965 | |
---|
1966 | owl_global_push_context(&g, OWL_CTX_EDITRESPONSE, tw, "editresponse"); |
---|
1967 | return tw; |
---|
1968 | } |
---|
1969 | |
---|
1970 | char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type) |
---|
1971 | { |
---|
1972 | /* if type == 1 display in a popup |
---|
1973 | * if type == 2 display an admin messages |
---|
1974 | * if type == 0 return output |
---|
1975 | * else display in a popup |
---|
1976 | */ |
---|
1977 | const char *redirect = " 2>&1 < /dev/null"; |
---|
1978 | char *newbuff; |
---|
1979 | char *out; |
---|
1980 | FILE *p; |
---|
1981 | |
---|
1982 | #if OWL_STDERR_REDIR |
---|
1983 | redirect = " < /dev/null"; |
---|
1984 | #endif |
---|
1985 | |
---|
1986 | if (argc<2) { |
---|
1987 | owl_function_error("Wrong number of arguments to the exec command"); |
---|
1988 | return NULL; |
---|
1989 | } |
---|
1990 | |
---|
1991 | buff = skiptokens(buff, 1); |
---|
1992 | newbuff = owl_sprintf("%s%s", buff, redirect); |
---|
1993 | |
---|
1994 | if (type == 1) { |
---|
1995 | owl_popexec_new(newbuff); |
---|
1996 | } else { |
---|
1997 | p = popen(newbuff, "r"); |
---|
1998 | out = owl_slurp(p); |
---|
1999 | pclose(p); |
---|
2000 | |
---|
2001 | if (type==1) { |
---|
2002 | owl_function_popless_text(out); |
---|
2003 | } else if (type==0) { |
---|
2004 | owl_free(newbuff); |
---|
2005 | return out; |
---|
2006 | } else if (type==2) { |
---|
2007 | owl_function_adminmsg(buff, out); |
---|
2008 | } else { |
---|
2009 | owl_function_popless_text(out); |
---|
2010 | } |
---|
2011 | owl_free(out); |
---|
2012 | } |
---|
2013 | owl_free(newbuff); |
---|
2014 | return NULL; |
---|
2015 | } |
---|
2016 | |
---|
2017 | char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type) |
---|
2018 | { |
---|
2019 | /* if type == 1 display in a popup |
---|
2020 | * if type == 2 display an admin messages |
---|
2021 | * if type == 0 return output |
---|
2022 | * else display in a popup |
---|
2023 | */ |
---|
2024 | char *perlout; |
---|
2025 | |
---|
2026 | if (argc<2) { |
---|
2027 | owl_function_error("Wrong number of arguments to perl command"); |
---|
2028 | return NULL; |
---|
2029 | } |
---|
2030 | |
---|
2031 | /* consume first token (argv[0]) */ |
---|
2032 | buff = skiptokens(buff, 1); |
---|
2033 | |
---|
2034 | perlout = owl_perlconfig_execute(buff); |
---|
2035 | if (perlout) { |
---|
2036 | if (type==1) { |
---|
2037 | owl_function_popless_text(perlout); |
---|
2038 | } else if (type==2) { |
---|
2039 | owl_function_adminmsg(buff, perlout); |
---|
2040 | } else if (type==0) { |
---|
2041 | return perlout; |
---|
2042 | } else { |
---|
2043 | owl_function_popless_text(perlout); |
---|
2044 | } |
---|
2045 | owl_free(perlout); |
---|
2046 | } |
---|
2047 | return NULL; |
---|
2048 | } |
---|
2049 | |
---|
2050 | /* Change the filter associated with the current view. |
---|
2051 | * This also figures out which message in the new filter |
---|
2052 | * should have the pointer. |
---|
2053 | */ |
---|
2054 | void owl_function_change_currentview_filter(const char *filtname) |
---|
2055 | { |
---|
2056 | owl_view *v; |
---|
2057 | owl_filter *f; |
---|
2058 | int curid=-1, newpos, curmsg; |
---|
2059 | const owl_message *curm=NULL; |
---|
2060 | |
---|
2061 | v=owl_global_get_current_view(&g); |
---|
2062 | |
---|
2063 | curmsg=owl_global_get_curmsg(&g); |
---|
2064 | if (curmsg==-1) { |
---|
2065 | owl_function_debugmsg("Hit the curmsg==-1 case in change_view"); |
---|
2066 | } else { |
---|
2067 | curm=owl_view_get_element(v, curmsg); |
---|
2068 | if (curm) { |
---|
2069 | curid=owl_message_get_id(curm); |
---|
2070 | owl_view_save_curmsgid(v, curid); |
---|
2071 | } |
---|
2072 | } |
---|
2073 | |
---|
2074 | f=owl_global_get_filter(&g, filtname); |
---|
2075 | if (!f) { |
---|
2076 | owl_function_error("Unknown filter %s", filtname); |
---|
2077 | return; |
---|
2078 | } |
---|
2079 | |
---|
2080 | owl_view_new_filter(v, f); |
---|
2081 | |
---|
2082 | /* Figure out what to set the current message to. |
---|
2083 | * - If the view we're leaving has messages in it, go to the closest message |
---|
2084 | * to the last message pointed to in that view. |
---|
2085 | * - If the view we're leaving is empty, try to restore the position |
---|
2086 | * from the last time we were in the new view. */ |
---|
2087 | if (curm) { |
---|
2088 | newpos = owl_view_get_nearest_to_msgid(v, curid); |
---|
2089 | } else { |
---|
2090 | newpos = owl_view_get_nearest_to_saved(v); |
---|
2091 | } |
---|
2092 | |
---|
2093 | owl_global_set_curmsg(&g, newpos); |
---|
2094 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
2095 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2096 | owl_global_set_direction_downwards(&g); |
---|
2097 | } |
---|
2098 | |
---|
2099 | /* Create a new filter, or replace an existing one |
---|
2100 | * with a new definition. |
---|
2101 | */ |
---|
2102 | void owl_function_create_filter(int argc, const char *const *argv) |
---|
2103 | { |
---|
2104 | owl_filter *f; |
---|
2105 | const owl_view *v; |
---|
2106 | int inuse = 0; |
---|
2107 | |
---|
2108 | if (argc < 2) { |
---|
2109 | owl_function_error("Wrong number of arguments to filter command"); |
---|
2110 | return; |
---|
2111 | } |
---|
2112 | |
---|
2113 | owl_function_debugmsg("owl_function_create_filter: starting to create filter named %s", argv[1]); |
---|
2114 | |
---|
2115 | v=owl_global_get_current_view(&g); |
---|
2116 | |
---|
2117 | /* don't touch the all filter */ |
---|
2118 | if (!strcmp(argv[1], "all")) { |
---|
2119 | owl_function_error("You may not change the 'all' filter."); |
---|
2120 | return; |
---|
2121 | } |
---|
2122 | |
---|
2123 | /* deal with the case of trying change the filter color */ |
---|
2124 | if (argc==4 && !strcmp(argv[2], "-c")) { |
---|
2125 | f=owl_global_get_filter(&g, argv[1]); |
---|
2126 | if (!f) { |
---|
2127 | owl_function_error("The filter '%s' does not exist.", argv[1]); |
---|
2128 | return; |
---|
2129 | } |
---|
2130 | if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { |
---|
2131 | owl_function_error("The color '%s' is not available.", argv[3]); |
---|
2132 | return; |
---|
2133 | } |
---|
2134 | owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3])); |
---|
2135 | owl_global_set_needrefresh(&g); |
---|
2136 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2137 | return; |
---|
2138 | } |
---|
2139 | if (argc==4 && !strcmp(argv[2], "-b")) { |
---|
2140 | f=owl_global_get_filter(&g, argv[1]); |
---|
2141 | if (!f) { |
---|
2142 | owl_function_error("The filter '%s' does not exist.", argv[1]); |
---|
2143 | return; |
---|
2144 | } |
---|
2145 | if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { |
---|
2146 | owl_function_error("The color '%s' is not available.", argv[3]); |
---|
2147 | return; |
---|
2148 | } |
---|
2149 | owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3])); |
---|
2150 | owl_global_set_needrefresh(&g); |
---|
2151 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2152 | return; |
---|
2153 | } |
---|
2154 | |
---|
2155 | /* create the filter and check for errors */ |
---|
2156 | f = owl_filter_new(argv[1], argc-2, argv+2); |
---|
2157 | if (f == NULL) { |
---|
2158 | owl_function_error("Invalid filter"); |
---|
2159 | return; |
---|
2160 | } |
---|
2161 | |
---|
2162 | /* if the named filter is in use by the current view, remember it */ |
---|
2163 | if (!strcmp(owl_view_get_filtname(v), argv[1])) { |
---|
2164 | inuse=1; |
---|
2165 | } |
---|
2166 | |
---|
2167 | /* if the named filter already exists, nuke it */ |
---|
2168 | if (owl_global_get_filter(&g, argv[1])) { |
---|
2169 | owl_global_remove_filter(&g, argv[1]); |
---|
2170 | } |
---|
2171 | |
---|
2172 | /* add the filter */ |
---|
2173 | owl_global_add_filter(&g, f); |
---|
2174 | |
---|
2175 | /* if it was in use by the current view then update */ |
---|
2176 | if (inuse) { |
---|
2177 | owl_function_change_currentview_filter(argv[1]); |
---|
2178 | } |
---|
2179 | owl_global_set_needrefresh(&g); |
---|
2180 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2181 | } |
---|
2182 | |
---|
2183 | /* If 'filtername' does not start with 'not-' create a filter named |
---|
2184 | * 'not-<filtername>' defined as "not filter <filtername>". If the |
---|
2185 | * filter 'not-<filtername>' already exists, do not overwrite it. If |
---|
2186 | * 'filtername' begins with 'not-' and a filter 'filtername' already |
---|
2187 | * exists, then do nothing. If the filter 'filtername' does not |
---|
2188 | * exist, create it and define it as 'not filter <filtername>' |
---|
2189 | * |
---|
2190 | * Returns the name of the negated filter, which the caller must free. |
---|
2191 | */ |
---|
2192 | char *owl_function_create_negative_filter(const char *filtername) |
---|
2193 | { |
---|
2194 | char *newname; |
---|
2195 | const owl_filter *tmpfilt; |
---|
2196 | const char *argv[5]; |
---|
2197 | |
---|
2198 | owl_function_debugmsg("owl_function_create_negative_filter"); |
---|
2199 | |
---|
2200 | if (!strncmp(filtername, "not-", 4)) { |
---|
2201 | newname=owl_strdup(filtername+4); |
---|
2202 | } else { |
---|
2203 | newname=owl_sprintf("not-%s", filtername); |
---|
2204 | } |
---|
2205 | |
---|
2206 | tmpfilt=owl_global_get_filter(&g, newname); |
---|
2207 | if (!tmpfilt) { |
---|
2208 | argv[0]="filter"; /* anything is fine here */ |
---|
2209 | argv[1]=newname; |
---|
2210 | argv[2]="not"; |
---|
2211 | argv[3]="filter"; |
---|
2212 | argv[4]=filtername; |
---|
2213 | owl_function_create_filter(5, argv); |
---|
2214 | } |
---|
2215 | |
---|
2216 | owl_function_debugmsg("owl_function_create_negative_filter: returning with %s", newname); |
---|
2217 | return(newname); |
---|
2218 | } |
---|
2219 | |
---|
2220 | void owl_function_show_filters(void) |
---|
2221 | { |
---|
2222 | const owl_filter *f; |
---|
2223 | GList *fl; |
---|
2224 | owl_fmtext fm; |
---|
2225 | |
---|
2226 | owl_fmtext_init_null(&fm); |
---|
2227 | |
---|
2228 | owl_fmtext_append_bold(&fm, "Filters:\n"); |
---|
2229 | |
---|
2230 | for (fl = g.filterlist; fl; fl = g_list_next(fl)) { |
---|
2231 | f = fl->data; |
---|
2232 | owl_fmtext_append_normal(&fm, " "); |
---|
2233 | if (owl_global_get_hascolors(&g)) { |
---|
2234 | owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f)); |
---|
2235 | } else { |
---|
2236 | owl_fmtext_append_normal(&fm, owl_filter_get_name(f)); |
---|
2237 | } |
---|
2238 | owl_fmtext_append_normal(&fm, "\n"); |
---|
2239 | } |
---|
2240 | owl_function_popless_fmtext(&fm); |
---|
2241 | owl_fmtext_cleanup(&fm); |
---|
2242 | } |
---|
2243 | |
---|
2244 | void owl_function_show_filter(const char *name) |
---|
2245 | { |
---|
2246 | const owl_filter *f; |
---|
2247 | char *buff, *tmp; |
---|
2248 | |
---|
2249 | f=owl_global_get_filter(&g, name); |
---|
2250 | if (!f) { |
---|
2251 | owl_function_error("There is no filter named %s", name); |
---|
2252 | return; |
---|
2253 | } |
---|
2254 | tmp = owl_filter_print(f); |
---|
2255 | buff = owl_sprintf("%s: %s", owl_filter_get_name(f), tmp); |
---|
2256 | owl_function_popless_text(buff); |
---|
2257 | owl_free(buff); |
---|
2258 | owl_free(tmp); |
---|
2259 | } |
---|
2260 | |
---|
2261 | void owl_function_show_zpunts(void) |
---|
2262 | { |
---|
2263 | const owl_filter *f; |
---|
2264 | const owl_list *fl; |
---|
2265 | char buff[5000]; |
---|
2266 | char *tmp; |
---|
2267 | owl_fmtext fm; |
---|
2268 | int i, j; |
---|
2269 | |
---|
2270 | owl_fmtext_init_null(&fm); |
---|
2271 | |
---|
2272 | fl=owl_global_get_puntlist(&g); |
---|
2273 | j=owl_list_get_size(fl); |
---|
2274 | owl_fmtext_append_bold(&fm, "Active zpunt filters:\n"); |
---|
2275 | |
---|
2276 | for (i=0; i<j; i++) { |
---|
2277 | f=owl_list_get_element(fl, i); |
---|
2278 | snprintf(buff, sizeof(buff), "[% 2d] ", i+1); |
---|
2279 | owl_fmtext_append_normal(&fm, buff); |
---|
2280 | tmp = owl_filter_print(f); |
---|
2281 | owl_fmtext_append_normal(&fm, tmp); |
---|
2282 | owl_free(tmp); |
---|
2283 | } |
---|
2284 | owl_function_popless_fmtext(&fm); |
---|
2285 | owl_fmtext_cleanup(&fm); |
---|
2286 | } |
---|
2287 | |
---|
2288 | /* Create a filter for a class, instance if one doesn't exist. If |
---|
2289 | * instance is NULL then catch all messgaes in the class. Returns the |
---|
2290 | * name of the filter, which the caller must free. |
---|
2291 | * If 'related' is nonzero, encompass unclasses and .d classes as well. |
---|
2292 | */ |
---|
2293 | char *owl_function_classinstfilt(const char *c, const char *i, int related) |
---|
2294 | { |
---|
2295 | owl_filter *f; |
---|
2296 | char *argbuff, *filtname; |
---|
2297 | char *tmpclass, *tmpinstance = NULL; |
---|
2298 | char *class, *instance = NULL; |
---|
2299 | |
---|
2300 | if (related) { |
---|
2301 | class = owl_util_baseclass(c); |
---|
2302 | if (i) { |
---|
2303 | instance = owl_util_baseclass(i); |
---|
2304 | } |
---|
2305 | } else { |
---|
2306 | class = owl_strdup(c); |
---|
2307 | if (i) { |
---|
2308 | instance = owl_strdup(i); |
---|
2309 | } |
---|
2310 | } |
---|
2311 | |
---|
2312 | /* name for the filter */ |
---|
2313 | if (!instance) { |
---|
2314 | filtname = owl_sprintf("%sclass-%s", related ? "related-" : "", class); |
---|
2315 | } else { |
---|
2316 | filtname = owl_sprintf("%sclass-%s-instance-%s", related ? "related-" : "", class, instance); |
---|
2317 | } |
---|
2318 | /* downcase it */ |
---|
2319 | { |
---|
2320 | char *temp = g_utf8_strdown(filtname, -1); |
---|
2321 | if (temp) { |
---|
2322 | owl_free(filtname); |
---|
2323 | filtname = temp; |
---|
2324 | } |
---|
2325 | } |
---|
2326 | /* turn spaces, single quotes, and double quotes into dots */ |
---|
2327 | owl_text_tr(filtname, ' ', '.'); |
---|
2328 | owl_text_tr(filtname, '\'', '.'); |
---|
2329 | owl_text_tr(filtname, '"', '.'); |
---|
2330 | |
---|
2331 | /* if it already exists then go with it. This lets users override */ |
---|
2332 | if (owl_global_get_filter(&g, filtname)) { |
---|
2333 | return(filtname); |
---|
2334 | } |
---|
2335 | |
---|
2336 | /* create the new filter */ |
---|
2337 | tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2338 | owl_text_tr(tmpclass, ' ', '.'); |
---|
2339 | owl_text_tr(tmpclass, '\'', '.'); |
---|
2340 | owl_text_tr(tmpclass, '"', '.'); |
---|
2341 | if (instance) { |
---|
2342 | tmpinstance=owl_text_quote(instance, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2343 | owl_text_tr(tmpinstance, ' ', '.'); |
---|
2344 | owl_text_tr(tmpinstance, '\'', '.'); |
---|
2345 | owl_text_tr(tmpinstance, '"', '.'); |
---|
2346 | } |
---|
2347 | |
---|
2348 | argbuff = owl_sprintf(related ? "class ^(un)*%s(\\.d)*$" : "class ^%s$", tmpclass); |
---|
2349 | if (tmpinstance) { |
---|
2350 | char *tmp = argbuff; |
---|
2351 | argbuff = owl_sprintf(related ? "%s and ( instance ^(un)*%s(\\.d)*$ )" : "%s and instance ^%s$", tmp, tmpinstance); |
---|
2352 | owl_free(tmp); |
---|
2353 | } |
---|
2354 | owl_free(tmpclass); |
---|
2355 | if (tmpinstance) owl_free(tmpinstance); |
---|
2356 | |
---|
2357 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
2358 | |
---|
2359 | /* add it to the global list */ |
---|
2360 | owl_global_add_filter(&g, f); |
---|
2361 | |
---|
2362 | owl_free(argbuff); |
---|
2363 | owl_free(class); |
---|
2364 | if (instance) { |
---|
2365 | owl_free(instance); |
---|
2366 | } |
---|
2367 | return(filtname); |
---|
2368 | } |
---|
2369 | |
---|
2370 | /* Create a filter for personal zephyrs to or from the specified |
---|
2371 | * zephyr user. Includes login/logout notifications for the user. |
---|
2372 | * The name of the filter will be 'user-<user>'. If a filter already |
---|
2373 | * exists with this name, no new filter will be created. This allows |
---|
2374 | * the configuration to override this function. Returns the name of |
---|
2375 | * the filter, which the caller must free. |
---|
2376 | */ |
---|
2377 | char *owl_function_zuserfilt(const char *user) |
---|
2378 | { |
---|
2379 | owl_filter *f; |
---|
2380 | char *argbuff, *longuser, *esclonguser, *shortuser, *filtname; |
---|
2381 | |
---|
2382 | /* stick the local realm on if it's not there */ |
---|
2383 | longuser=long_zuser(user); |
---|
2384 | shortuser=short_zuser(user); |
---|
2385 | |
---|
2386 | /* name for the filter */ |
---|
2387 | filtname=owl_sprintf("user-%s", shortuser); |
---|
2388 | |
---|
2389 | /* if it already exists then go with it. This lets users override */ |
---|
2390 | if (owl_global_get_filter(&g, filtname)) { |
---|
2391 | return filtname; |
---|
2392 | } |
---|
2393 | |
---|
2394 | /* create the new-internal filter */ |
---|
2395 | esclonguser = owl_text_quote(longuser, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2396 | |
---|
2397 | argbuff=owl_sprintf("( type ^zephyr$ and filter personal and " |
---|
2398 | "( ( direction ^in$ and sender ^%1$s$ ) or ( direction ^out$ and " |
---|
2399 | "recipient ^%1$s$ ) ) ) or ( ( class ^login$ ) and ( sender ^%1$s$ ) )", |
---|
2400 | esclonguser); |
---|
2401 | |
---|
2402 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
2403 | |
---|
2404 | /* add it to the global list */ |
---|
2405 | owl_global_add_filter(&g, f); |
---|
2406 | |
---|
2407 | /* free stuff */ |
---|
2408 | owl_free(argbuff); |
---|
2409 | owl_free(longuser); |
---|
2410 | owl_free(esclonguser); |
---|
2411 | owl_free(shortuser); |
---|
2412 | |
---|
2413 | return(filtname); |
---|
2414 | } |
---|
2415 | |
---|
2416 | /* Create a filter for AIM IM messages to or from the specified |
---|
2417 | * screenname. The name of the filter will be 'aimuser-<user>'. If a |
---|
2418 | * filter already exists with this name, no new filter will be |
---|
2419 | * created. This allows the configuration to override this function. |
---|
2420 | * Returns the name of the filter, which the caller must free. |
---|
2421 | */ |
---|
2422 | char *owl_function_aimuserfilt(const char *user) |
---|
2423 | { |
---|
2424 | owl_filter *f; |
---|
2425 | char *argbuff, *filtname; |
---|
2426 | char *escuser; |
---|
2427 | |
---|
2428 | /* name for the filter */ |
---|
2429 | filtname=owl_sprintf("aimuser-%s", user); |
---|
2430 | |
---|
2431 | /* if it already exists then go with it. This lets users override */ |
---|
2432 | if (owl_global_get_filter(&g, filtname)) { |
---|
2433 | return(owl_strdup(filtname)); |
---|
2434 | } |
---|
2435 | |
---|
2436 | /* create the new-internal filter */ |
---|
2437 | escuser = owl_text_quote(user, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2438 | |
---|
2439 | argbuff = owl_sprintf( |
---|
2440 | "( type ^aim$ and ( ( sender ^%1$s$ and recipient ^%2$s$ ) or " |
---|
2441 | "( sender ^%2$s$ and recipient ^%1$s$ ) ) )", |
---|
2442 | escuser, owl_global_get_aim_screenname_for_filters(&g)); |
---|
2443 | |
---|
2444 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
2445 | |
---|
2446 | /* add it to the global list */ |
---|
2447 | owl_global_add_filter(&g, f); |
---|
2448 | |
---|
2449 | /* free stuff */ |
---|
2450 | owl_free(argbuff); |
---|
2451 | owl_free(escuser); |
---|
2452 | |
---|
2453 | return(filtname); |
---|
2454 | } |
---|
2455 | |
---|
2456 | char *owl_function_typefilt(const char *type) |
---|
2457 | { |
---|
2458 | owl_filter *f; |
---|
2459 | char *argbuff, *filtname, *esctype; |
---|
2460 | |
---|
2461 | /* name for the filter */ |
---|
2462 | filtname=owl_sprintf("type-%s", type); |
---|
2463 | |
---|
2464 | /* if it already exists then go with it. This lets users override */ |
---|
2465 | if (owl_global_get_filter(&g, filtname)) { |
---|
2466 | return filtname; |
---|
2467 | } |
---|
2468 | |
---|
2469 | /* create the new-internal filter */ |
---|
2470 | esctype = owl_text_quote(type, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2471 | |
---|
2472 | argbuff = owl_sprintf("type ^%s$", esctype); |
---|
2473 | |
---|
2474 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
2475 | |
---|
2476 | /* add it to the global list */ |
---|
2477 | owl_global_add_filter(&g, f); |
---|
2478 | |
---|
2479 | /* free stuff */ |
---|
2480 | owl_free(argbuff); |
---|
2481 | owl_free(esctype); |
---|
2482 | |
---|
2483 | return filtname; |
---|
2484 | } |
---|
2485 | |
---|
2486 | /* If flag is 1, marks for deletion. If flag is 0, |
---|
2487 | * unmarks for deletion. */ |
---|
2488 | void owl_function_delete_curview_msgs(int flag) |
---|
2489 | { |
---|
2490 | const owl_view *v; |
---|
2491 | int i, j; |
---|
2492 | |
---|
2493 | v=owl_global_get_current_view(&g); |
---|
2494 | j=owl_view_get_size(v); |
---|
2495 | for (i=0; i<j; i++) { |
---|
2496 | if (flag == 1) { |
---|
2497 | owl_message_mark_delete(owl_view_get_element(v, i)); |
---|
2498 | } else if (flag == 0) { |
---|
2499 | owl_message_unmark_delete(owl_view_get_element(v, i)); |
---|
2500 | } |
---|
2501 | } |
---|
2502 | |
---|
2503 | owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un"); |
---|
2504 | |
---|
2505 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2506 | } |
---|
2507 | |
---|
2508 | static char *owl_function_smartfilter_cc(const owl_message *m) { |
---|
2509 | const char *ccs; |
---|
2510 | char *filtname; |
---|
2511 | char *text; |
---|
2512 | owl_filter *f; |
---|
2513 | |
---|
2514 | ccs = owl_message_get_attribute_value(m, "zephyr_ccs"); |
---|
2515 | |
---|
2516 | filtname = owl_sprintf("conversation-%s", ccs); |
---|
2517 | owl_text_tr(filtname, ' ', '-'); |
---|
2518 | |
---|
2519 | if (owl_global_get_filter(&g, filtname)) { |
---|
2520 | return filtname; |
---|
2521 | } |
---|
2522 | |
---|
2523 | text = owl_sprintf("type ^zephyr$ and filter personal and " |
---|
2524 | "zephyr_ccs ^%s%s%s$", |
---|
2525 | owl_getquoting(ccs), ccs, owl_getquoting(ccs)); |
---|
2526 | |
---|
2527 | f = owl_filter_new_fromstring(filtname, text); |
---|
2528 | |
---|
2529 | owl_global_add_filter(&g, f); |
---|
2530 | |
---|
2531 | owl_free(text); |
---|
2532 | |
---|
2533 | return filtname; |
---|
2534 | } |
---|
2535 | |
---|
2536 | /* Create a filter based on the current message. Returns the name of |
---|
2537 | * a filter or null. The caller must free this name. |
---|
2538 | * |
---|
2539 | * if the curmsg is a personal zephyr return a filter name |
---|
2540 | * to the zephyr conversation with that user. |
---|
2541 | * If the curmsg is a zephyr class message, instance foo, recip *, |
---|
2542 | * return a filter name to the class, inst. |
---|
2543 | * If the curmsg is a zephyr class message and type==0 then |
---|
2544 | * return a filter name for just the class. |
---|
2545 | * If the curmsg is a zephyr class message and type==1 then |
---|
2546 | * return a filter name for the class and instance. |
---|
2547 | * If the curmsg is a personal AIM message returna filter |
---|
2548 | * name to the AIM conversation with that user |
---|
2549 | */ |
---|
2550 | char *owl_function_smartfilter(int type, int invert_related) |
---|
2551 | { |
---|
2552 | const owl_view *v; |
---|
2553 | const owl_message *m; |
---|
2554 | char *zperson, *filtname=NULL; |
---|
2555 | const char *argv[2]; |
---|
2556 | int related = owl_global_is_narrow_related(&g) ^ invert_related; |
---|
2557 | |
---|
2558 | v=owl_global_get_current_view(&g); |
---|
2559 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
2560 | |
---|
2561 | if (!m || owl_view_get_size(v)==0) { |
---|
2562 | owl_function_error("No message selected\n"); |
---|
2563 | return(NULL); |
---|
2564 | } |
---|
2565 | |
---|
2566 | /* very simple handling of admin messages for now */ |
---|
2567 | if (owl_message_is_type_admin(m)) { |
---|
2568 | return(owl_function_typefilt("admin")); |
---|
2569 | } |
---|
2570 | |
---|
2571 | /* very simple handling of loopback messages for now */ |
---|
2572 | if (owl_message_is_type_loopback(m)) { |
---|
2573 | return(owl_function_typefilt("loopback")); |
---|
2574 | } |
---|
2575 | |
---|
2576 | /* aim messages */ |
---|
2577 | if (owl_message_is_type_aim(m)) { |
---|
2578 | if (owl_message_is_direction_in(m)) { |
---|
2579 | filtname=owl_function_aimuserfilt(owl_message_get_sender(m)); |
---|
2580 | } else if (owl_message_is_direction_out(m)) { |
---|
2581 | filtname=owl_function_aimuserfilt(owl_message_get_recipient(m)); |
---|
2582 | } |
---|
2583 | return(filtname); |
---|
2584 | } |
---|
2585 | |
---|
2586 | /* narrow personal and login messages to the sender or recip as appropriate */ |
---|
2587 | if (owl_message_is_type_zephyr(m)) { |
---|
2588 | if (owl_message_is_personal(m) || owl_message_is_loginout(m)) { |
---|
2589 | if (owl_message_get_attribute_value(m, "zephyr_ccs") != NULL) { |
---|
2590 | return owl_function_smartfilter_cc(m); |
---|
2591 | } |
---|
2592 | |
---|
2593 | if (owl_message_is_direction_in(m)) { |
---|
2594 | zperson=short_zuser(owl_message_get_sender(m)); |
---|
2595 | } else { |
---|
2596 | zperson=short_zuser(owl_message_get_recipient(m)); |
---|
2597 | } |
---|
2598 | filtname=owl_function_zuserfilt(zperson); |
---|
2599 | owl_free(zperson); |
---|
2600 | return(filtname); |
---|
2601 | } |
---|
2602 | |
---|
2603 | /* narrow class MESSAGE, instance foo, recip * messages to class, inst */ |
---|
2604 | if (!strcasecmp(owl_message_get_class(m), "message")) { |
---|
2605 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m), related); |
---|
2606 | return(filtname); |
---|
2607 | } |
---|
2608 | |
---|
2609 | /* otherwise narrow to the class */ |
---|
2610 | if (type==0) { |
---|
2611 | filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL, related); |
---|
2612 | } else if (type==1) { |
---|
2613 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m), related); |
---|
2614 | } |
---|
2615 | return(filtname); |
---|
2616 | } |
---|
2617 | |
---|
2618 | /* pass it off to perl */ |
---|
2619 | argv[0] = type ? "1" : "0"; |
---|
2620 | argv[1] = related ? "1" : "0"; |
---|
2621 | return owl_perlconfig_message_call_method(m, "smartfilter", 2, argv); |
---|
2622 | } |
---|
2623 | |
---|
2624 | void owl_function_smartzpunt(int type) |
---|
2625 | { |
---|
2626 | /* Starts a zpunt command based on the current class,instance pair. |
---|
2627 | * If type=0, uses just class. If type=1, uses instance as well. */ |
---|
2628 | const owl_view *v; |
---|
2629 | const owl_message *m; |
---|
2630 | const char *cmdprefix, *mclass, *minst; |
---|
2631 | char *cmd; |
---|
2632 | |
---|
2633 | v=owl_global_get_current_view(&g); |
---|
2634 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
2635 | |
---|
2636 | if (!m || owl_view_get_size(v)==0) { |
---|
2637 | owl_function_error("No message selected\n"); |
---|
2638 | return; |
---|
2639 | } |
---|
2640 | |
---|
2641 | /* for now we skip admin messages. */ |
---|
2642 | if (owl_message_is_type_admin(m) |
---|
2643 | || owl_message_is_loginout(m) |
---|
2644 | || !owl_message_is_type_zephyr(m)) { |
---|
2645 | owl_function_error("smartzpunt doesn't support this message type."); |
---|
2646 | return; |
---|
2647 | } |
---|
2648 | |
---|
2649 | mclass = owl_message_get_class(m); |
---|
2650 | minst = owl_message_get_instance(m); |
---|
2651 | if (!mclass || !*mclass || *mclass==' ' |
---|
2652 | || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal")) |
---|
2653 | || (type && (!minst || !*minst|| *minst==' '))) { |
---|
2654 | owl_function_error("smartzpunt can't safely do this for <%s,%s>", |
---|
2655 | mclass, minst); |
---|
2656 | } else { |
---|
2657 | cmdprefix = "start-command zpunt "; |
---|
2658 | cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+10); |
---|
2659 | strcpy(cmd, cmdprefix); |
---|
2660 | strcat(cmd, owl_getquoting(mclass)); |
---|
2661 | strcat(cmd, mclass); |
---|
2662 | strcat(cmd, owl_getquoting(mclass)); |
---|
2663 | if (type) { |
---|
2664 | strcat(cmd, " "); |
---|
2665 | strcat(cmd, owl_getquoting(minst)); |
---|
2666 | strcat(cmd, minst); |
---|
2667 | strcat(cmd, owl_getquoting(minst)); |
---|
2668 | } else { |
---|
2669 | strcat(cmd, " *"); |
---|
2670 | } |
---|
2671 | owl_function_command(cmd); |
---|
2672 | owl_free(cmd); |
---|
2673 | } |
---|
2674 | } |
---|
2675 | |
---|
2676 | /* Set the color of the current view's filter to |
---|
2677 | * be 'color' |
---|
2678 | */ |
---|
2679 | void owl_function_color_current_filter(const char *fgcolor, const char *bgcolor) |
---|
2680 | { |
---|
2681 | const char *name; |
---|
2682 | |
---|
2683 | name=owl_view_get_filtname(owl_global_get_current_view(&g)); |
---|
2684 | owl_function_color_filter(name, fgcolor, bgcolor); |
---|
2685 | } |
---|
2686 | |
---|
2687 | /* Set the color of the filter 'filter' to be 'color'. If the color |
---|
2688 | * name does not exist, return -1, if the filter does not exist or is |
---|
2689 | * the "all" filter, return -2. Return 0 on success |
---|
2690 | */ |
---|
2691 | int owl_function_color_filter(const char *filtname, const char *fgcolor, const char *bgcolor) |
---|
2692 | { |
---|
2693 | owl_filter *f; |
---|
2694 | |
---|
2695 | f=owl_global_get_filter(&g, filtname); |
---|
2696 | if (!f) { |
---|
2697 | owl_function_error("Unknown filter"); |
---|
2698 | return(-2); |
---|
2699 | } |
---|
2700 | |
---|
2701 | /* don't touch the all filter */ |
---|
2702 | if (!strcmp(filtname, "all")) { |
---|
2703 | owl_function_error("You may not change the 'all' filter."); |
---|
2704 | return(-2); |
---|
2705 | } |
---|
2706 | |
---|
2707 | if (owl_util_string_to_color(fgcolor)==OWL_COLOR_INVALID) { |
---|
2708 | owl_function_error("No color named '%s' avilable.", fgcolor); |
---|
2709 | return(-1); |
---|
2710 | } |
---|
2711 | |
---|
2712 | |
---|
2713 | if (bgcolor != NULL) { |
---|
2714 | if (owl_util_string_to_color(bgcolor)==OWL_COLOR_INVALID) { |
---|
2715 | owl_function_error("No color named '%s' avilable.", bgcolor); |
---|
2716 | return(-1); |
---|
2717 | } |
---|
2718 | owl_filter_set_bgcolor(f, owl_util_string_to_color(bgcolor)); |
---|
2719 | } |
---|
2720 | owl_filter_set_fgcolor(f, owl_util_string_to_color(fgcolor)); |
---|
2721 | |
---|
2722 | owl_global_set_needrefresh(&g); |
---|
2723 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2724 | return(0); |
---|
2725 | } |
---|
2726 | |
---|
2727 | void owl_function_show_colors(void) |
---|
2728 | { |
---|
2729 | owl_fmtext fm; |
---|
2730 | int i; |
---|
2731 | |
---|
2732 | owl_fmtext_init_null(&fm); |
---|
2733 | owl_fmtext_append_normal(&fm, "default: "); |
---|
2734 | owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT); |
---|
2735 | |
---|
2736 | owl_fmtext_append_normal(&fm,"red: "); |
---|
2737 | owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED, OWL_COLOR_DEFAULT); |
---|
2738 | |
---|
2739 | owl_fmtext_append_normal(&fm,"green: "); |
---|
2740 | owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN, OWL_COLOR_DEFAULT); |
---|
2741 | |
---|
2742 | owl_fmtext_append_normal(&fm,"yellow: "); |
---|
2743 | owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW, OWL_COLOR_DEFAULT); |
---|
2744 | |
---|
2745 | owl_fmtext_append_normal(&fm,"blue: "); |
---|
2746 | owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE, OWL_COLOR_DEFAULT); |
---|
2747 | |
---|
2748 | owl_fmtext_append_normal(&fm,"magenta: "); |
---|
2749 | owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA, OWL_COLOR_DEFAULT); |
---|
2750 | |
---|
2751 | owl_fmtext_append_normal(&fm,"cyan: "); |
---|
2752 | owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN, OWL_COLOR_DEFAULT); |
---|
2753 | |
---|
2754 | owl_fmtext_append_normal(&fm,"white: "); |
---|
2755 | owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT); |
---|
2756 | |
---|
2757 | for(i = 8; i < COLORS; ++i) { |
---|
2758 | char* str1 = owl_sprintf("%4i: ",i); |
---|
2759 | char* str2 = owl_sprintf("%i\n",i); |
---|
2760 | owl_fmtext_append_normal(&fm,str1); |
---|
2761 | owl_fmtext_append_normal_color(&fm, str2, i, OWL_COLOR_DEFAULT); |
---|
2762 | owl_free(str1); |
---|
2763 | owl_free(str2); |
---|
2764 | } |
---|
2765 | |
---|
2766 | owl_function_popless_fmtext(&fm); |
---|
2767 | owl_fmtext_cleanup(&fm); |
---|
2768 | } |
---|
2769 | |
---|
2770 | /* add the given class, inst, recip to the punt list for filtering. |
---|
2771 | * if direction==0 then punt |
---|
2772 | * if direction==1 then unpunt |
---|
2773 | */ |
---|
2774 | void owl_function_zpunt(const char *class, const char *inst, const char *recip, int direction) |
---|
2775 | { |
---|
2776 | char *puntexpr, *classexpr, *instexpr, *recipexpr; |
---|
2777 | char *quoted; |
---|
2778 | |
---|
2779 | if (!strcmp(class, "*")) { |
---|
2780 | classexpr = owl_sprintf("class .*"); |
---|
2781 | } else { |
---|
2782 | quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2783 | owl_text_tr(quoted, ' ', '.'); |
---|
2784 | owl_text_tr(quoted, '\'', '.'); |
---|
2785 | owl_text_tr(quoted, '"', '.'); |
---|
2786 | classexpr = owl_sprintf("class ^(un)*%s(\\.d)*$", quoted); |
---|
2787 | owl_free(quoted); |
---|
2788 | } |
---|
2789 | if (!strcmp(inst, "*")) { |
---|
2790 | instexpr = owl_sprintf(" and instance .*"); |
---|
2791 | } else { |
---|
2792 | quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2793 | owl_text_tr(quoted, ' ', '.'); |
---|
2794 | owl_text_tr(quoted, '\'', '.'); |
---|
2795 | owl_text_tr(quoted, '"', '.'); |
---|
2796 | instexpr = owl_sprintf(" and instance ^(un)*%s(\\.d)*$", quoted); |
---|
2797 | owl_free(quoted); |
---|
2798 | } |
---|
2799 | if (!strcmp(recip, "*")) { |
---|
2800 | recipexpr = owl_sprintf(""); |
---|
2801 | } else { |
---|
2802 | if(!strcmp(recip, "%me%")) { |
---|
2803 | recip = owl_zephyr_get_sender(); |
---|
2804 | } |
---|
2805 | quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
2806 | owl_text_tr(quoted, ' ', '.'); |
---|
2807 | owl_text_tr(quoted, '\'', '.'); |
---|
2808 | owl_text_tr(quoted, '"', '.'); |
---|
2809 | recipexpr = owl_sprintf(" and recipient ^%s$", quoted); |
---|
2810 | owl_free(quoted); |
---|
2811 | } |
---|
2812 | |
---|
2813 | puntexpr = owl_sprintf("%s %s %s", classexpr, instexpr, recipexpr); |
---|
2814 | owl_function_punt(puntexpr, direction); |
---|
2815 | owl_free(puntexpr); |
---|
2816 | owl_free(classexpr); |
---|
2817 | owl_free(instexpr); |
---|
2818 | owl_free(recipexpr); |
---|
2819 | } |
---|
2820 | |
---|
2821 | void owl_function_punt(const char *filter, int direction) |
---|
2822 | { |
---|
2823 | owl_filter *f; |
---|
2824 | owl_list *fl; |
---|
2825 | int i, j; |
---|
2826 | fl=owl_global_get_puntlist(&g); |
---|
2827 | |
---|
2828 | /* first, create the filter */ |
---|
2829 | owl_function_debugmsg("About to filter %s", filter); |
---|
2830 | f = owl_filter_new_fromstring("punt-filter", filter); |
---|
2831 | if (f == NULL) { |
---|
2832 | owl_function_error("Error creating filter for zpunt"); |
---|
2833 | return; |
---|
2834 | } |
---|
2835 | |
---|
2836 | /* Check for an identical filter */ |
---|
2837 | j=owl_list_get_size(fl); |
---|
2838 | for (i=0; i<j; i++) { |
---|
2839 | if (owl_filter_equiv(f, owl_list_get_element(fl, i))) { |
---|
2840 | owl_function_debugmsg("found an equivalent punt filter"); |
---|
2841 | /* if we're punting, then just silently bow out on this duplicate */ |
---|
2842 | if (direction==0) { |
---|
2843 | owl_filter_delete(f); |
---|
2844 | return; |
---|
2845 | } |
---|
2846 | |
---|
2847 | /* if we're unpunting, then remove this filter from the puntlist */ |
---|
2848 | if (direction==1) { |
---|
2849 | owl_filter_delete(owl_list_get_element(fl, i)); |
---|
2850 | owl_list_remove_element(fl, i); |
---|
2851 | owl_filter_delete(f); |
---|
2852 | return; |
---|
2853 | } |
---|
2854 | } |
---|
2855 | } |
---|
2856 | |
---|
2857 | owl_function_debugmsg("punting"); |
---|
2858 | /* If we're punting, add the filter to the global punt list */ |
---|
2859 | if (direction==0) { |
---|
2860 | owl_list_append_element(fl, f); |
---|
2861 | } |
---|
2862 | } |
---|
2863 | |
---|
2864 | void owl_function_show_keymaps(void) |
---|
2865 | { |
---|
2866 | owl_list l; |
---|
2867 | owl_fmtext fm; |
---|
2868 | const owl_keymap *km; |
---|
2869 | const owl_keyhandler *kh; |
---|
2870 | int i, numkm; |
---|
2871 | const char *kmname; |
---|
2872 | |
---|
2873 | kh = owl_global_get_keyhandler(&g); |
---|
2874 | owl_fmtext_init_null(&fm); |
---|
2875 | owl_fmtext_append_bold(&fm, "Keymaps: "); |
---|
2876 | owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n"); |
---|
2877 | owl_keyhandler_get_keymap_names(kh, &l); |
---|
2878 | owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary); |
---|
2879 | owl_fmtext_append_normal(&fm, "\n"); |
---|
2880 | |
---|
2881 | numkm = owl_list_get_size(&l); |
---|
2882 | for (i=0; i<numkm; i++) { |
---|
2883 | kmname = owl_list_get_element(&l, i); |
---|
2884 | km = owl_keyhandler_get_keymap(kh, kmname); |
---|
2885 | owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n"); |
---|
2886 | owl_keymap_get_details(km, &fm); |
---|
2887 | } |
---|
2888 | owl_fmtext_append_normal(&fm, "\n"); |
---|
2889 | |
---|
2890 | owl_function_popless_fmtext(&fm); |
---|
2891 | owl_keyhandler_keymap_namelist_cleanup(&l); |
---|
2892 | owl_fmtext_cleanup(&fm); |
---|
2893 | } |
---|
2894 | |
---|
2895 | char *owl_function_keymap_summary(const char *name) |
---|
2896 | { |
---|
2897 | const owl_keymap *km |
---|
2898 | = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
2899 | if (km) return owl_keymap_summary(km); |
---|
2900 | else return(NULL); |
---|
2901 | } |
---|
2902 | |
---|
2903 | /* TODO: implement for real */ |
---|
2904 | void owl_function_show_keymap(const char *name) |
---|
2905 | { |
---|
2906 | owl_fmtext fm; |
---|
2907 | const owl_keymap *km; |
---|
2908 | |
---|
2909 | owl_fmtext_init_null(&fm); |
---|
2910 | km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
2911 | if (km) { |
---|
2912 | owl_keymap_get_details(km, &fm); |
---|
2913 | } else { |
---|
2914 | owl_fmtext_append_normal(&fm, "No such keymap...\n"); |
---|
2915 | } |
---|
2916 | owl_function_popless_fmtext(&fm); |
---|
2917 | owl_fmtext_cleanup(&fm); |
---|
2918 | } |
---|
2919 | |
---|
2920 | void owl_function_help_for_command(const char *cmdname) |
---|
2921 | { |
---|
2922 | owl_fmtext fm; |
---|
2923 | |
---|
2924 | owl_fmtext_init_null(&fm); |
---|
2925 | owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm); |
---|
2926 | owl_function_popless_fmtext(&fm); |
---|
2927 | owl_fmtext_cleanup(&fm); |
---|
2928 | } |
---|
2929 | |
---|
2930 | void owl_function_search_start(const char *string, int direction) |
---|
2931 | { |
---|
2932 | /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS or |
---|
2933 | * OWL_DIRECTION_NONE */ |
---|
2934 | owl_regex re; |
---|
2935 | |
---|
2936 | if (string && owl_regex_create_quoted(&re, string) == 0) { |
---|
2937 | owl_global_set_search_re(&g, &re); |
---|
2938 | owl_regex_cleanup(&re); |
---|
2939 | } else { |
---|
2940 | owl_global_set_search_re(&g, NULL); |
---|
2941 | } |
---|
2942 | |
---|
2943 | if (direction == OWL_DIRECTION_NONE) |
---|
2944 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2945 | else |
---|
2946 | owl_function_search_helper(0, direction); |
---|
2947 | } |
---|
2948 | |
---|
2949 | void owl_function_search_continue(int direction) |
---|
2950 | { |
---|
2951 | /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */ |
---|
2952 | owl_function_search_helper(1, direction); |
---|
2953 | } |
---|
2954 | |
---|
2955 | void owl_function_search_helper(int mode, int direction) |
---|
2956 | { |
---|
2957 | /* move to a message that contains the string. If direction is |
---|
2958 | * OWL_DIRECTION_DOWNWARDS then search fowards, if direction is |
---|
2959 | * OWL_DIRECTION_UPWARDS then search backwards. |
---|
2960 | * |
---|
2961 | * If mode==0 then it will stay on the current message if it |
---|
2962 | * contains the string. |
---|
2963 | */ |
---|
2964 | |
---|
2965 | const owl_view *v; |
---|
2966 | int viewsize, i, curmsg, start; |
---|
2967 | owl_message *m; |
---|
2968 | |
---|
2969 | v=owl_global_get_current_view(&g); |
---|
2970 | viewsize=owl_view_get_size(v); |
---|
2971 | curmsg=owl_global_get_curmsg(&g); |
---|
2972 | |
---|
2973 | if (viewsize==0) { |
---|
2974 | owl_function_error("No messages present"); |
---|
2975 | return; |
---|
2976 | } |
---|
2977 | |
---|
2978 | if (mode==0) { |
---|
2979 | start=curmsg; |
---|
2980 | } else if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
2981 | start=curmsg+1; |
---|
2982 | } else { |
---|
2983 | start=curmsg-1; |
---|
2984 | } |
---|
2985 | |
---|
2986 | /* bounds check */ |
---|
2987 | if (start>=viewsize || start<0) { |
---|
2988 | owl_function_error("No further matches found"); |
---|
2989 | return; |
---|
2990 | } |
---|
2991 | |
---|
2992 | for (i=start; i<viewsize && i>=0;) { |
---|
2993 | m=owl_view_get_element(v, i); |
---|
2994 | if (owl_message_search(m, owl_global_get_search_re(&g))) { |
---|
2995 | owl_global_set_curmsg(&g, i); |
---|
2996 | owl_function_calculate_topmsg(direction); |
---|
2997 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
2998 | if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
2999 | owl_global_set_direction_downwards(&g); |
---|
3000 | } else { |
---|
3001 | owl_global_set_direction_upwards(&g); |
---|
3002 | } |
---|
3003 | return; |
---|
3004 | } |
---|
3005 | if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
3006 | i++; |
---|
3007 | } else { |
---|
3008 | i--; |
---|
3009 | } |
---|
3010 | owl_function_mask_sigint(NULL); |
---|
3011 | if(owl_global_is_interrupted(&g)) { |
---|
3012 | owl_global_unset_interrupted(&g); |
---|
3013 | owl_function_unmask_sigint(NULL); |
---|
3014 | owl_function_makemsg("Search interrupted!"); |
---|
3015 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
3016 | return; |
---|
3017 | } |
---|
3018 | owl_function_unmask_sigint(NULL); |
---|
3019 | } |
---|
3020 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
3021 | owl_function_error("No matches found"); |
---|
3022 | } |
---|
3023 | |
---|
3024 | /* strips formatting from ztext and returns the unformatted text. |
---|
3025 | * caller is responsible for freeing. */ |
---|
3026 | char *owl_function_ztext_stylestrip(const char *zt) |
---|
3027 | { |
---|
3028 | owl_fmtext fm; |
---|
3029 | char *plaintext; |
---|
3030 | |
---|
3031 | owl_fmtext_init_null(&fm); |
---|
3032 | owl_fmtext_append_ztext(&fm, zt); |
---|
3033 | plaintext = owl_fmtext_print_plain(&fm); |
---|
3034 | owl_fmtext_cleanup(&fm); |
---|
3035 | return(plaintext); |
---|
3036 | } |
---|
3037 | |
---|
3038 | /* Popup a buddylisting. If filename is NULL use the default .anyone */ |
---|
3039 | void owl_function_buddylist(int aim, int zephyr, const char *filename) |
---|
3040 | { |
---|
3041 | int i, j, idle; |
---|
3042 | int interrupted = 0; |
---|
3043 | owl_fmtext fm; |
---|
3044 | const owl_buddylist *bl; |
---|
3045 | const owl_buddy *b; |
---|
3046 | char *timestr; |
---|
3047 | #ifdef HAVE_LIBZEPHYR |
---|
3048 | int x; |
---|
3049 | owl_list anyone; |
---|
3050 | const char *user; |
---|
3051 | char *tmp; |
---|
3052 | ZLocations_t location[200]; |
---|
3053 | int numlocs, ret; |
---|
3054 | #endif |
---|
3055 | |
---|
3056 | owl_fmtext_init_null(&fm); |
---|
3057 | |
---|
3058 | /* AIM first */ |
---|
3059 | if (aim && owl_global_is_aimloggedin(&g)) { |
---|
3060 | bl=owl_global_get_buddylist(&g); |
---|
3061 | |
---|
3062 | owl_fmtext_append_bold(&fm, "AIM users logged in:\n"); |
---|
3063 | /* we're assuming AIM for now */ |
---|
3064 | j=owl_buddylist_get_size(bl); |
---|
3065 | for (i=0; i<j; i++) { |
---|
3066 | b=owl_buddylist_get_buddy_n(bl, i); |
---|
3067 | idle=owl_buddy_get_idle_time(b); |
---|
3068 | if (idle!=0) { |
---|
3069 | timestr=owl_util_minutes_to_timestr(idle); |
---|
3070 | } else { |
---|
3071 | timestr=owl_strdup(""); |
---|
3072 | } |
---|
3073 | owl_fmtext_appendf_normal(&fm, " %-20.20s %-12.12s\n", owl_buddy_get_name(b), timestr); |
---|
3074 | owl_free(timestr); |
---|
3075 | } |
---|
3076 | } |
---|
3077 | |
---|
3078 | #ifdef HAVE_LIBZEPHYR |
---|
3079 | if (zephyr) { |
---|
3080 | if(!owl_global_is_havezephyr(&g)) { |
---|
3081 | owl_function_error("Zephyr currently not available."); |
---|
3082 | } else { |
---|
3083 | owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n"); |
---|
3084 | owl_list_create(&anyone); |
---|
3085 | ret=owl_zephyr_get_anyone_list(&anyone, filename); |
---|
3086 | if (ret) { |
---|
3087 | if (errno == ENOENT) { |
---|
3088 | owl_fmtext_append_normal(&fm, " You have not added any zephyr buddies. Use the\n"); |
---|
3089 | owl_fmtext_append_normal(&fm, " command ':addbuddy zephyr "); |
---|
3090 | owl_fmtext_append_bold( &fm, "<username>"); |
---|
3091 | owl_fmtext_append_normal(&fm, "'.\n"); |
---|
3092 | } else { |
---|
3093 | owl_fmtext_append_normal(&fm, " Could not read zephyr buddies from the .anyone file.\n"); |
---|
3094 | } |
---|
3095 | } else { |
---|
3096 | j=owl_list_get_size(&anyone); |
---|
3097 | for (i=0; i<j; i++) { |
---|
3098 | user=owl_list_get_element(&anyone, i); |
---|
3099 | ret=ZLocateUser(zstr(user), &numlocs, ZAUTH); |
---|
3100 | |
---|
3101 | owl_function_mask_sigint(NULL); |
---|
3102 | if(owl_global_is_interrupted(&g)) { |
---|
3103 | interrupted = 1; |
---|
3104 | owl_global_unset_interrupted(&g); |
---|
3105 | owl_function_unmask_sigint(NULL); |
---|
3106 | owl_function_makemsg("Interrupted!"); |
---|
3107 | break; |
---|
3108 | } |
---|
3109 | |
---|
3110 | owl_function_unmask_sigint(NULL); |
---|
3111 | |
---|
3112 | if (ret!=ZERR_NONE) { |
---|
3113 | owl_function_error("Error getting location for %s", user); |
---|
3114 | continue; |
---|
3115 | } |
---|
3116 | |
---|
3117 | numlocs=200; |
---|
3118 | ret=ZGetLocations(location, &numlocs); |
---|
3119 | if (ret==0) { |
---|
3120 | for (x=0; x<numlocs; x++) { |
---|
3121 | tmp=short_zuser(user); |
---|
3122 | owl_fmtext_appendf_normal(&fm, " %-10.10s %-24.24s %-12.12s %20.20s\n", |
---|
3123 | tmp, |
---|
3124 | location[x].host, |
---|
3125 | location[x].tty, |
---|
3126 | location[x].time); |
---|
3127 | owl_free(tmp); |
---|
3128 | } |
---|
3129 | if (numlocs>=200) { |
---|
3130 | owl_fmtext_append_normal(&fm, " Too many locations found for this user, truncating.\n"); |
---|
3131 | } |
---|
3132 | } |
---|
3133 | } |
---|
3134 | } |
---|
3135 | owl_list_cleanup(&anyone, owl_free); |
---|
3136 | } |
---|
3137 | } |
---|
3138 | #endif |
---|
3139 | |
---|
3140 | if (aim && zephyr) { |
---|
3141 | if (owl_perlconfig_is_function("BarnOwl::Hooks::_get_blist")) { |
---|
3142 | char * perlblist = owl_perlconfig_execute("BarnOwl::Hooks::_get_blist()"); |
---|
3143 | if (perlblist) { |
---|
3144 | owl_fmtext_append_ztext(&fm, perlblist); |
---|
3145 | owl_free(perlblist); |
---|
3146 | } |
---|
3147 | } |
---|
3148 | } |
---|
3149 | |
---|
3150 | if(!interrupted) { |
---|
3151 | owl_function_popless_fmtext(&fm); |
---|
3152 | } |
---|
3153 | owl_fmtext_cleanup(&fm); |
---|
3154 | } |
---|
3155 | |
---|
3156 | /* Dump messages in the current view to the file 'filename'. */ |
---|
3157 | void owl_function_dump(const char *filename) |
---|
3158 | { |
---|
3159 | int i, j; |
---|
3160 | owl_message *m; |
---|
3161 | const owl_view *v; |
---|
3162 | FILE *file; |
---|
3163 | char *plaintext; |
---|
3164 | |
---|
3165 | v=owl_global_get_current_view(&g); |
---|
3166 | |
---|
3167 | /* in the future make it ask yes/no */ |
---|
3168 | /* |
---|
3169 | ret=stat(filename, &sbuf); |
---|
3170 | if (!ret) { |
---|
3171 | ret=owl_function_askyesno("File exists, continue? [Y/n]"); |
---|
3172 | if (!ret) return; |
---|
3173 | } |
---|
3174 | */ |
---|
3175 | |
---|
3176 | file=fopen(filename, "w"); |
---|
3177 | if (!file) { |
---|
3178 | owl_function_error("Error opening file"); |
---|
3179 | return; |
---|
3180 | } |
---|
3181 | |
---|
3182 | j=owl_view_get_size(v); |
---|
3183 | for (i=0; i<j; i++) { |
---|
3184 | m=owl_view_get_element(v, i); |
---|
3185 | plaintext = owl_strip_format_chars(owl_message_get_text(m)); |
---|
3186 | if (plaintext) { |
---|
3187 | fputs(plaintext, file); |
---|
3188 | owl_free(plaintext); |
---|
3189 | } |
---|
3190 | } |
---|
3191 | fclose(file); |
---|
3192 | owl_function_makemsg("Messages dumped to %s", filename); |
---|
3193 | } |
---|
3194 | |
---|
3195 | void owl_function_do_newmsgproc(void) |
---|
3196 | { |
---|
3197 | if (owl_global_get_newmsgproc(&g) && strcmp(owl_global_get_newmsgproc(&g), "")) { |
---|
3198 | /* if there's a process out there, we need to check on it */ |
---|
3199 | if (owl_global_get_newmsgproc_pid(&g)) { |
---|
3200 | owl_function_debugmsg("Checking on newmsgproc pid==%i", owl_global_get_newmsgproc_pid(&g)); |
---|
3201 | owl_function_debugmsg("Waitpid return is %i", waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)); |
---|
3202 | waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG); |
---|
3203 | if (waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)==-1) { |
---|
3204 | /* it exited */ |
---|
3205 | owl_global_set_newmsgproc_pid(&g, 0); |
---|
3206 | owl_function_debugmsg("newmsgproc exited"); |
---|
3207 | } else { |
---|
3208 | owl_function_debugmsg("newmsgproc did not exit"); |
---|
3209 | } |
---|
3210 | } |
---|
3211 | |
---|
3212 | /* if it exited, fork & exec a new one */ |
---|
3213 | if (owl_global_get_newmsgproc_pid(&g)==0) { |
---|
3214 | pid_t i; |
---|
3215 | int myargc; |
---|
3216 | i=fork(); |
---|
3217 | if (i) { |
---|
3218 | /* parent set the child's pid */ |
---|
3219 | owl_global_set_newmsgproc_pid(&g, i); |
---|
3220 | owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i); |
---|
3221 | } else { |
---|
3222 | /* child exec's the program */ |
---|
3223 | char **parsed; |
---|
3224 | parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc); |
---|
3225 | if (myargc < 0) { |
---|
3226 | owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g)); |
---|
3227 | } |
---|
3228 | if (myargc <= 0) { |
---|
3229 | _exit(127); |
---|
3230 | } |
---|
3231 | parsed=owl_realloc(parsed, sizeof(*parsed) * (myargc+1)); |
---|
3232 | parsed[myargc] = NULL; |
---|
3233 | |
---|
3234 | owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc); |
---|
3235 | |
---|
3236 | execvp(parsed[0], parsed); |
---|
3237 | |
---|
3238 | |
---|
3239 | /* was there an error exec'ing? */ |
---|
3240 | owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s", |
---|
3241 | owl_global_get_newmsgproc(&g), parsed[0], strerror(errno)); |
---|
3242 | _exit(127); |
---|
3243 | } |
---|
3244 | } |
---|
3245 | } |
---|
3246 | } |
---|
3247 | |
---|
3248 | /* print the xterm escape sequence to raise the window */ |
---|
3249 | void owl_function_xterm_raise(void) |
---|
3250 | { |
---|
3251 | printf("\033[5t"); |
---|
3252 | } |
---|
3253 | |
---|
3254 | /* print the xterm escape sequence to deiconify the window */ |
---|
3255 | void owl_function_xterm_deiconify(void) |
---|
3256 | { |
---|
3257 | printf("\033[1t"); |
---|
3258 | } |
---|
3259 | |
---|
3260 | /* Add the specified command to the startup file. Eventually this |
---|
3261 | * should be clever, and rewriting settings that will obviosly |
---|
3262 | * override earlier settings with 'set' 'bindkey' and 'alias' |
---|
3263 | * commands. For now though we just remove any line that would |
---|
3264 | * duplicate this one and then append this line to the end of |
---|
3265 | * startupfile. |
---|
3266 | */ |
---|
3267 | void owl_function_addstartup(const char *buff) |
---|
3268 | { |
---|
3269 | FILE *file; |
---|
3270 | const char *filename; |
---|
3271 | |
---|
3272 | filename=owl_global_get_startupfile(&g); |
---|
3273 | |
---|
3274 | /* delete earlier copies */ |
---|
3275 | owl_util_file_deleteline(filename, buff, 1); |
---|
3276 | |
---|
3277 | file=fopen(filename, "a"); |
---|
3278 | if (!file) { |
---|
3279 | owl_function_error("Error opening startupfile for new command"); |
---|
3280 | return; |
---|
3281 | } |
---|
3282 | |
---|
3283 | /* add this line */ |
---|
3284 | fprintf(file, "%s\n", buff); |
---|
3285 | |
---|
3286 | fclose(file); |
---|
3287 | } |
---|
3288 | |
---|
3289 | /* Remove the specified command from the startup file. */ |
---|
3290 | void owl_function_delstartup(const char *buff) |
---|
3291 | { |
---|
3292 | const char *filename; |
---|
3293 | filename=owl_global_get_startupfile(&g); |
---|
3294 | owl_util_file_deleteline(filename, buff, 1); |
---|
3295 | } |
---|
3296 | |
---|
3297 | /* Execute owl commands from the given filename. If the filename |
---|
3298 | * is NULL, use the default owl startup commands file. |
---|
3299 | */ |
---|
3300 | void owl_function_source(const char *filename) |
---|
3301 | { |
---|
3302 | char *path; |
---|
3303 | FILE *file; |
---|
3304 | char *s = NULL; |
---|
3305 | int fail_silent = 0; |
---|
3306 | |
---|
3307 | if (!filename) { |
---|
3308 | fail_silent = 1; |
---|
3309 | path = owl_strdup(owl_global_get_startupfile(&g)); |
---|
3310 | } else { |
---|
3311 | path = owl_util_makepath(filename); |
---|
3312 | } |
---|
3313 | file = fopen(path, "r"); |
---|
3314 | owl_free(path); |
---|
3315 | if (!file) { |
---|
3316 | if (!fail_silent) { |
---|
3317 | owl_function_error("Error opening file: %s", filename); |
---|
3318 | } |
---|
3319 | return; |
---|
3320 | } |
---|
3321 | while (owl_getline_chomp(&s, file)) { |
---|
3322 | if (s[0] == '\0' || s[0] == '#') |
---|
3323 | continue; |
---|
3324 | owl_function_command(s); |
---|
3325 | } |
---|
3326 | |
---|
3327 | owl_free(s); |
---|
3328 | fclose(file); |
---|
3329 | } |
---|
3330 | |
---|
3331 | void owl_function_change_style(owl_view *v, const char *stylename) |
---|
3332 | { |
---|
3333 | const owl_style *s; |
---|
3334 | |
---|
3335 | s=owl_global_get_style_by_name(&g, stylename); |
---|
3336 | if (!s) { |
---|
3337 | owl_function_error("No style named %s", stylename); |
---|
3338 | return; |
---|
3339 | } |
---|
3340 | owl_view_set_style(v, s); |
---|
3341 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
3342 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
3343 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
3344 | } |
---|
3345 | |
---|
3346 | void owl_function_toggleoneline(void) |
---|
3347 | { |
---|
3348 | owl_view *v; |
---|
3349 | const owl_style *s; |
---|
3350 | |
---|
3351 | v=owl_global_get_current_view(&g); |
---|
3352 | s=owl_view_get_style(v); |
---|
3353 | |
---|
3354 | if (!owl_style_matches_name(s, "oneline")) { |
---|
3355 | owl_function_change_style(v, "oneline"); |
---|
3356 | } else { |
---|
3357 | owl_function_change_style(v, owl_global_get_default_style(&g)); |
---|
3358 | } |
---|
3359 | |
---|
3360 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
3361 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
3362 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
3363 | } |
---|
3364 | |
---|
3365 | void owl_function_error(const char *fmt, ...) |
---|
3366 | { |
---|
3367 | static int in_error = 0; |
---|
3368 | va_list ap; |
---|
3369 | char *buff; |
---|
3370 | const char *nl; |
---|
3371 | |
---|
3372 | if (++in_error > 2) { |
---|
3373 | /* More than two nested errors, bail immediately. */ |
---|
3374 | in_error--; |
---|
3375 | return; |
---|
3376 | } |
---|
3377 | |
---|
3378 | va_start(ap, fmt); |
---|
3379 | buff = g_strdup_vprintf(fmt, ap); |
---|
3380 | va_end(ap); |
---|
3381 | |
---|
3382 | owl_function_debugmsg("ERROR: %s", buff); |
---|
3383 | owl_function_log_err(buff); |
---|
3384 | |
---|
3385 | nl = strchr(buff, '\n'); |
---|
3386 | |
---|
3387 | /* |
---|
3388 | Showing admin messages triggers a lot of code. If we have a |
---|
3389 | recursive error call, that's the most likely candidate, so |
---|
3390 | suppress the call in that case, to try to avoid infinite looping. |
---|
3391 | */ |
---|
3392 | |
---|
3393 | if(nl && *(nl + 1) && in_error == 1) { |
---|
3394 | /* Multiline error */ |
---|
3395 | owl_function_adminmsg("ERROR", buff); |
---|
3396 | } else { |
---|
3397 | owl_function_makemsg("[Error] %s", buff); |
---|
3398 | } |
---|
3399 | |
---|
3400 | owl_free(buff); |
---|
3401 | |
---|
3402 | in_error--; |
---|
3403 | } |
---|
3404 | |
---|
3405 | void owl_function_log_err(const char *string) |
---|
3406 | { |
---|
3407 | char *date; |
---|
3408 | time_t now; |
---|
3409 | char *buff; |
---|
3410 | |
---|
3411 | now=time(NULL); |
---|
3412 | date=owl_strdup(ctime(&now)); |
---|
3413 | date[strlen(date)-1]='\0'; |
---|
3414 | |
---|
3415 | buff = owl_sprintf("%s %s", date, string); |
---|
3416 | |
---|
3417 | owl_errqueue_append_err(owl_global_get_errqueue(&g), buff); |
---|
3418 | |
---|
3419 | owl_free(buff); |
---|
3420 | owl_free(date); |
---|
3421 | } |
---|
3422 | |
---|
3423 | void owl_function_showerrs(void) |
---|
3424 | { |
---|
3425 | owl_fmtext fm; |
---|
3426 | |
---|
3427 | owl_fmtext_init_null(&fm); |
---|
3428 | owl_fmtext_append_normal(&fm, "Errors:\n\n"); |
---|
3429 | owl_errqueue_to_fmtext(owl_global_get_errqueue(&g), &fm); |
---|
3430 | owl_function_popless_fmtext(&fm); |
---|
3431 | } |
---|
3432 | |
---|
3433 | void owl_function_makemsg(const char *fmt, ...) |
---|
3434 | { |
---|
3435 | va_list ap; |
---|
3436 | char buff[2048]; |
---|
3437 | |
---|
3438 | if (!owl_global_get_curs_msgwin(&g)) return; |
---|
3439 | |
---|
3440 | va_start(ap, fmt); |
---|
3441 | werase(owl_global_get_curs_msgwin(&g)); |
---|
3442 | |
---|
3443 | vsnprintf(buff, 2048, fmt, ap); |
---|
3444 | owl_function_debugmsg("makemsg: %s", buff); |
---|
3445 | waddstr(owl_global_get_curs_msgwin(&g), buff); |
---|
3446 | owl_global_set_needrefresh(&g); |
---|
3447 | va_end(ap); |
---|
3448 | } |
---|
3449 | |
---|
3450 | /* get locations for everyone in .anyone. If 'notify' is '1' then |
---|
3451 | * send a pseudo login or logout message for everyone not in sync with |
---|
3452 | * the global zephyr buddy list. The list is updated regardless of |
---|
3453 | * the status of 'notify'. |
---|
3454 | */ |
---|
3455 | void owl_function_zephyr_buddy_check(int notify) |
---|
3456 | { |
---|
3457 | #ifdef HAVE_LIBZEPHYR |
---|
3458 | int i, j; |
---|
3459 | owl_list anyone; |
---|
3460 | owl_zbuddylist *zbl; |
---|
3461 | GList **zaldlist; |
---|
3462 | GList *zaldptr; |
---|
3463 | ZAsyncLocateData_t *zald; |
---|
3464 | const char *user; |
---|
3465 | |
---|
3466 | if (!owl_global_is_havezephyr(&g)) return; |
---|
3467 | owl_global_set_pseudologin_notify(&g, notify); |
---|
3468 | zbl = owl_global_get_zephyr_buddylist(&g); |
---|
3469 | zaldlist = owl_global_get_zaldlist(&g); |
---|
3470 | |
---|
3471 | /* Clear the existing ZALDs first. */ |
---|
3472 | zaldptr = g_list_first(*zaldlist); |
---|
3473 | while (zaldptr) { |
---|
3474 | ZFreeALD(zaldptr->data); |
---|
3475 | owl_free(zaldptr->data); |
---|
3476 | zaldptr = g_list_next(zaldptr); |
---|
3477 | } |
---|
3478 | g_list_free(*zaldlist); |
---|
3479 | *zaldlist = NULL; |
---|
3480 | |
---|
3481 | owl_list_create(&anyone); |
---|
3482 | owl_zephyr_get_anyone_list(&anyone, NULL); |
---|
3483 | j = owl_list_get_size(&anyone); |
---|
3484 | for (i = 0; i < j; i++) { |
---|
3485 | user = owl_list_get_element(&anyone, i); |
---|
3486 | zald = owl_malloc(sizeof(ZAsyncLocateData_t)); |
---|
3487 | if (ZRequestLocations(zstr(user), zald, UNACKED, ZAUTH) == ZERR_NONE) { |
---|
3488 | *zaldlist = g_list_append(*zaldlist, zald); |
---|
3489 | } else { |
---|
3490 | owl_free(zald); |
---|
3491 | } |
---|
3492 | } |
---|
3493 | |
---|
3494 | owl_list_cleanup(&anyone, owl_free); |
---|
3495 | #endif |
---|
3496 | } |
---|
3497 | |
---|
3498 | void owl_function_aimsearch_results(const char *email, owl_list *namelist) |
---|
3499 | { |
---|
3500 | owl_fmtext fm; |
---|
3501 | int i, j; |
---|
3502 | |
---|
3503 | owl_fmtext_init_null(&fm); |
---|
3504 | owl_fmtext_append_normal(&fm, "AIM screennames associated with "); |
---|
3505 | owl_fmtext_append_normal(&fm, email); |
---|
3506 | owl_fmtext_append_normal(&fm, ":\n"); |
---|
3507 | |
---|
3508 | j=owl_list_get_size(namelist); |
---|
3509 | for (i=0; i<j; i++) { |
---|
3510 | owl_fmtext_append_normal(&fm, " "); |
---|
3511 | owl_fmtext_append_normal(&fm, owl_list_get_element(namelist, i)); |
---|
3512 | owl_fmtext_append_normal(&fm, "\n"); |
---|
3513 | } |
---|
3514 | |
---|
3515 | owl_function_popless_fmtext(&fm); |
---|
3516 | owl_fmtext_cleanup(&fm); |
---|
3517 | } |
---|
3518 | |
---|
3519 | int owl_function_get_color_count(void) |
---|
3520 | { |
---|
3521 | return COLORS; |
---|
3522 | } |
---|
3523 | |
---|
3524 | void owl_function_mask_sigint(sigset_t *oldmask) { |
---|
3525 | sigset_t intr; |
---|
3526 | |
---|
3527 | sigemptyset(&intr); |
---|
3528 | sigaddset(&intr, SIGINT); |
---|
3529 | sigprocmask(SIG_BLOCK, &intr, oldmask); |
---|
3530 | } |
---|
3531 | |
---|
3532 | void owl_function_unmask_sigint(sigset_t *oldmask) { |
---|
3533 | sigset_t intr; |
---|
3534 | |
---|
3535 | sigemptyset(&intr); |
---|
3536 | sigaddset(&intr, SIGINT); |
---|
3537 | sigprocmask(SIG_UNBLOCK, &intr, oldmask); |
---|
3538 | } |
---|
3539 | |
---|
3540 | void _owl_function_mark_message(const owl_message *m) |
---|
3541 | { |
---|
3542 | if (m) { |
---|
3543 | owl_global_set_markedmsgid(&g, owl_message_get_id(m)); |
---|
3544 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
3545 | } |
---|
3546 | } |
---|
3547 | |
---|
3548 | void owl_function_mark_message(void) |
---|
3549 | { |
---|
3550 | const owl_message *m; |
---|
3551 | const owl_view *v; |
---|
3552 | |
---|
3553 | v=owl_global_get_current_view(&g); |
---|
3554 | |
---|
3555 | /* bail if there's no current message */ |
---|
3556 | if (owl_view_get_size(v) < 1) { |
---|
3557 | owl_function_error("No messages to mark"); |
---|
3558 | return; |
---|
3559 | } |
---|
3560 | |
---|
3561 | /* mark the message */ |
---|
3562 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
3563 | _owl_function_mark_message(m); |
---|
3564 | owl_function_makemsg("Mark set"); |
---|
3565 | } |
---|
3566 | |
---|
3567 | void owl_function_swap_cur_marked(void) |
---|
3568 | { |
---|
3569 | int marked_id; |
---|
3570 | const owl_message *m; |
---|
3571 | const owl_view *v; |
---|
3572 | |
---|
3573 | marked_id=owl_global_get_markedmsgid(&g); |
---|
3574 | if (marked_id == -1) { |
---|
3575 | owl_function_error("Mark not set."); |
---|
3576 | return; |
---|
3577 | } |
---|
3578 | |
---|
3579 | v=owl_global_get_current_view(&g); |
---|
3580 | /* bail if there's no current message */ |
---|
3581 | if (owl_view_get_size(v) < 1) { |
---|
3582 | return; |
---|
3583 | } |
---|
3584 | |
---|
3585 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
3586 | _owl_function_mark_message(m); |
---|
3587 | owl_global_set_curmsg(&g, owl_view_get_nearest_to_msgid(v, marked_id)); |
---|
3588 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
3589 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
3590 | owl_global_set_direction_downwards(&g); |
---|
3591 | } |
---|