[7d4fbcd] | 1 | #include <stdio.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include <unistd.h> |
---|
| 4 | #include <signal.h> |
---|
[789462a] | 5 | #include <netinet/in.h> |
---|
[7d4fbcd] | 6 | #include <string.h> |
---|
| 7 | #include <time.h> |
---|
[2adaf1d] | 8 | #include <sys/types.h> |
---|
| 9 | #include <sys/stat.h> |
---|
[8f44c6b] | 10 | #include <sys/wait.h> |
---|
| 11 | #include <errno.h> |
---|
[d09e5a1] | 12 | #include <signal.h> |
---|
[7d4fbcd] | 13 | #include "owl.h" |
---|
[d564c3d] | 14 | #include "filterproc.h" |
---|
[7d4fbcd] | 15 | |
---|
[e19eb97] | 16 | char *owl_function_command(const char *cmdbuff) |
---|
[d54838d] | 17 | { |
---|
[7d4fbcd] | 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 | |
---|
[e19eb97] | 23 | char *owl_function_command_argv(const char *const *argv, int argc) |
---|
[c4ba74d] | 24 | { |
---|
| 25 | return owl_cmddict_execute_argv(owl_global_get_cmddict(&g), |
---|
| 26 | owl_global_get_context(&g), |
---|
| 27 | argv, argc); |
---|
| 28 | } |
---|
| 29 | |
---|
[e19eb97] | 30 | void owl_function_command_norv(const char *cmdbuff) |
---|
[d54838d] | 31 | { |
---|
[7d4fbcd] | 32 | char *rv; |
---|
[4b464a4] | 33 | rv=owl_function_command(cmdbuff); |
---|
[7d4fbcd] | 34 | if (rv) owl_free(rv); |
---|
| 35 | } |
---|
| 36 | |
---|
[e19eb97] | 37 | void owl_function_command_alias(const char *alias_from, const char *alias_to) |
---|
[d54838d] | 38 | { |
---|
[7d4fbcd] | 39 | owl_cmddict_add_alias(owl_global_get_cmddict(&g), alias_from, alias_to); |
---|
| 40 | } |
---|
| 41 | |
---|
[0a0fb74] | 42 | const owl_cmd *owl_function_get_cmd(const char *name) |
---|
[d54838d] | 43 | { |
---|
[7d4fbcd] | 44 | return owl_cmddict_find(owl_global_get_cmddict(&g), name); |
---|
| 45 | } |
---|
| 46 | |
---|
[c79a047] | 47 | void owl_function_show_commands(void) |
---|
[d54838d] | 48 | { |
---|
[7d4fbcd] | 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); |
---|
[8d4b521] | 59 | owl_cmddict_namelist_cleanup(&l); |
---|
[7ab0020] | 60 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 61 | } |
---|
| 62 | |
---|
[e19eb97] | 63 | void owl_function_show_view(const char *viewname) |
---|
[ef56a67] | 64 | { |
---|
[9e5c9f3] | 65 | const owl_view *v; |
---|
[ef56a67] | 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))) { |
---|
[ec6ff52] | 71 | owl_function_error("No view named '%s'", viewname); |
---|
[ef56a67] | 72 | return; |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | owl_fmtext_init_null(&fm); |
---|
| 76 | owl_view_to_fmtext(v, &fm); |
---|
| 77 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 78 | owl_fmtext_cleanup(&fm); |
---|
[ef56a67] | 79 | } |
---|
| 80 | |
---|
[c79a047] | 81 | void owl_function_show_styles(void) { |
---|
[f1e629d] | 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); |
---|
[8c59178] | 91 | owl_list_cleanup(&l, owl_free); |
---|
[7ab0020] | 92 | owl_fmtext_cleanup(&fm); |
---|
[f1e629d] | 93 | } |
---|
| 94 | |
---|
[e19eb97] | 95 | char *owl_function_style_describe(const char *name) { |
---|
| 96 | const char *desc; |
---|
[65b2173] | 97 | char *s; |
---|
[1fdab04] | 98 | const owl_style *style; |
---|
[f1e629d] | 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 | } |
---|
[ef56a67] | 110 | |
---|
[e19eb97] | 111 | char *owl_function_cmd_describe(const char *name) |
---|
[d54838d] | 112 | { |
---|
[0a0fb74] | 113 | const owl_cmd *cmd = owl_cmddict_find(owl_global_get_cmddict(&g), name); |
---|
[7d4fbcd] | 114 | if (cmd) return owl_cmd_describe(cmd); |
---|
| 115 | else return(NULL); |
---|
| 116 | } |
---|
| 117 | |
---|
[e19eb97] | 118 | void owl_function_show_command(const char *name) |
---|
[d54838d] | 119 | { |
---|
[7d4fbcd] | 120 | owl_function_help_for_command(name); |
---|
| 121 | } |
---|
| 122 | |
---|
[c79a047] | 123 | void owl_function_show_license(void) |
---|
[debb15d] | 124 | { |
---|
[e19eb97] | 125 | const char *text; |
---|
[debb15d] | 126 | |
---|
| 127 | text="" |
---|
[4228f8b] | 128 | "barnowl version " OWL_VERSION_STRING "\n" |
---|
[1cfcab7] | 129 | "Copyright (c) 2006-2010 The BarnOwl Developers. All rights reserved.\n" |
---|
[debb15d] | 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 | |
---|
[c79a047] | 169 | void owl_function_show_quickstart(void) |
---|
[799b60e] | 170 | { |
---|
[e19eb97] | 171 | const char *message = |
---|
[799b60e] | 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 | |
---|
[15b34fd] | 199 | /* Create an admin message, append it to the global list of messages |
---|
| 200 | * and redisplay if necessary. |
---|
| 201 | */ |
---|
[e19eb97] | 202 | void owl_function_adminmsg(const char *header, const char *body) |
---|
[d54838d] | 203 | { |
---|
[7d4fbcd] | 204 | owl_message *m; |
---|
[4b464a4] | 205 | |
---|
[7d4fbcd] | 206 | m=owl_malloc(sizeof(owl_message)); |
---|
[15b34fd] | 207 | owl_message_create_admin(m, header, body); |
---|
| 208 | |
---|
[8fec514] | 209 | /* add it to the global list and current view */ |
---|
[7d4fbcd] | 210 | owl_messagelist_append_element(owl_global_get_msglist(&g), m); |
---|
| 211 | owl_view_consider_message(owl_global_get_current_view(&g), m); |
---|
| 212 | |
---|
[15b34fd] | 213 | /* do followlast if necessary */ |
---|
| 214 | if (owl_global_should_followlast(&g)) owl_function_lastmsg_noredisplay(); |
---|
[7d4fbcd] | 215 | |
---|
[15b34fd] | 216 | /* redisplay etc. */ |
---|
[7d4fbcd] | 217 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 218 | } |
---|
| 219 | |
---|
[15b34fd] | 220 | /* Create an outgoing zephyr message and return a pointer to it. Does |
---|
[13fe062] | 221 | * not put it on the global queue, use owl_global_messagequeue_addmsg() for |
---|
[15b34fd] | 222 | * that. |
---|
| 223 | */ |
---|
[987cf3f] | 224 | owl_message *owl_function_make_outgoing_zephyr(const owl_zwrite *z) |
---|
[d09e5a1] | 225 | { |
---|
| 226 | owl_message *m; |
---|
| 227 | |
---|
| 228 | /* create the message */ |
---|
| 229 | m=owl_malloc(sizeof(owl_message)); |
---|
[987cf3f] | 230 | owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z)); |
---|
[15b34fd] | 231 | |
---|
| 232 | return(m); |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | /* Create an outgoing AIM message, returns a pointer to the created |
---|
| 236 | * message or NULL if we're not logged into AIM (and thus unable to |
---|
| 237 | * create the message). Does not put it on the global queue. Use |
---|
[13fe062] | 238 | * owl_global_messagequeue_addmsg() for that . |
---|
[15b34fd] | 239 | */ |
---|
[e19eb97] | 240 | owl_message *owl_function_make_outgoing_aim(const char *body, const char *to) |
---|
[15b34fd] | 241 | { |
---|
| 242 | owl_message *m; |
---|
| 243 | |
---|
| 244 | /* error if we're not logged into aim */ |
---|
| 245 | if (!owl_global_is_aimloggedin(&g)) return(NULL); |
---|
| 246 | |
---|
| 247 | m=owl_malloc(sizeof(owl_message)); |
---|
[d559df9] | 248 | owl_message_create_aim(m, |
---|
| 249 | owl_global_get_aim_screenname(&g), |
---|
| 250 | to, |
---|
| 251 | body, |
---|
| 252 | OWL_MESSAGE_DIRECTION_OUT, |
---|
| 253 | 0); |
---|
[15b34fd] | 254 | return(m); |
---|
[d09e5a1] | 255 | } |
---|
| 256 | |
---|
[15b34fd] | 257 | /* Create an outgoing loopback message and return a pointer to it. |
---|
| 258 | * Does not append it to the global queue, use |
---|
[13fe062] | 259 | * owl_global_messagequeue_addmsg() for that. |
---|
[15b34fd] | 260 | */ |
---|
[e19eb97] | 261 | owl_message *owl_function_make_outgoing_loopback(const char *body) |
---|
[37eab7f] | 262 | { |
---|
| 263 | owl_message *m; |
---|
| 264 | |
---|
| 265 | /* create the message */ |
---|
| 266 | m=owl_malloc(sizeof(owl_message)); |
---|
| 267 | owl_message_create_loopback(m, body); |
---|
| 268 | owl_message_set_direction_out(m); |
---|
| 269 | |
---|
[15b34fd] | 270 | return(m); |
---|
[37eab7f] | 271 | } |
---|
| 272 | |
---|
[1b1cd2c] | 273 | void owl_function_start_edit_win(const char *line, void (*callback)(owl_editwin *), void *data, void (*cleanup)(void *)) |
---|
[d54838d] | 274 | { |
---|
[7d4fbcd] | 275 | owl_editwin *e; |
---|
[c394de8] | 276 | owl_context *ctx; |
---|
[bdbec0a] | 277 | char *s; |
---|
| 278 | |
---|
| 279 | /* create and setup the editwin */ |
---|
[58d47ca] | 280 | e = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_MULTILINE, |
---|
| 281 | owl_global_get_msg_history(&g)); |
---|
[bdbec0a] | 282 | owl_editwin_set_dotsend(e); |
---|
| 283 | s = owl_sprintf("----> %s\n", line); |
---|
| 284 | owl_editwin_set_locktext(e, s); |
---|
| 285 | owl_free(s); |
---|
| 286 | |
---|
[38cc669] | 287 | owl_editwin_set_cbdata(e, data, cleanup); |
---|
| 288 | owl_editwin_set_callback(e, callback); |
---|
[4a41f16] | 289 | ctx = owl_editcontext_new(OWL_CTX_EDITMULTI, e, "editmulti", |
---|
| 290 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 291 | owl_global_push_context_obj(&g, ctx); |
---|
| 292 | |
---|
[bdbec0a] | 293 | } |
---|
| 294 | |
---|
[987cf3f] | 295 | static void owl_function_write_setup(const char *noun) |
---|
[bdbec0a] | 296 | { |
---|
| 297 | |
---|
| 298 | if (!owl_global_get_lockout_ctrld(&g)) |
---|
| 299 | owl_function_makemsg("Type your %s below. " |
---|
| 300 | "End with ^D or a dot on a line by itself." |
---|
| 301 | " ^C will quit.", noun); |
---|
| 302 | else |
---|
| 303 | owl_function_makemsg("Type your %s below. " |
---|
| 304 | "End with a dot on a line by itself. ^C will quit.", |
---|
| 305 | noun); |
---|
| 306 | } |
---|
| 307 | |
---|
[987cf3f] | 308 | void owl_function_zwrite_setup(owl_zwrite *z) |
---|
[bdbec0a] | 309 | { |
---|
[7d4fbcd] | 310 | /* send a ping if necessary */ |
---|
| 311 | if (owl_global_is_txping(&g)) { |
---|
[987cf3f] | 312 | owl_zwrite_send_ping(z); |
---|
[7d4fbcd] | 313 | } |
---|
| 314 | |
---|
[987cf3f] | 315 | |
---|
| 316 | owl_function_write_setup("zephyr"); |
---|
| 317 | owl_function_start_edit_win(z->zwriteline, |
---|
| 318 | &owl_callback_zwrite, |
---|
| 319 | z, (void(*)(void*))owl_zwrite_delete); |
---|
[7d4fbcd] | 320 | } |
---|
| 321 | |
---|
[e19eb97] | 322 | void owl_function_aimwrite_setup(const char *line) |
---|
[d09e5a1] | 323 | { |
---|
[987cf3f] | 324 | owl_function_write_setup("message"); |
---|
| 325 | owl_function_start_edit_win(line, |
---|
| 326 | &owl_callback_aimwrite, |
---|
| 327 | owl_strdup(line), |
---|
| 328 | owl_free); |
---|
| 329 | |
---|
[d09e5a1] | 330 | } |
---|
| 331 | |
---|
[c79a047] | 332 | void owl_function_loopwrite_setup(void) |
---|
[37eab7f] | 333 | { |
---|
[987cf3f] | 334 | owl_function_write_setup("message"); |
---|
| 335 | owl_function_start_edit_win("loopwrite", |
---|
| 336 | &owl_callback_loopwrite, |
---|
| 337 | "loopwrite", NULL); |
---|
[1b6b2f3] | 338 | } |
---|
| 339 | |
---|
| 340 | void owl_callback_zwrite(owl_editwin *e) { |
---|
[987cf3f] | 341 | owl_zwrite *z = owl_editwin_get_cbdata(e); |
---|
| 342 | owl_function_zwrite(z, owl_editwin_get_text(e)); |
---|
[37eab7f] | 343 | } |
---|
| 344 | |
---|
[9ceee9d] | 345 | /* send, log and display an outgoing zephyr. If 'msg' is NULL |
---|
| 346 | * the message is expected to be set from the zwrite line itself |
---|
| 347 | */ |
---|
[987cf3f] | 348 | void owl_function_zwrite(owl_zwrite *z, const char *msg) |
---|
[d54838d] | 349 | { |
---|
[15b34fd] | 350 | owl_message *m; |
---|
[0743696] | 351 | int ret; |
---|
[d309eb3] | 352 | |
---|
[987cf3f] | 353 | if(strcmp(z->cmd, "zcrypt") == 0) { |
---|
| 354 | owl_function_zcrypt(z, msg); |
---|
[a5fc448] | 355 | return; |
---|
| 356 | } |
---|
| 357 | |
---|
[9ceee9d] | 358 | /* create the zwrite and send the message */ |
---|
[987cf3f] | 359 | owl_zwrite_populate_zsig(z); |
---|
[9ceee9d] | 360 | if (msg) { |
---|
[987cf3f] | 361 | owl_zwrite_set_message(z, msg); |
---|
[d309eb3] | 362 | } |
---|
[0743696] | 363 | ret = owl_zwrite_send_message(z); |
---|
| 364 | if (ret != 0) { |
---|
| 365 | owl_function_makemsg("Error sending zephyr: %s", error_message(ret)); |
---|
| 366 | return; |
---|
| 367 | } |
---|
[9ceee9d] | 368 | owl_function_makemsg("Waiting for ack..."); |
---|
[d309eb3] | 369 | |
---|
[15b34fd] | 370 | /* If it's personal */ |
---|
[987cf3f] | 371 | if (owl_zwrite_is_personal(z)) { |
---|
[15b34fd] | 372 | /* create the outgoing message */ |
---|
[987cf3f] | 373 | m=owl_function_make_outgoing_zephyr(z); |
---|
[d309eb3] | 374 | |
---|
[3c7d086a] | 375 | if (m) { |
---|
[13a3c1db] | 376 | owl_global_messagequeue_addmsg(&g, m); |
---|
[15b34fd] | 377 | } else { |
---|
[3c7d086a] | 378 | owl_function_error("Could not create outgoing zephyr message"); |
---|
[9ceee9d] | 379 | } |
---|
| 380 | } |
---|
[d309eb3] | 381 | } |
---|
| 382 | |
---|
[9ceee9d] | 383 | /* send, log and display an outgoing zcrypt zephyr. If 'msg' is NULL |
---|
[ce7db4d] | 384 | * the message is expected to be set from the zwrite line itself |
---|
| 385 | */ |
---|
[987cf3f] | 386 | void owl_function_zcrypt(owl_zwrite *z, const char *msg) |
---|
[d54838d] | 387 | { |
---|
[9ceee9d] | 388 | char *cryptmsg; |
---|
[15b34fd] | 389 | owl_message *m; |
---|
[d564c3d] | 390 | const char *argv[7]; |
---|
[9a7b4f2] | 391 | char *zcrypt; |
---|
[d564c3d] | 392 | int rv, status; |
---|
[96582d5] | 393 | char *old_msg; |
---|
[7d4fbcd] | 394 | |
---|
| 395 | /* create the zwrite and send the message */ |
---|
[987cf3f] | 396 | owl_zwrite_populate_zsig(z); |
---|
[ce7db4d] | 397 | if (msg) { |
---|
[987cf3f] | 398 | owl_zwrite_set_message(z, msg); |
---|
[ce7db4d] | 399 | } |
---|
[96582d5] | 400 | old_msg = owl_strdup(owl_zwrite_get_message(z)); |
---|
[d564c3d] | 401 | |
---|
[9a7b4f2] | 402 | zcrypt = owl_sprintf("%s/zcrypt", owl_get_bindir()); |
---|
[d564c3d] | 403 | argv[0] = "zcrypt"; |
---|
| 404 | argv[1] = "-E"; |
---|
[987cf3f] | 405 | argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z); |
---|
| 406 | argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(z); |
---|
[d564c3d] | 407 | argv[6] = NULL; |
---|
| 408 | |
---|
[987cf3f] | 409 | rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status); |
---|
[9a7b4f2] | 410 | |
---|
| 411 | owl_free(zcrypt); |
---|
[d564c3d] | 412 | |
---|
| 413 | if (rv || status) { |
---|
| 414 | if(cryptmsg) owl_free(cryptmsg); |
---|
[96582d5] | 415 | owl_free(old_msg); |
---|
[ec6ff52] | 416 | owl_function_error("Error in zcrypt, possibly no key found. Message not sent."); |
---|
[9ceee9d] | 417 | owl_function_beep(); |
---|
| 418 | return; |
---|
| 419 | } |
---|
| 420 | |
---|
[7bfc613] | 421 | owl_zwrite_set_message_raw(z, cryptmsg); |
---|
[987cf3f] | 422 | owl_zwrite_set_opcode(z, "crypt"); |
---|
[7bfc613] | 423 | |
---|
[987cf3f] | 424 | owl_zwrite_send_message(z); |
---|
[7d4fbcd] | 425 | owl_function_makemsg("Waiting for ack..."); |
---|
| 426 | |
---|
[15b34fd] | 427 | /* If it's personal */ |
---|
[987cf3f] | 428 | if (owl_zwrite_is_personal(z)) { |
---|
[c43c77b] | 429 | /* Create the outgoing message. Restore the un-crypted message for display. */ |
---|
[7bfc613] | 430 | owl_zwrite_set_message_raw(z, old_msg); |
---|
[987cf3f] | 431 | m=owl_function_make_outgoing_zephyr(z); |
---|
[3c7d086a] | 432 | if (m) { |
---|
[13a3c1db] | 433 | owl_global_messagequeue_addmsg(&g, m); |
---|
[15b34fd] | 434 | } else { |
---|
[3c7d086a] | 435 | owl_function_error("Could not create outgoing zephyr message"); |
---|
[7d4fbcd] | 436 | } |
---|
| 437 | } |
---|
| 438 | |
---|
| 439 | /* free the zwrite */ |
---|
[9ceee9d] | 440 | owl_free(cryptmsg); |
---|
[7d4fbcd] | 441 | } |
---|
| 442 | |
---|
[1b6b2f3] | 443 | void owl_callback_aimwrite(owl_editwin *e) { |
---|
[8dfb59c] | 444 | char *command = owl_editwin_get_cbdata(e); |
---|
| 445 | owl_function_aimwrite(command, |
---|
[1b6b2f3] | 446 | owl_editwin_get_text(e)); |
---|
| 447 | } |
---|
| 448 | |
---|
[e19eb97] | 449 | void owl_function_aimwrite(const char *line, const char *msg) |
---|
[d09e5a1] | 450 | { |
---|
[ec6ff52] | 451 | int ret; |
---|
[e19eb97] | 452 | const char *to; |
---|
[65b2173] | 453 | char *format_msg; |
---|
[15b34fd] | 454 | owl_message *m; |
---|
[f82e233] | 455 | |
---|
[4211f50b] | 456 | to = line + 9; |
---|
| 457 | |
---|
[f82e233] | 458 | /* make a formatted copy of the message */ |
---|
| 459 | format_msg=owl_strdup(msg); |
---|
| 460 | owl_text_wordunwrap(format_msg); |
---|
[ec6ff52] | 461 | |
---|
[f82e233] | 462 | /* send the message */ |
---|
| 463 | ret=owl_aim_send_im(to, format_msg); |
---|
[ec6ff52] | 464 | if (!ret) { |
---|
| 465 | owl_function_makemsg("AIM message sent."); |
---|
| 466 | } else { |
---|
| 467 | owl_function_error("Could not send AIM message."); |
---|
| 468 | } |
---|
[d09e5a1] | 469 | |
---|
[15b34fd] | 470 | /* create the outgoing message */ |
---|
| 471 | m=owl_function_make_outgoing_aim(msg, to); |
---|
| 472 | |
---|
[3c7d086a] | 473 | if (m) { |
---|
[13a3c1db] | 474 | owl_global_messagequeue_addmsg(&g, m); |
---|
[15b34fd] | 475 | } else { |
---|
[3c7d086a] | 476 | owl_function_error("Could not create outgoing AIM message"); |
---|
[d09e5a1] | 477 | } |
---|
[f82e233] | 478 | |
---|
| 479 | owl_free(format_msg); |
---|
[d09e5a1] | 480 | } |
---|
| 481 | |
---|
[e19eb97] | 482 | void owl_function_send_aimawymsg(const char *to, const char *msg) |
---|
[9854278] | 483 | { |
---|
| 484 | int ret; |
---|
| 485 | char *format_msg; |
---|
[15b34fd] | 486 | owl_message *m; |
---|
[9854278] | 487 | |
---|
| 488 | /* make a formatted copy of the message */ |
---|
| 489 | format_msg=owl_strdup(msg); |
---|
| 490 | owl_text_wordunwrap(format_msg); |
---|
| 491 | |
---|
| 492 | /* send the message */ |
---|
| 493 | ret=owl_aim_send_awaymsg(to, format_msg); |
---|
| 494 | if (!ret) { |
---|
| 495 | /* owl_function_makemsg("AIM message sent."); */ |
---|
| 496 | } else { |
---|
| 497 | owl_function_error("Could not send AIM message."); |
---|
| 498 | } |
---|
| 499 | |
---|
[15b34fd] | 500 | /* create the message */ |
---|
| 501 | m=owl_function_make_outgoing_aim(msg, to); |
---|
| 502 | if (m) { |
---|
[13a3c1db] | 503 | owl_global_messagequeue_addmsg(&g, m); |
---|
[15b34fd] | 504 | } else { |
---|
| 505 | owl_function_error("Could not create AIM message"); |
---|
[9854278] | 506 | } |
---|
| 507 | owl_free(format_msg); |
---|
| 508 | } |
---|
| 509 | |
---|
[1b6b2f3] | 510 | void owl_callback_loopwrite(owl_editwin *e) { |
---|
| 511 | owl_function_loopwrite(owl_editwin_get_text(e)); |
---|
| 512 | } |
---|
| 513 | |
---|
[e19eb97] | 514 | void owl_function_loopwrite(const char *msg) |
---|
[37eab7f] | 515 | { |
---|
[15b34fd] | 516 | owl_message *min, *mout; |
---|
[37eab7f] | 517 | |
---|
| 518 | /* create a message and put it on the message queue. This simulates |
---|
| 519 | * an incoming message */ |
---|
[15b34fd] | 520 | min=owl_malloc(sizeof(owl_message)); |
---|
[4211f50b] | 521 | mout=owl_function_make_outgoing_loopback(msg); |
---|
[13a3c1db] | 522 | |
---|
[37eab7f] | 523 | if (owl_global_is_displayoutgoing(&g)) { |
---|
[13a3c1db] | 524 | owl_global_messagequeue_addmsg(&g, mout); |
---|
[15b34fd] | 525 | } else { |
---|
[91634ec] | 526 | owl_message_delete(mout); |
---|
[37eab7f] | 527 | } |
---|
| 528 | |
---|
[13a3c1db] | 529 | owl_message_create_loopback(min, msg); |
---|
| 530 | owl_message_set_direction_in(min); |
---|
| 531 | owl_global_messagequeue_addmsg(&g, min); |
---|
| 532 | |
---|
[37eab7f] | 533 | /* fake a makemsg */ |
---|
| 534 | owl_function_makemsg("loopback message sent"); |
---|
| 535 | } |
---|
| 536 | |
---|
[b950088] | 537 | /* If filter is non-null, looks for the next message matching |
---|
| 538 | * that filter. If skip_deleted, skips any deleted messages. |
---|
| 539 | * If last_if_none, will stop at the last message in the view |
---|
| 540 | * if no matching messages are found. */ |
---|
[e19eb97] | 541 | void owl_function_nextmsg_full(const char *filter, int skip_deleted, int last_if_none) |
---|
[d54838d] | 542 | { |
---|
[b950088] | 543 | int curmsg, i, viewsize, found; |
---|
[9e5c9f3] | 544 | const owl_view *v; |
---|
[4542047] | 545 | const owl_filter *f = NULL; |
---|
[c08c70a] | 546 | const owl_message *m; |
---|
[7d4fbcd] | 547 | |
---|
| 548 | v=owl_global_get_current_view(&g); |
---|
[b950088] | 549 | |
---|
| 550 | if (filter) { |
---|
| 551 | f=owl_global_get_filter(&g, filter); |
---|
| 552 | if (!f) { |
---|
[ec6ff52] | 553 | owl_function_error("No %s filter defined", filter); |
---|
[b950088] | 554 | return; |
---|
| 555 | } |
---|
[7d4fbcd] | 556 | } |
---|
| 557 | |
---|
[b950088] | 558 | curmsg=owl_global_get_curmsg(&g); |
---|
| 559 | viewsize=owl_view_get_size(v); |
---|
| 560 | found=0; |
---|
[7d4fbcd] | 561 | |
---|
[b950088] | 562 | /* just check to make sure we're in bounds... */ |
---|
| 563 | if (curmsg>viewsize-1) curmsg=viewsize-1; |
---|
| 564 | if (curmsg<0) curmsg=0; |
---|
[7d4fbcd] | 565 | |
---|
[b950088] | 566 | for (i=curmsg+1; i<viewsize; i++) { |
---|
| 567 | m=owl_view_get_element(v, i); |
---|
| 568 | if (skip_deleted && owl_message_is_delete(m)) continue; |
---|
| 569 | if (f && !owl_filter_message_match(f, m)) continue; |
---|
| 570 | found = 1; |
---|
| 571 | break; |
---|
| 572 | } |
---|
| 573 | |
---|
| 574 | if (i>owl_view_get_size(v)-1) i=owl_view_get_size(v)-1; |
---|
[5763474] | 575 | if (i<0) i=0; |
---|
[b950088] | 576 | |
---|
| 577 | if (!found) { |
---|
[799b60e] | 578 | owl_function_makemsg("already at last%s message%s%s%s", |
---|
[b950088] | 579 | skip_deleted?" non-deleted":"", |
---|
[799b60e] | 580 | filter?" in ":"", filter?filter:"", |
---|
| 581 | owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g)) ? |
---|
| 582 | ", press Enter to scroll" : ""); |
---|
[5a6e6b9] | 583 | /* if (!skip_deleted) owl_function_beep(); */ |
---|
[7d4fbcd] | 584 | } |
---|
| 585 | |
---|
[b950088] | 586 | if (last_if_none || found) { |
---|
| 587 | owl_global_set_curmsg(&g, i); |
---|
| 588 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 589 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 590 | owl_global_set_direction_downwards(&g); |
---|
| 591 | } |
---|
| 592 | } |
---|
[7d4fbcd] | 593 | |
---|
[e19eb97] | 594 | void owl_function_prevmsg_full(const char *filter, int skip_deleted, int first_if_none) |
---|
[d54838d] | 595 | { |
---|
[402eb16f] | 596 | int curmsg, i, found; |
---|
[9e5c9f3] | 597 | const owl_view *v; |
---|
[4542047] | 598 | const owl_filter *f = NULL; |
---|
[c08c70a] | 599 | const owl_message *m; |
---|
[7d4fbcd] | 600 | |
---|
| 601 | v=owl_global_get_current_view(&g); |
---|
| 602 | |
---|
[b950088] | 603 | if (filter) { |
---|
| 604 | f=owl_global_get_filter(&g, filter); |
---|
| 605 | if (!f) { |
---|
[ec6ff52] | 606 | owl_function_error("No %s filter defined", filter); |
---|
[b950088] | 607 | return; |
---|
[7d4fbcd] | 608 | } |
---|
[b950088] | 609 | } |
---|
[7d4fbcd] | 610 | |
---|
[b950088] | 611 | curmsg=owl_global_get_curmsg(&g); |
---|
| 612 | found=0; |
---|
| 613 | |
---|
| 614 | /* just check to make sure we're in bounds... */ |
---|
| 615 | if (curmsg<0) curmsg=0; |
---|
| 616 | |
---|
| 617 | for (i=curmsg-1; i>=0; i--) { |
---|
| 618 | m=owl_view_get_element(v, i); |
---|
| 619 | if (skip_deleted && owl_message_is_delete(m)) continue; |
---|
| 620 | if (f && !owl_filter_message_match(f, m)) continue; |
---|
| 621 | found = 1; |
---|
| 622 | break; |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | if (i<0) i=0; |
---|
| 626 | |
---|
| 627 | if (!found) { |
---|
[f51bc78] | 628 | owl_function_makemsg("already at first%s message%s%s", |
---|
[b950088] | 629 | skip_deleted?" non-deleted":"", |
---|
| 630 | filter?" in ":"", filter?filter:""); |
---|
[5a6e6b9] | 631 | /* if (!skip_deleted) owl_function_beep(); */ |
---|
[b950088] | 632 | } |
---|
| 633 | |
---|
| 634 | if (first_if_none || found) { |
---|
| 635 | owl_global_set_curmsg(&g, i); |
---|
| 636 | owl_function_calculate_topmsg(OWL_DIRECTION_UPWARDS); |
---|
| 637 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 638 | owl_global_set_direction_upwards(&g); |
---|
[7d4fbcd] | 639 | } |
---|
| 640 | } |
---|
| 641 | |
---|
[c79a047] | 642 | void owl_function_nextmsg(void) |
---|
[d54838d] | 643 | { |
---|
[b950088] | 644 | owl_function_nextmsg_full(NULL, 0, 1); |
---|
| 645 | } |
---|
[7d4fbcd] | 646 | |
---|
[c79a047] | 647 | void owl_function_prevmsg(void) |
---|
[d54838d] | 648 | { |
---|
[b950088] | 649 | owl_function_prevmsg_full(NULL, 0, 1); |
---|
| 650 | } |
---|
[7d4fbcd] | 651 | |
---|
[c79a047] | 652 | void owl_function_nextmsg_notdeleted(void) |
---|
[d54838d] | 653 | { |
---|
[b950088] | 654 | owl_function_nextmsg_full(NULL, 1, 1); |
---|
| 655 | } |
---|
[7d4fbcd] | 656 | |
---|
[c79a047] | 657 | void owl_function_prevmsg_notdeleted(void) |
---|
[d54838d] | 658 | { |
---|
[b950088] | 659 | owl_function_prevmsg_full(NULL, 1, 1); |
---|
[7d4fbcd] | 660 | } |
---|
| 661 | |
---|
[b950088] | 662 | /* if move_after is 1, moves after the delete */ |
---|
[d54838d] | 663 | void owl_function_deletecur(int move_after) |
---|
| 664 | { |
---|
[7d4fbcd] | 665 | int curmsg; |
---|
| 666 | owl_view *v; |
---|
| 667 | |
---|
| 668 | v=owl_global_get_current_view(&g); |
---|
| 669 | |
---|
| 670 | /* bail if there's no current message */ |
---|
| 671 | if (owl_view_get_size(v) < 1) { |
---|
[ec6ff52] | 672 | owl_function_error("No current message to delete"); |
---|
[7d4fbcd] | 673 | return; |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | /* mark the message for deletion */ |
---|
| 677 | curmsg=owl_global_get_curmsg(&g); |
---|
| 678 | owl_view_delete_element(v, curmsg); |
---|
| 679 | |
---|
[b950088] | 680 | if (move_after) { |
---|
| 681 | /* move the poiner in the appropriate direction |
---|
| 682 | * to the next undeleted msg */ |
---|
| 683 | if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { |
---|
| 684 | owl_function_prevmsg_notdeleted(); |
---|
| 685 | } else { |
---|
| 686 | owl_function_nextmsg_notdeleted(); |
---|
| 687 | } |
---|
[7d4fbcd] | 688 | } |
---|
| 689 | } |
---|
| 690 | |
---|
[d54838d] | 691 | void owl_function_undeletecur(int move_after) |
---|
| 692 | { |
---|
[7d4fbcd] | 693 | int curmsg; |
---|
| 694 | owl_view *v; |
---|
| 695 | |
---|
| 696 | v=owl_global_get_current_view(&g); |
---|
| 697 | |
---|
| 698 | if (owl_view_get_size(v) < 1) { |
---|
[ec6ff52] | 699 | owl_function_error("No current message to undelete"); |
---|
[7d4fbcd] | 700 | return; |
---|
| 701 | } |
---|
| 702 | curmsg=owl_global_get_curmsg(&g); |
---|
| 703 | |
---|
| 704 | owl_view_undelete_element(v, curmsg); |
---|
| 705 | |
---|
[b950088] | 706 | if (move_after) { |
---|
| 707 | if (owl_global_get_direction(&g)==OWL_DIRECTION_UPWARDS) { |
---|
| 708 | if (curmsg>0) { |
---|
| 709 | owl_function_prevmsg(); |
---|
| 710 | } else { |
---|
| 711 | owl_function_nextmsg(); |
---|
| 712 | } |
---|
[7d4fbcd] | 713 | } else { |
---|
[b950088] | 714 | owl_function_nextmsg(); |
---|
[7d4fbcd] | 715 | } |
---|
| 716 | } |
---|
| 717 | |
---|
| 718 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 719 | } |
---|
| 720 | |
---|
[c79a047] | 721 | void owl_function_expunge(void) |
---|
[d54838d] | 722 | { |
---|
[7d4fbcd] | 723 | int curmsg; |
---|
[c08c70a] | 724 | const owl_message *m; |
---|
[7d4fbcd] | 725 | owl_messagelist *ml; |
---|
| 726 | owl_view *v; |
---|
[486688f] | 727 | int lastmsgid=0; |
---|
[7d4fbcd] | 728 | |
---|
| 729 | curmsg=owl_global_get_curmsg(&g); |
---|
| 730 | v=owl_global_get_current_view(&g); |
---|
| 731 | ml=owl_global_get_msglist(&g); |
---|
| 732 | |
---|
| 733 | m=owl_view_get_element(v, curmsg); |
---|
[486688f] | 734 | if (m) lastmsgid = owl_message_get_id(m); |
---|
[7d4fbcd] | 735 | |
---|
| 736 | /* expunge the message list */ |
---|
| 737 | owl_messagelist_expunge(ml); |
---|
| 738 | |
---|
| 739 | /* update all views (we only have one right now) */ |
---|
| 740 | owl_view_recalculate(v); |
---|
| 741 | |
---|
[486688f] | 742 | /* find where the new position should be |
---|
| 743 | (as close as possible to where we last where) */ |
---|
| 744 | curmsg = owl_view_get_nearest_to_msgid(v, lastmsgid); |
---|
| 745 | if (curmsg>owl_view_get_size(v)-1) curmsg = owl_view_get_size(v)-1; |
---|
| 746 | if (curmsg<0) curmsg = 0; |
---|
| 747 | owl_global_set_curmsg(&g, curmsg); |
---|
| 748 | owl_function_calculate_topmsg(OWL_DIRECTION_NONE); |
---|
[7d4fbcd] | 749 | /* if there are no messages set the direction to down in case we |
---|
| 750 | delete everything upwards */ |
---|
| 751 | owl_global_set_direction_downwards(&g); |
---|
| 752 | |
---|
| 753 | owl_function_makemsg("Messages expunged"); |
---|
| 754 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 755 | } |
---|
| 756 | |
---|
[c79a047] | 757 | void owl_function_firstmsg(void) |
---|
[d54838d] | 758 | { |
---|
[7d4fbcd] | 759 | owl_global_set_curmsg(&g, 0); |
---|
| 760 | owl_global_set_topmsg(&g, 0); |
---|
| 761 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 762 | owl_global_set_direction_downwards(&g); |
---|
| 763 | } |
---|
| 764 | |
---|
[c79a047] | 765 | void owl_function_lastmsg_noredisplay(void) |
---|
[d54838d] | 766 | { |
---|
[5eeea3b] | 767 | int oldcurmsg, curmsg; |
---|
[9e5c9f3] | 768 | const owl_view *v; |
---|
[7d4fbcd] | 769 | |
---|
| 770 | v=owl_global_get_current_view(&g); |
---|
[5eeea3b] | 771 | oldcurmsg=owl_global_get_curmsg(&g); |
---|
| 772 | curmsg=owl_view_get_size(v)-1; |
---|
[7d4fbcd] | 773 | if (curmsg<0) curmsg=0; |
---|
| 774 | owl_global_set_curmsg(&g, curmsg); |
---|
[5eeea3b] | 775 | if (oldcurmsg < curmsg) { |
---|
| 776 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 777 | } else if (curmsg<owl_view_get_size(v)) { |
---|
| 778 | /* If already at the end, blank the screen and move curmsg |
---|
| 779 | * past the end of the messages. */ |
---|
| 780 | owl_global_set_topmsg(&g, curmsg+1); |
---|
| 781 | owl_global_set_curmsg(&g, curmsg+1); |
---|
| 782 | } |
---|
[6b580b0] | 783 | /* owl_mainwin_redisplay(owl_global_get_mainwin(&g)); */ |
---|
[7d4fbcd] | 784 | owl_global_set_direction_downwards(&g); |
---|
| 785 | } |
---|
| 786 | |
---|
[c79a047] | 787 | void owl_function_lastmsg(void) |
---|
[d54838d] | 788 | { |
---|
[7d4fbcd] | 789 | owl_function_lastmsg_noredisplay(); |
---|
| 790 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 791 | } |
---|
| 792 | |
---|
[c79a047] | 793 | void owl_function_shift_right(void) |
---|
[d54838d] | 794 | { |
---|
[7d4fbcd] | 795 | owl_global_set_rightshift(&g, owl_global_get_rightshift(&g)+10); |
---|
| 796 | } |
---|
| 797 | |
---|
[c79a047] | 798 | void owl_function_shift_left(void) |
---|
[d54838d] | 799 | { |
---|
[7d4fbcd] | 800 | int shift; |
---|
| 801 | |
---|
| 802 | shift=owl_global_get_rightshift(&g); |
---|
[8c97fa1] | 803 | if (shift > 0) { |
---|
| 804 | owl_global_set_rightshift(&g, MAX(shift - 10, 0)); |
---|
[7d4fbcd] | 805 | } else { |
---|
| 806 | owl_function_beep(); |
---|
[f51bc78] | 807 | owl_function_makemsg("Already full left"); |
---|
[7d4fbcd] | 808 | } |
---|
| 809 | } |
---|
| 810 | |
---|
[c79a047] | 811 | void owl_function_unsuball(void) |
---|
[d54838d] | 812 | { |
---|
[7d4fbcd] | 813 | unsuball(); |
---|
| 814 | owl_function_makemsg("Unsubscribed from all messages."); |
---|
| 815 | } |
---|
| 816 | |
---|
[95474d7] | 817 | |
---|
| 818 | /* Load zephyr subscriptions from the named 'file' and load zephyr's |
---|
| 819 | * default subscriptions as well. An error message is printed if |
---|
| 820 | * 'file' can't be opened or if zephyr reports an error in |
---|
| 821 | * subscribing. |
---|
| 822 | * |
---|
| 823 | * If 'file' is NULL, this look for the default filename |
---|
| 824 | * $HOME/.zephyr.subs. If the file can not be opened in this case |
---|
| 825 | * only, no error message is printed. |
---|
| 826 | */ |
---|
[e19eb97] | 827 | void owl_function_loadsubs(const char *file) |
---|
[d54838d] | 828 | { |
---|
[4357be8] | 829 | int ret, ret2; |
---|
[e19eb97] | 830 | const char *foo; |
---|
[65b2173] | 831 | char *path; |
---|
[ecd5dc5] | 832 | |
---|
[95474d7] | 833 | if (file==NULL) { |
---|
| 834 | ret=owl_zephyr_loadsubs(NULL, 0); |
---|
| 835 | } else { |
---|
[27d8d83] | 836 | path = owl_util_makepath(file); |
---|
| 837 | ret=owl_zephyr_loadsubs(path, 1); |
---|
[27f6487] | 838 | owl_free(path); |
---|
[95474d7] | 839 | } |
---|
[ecd5dc5] | 840 | |
---|
[4357be8] | 841 | /* for backwards compatibility for now */ |
---|
| 842 | ret2=owl_zephyr_loaddefaultsubs(); |
---|
| 843 | |
---|
[ecd5dc5] | 844 | if (!owl_context_is_interactive(owl_global_get_context(&g))) return; |
---|
[95474d7] | 845 | |
---|
| 846 | foo=file?file:"file"; |
---|
| 847 | if (ret==0 && ret2==0) { |
---|
| 848 | if (!file) { |
---|
| 849 | owl_function_makemsg("Subscribed to messages."); |
---|
| 850 | } else { |
---|
| 851 | owl_function_makemsg("Subscribed to messages from %s", file); |
---|
| 852 | } |
---|
[7d4fbcd] | 853 | } else if (ret==-1) { |
---|
[95474d7] | 854 | owl_function_error("Could not read %s", foo); |
---|
[7d4fbcd] | 855 | } else { |
---|
[95474d7] | 856 | owl_function_error("Error subscribing to messages"); |
---|
[7d4fbcd] | 857 | } |
---|
| 858 | } |
---|
| 859 | |
---|
[e19eb97] | 860 | void owl_function_loadloginsubs(const char *file) |
---|
[d54838d] | 861 | { |
---|
[7933748] | 862 | int ret; |
---|
[ecd5dc5] | 863 | |
---|
[7933748] | 864 | ret=owl_zephyr_loadloginsubs(file); |
---|
[ecd5dc5] | 865 | |
---|
| 866 | if (!owl_context_is_interactive(owl_global_get_context(&g))) return; |
---|
[7933748] | 867 | if (ret==0) { |
---|
| 868 | } else if (ret==-1) { |
---|
[ec6ff52] | 869 | owl_function_error("Could not open file for login subscriptions."); |
---|
[7933748] | 870 | } else { |
---|
[ec6ff52] | 871 | owl_function_error("Error subscribing to login messages from file."); |
---|
[7933748] | 872 | } |
---|
| 873 | } |
---|
| 874 | |
---|
[1b6b2f3] | 875 | void owl_callback_aimlogin(owl_editwin *e) { |
---|
[8dfb59c] | 876 | char *user = owl_editwin_get_cbdata(e); |
---|
| 877 | owl_function_aimlogin(user, |
---|
[db8b00b] | 878 | owl_editwin_get_text(e)); |
---|
[1b6b2f3] | 879 | } |
---|
| 880 | |
---|
[e19eb97] | 881 | void owl_function_aimlogin(const char *user, const char *passwd) { |
---|
[4211f50b] | 882 | int ret; |
---|
| 883 | |
---|
| 884 | /* clear the buddylist */ |
---|
| 885 | owl_buddylist_clear(owl_global_get_buddylist(&g)); |
---|
| 886 | |
---|
| 887 | /* try to login */ |
---|
| 888 | ret=owl_aim_login(user, passwd); |
---|
| 889 | if (ret) owl_function_makemsg("Warning: login for %s failed.\n", user); |
---|
| 890 | } |
---|
| 891 | |
---|
[c79a047] | 892 | void owl_function_suspend(void) |
---|
[d54838d] | 893 | { |
---|
[7d4fbcd] | 894 | endwin(); |
---|
| 895 | printf("\n"); |
---|
| 896 | kill(getpid(), SIGSTOP); |
---|
| 897 | |
---|
| 898 | /* resize to reinitialize all the windows when we come back */ |
---|
| 899 | owl_command_resize(); |
---|
| 900 | } |
---|
| 901 | |
---|
[c79a047] | 902 | void owl_function_zaway_toggle(void) |
---|
[d54838d] | 903 | { |
---|
[7d4fbcd] | 904 | if (!owl_global_is_zaway(&g)) { |
---|
| 905 | owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g)); |
---|
| 906 | owl_function_zaway_on(); |
---|
| 907 | } else { |
---|
| 908 | owl_function_zaway_off(); |
---|
| 909 | } |
---|
| 910 | } |
---|
| 911 | |
---|
[c79a047] | 912 | void owl_function_zaway_on(void) |
---|
[d54838d] | 913 | { |
---|
[7d4fbcd] | 914 | owl_global_set_zaway_on(&g); |
---|
[4b660cc] | 915 | owl_function_makemsg("zaway set (%s)", owl_global_get_zaway_msg(&g)); |
---|
[7d4fbcd] | 916 | } |
---|
| 917 | |
---|
[c79a047] | 918 | void owl_function_zaway_off(void) |
---|
[d54838d] | 919 | { |
---|
[7d4fbcd] | 920 | owl_global_set_zaway_off(&g); |
---|
[4b660cc] | 921 | owl_function_makemsg("zaway off"); |
---|
| 922 | } |
---|
| 923 | |
---|
[c79a047] | 924 | void owl_function_aaway_toggle(void) |
---|
[4b660cc] | 925 | { |
---|
| 926 | if (!owl_global_is_aaway(&g)) { |
---|
| 927 | owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g)); |
---|
| 928 | owl_function_aaway_on(); |
---|
| 929 | } else { |
---|
| 930 | owl_function_aaway_off(); |
---|
| 931 | } |
---|
| 932 | } |
---|
| 933 | |
---|
[c79a047] | 934 | void owl_function_aaway_on(void) |
---|
[4b660cc] | 935 | { |
---|
| 936 | owl_global_set_aaway_on(&g); |
---|
| 937 | /* owl_aim_set_awaymsg(owl_global_get_zaway_msg(&g)); */ |
---|
| 938 | owl_function_makemsg("AIM away set (%s)", owl_global_get_aaway_msg(&g)); |
---|
| 939 | } |
---|
| 940 | |
---|
[c79a047] | 941 | void owl_function_aaway_off(void) |
---|
[4b660cc] | 942 | { |
---|
| 943 | owl_global_set_aaway_off(&g); |
---|
| 944 | /* owl_aim_set_awaymsg(""); */ |
---|
| 945 | owl_function_makemsg("AIM away off"); |
---|
[7d4fbcd] | 946 | } |
---|
| 947 | |
---|
[c79a047] | 948 | void owl_function_quit(void) |
---|
[d54838d] | 949 | { |
---|
[7d4fbcd] | 950 | char *ret; |
---|
| 951 | |
---|
| 952 | /* zlog out if we need to */ |
---|
[7433402] | 953 | if (owl_global_is_havezephyr(&g) && |
---|
| 954 | owl_global_is_shutdownlogout(&g)) { |
---|
[31e48a3] | 955 | owl_zephyr_zlog_out(); |
---|
[7d4fbcd] | 956 | } |
---|
| 957 | |
---|
| 958 | /* execute the commands in shutdown */ |
---|
[0337203] | 959 | ret = owl_perlconfig_execute("BarnOwl::Hooks::_shutdown();"); |
---|
[7d4fbcd] | 960 | if (ret) owl_free(ret); |
---|
| 961 | |
---|
[d09e5a1] | 962 | /* signal our child process, if any */ |
---|
| 963 | if (owl_global_get_newmsgproc_pid(&g)) { |
---|
| 964 | kill(owl_global_get_newmsgproc_pid(&g), SIGHUP); |
---|
| 965 | } |
---|
[8c46404] | 966 | |
---|
| 967 | /* Quit AIM */ |
---|
| 968 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 969 | owl_aim_logout(); |
---|
| 970 | } |
---|
| 971 | |
---|
[7d4fbcd] | 972 | owl_function_debugmsg("Quitting Owl"); |
---|
[3ecd78b] | 973 | owl_select_quit_loop(); |
---|
[7d4fbcd] | 974 | } |
---|
| 975 | |
---|
[d54838d] | 976 | void owl_function_calculate_topmsg(int direction) |
---|
| 977 | { |
---|
[aa2f33b3] | 978 | int recwinlines, topmsg, curmsg; |
---|
[9e5c9f3] | 979 | const owl_view *v; |
---|
[7d4fbcd] | 980 | |
---|
| 981 | v=owl_global_get_current_view(&g); |
---|
[aa2f33b3] | 982 | curmsg=owl_global_get_curmsg(&g); |
---|
| 983 | topmsg=owl_global_get_topmsg(&g); |
---|
[7d4fbcd] | 984 | recwinlines=owl_global_get_recwin_lines(&g); |
---|
| 985 | |
---|
[f9c43ae] | 986 | /* |
---|
[7d4fbcd] | 987 | if (owl_view_get_size(v) < 1) { |
---|
| 988 | return; |
---|
| 989 | } |
---|
[f9c43ae] | 990 | */ |
---|
[aa2f33b3] | 991 | |
---|
| 992 | switch (owl_global_get_scrollmode(&g)) { |
---|
| 993 | case OWL_SCROLLMODE_TOP: |
---|
[f9c43ae] | 994 | topmsg = owl_function_calculate_topmsg_top(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 995 | break; |
---|
| 996 | case OWL_SCROLLMODE_NEARTOP: |
---|
[f9c43ae] | 997 | topmsg = owl_function_calculate_topmsg_neartop(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 998 | break; |
---|
| 999 | case OWL_SCROLLMODE_CENTER: |
---|
[f9c43ae] | 1000 | topmsg = owl_function_calculate_topmsg_center(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 1001 | break; |
---|
| 1002 | case OWL_SCROLLMODE_PAGED: |
---|
[f9c43ae] | 1003 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 0); |
---|
[aa2f33b3] | 1004 | break; |
---|
| 1005 | case OWL_SCROLLMODE_PAGEDCENTER: |
---|
[f9c43ae] | 1006 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 1); |
---|
[aa2f33b3] | 1007 | break; |
---|
| 1008 | case OWL_SCROLLMODE_NORMAL: |
---|
| 1009 | default: |
---|
[f9c43ae] | 1010 | topmsg = owl_function_calculate_topmsg_normal(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 1011 | } |
---|
[3a2daac] | 1012 | owl_function_debugmsg("Calculated a topmsg of %i", topmsg); |
---|
[aa2f33b3] | 1013 | owl_global_set_topmsg(&g, topmsg); |
---|
| 1014 | } |
---|
| 1015 | |
---|
| 1016 | /* Returns what the new topmsg should be. |
---|
| 1017 | * Passed the last direction of movement, |
---|
| 1018 | * the current view, |
---|
| 1019 | * the current message number in the view, |
---|
| 1020 | * the top message currently being displayed, |
---|
| 1021 | * and the number of lines in the recwin. |
---|
| 1022 | */ |
---|
[9e5c9f3] | 1023 | int owl_function_calculate_topmsg_top(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1024 | { |
---|
[f9c43ae] | 1025 | return(curmsg); |
---|
[aa2f33b3] | 1026 | } |
---|
| 1027 | |
---|
[9e5c9f3] | 1028 | int owl_function_calculate_topmsg_neartop(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1029 | { |
---|
[aa2f33b3] | 1030 | if (curmsg>0 |
---|
| 1031 | && (owl_message_get_numlines(owl_view_get_element(v, curmsg-1)) |
---|
| 1032 | < recwinlines/2)) { |
---|
[f9c43ae] | 1033 | return(curmsg-1); |
---|
[aa2f33b3] | 1034 | } else { |
---|
[f9c43ae] | 1035 | return(curmsg); |
---|
[aa2f33b3] | 1036 | } |
---|
| 1037 | } |
---|
| 1038 | |
---|
[9e5c9f3] | 1039 | int owl_function_calculate_topmsg_center(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1040 | { |
---|
[aa2f33b3] | 1041 | int i, last, lines; |
---|
| 1042 | |
---|
| 1043 | last = curmsg; |
---|
| 1044 | lines = 0; |
---|
| 1045 | for (i=curmsg-1; i>=0; i--) { |
---|
| 1046 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1047 | if (lines > recwinlines/2) break; |
---|
| 1048 | last = i; |
---|
| 1049 | } |
---|
[f9c43ae] | 1050 | return(last); |
---|
[aa2f33b3] | 1051 | } |
---|
| 1052 | |
---|
[9e5c9f3] | 1053 | int owl_function_calculate_topmsg_paged(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines, int center_on_page) |
---|
[d54838d] | 1054 | { |
---|
[aa2f33b3] | 1055 | int i, last, lines, savey; |
---|
| 1056 | |
---|
| 1057 | /* If we're off the top of the screen, scroll up such that the |
---|
| 1058 | * curmsg is near the botton of the screen. */ |
---|
| 1059 | if (curmsg < topmsg) { |
---|
| 1060 | last = curmsg; |
---|
| 1061 | lines = 0; |
---|
| 1062 | for (i=curmsg; i>=0; i--) { |
---|
| 1063 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1064 | if (lines > recwinlines) break; |
---|
| 1065 | last = i; |
---|
| 1066 | } |
---|
| 1067 | if (center_on_page) { |
---|
[f9c43ae] | 1068 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
[aa2f33b3] | 1069 | } else { |
---|
[f9c43ae] | 1070 | return(last); |
---|
[aa2f33b3] | 1071 | } |
---|
| 1072 | } |
---|
| 1073 | |
---|
| 1074 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
| 1075 | savey=0; |
---|
| 1076 | for (i=topmsg; i<=curmsg; i++) { |
---|
| 1077 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1078 | } |
---|
| 1079 | |
---|
| 1080 | /* if we're off the bottom of the screen, scroll down */ |
---|
| 1081 | if (savey > recwinlines) { |
---|
| 1082 | if (center_on_page) { |
---|
[f9c43ae] | 1083 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
[aa2f33b3] | 1084 | } else { |
---|
[f9c43ae] | 1085 | return(curmsg); |
---|
[aa2f33b3] | 1086 | } |
---|
| 1087 | } |
---|
| 1088 | |
---|
| 1089 | /* else just stay as we are... */ |
---|
[f9c43ae] | 1090 | return(topmsg); |
---|
[aa2f33b3] | 1091 | } |
---|
| 1092 | |
---|
[9e5c9f3] | 1093 | int owl_function_calculate_topmsg_normal(int direction, const owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
[d54838d] | 1094 | { |
---|
[801b7ac] | 1095 | int savey, i, foo, y; |
---|
[f9c43ae] | 1096 | |
---|
[88736cb] | 1097 | if (curmsg<0) return(topmsg); |
---|
| 1098 | |
---|
[f9c43ae] | 1099 | /* If we're off the top of the screen then center */ |
---|
| 1100 | if (curmsg<topmsg) { |
---|
| 1101 | topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines); |
---|
| 1102 | } |
---|
| 1103 | |
---|
[801b7ac] | 1104 | /* If curmsg is so far past topmsg that there are more messages than |
---|
| 1105 | lines, skip the line counting that follows because we're |
---|
| 1106 | certainly off screen. */ |
---|
| 1107 | savey=curmsg-topmsg; |
---|
| 1108 | if (savey <= recwinlines) { |
---|
| 1109 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
| 1110 | savey = 0; |
---|
| 1111 | for (i=topmsg; i<=curmsg; i++) { |
---|
| 1112 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1113 | } |
---|
[7d4fbcd] | 1114 | } |
---|
| 1115 | |
---|
[f9c43ae] | 1116 | /* If we're off the bottom of the screen, set the topmsg to curmsg |
---|
| 1117 | * and scroll upwards */ |
---|
| 1118 | if (savey > recwinlines) { |
---|
| 1119 | topmsg=curmsg; |
---|
[801b7ac] | 1120 | savey=owl_message_get_numlines(owl_view_get_element(v, curmsg)); |
---|
[f9c43ae] | 1121 | direction=OWL_DIRECTION_UPWARDS; |
---|
[7d4fbcd] | 1122 | } |
---|
[f9c43ae] | 1123 | |
---|
[7d4fbcd] | 1124 | /* If our bottom line is less than 1/4 down the screen then scroll up */ |
---|
| 1125 | if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) { |
---|
| 1126 | if (savey < (recwinlines / 4)) { |
---|
| 1127 | y=0; |
---|
[801b7ac] | 1128 | for (i=curmsg; i>=0; i--) { |
---|
| 1129 | foo=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
[7d4fbcd] | 1130 | /* will we run the curmsg off the screen? */ |
---|
| 1131 | if ((foo+y) >= recwinlines) { |
---|
[801b7ac] | 1132 | i++; |
---|
| 1133 | if (i>curmsg) i=curmsg; |
---|
[7d4fbcd] | 1134 | break; |
---|
| 1135 | } |
---|
| 1136 | /* have saved 1/2 the screen space? */ |
---|
| 1137 | y+=foo; |
---|
| 1138 | if (y > (recwinlines / 2)) break; |
---|
| 1139 | } |
---|
[801b7ac] | 1140 | if (i<0) i=0; |
---|
| 1141 | return(i); |
---|
[7d4fbcd] | 1142 | } |
---|
| 1143 | } |
---|
| 1144 | |
---|
| 1145 | if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) { |
---|
| 1146 | /* If curmsg bottom line is more than 3/4 down the screen then scroll down */ |
---|
| 1147 | if (savey > ((recwinlines * 3)/4)) { |
---|
| 1148 | y=0; |
---|
| 1149 | /* count lines from the top until we can save 1/2 the screen size */ |
---|
[801b7ac] | 1150 | for (i=topmsg; i<curmsg; i++) { |
---|
| 1151 | y+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
[7d4fbcd] | 1152 | if (y > (recwinlines / 2)) break; |
---|
| 1153 | } |
---|
[801b7ac] | 1154 | if (i==curmsg) { |
---|
| 1155 | i--; |
---|
[7d4fbcd] | 1156 | } |
---|
[801b7ac] | 1157 | return(i+1); |
---|
[7d4fbcd] | 1158 | } |
---|
| 1159 | } |
---|
[aa2f33b3] | 1160 | |
---|
[f9c43ae] | 1161 | return(topmsg); |
---|
[7d4fbcd] | 1162 | } |
---|
| 1163 | |
---|
[c79a047] | 1164 | void owl_function_resize(void) |
---|
[d54838d] | 1165 | { |
---|
[7d4fbcd] | 1166 | owl_global_set_resize_pending(&g); |
---|
| 1167 | } |
---|
| 1168 | |
---|
[e19eb97] | 1169 | void owl_function_debugmsg(const char *fmt, ...) |
---|
[d54838d] | 1170 | { |
---|
[7d4fbcd] | 1171 | FILE *file; |
---|
| 1172 | time_t now; |
---|
| 1173 | va_list ap; |
---|
| 1174 | va_start(ap, fmt); |
---|
| 1175 | |
---|
[52761cc] | 1176 | if (!owl_global_is_debug_fast(&g)) |
---|
| 1177 | return; |
---|
[7d4fbcd] | 1178 | |
---|
[d12a8c7] | 1179 | file = owl_global_get_debug_file_handle(&g); |
---|
[52761cc] | 1180 | if (!file) /* XXX should report this */ |
---|
| 1181 | return; |
---|
[7d4fbcd] | 1182 | |
---|
[52761cc] | 1183 | now = time(NULL); |
---|
[7d4fbcd] | 1184 | |
---|
[52761cc] | 1185 | fprintf(file, "[%d - %.24s - %lds]: ", |
---|
| 1186 | (int) getpid(), ctime(&now), now - owl_global_get_starttime(&g)); |
---|
[7d4fbcd] | 1187 | vfprintf(file, fmt, ap); |
---|
[52761cc] | 1188 | putc('\n', file); |
---|
[d12a8c7] | 1189 | fflush(file); |
---|
[7d4fbcd] | 1190 | |
---|
| 1191 | va_end(ap); |
---|
| 1192 | } |
---|
| 1193 | |
---|
[c79a047] | 1194 | void owl_function_beep(void) |
---|
[d54838d] | 1195 | { |
---|
[7d4fbcd] | 1196 | if (owl_global_is_bell(&g)) { |
---|
| 1197 | beep(); |
---|
| 1198 | } |
---|
| 1199 | } |
---|
| 1200 | |
---|
[e19eb97] | 1201 | int owl_function_subscribe(const char *class, const char *inst, const char *recip) |
---|
[d54838d] | 1202 | { |
---|
[7d4fbcd] | 1203 | int ret; |
---|
| 1204 | |
---|
| 1205 | ret=owl_zephyr_sub(class, inst, recip); |
---|
| 1206 | if (ret) { |
---|
[ec6ff52] | 1207 | owl_function_error("Error subscribing."); |
---|
[7d4fbcd] | 1208 | } else { |
---|
| 1209 | owl_function_makemsg("Subscribed."); |
---|
| 1210 | } |
---|
[3617286] | 1211 | return(ret); |
---|
[7d4fbcd] | 1212 | } |
---|
| 1213 | |
---|
[e19eb97] | 1214 | void owl_function_unsubscribe(const char *class, const char *inst, const char *recip) |
---|
[d54838d] | 1215 | { |
---|
[7d4fbcd] | 1216 | int ret; |
---|
| 1217 | |
---|
| 1218 | ret=owl_zephyr_unsub(class, inst, recip); |
---|
| 1219 | if (ret) { |
---|
[ec6ff52] | 1220 | owl_function_error("Error subscribing."); |
---|
[7d4fbcd] | 1221 | } else { |
---|
| 1222 | owl_function_makemsg("Unsubscribed."); |
---|
| 1223 | } |
---|
| 1224 | } |
---|
| 1225 | |
---|
[e8128c5] | 1226 | static void _dirty_everything(owl_window *w) { |
---|
| 1227 | if (!owl_window_is_realized(w)) |
---|
| 1228 | return; |
---|
| 1229 | owl_window_dirty(w); |
---|
| 1230 | owl_window_children_foreach(w, (GFunc)_dirty_everything, NULL); |
---|
[7d4fbcd] | 1231 | } |
---|
| 1232 | |
---|
[c79a047] | 1233 | void owl_function_full_redisplay(void) |
---|
[d54838d] | 1234 | { |
---|
[e8128c5] | 1235 | _dirty_everything(owl_window_get_screen()); |
---|
[7d4fbcd] | 1236 | } |
---|
| 1237 | |
---|
[e19eb97] | 1238 | void owl_function_popless_text(const char *text) |
---|
[d54838d] | 1239 | { |
---|
[7d4fbcd] | 1240 | owl_popwin *pw; |
---|
| 1241 | owl_viewwin *v; |
---|
| 1242 | |
---|
[9eb38bb] | 1243 | if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) { |
---|
[4cf7b1b] | 1244 | owl_function_error("Popwin already in use."); |
---|
| 1245 | return; |
---|
| 1246 | } |
---|
[03ca005] | 1247 | pw = owl_popwin_new(); |
---|
| 1248 | owl_global_set_popwin(&g, pw); |
---|
| 1249 | owl_popwin_up(pw); |
---|
[9eb38bb] | 1250 | |
---|
| 1251 | v = owl_viewwin_new_text(owl_popwin_get_content(pw), text); |
---|
| 1252 | owl_global_set_viewwin(&g, v); |
---|
| 1253 | |
---|
[07b59ea] | 1254 | owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL); |
---|
[7d4fbcd] | 1255 | } |
---|
| 1256 | |
---|
[075ba92] | 1257 | void owl_function_popless_fmtext(const owl_fmtext *fm) |
---|
[d54838d] | 1258 | { |
---|
[7d4fbcd] | 1259 | owl_popwin *pw; |
---|
| 1260 | owl_viewwin *v; |
---|
| 1261 | |
---|
[9eb38bb] | 1262 | if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) { |
---|
[4cf7b1b] | 1263 | owl_function_error("Popwin already in use."); |
---|
| 1264 | return; |
---|
| 1265 | } |
---|
[03ca005] | 1266 | pw = owl_popwin_new(); |
---|
| 1267 | owl_global_set_popwin(&g, pw); |
---|
| 1268 | owl_popwin_up(pw); |
---|
[9eb38bb] | 1269 | |
---|
| 1270 | v = owl_viewwin_new_fmtext(owl_popwin_get_content(pw), fm); |
---|
| 1271 | owl_global_set_viewwin(&g, v); |
---|
| 1272 | |
---|
[07b59ea] | 1273 | owl_global_push_context(&g, OWL_CTX_POPLESS, v, "popless", NULL); |
---|
[f17bff98] | 1274 | } |
---|
| 1275 | |
---|
[e19eb97] | 1276 | void owl_function_popless_file(const char *filename) |
---|
[f17bff98] | 1277 | { |
---|
| 1278 | owl_fmtext fm; |
---|
| 1279 | FILE *file; |
---|
[b7ee89b] | 1280 | char *s = NULL; |
---|
[f17bff98] | 1281 | |
---|
| 1282 | file=fopen(filename, "r"); |
---|
| 1283 | if (!file) { |
---|
| 1284 | owl_function_error("Could not open file: %s", filename); |
---|
| 1285 | return; |
---|
| 1286 | } |
---|
| 1287 | |
---|
| 1288 | owl_fmtext_init_null(&fm); |
---|
[b7ee89b] | 1289 | while (owl_getline(&s, file)) |
---|
| 1290 | owl_fmtext_append_normal(&fm, s); |
---|
| 1291 | owl_free(s); |
---|
[f17bff98] | 1292 | |
---|
| 1293 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1294 | owl_fmtext_cleanup(&fm); |
---|
[f17bff98] | 1295 | fclose(file); |
---|
[7d4fbcd] | 1296 | } |
---|
| 1297 | |
---|
[c79a047] | 1298 | void owl_function_about(void) |
---|
[d54838d] | 1299 | { |
---|
[2101a50] | 1300 | owl_function_popless_text( |
---|
| 1301 | "This is barnowl version " OWL_VERSION_STRING ".\n\n" |
---|
| 1302 | "barnowl is a fork of the Owl zephyr client, written and\n" |
---|
| 1303 | "maintained by Alejandro Sedeno and Nelson Elhage at the\n" |
---|
| 1304 | "Massachusetts Institute of Technology. \n" |
---|
| 1305 | "\n" |
---|
| 1306 | "Owl was written by James Kretchmar. The first version, 0.5, was\n" |
---|
| 1307 | "released in March 2002.\n" |
---|
| 1308 | "\n" |
---|
| 1309 | "The name 'owl' was chosen in reference to the owls in the\n" |
---|
| 1310 | "Harry Potter novels, who are tasked with carrying messages\n" |
---|
| 1311 | "between Witches and Wizards. The name 'barnowl' was chosen\n" |
---|
| 1312 | "because we feel our owls should live closer to our ponies.\n" |
---|
| 1313 | "\n" |
---|
[1cfcab7] | 1314 | "Copyright (c) 2006-2010 The BarnOwl Developers. All rights reserved.\n" |
---|
[2101a50] | 1315 | "Copyright (c) 2004 James Kretchmar. All rights reserved.\n" |
---|
| 1316 | "Copyright 2002 Massachusetts Institute of Technology\n" |
---|
| 1317 | "\n" |
---|
| 1318 | "This program is free software. You can redistribute it and/or\n" |
---|
| 1319 | "modify under the terms of the Sleepycat License. Use the \n" |
---|
| 1320 | "':show license' command to display the full license\n" |
---|
| 1321 | ); |
---|
[7d4fbcd] | 1322 | } |
---|
| 1323 | |
---|
[c79a047] | 1324 | void owl_function_info(void) |
---|
[d54838d] | 1325 | { |
---|
[c08c70a] | 1326 | const owl_message *m; |
---|
[5789230] | 1327 | owl_fmtext fm, attrfm; |
---|
[9e5c9f3] | 1328 | const owl_view *v; |
---|
[09489b89] | 1329 | #ifdef HAVE_LIBZEPHYR |
---|
[1077891a] | 1330 | const ZNotice_t *n; |
---|
[09489b89] | 1331 | #endif |
---|
[7d4fbcd] | 1332 | |
---|
[d0d65df] | 1333 | owl_fmtext_init_null(&fm); |
---|
| 1334 | |
---|
[7d4fbcd] | 1335 | v=owl_global_get_current_view(&g); |
---|
[5eeea3b] | 1336 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 1337 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 1338 | owl_function_error("No message selected\n"); |
---|
[7d4fbcd] | 1339 | return; |
---|
| 1340 | } |
---|
| 1341 | |
---|
[5789230] | 1342 | owl_fmtext_append_bold(&fm, "General Information:\n"); |
---|
[57609b3] | 1343 | owl_fmtext_appendf_normal(&fm, " Msg Id : %i\n", owl_message_get_id(m)); |
---|
[df0d93a] | 1344 | |
---|
[5789230] | 1345 | owl_fmtext_append_normal(&fm, " Type : "); |
---|
[37eab7f] | 1346 | owl_fmtext_append_bold(&fm, owl_message_get_type(m)); |
---|
[df0d93a] | 1347 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1348 | |
---|
[4b464a4] | 1349 | if (owl_message_is_direction_in(m)) { |
---|
[5789230] | 1350 | owl_fmtext_append_normal(&fm, " Direction : in\n"); |
---|
[4b464a4] | 1351 | } else if (owl_message_is_direction_out(m)) { |
---|
[5789230] | 1352 | owl_fmtext_append_normal(&fm, " Direction : out\n"); |
---|
[4b464a4] | 1353 | } else if (owl_message_is_direction_none(m)) { |
---|
[5789230] | 1354 | owl_fmtext_append_normal(&fm, " Direction : none\n"); |
---|
[4b464a4] | 1355 | } else { |
---|
[5789230] | 1356 | owl_fmtext_append_normal(&fm, " Direction : unknown\n"); |
---|
[4b464a4] | 1357 | } |
---|
[df0d93a] | 1358 | |
---|
[57609b3] | 1359 | owl_fmtext_appendf_normal(&fm, " Time : %s\n", owl_message_get_timestr(m)); |
---|
[4b464a4] | 1360 | |
---|
[df0d93a] | 1361 | if (!owl_message_is_type_admin(m)) { |
---|
[57609b3] | 1362 | owl_fmtext_appendf_normal(&fm, " Sender : %s\n", owl_message_get_sender(m)); |
---|
| 1363 | owl_fmtext_appendf_normal(&fm, " Recipient : %s\n", owl_message_get_recipient(m)); |
---|
[df0d93a] | 1364 | } |
---|
[57609b3] | 1365 | |
---|
[0ff8fb57] | 1366 | if (owl_message_is_type_zephyr(m)) { |
---|
[5789230] | 1367 | owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n"); |
---|
[0ff8fb57] | 1368 | |
---|
[57609b3] | 1369 | owl_fmtext_appendf_normal(&fm, " Class : %s\n", owl_message_get_class(m)); |
---|
| 1370 | owl_fmtext_appendf_normal(&fm, " Instance : %s\n", owl_message_get_instance(m)); |
---|
| 1371 | owl_fmtext_appendf_normal(&fm, " Opcode : %s\n", owl_message_get_opcode(m)); |
---|
[09489b89] | 1372 | #ifdef HAVE_LIBZEPHYR |
---|
[d0d65df] | 1373 | if (owl_message_is_direction_in(m)) { |
---|
[09489b89] | 1374 | char *ptr, tmpbuff[1024]; |
---|
| 1375 | int i, j, fields, len; |
---|
| 1376 | |
---|
[d0d65df] | 1377 | n=owl_message_get_notice(m); |
---|
[df0d93a] | 1378 | |
---|
[5a95b69] | 1379 | if (!owl_message_is_pseudo(m)) { |
---|
| 1380 | owl_fmtext_append_normal(&fm, " Kind : "); |
---|
| 1381 | if (n->z_kind==UNSAFE) { |
---|
| 1382 | owl_fmtext_append_normal(&fm, "UNSAFE\n"); |
---|
| 1383 | } else if (n->z_kind==UNACKED) { |
---|
| 1384 | owl_fmtext_append_normal(&fm, "UNACKED\n"); |
---|
| 1385 | } else if (n->z_kind==ACKED) { |
---|
| 1386 | owl_fmtext_append_normal(&fm, "ACKED\n"); |
---|
| 1387 | } else if (n->z_kind==HMACK) { |
---|
| 1388 | owl_fmtext_append_normal(&fm, "HMACK\n"); |
---|
| 1389 | } else if (n->z_kind==HMCTL) { |
---|
| 1390 | owl_fmtext_append_normal(&fm, "HMCTL\n"); |
---|
| 1391 | } else if (n->z_kind==SERVACK) { |
---|
| 1392 | owl_fmtext_append_normal(&fm, "SERVACK\n"); |
---|
| 1393 | } else if (n->z_kind==SERVNAK) { |
---|
| 1394 | owl_fmtext_append_normal(&fm, "SERVNACK\n"); |
---|
| 1395 | } else if (n->z_kind==CLIENTACK) { |
---|
| 1396 | owl_fmtext_append_normal(&fm, "CLIENTACK\n"); |
---|
| 1397 | } else if (n->z_kind==STAT) { |
---|
| 1398 | owl_fmtext_append_normal(&fm, "STAT\n"); |
---|
| 1399 | } else { |
---|
| 1400 | owl_fmtext_append_normal(&fm, "ILLEGAL VALUE\n"); |
---|
| 1401 | } |
---|
[d0d65df] | 1402 | } |
---|
[57609b3] | 1403 | owl_fmtext_appendf_normal(&fm, " Host : %s\n", owl_message_get_hostname(m)); |
---|
[5a95b69] | 1404 | |
---|
| 1405 | if (!owl_message_is_pseudo(m)) { |
---|
| 1406 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[57609b3] | 1407 | owl_fmtext_appendf_normal(&fm, " Port : %i\n", ntohs(n->z_port)); |
---|
[f12d199] | 1408 | owl_fmtext_appendf_normal(&fm, " Auth : %s\n", owl_zephyr_get_authstr(n)); |
---|
[57609b3] | 1409 | |
---|
| 1410 | /* FIXME make these more descriptive */ |
---|
[f12d199] | 1411 | owl_fmtext_appendf_normal(&fm, " Checkd Ath: %i\n", n->z_checked_auth); |
---|
[57609b3] | 1412 | owl_fmtext_appendf_normal(&fm, " Multi notc: %s\n", n->z_multinotice); |
---|
| 1413 | owl_fmtext_appendf_normal(&fm, " Num other : %i\n", n->z_num_other_fields); |
---|
| 1414 | owl_fmtext_appendf_normal(&fm, " Msg Len : %i\n", n->z_message_len); |
---|
[5a95b69] | 1415 | |
---|
| 1416 | fields=owl_zephyr_get_num_fields(n); |
---|
[57609b3] | 1417 | owl_fmtext_appendf_normal(&fm, " Fields : %i\n", fields); |
---|
| 1418 | |
---|
[5a95b69] | 1419 | for (i=0; i<fields; i++) { |
---|
[5376a95] | 1420 | ptr=owl_zephyr_get_field_as_utf8(n, i+1); |
---|
[b0430a6] | 1421 | len=strlen(ptr); |
---|
[5a95b69] | 1422 | if (len<30) { |
---|
| 1423 | strncpy(tmpbuff, ptr, len); |
---|
| 1424 | tmpbuff[len]='\0'; |
---|
| 1425 | } else { |
---|
| 1426 | strncpy(tmpbuff, ptr, 30); |
---|
| 1427 | tmpbuff[30]='\0'; |
---|
| 1428 | strcat(tmpbuff, "..."); |
---|
| 1429 | } |
---|
[b0430a6] | 1430 | owl_free(ptr); |
---|
[57609b3] | 1431 | |
---|
[5a95b69] | 1432 | for (j=0; j<strlen(tmpbuff); j++) { |
---|
| 1433 | if (tmpbuff[j]=='\n') tmpbuff[j]='~'; |
---|
| 1434 | if (tmpbuff[j]=='\r') tmpbuff[j]='!'; |
---|
| 1435 | } |
---|
[57609b3] | 1436 | |
---|
| 1437 | owl_fmtext_appendf_normal(&fm, " Field %i : %s\n", i+1, tmpbuff); |
---|
[5a95b69] | 1438 | } |
---|
[57609b3] | 1439 | owl_fmtext_appendf_normal(&fm, " Default Fm: %s\n", n->z_default_format); |
---|
[d0d65df] | 1440 | } |
---|
[57609b3] | 1441 | |
---|
[7d4fbcd] | 1442 | } |
---|
[57609b3] | 1443 | #endif |
---|
[7d4fbcd] | 1444 | } |
---|
[0ff8fb57] | 1445 | |
---|
[5789230] | 1446 | owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n"); |
---|
| 1447 | owl_message_attributes_tofmtext(m, &attrfm); |
---|
| 1448 | owl_fmtext_append_fmtext(&fm, &attrfm); |
---|
[d0d65df] | 1449 | |
---|
| 1450 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1451 | owl_fmtext_cleanup(&fm); |
---|
| 1452 | owl_fmtext_cleanup(&attrfm); |
---|
[7d4fbcd] | 1453 | } |
---|
| 1454 | |
---|
[5639bf2] | 1455 | /* print the current message in a popup window. |
---|
| 1456 | * Use the 'default' style regardless of whatever |
---|
| 1457 | * style the user may be using |
---|
| 1458 | */ |
---|
[c79a047] | 1459 | void owl_function_curmsg_to_popwin(void) |
---|
[d54838d] | 1460 | { |
---|
[9e5c9f3] | 1461 | const owl_view *v; |
---|
[c08c70a] | 1462 | const owl_message *m; |
---|
[1fdab04] | 1463 | const owl_style *s; |
---|
[5639bf2] | 1464 | owl_fmtext fm; |
---|
[7d4fbcd] | 1465 | |
---|
[5639bf2] | 1466 | v=owl_global_get_current_view(&g); |
---|
| 1467 | s=owl_global_get_style_by_name(&g, "default"); |
---|
[7d4fbcd] | 1468 | |
---|
[5eeea3b] | 1469 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 1470 | |
---|
| 1471 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 1472 | owl_function_error("No current message"); |
---|
[7d4fbcd] | 1473 | return; |
---|
| 1474 | } |
---|
| 1475 | |
---|
[5639bf2] | 1476 | owl_fmtext_init_null(&fm); |
---|
| 1477 | owl_style_get_formattext(s, &fm, m); |
---|
| 1478 | |
---|
| 1479 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1480 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1481 | } |
---|
| 1482 | |
---|
[d54838d] | 1483 | void owl_function_page_curmsg(int step) |
---|
| 1484 | { |
---|
[7d4fbcd] | 1485 | /* scroll down or up within the current message IF the message is truncated */ |
---|
| 1486 | |
---|
| 1487 | int offset, curmsg, lines; |
---|
[9e5c9f3] | 1488 | const owl_view *v; |
---|
[7d4fbcd] | 1489 | owl_message *m; |
---|
| 1490 | |
---|
| 1491 | offset=owl_global_get_curmsg_vert_offset(&g); |
---|
| 1492 | v=owl_global_get_current_view(&g); |
---|
| 1493 | curmsg=owl_global_get_curmsg(&g); |
---|
| 1494 | m=owl_view_get_element(v, curmsg); |
---|
[5eeea3b] | 1495 | if (!m || owl_view_get_size(v)==0) return; |
---|
[7d4fbcd] | 1496 | lines=owl_message_get_numlines(m); |
---|
| 1497 | |
---|
| 1498 | if (offset==0) { |
---|
| 1499 | /* Bail if the curmsg isn't the last one displayed */ |
---|
| 1500 | if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) { |
---|
[f51bc78] | 1501 | owl_function_makemsg("The entire message is already displayed"); |
---|
[7d4fbcd] | 1502 | return; |
---|
| 1503 | } |
---|
| 1504 | |
---|
| 1505 | /* Bail if we're not truncated */ |
---|
| 1506 | if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) { |
---|
[f51bc78] | 1507 | owl_function_makemsg("The entire message is already displayed"); |
---|
[7d4fbcd] | 1508 | return; |
---|
| 1509 | } |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | |
---|
| 1513 | /* don't scroll past the last line */ |
---|
| 1514 | if (step>0) { |
---|
| 1515 | if (offset+step > lines-1) { |
---|
| 1516 | owl_global_set_curmsg_vert_offset(&g, lines-1); |
---|
| 1517 | } else { |
---|
| 1518 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
| 1519 | } |
---|
| 1520 | } |
---|
| 1521 | |
---|
| 1522 | /* would we be before the beginning of the message? */ |
---|
| 1523 | if (step<0) { |
---|
| 1524 | if (offset+step<0) { |
---|
| 1525 | owl_global_set_curmsg_vert_offset(&g, 0); |
---|
| 1526 | } else { |
---|
| 1527 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
| 1528 | } |
---|
| 1529 | } |
---|
| 1530 | |
---|
| 1531 | /* redisplay */ |
---|
| 1532 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 1533 | } |
---|
| 1534 | |
---|
[d54838d] | 1535 | void owl_function_resize_typwin(int newsize) |
---|
| 1536 | { |
---|
[7d4fbcd] | 1537 | owl_global_set_typwin_lines(&g, newsize); |
---|
[f6fae8d] | 1538 | owl_mainpanel_layout_contents(&g.mainpanel); |
---|
[7d4fbcd] | 1539 | } |
---|
| 1540 | |
---|
[c79a047] | 1541 | void owl_function_mainwin_pagedown(void) |
---|
[d54838d] | 1542 | { |
---|
[7d4fbcd] | 1543 | int i; |
---|
| 1544 | |
---|
| 1545 | i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g)); |
---|
| 1546 | if (i<0) return; |
---|
[f2e36b5] | 1547 | if (owl_mainwin_is_last_msg_truncated(owl_global_get_mainwin(&g)) |
---|
| 1548 | && (owl_global_get_curmsg(&g) < i) |
---|
| 1549 | && (i>0)) { |
---|
| 1550 | i--; |
---|
| 1551 | } |
---|
[7d4fbcd] | 1552 | owl_global_set_curmsg(&g, i); |
---|
| 1553 | owl_function_nextmsg(); |
---|
| 1554 | } |
---|
| 1555 | |
---|
[c79a047] | 1556 | void owl_function_mainwin_pageup(void) |
---|
[d54838d] | 1557 | { |
---|
[7d4fbcd] | 1558 | owl_global_set_curmsg(&g, owl_global_get_topmsg(&g)); |
---|
| 1559 | owl_function_prevmsg(); |
---|
| 1560 | } |
---|
| 1561 | |
---|
[c79a047] | 1562 | void owl_function_getsubs(void) |
---|
[d54838d] | 1563 | { |
---|
[09489b89] | 1564 | char *buff; |
---|
[7d4fbcd] | 1565 | |
---|
[09489b89] | 1566 | buff=owl_zephyr_getsubs(); |
---|
[7d4fbcd] | 1567 | |
---|
[09489b89] | 1568 | if (buff) { |
---|
| 1569 | owl_function_popless_text(buff); |
---|
| 1570 | } else { |
---|
| 1571 | owl_function_popless_text("Error getting subscriptions"); |
---|
[7d4fbcd] | 1572 | } |
---|
[09489b89] | 1573 | |
---|
[1c6c4d3] | 1574 | owl_free(buff); |
---|
[7d4fbcd] | 1575 | } |
---|
| 1576 | |
---|
[c79a047] | 1577 | void owl_function_printallvars(void) |
---|
[d54838d] | 1578 | { |
---|
[e19eb97] | 1579 | const char *name; |
---|
[b4c270c] | 1580 | char var[LINE]; |
---|
[7d4fbcd] | 1581 | owl_list varnames; |
---|
[b4c270c] | 1582 | int i, numvarnames; |
---|
| 1583 | GString *str = g_string_new(""); |
---|
[7d4fbcd] | 1584 | |
---|
[b4c270c] | 1585 | g_string_append_printf(str, "%-20s = %s\n", "VARIABLE", "VALUE"); |
---|
| 1586 | g_string_append_printf(str, "%-20s %s\n", "--------", "-----"); |
---|
[7d4fbcd] | 1587 | owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); |
---|
| 1588 | numvarnames = owl_list_get_size(&varnames); |
---|
| 1589 | for (i=0; i<numvarnames; i++) { |
---|
| 1590 | name = owl_list_get_element(&varnames, i); |
---|
| 1591 | if (name && name[0]!='_') { |
---|
[b4c270c] | 1592 | g_string_append_printf(str, "\n%-20s = ", name); |
---|
| 1593 | owl_variable_get_tostring(owl_global_get_vardict(&g), name, var, LINE); |
---|
| 1594 | g_string_append(str, var); |
---|
[7d4fbcd] | 1595 | } |
---|
| 1596 | } |
---|
[b4c270c] | 1597 | g_string_append(str, "\n"); |
---|
[0e57335] | 1598 | owl_variable_dict_namelist_cleanup(&varnames); |
---|
[b4c270c] | 1599 | |
---|
| 1600 | owl_function_popless_text(str->str); |
---|
| 1601 | g_string_free(str, TRUE); |
---|
[7d4fbcd] | 1602 | } |
---|
| 1603 | |
---|
[c79a047] | 1604 | void owl_function_show_variables(void) |
---|
[d54838d] | 1605 | { |
---|
[7d4fbcd] | 1606 | owl_list varnames; |
---|
| 1607 | owl_fmtext fm; |
---|
| 1608 | int i, numvarnames; |
---|
[e19eb97] | 1609 | const char *varname; |
---|
[7d4fbcd] | 1610 | |
---|
| 1611 | owl_fmtext_init_null(&fm); |
---|
| 1612 | owl_fmtext_append_bold(&fm, |
---|
| 1613 | "Variables: (use 'show variable <name>' for details)\n"); |
---|
| 1614 | owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); |
---|
| 1615 | numvarnames = owl_list_get_size(&varnames); |
---|
| 1616 | for (i=0; i<numvarnames; i++) { |
---|
| 1617 | varname = owl_list_get_element(&varnames, i); |
---|
| 1618 | if (varname && varname[0]!='_') { |
---|
[aa2f33b3] | 1619 | owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); |
---|
[7d4fbcd] | 1620 | } |
---|
| 1621 | } |
---|
[0e57335] | 1622 | owl_variable_dict_namelist_cleanup(&varnames); |
---|
[7d4fbcd] | 1623 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1624 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1625 | } |
---|
| 1626 | |
---|
[e19eb97] | 1627 | void owl_function_show_variable(const char *name) |
---|
[d54838d] | 1628 | { |
---|
[7d4fbcd] | 1629 | owl_fmtext fm; |
---|
| 1630 | |
---|
| 1631 | owl_fmtext_init_null(&fm); |
---|
| 1632 | owl_variable_get_help(owl_global_get_vardict(&g), name, &fm); |
---|
| 1633 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1634 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1635 | } |
---|
| 1636 | |
---|
| 1637 | /* note: this applies to global message list, not to view. |
---|
| 1638 | * If flag is 1, deletes. If flag is 0, undeletes. */ |
---|
[d54838d] | 1639 | void owl_function_delete_by_id(int id, int flag) |
---|
| 1640 | { |
---|
[3eb599d] | 1641 | const owl_messagelist *ml; |
---|
[7d4fbcd] | 1642 | owl_message *m; |
---|
| 1643 | ml = owl_global_get_msglist(&g); |
---|
| 1644 | m = owl_messagelist_get_by_id(ml, id); |
---|
| 1645 | if (m) { |
---|
| 1646 | if (flag == 1) { |
---|
| 1647 | owl_message_mark_delete(m); |
---|
| 1648 | } else if (flag == 0) { |
---|
| 1649 | owl_message_unmark_delete(m); |
---|
| 1650 | } |
---|
| 1651 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 1652 | } else { |
---|
[ec6ff52] | 1653 | owl_function_error("No message with id %d: unable to mark for (un)delete",id); |
---|
[7d4fbcd] | 1654 | } |
---|
| 1655 | } |
---|
| 1656 | |
---|
[c79a047] | 1657 | void owl_function_delete_automsgs(void) |
---|
[d54838d] | 1658 | { |
---|
[7d4fbcd] | 1659 | /* mark for deletion all messages in the current view that match the |
---|
| 1660 | * 'trash' filter */ |
---|
| 1661 | |
---|
| 1662 | int i, j, count; |
---|
| 1663 | owl_message *m; |
---|
[9e5c9f3] | 1664 | const owl_view *v; |
---|
[4542047] | 1665 | const owl_filter *f; |
---|
[7d4fbcd] | 1666 | |
---|
| 1667 | /* get the trash filter */ |
---|
| 1668 | f=owl_global_get_filter(&g, "trash"); |
---|
| 1669 | if (!f) { |
---|
[ec6ff52] | 1670 | owl_function_error("No trash filter defined"); |
---|
[7d4fbcd] | 1671 | return; |
---|
| 1672 | } |
---|
| 1673 | |
---|
| 1674 | v=owl_global_get_current_view(&g); |
---|
| 1675 | |
---|
| 1676 | count=0; |
---|
| 1677 | j=owl_view_get_size(v); |
---|
| 1678 | for (i=0; i<j; i++) { |
---|
| 1679 | m=owl_view_get_element(v, i); |
---|
| 1680 | if (owl_filter_message_match(f, m)) { |
---|
| 1681 | count++; |
---|
| 1682 | owl_message_mark_delete(m); |
---|
| 1683 | } |
---|
| 1684 | } |
---|
| 1685 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[1c6c4d3] | 1686 | owl_function_makemsg("%i messages marked for deletion", count); |
---|
[7d4fbcd] | 1687 | } |
---|
| 1688 | |
---|
[c79a047] | 1689 | void owl_function_status(void) |
---|
[d54838d] | 1690 | { |
---|
[49a8434] | 1691 | char buff[MAXPATHLEN+1]; |
---|
[7d4fbcd] | 1692 | time_t start; |
---|
| 1693 | int up, days, hours, minutes; |
---|
[a352335c] | 1694 | owl_fmtext fm; |
---|
| 1695 | |
---|
| 1696 | owl_fmtext_init_null(&fm); |
---|
[7d4fbcd] | 1697 | |
---|
| 1698 | start=owl_global_get_starttime(&g); |
---|
| 1699 | |
---|
[d9b0b972] | 1700 | owl_fmtext_append_normal(&fm, "General Information:\n"); |
---|
| 1701 | |
---|
| 1702 | owl_fmtext_append_normal(&fm, " Version: "); |
---|
[a352335c] | 1703 | owl_fmtext_append_normal(&fm, OWL_VERSION_STRING); |
---|
| 1704 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1705 | |
---|
[cdd3959] | 1706 | owl_fmtext_append_normal(&fm, " Startup Arguments: "); |
---|
[a352335c] | 1707 | owl_fmtext_append_normal(&fm, owl_global_get_startupargs(&g)); |
---|
| 1708 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[b6a7367] | 1709 | |
---|
| 1710 | owl_fmtext_append_normal(&fm, " Current Directory: "); |
---|
[49a8434] | 1711 | if(getcwd(buff, MAXPATHLEN) == NULL) { |
---|
| 1712 | owl_fmtext_append_normal(&fm, "<Error in getcwd>"); |
---|
| 1713 | } else { |
---|
| 1714 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1715 | } |
---|
[b6a7367] | 1716 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1717 | |
---|
[c1d166b] | 1718 | owl_fmtext_appendf_normal(&fm, " Startup Time: %s", ctime(&start)); |
---|
[7d4fbcd] | 1719 | |
---|
| 1720 | up=owl_global_get_runtime(&g); |
---|
| 1721 | days=up/86400; |
---|
| 1722 | up-=days*86400; |
---|
| 1723 | hours=up/3600; |
---|
| 1724 | up-=hours*3600; |
---|
| 1725 | minutes=up/60; |
---|
| 1726 | up-=minutes*60; |
---|
[c1d166b] | 1727 | owl_fmtext_appendf_normal(&fm, " Run Time: %i days %2.2i:%2.2i:%2.2i\n", days, hours, minutes, up); |
---|
[7d4fbcd] | 1728 | |
---|
[d9b0b972] | 1729 | owl_fmtext_append_normal(&fm, "\nProtocol Options:\n"); |
---|
| 1730 | owl_fmtext_append_normal(&fm, " Zephyr included : "); |
---|
| 1731 | if (owl_global_is_havezephyr(&g)) { |
---|
| 1732 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
[7d4fbcd] | 1733 | } else { |
---|
[d9b0b972] | 1734 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
[7d4fbcd] | 1735 | } |
---|
[d9b0b972] | 1736 | owl_fmtext_append_normal(&fm, " AIM included : yes\n"); |
---|
| 1737 | owl_fmtext_append_normal(&fm, " Loopback included : yes\n"); |
---|
| 1738 | |
---|
[8262340] | 1739 | |
---|
[d9b0b972] | 1740 | owl_fmtext_append_normal(&fm, "\nBuild Options:\n"); |
---|
| 1741 | owl_fmtext_append_normal(&fm, " Stderr redirection : "); |
---|
| 1742 | #if OWL_STDERR_REDIR |
---|
| 1743 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
| 1744 | #else |
---|
| 1745 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
| 1746 | #endif |
---|
| 1747 | |
---|
| 1748 | |
---|
| 1749 | owl_fmtext_append_normal(&fm, "\nAIM Status:\n"); |
---|
| 1750 | owl_fmtext_append_normal(&fm, " Logged in: "); |
---|
[a352335c] | 1751 | if (owl_global_is_aimloggedin(&g)) { |
---|
| 1752 | owl_fmtext_append_normal(&fm, owl_global_get_aim_screenname(&g)); |
---|
| 1753 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1754 | } else { |
---|
[d9b0b972] | 1755 | owl_fmtext_append_normal(&fm, "(not logged in)\n"); |
---|
[a352335c] | 1756 | } |
---|
[d9b0b972] | 1757 | |
---|
| 1758 | owl_fmtext_append_normal(&fm, " Processing events: "); |
---|
[a352335c] | 1759 | if (owl_global_is_doaimevents(&g)) { |
---|
[d9b0b972] | 1760 | owl_fmtext_append_normal(&fm, "yes\n"); |
---|
[a352335c] | 1761 | } else { |
---|
[d9b0b972] | 1762 | owl_fmtext_append_normal(&fm, "no\n"); |
---|
[a352335c] | 1763 | } |
---|
| 1764 | |
---|
| 1765 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1766 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1767 | } |
---|
| 1768 | |
---|
[c79a047] | 1769 | void owl_function_show_term(void) |
---|
[d54838d] | 1770 | { |
---|
[7d4fbcd] | 1771 | owl_fmtext fm; |
---|
| 1772 | |
---|
| 1773 | owl_fmtext_init_null(&fm); |
---|
[c1d166b] | 1774 | owl_fmtext_appendf_normal(&fm, "Terminal Lines: %i\nTerminal Columns: %i\n", |
---|
[7d4fbcd] | 1775 | owl_global_get_lines(&g), |
---|
| 1776 | owl_global_get_cols(&g)); |
---|
| 1777 | |
---|
| 1778 | if (owl_global_get_hascolors(&g)) { |
---|
| 1779 | owl_fmtext_append_normal(&fm, "Color: Yes\n"); |
---|
[c1d166b] | 1780 | owl_fmtext_appendf_normal(&fm, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g)); |
---|
| 1781 | owl_fmtext_appendf_normal(&fm, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); |
---|
[7d4fbcd] | 1782 | } else { |
---|
| 1783 | owl_fmtext_append_normal(&fm, "Color: No\n"); |
---|
| 1784 | } |
---|
| 1785 | |
---|
| 1786 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1787 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1788 | } |
---|
| 1789 | |
---|
[e7cc1c3] | 1790 | /* if type = 0 then normal reply. |
---|
| 1791 | * if type = 1 then it's a reply to sender |
---|
| 1792 | * if enter = 0 then allow the command to be edited |
---|
| 1793 | * if enter = 1 then don't wait for editing |
---|
| 1794 | */ |
---|
[d54838d] | 1795 | void owl_function_reply(int type, int enter) |
---|
| 1796 | { |
---|
[740d5f7] | 1797 | char *buff=NULL; |
---|
[c08c70a] | 1798 | const owl_message *m; |
---|
[4542047] | 1799 | const owl_filter *f; |
---|
[7d4fbcd] | 1800 | |
---|
| 1801 | if (owl_view_get_size(owl_global_get_current_view(&g))==0) { |
---|
[ec6ff52] | 1802 | owl_function_error("No message selected"); |
---|
[7d4fbcd] | 1803 | } else { |
---|
[5ebc202] | 1804 | char *cmd; |
---|
[7d4fbcd] | 1805 | |
---|
| 1806 | m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g)); |
---|
[5eeea3b] | 1807 | if (!m) { |
---|
[ec6ff52] | 1808 | owl_function_error("No message selected"); |
---|
[5eeea3b] | 1809 | return; |
---|
| 1810 | } |
---|
| 1811 | |
---|
[7d4fbcd] | 1812 | /* first check if we catch the reply-lockout filter */ |
---|
| 1813 | f=owl_global_get_filter(&g, "reply-lockout"); |
---|
| 1814 | if (f) { |
---|
| 1815 | if (owl_filter_message_match(f, m)) { |
---|
[ec6ff52] | 1816 | owl_function_error("Sorry, replies to this message have been disabled by the reply-lockout filter"); |
---|
[7d4fbcd] | 1817 | return; |
---|
| 1818 | } |
---|
| 1819 | } |
---|
[4b464a4] | 1820 | |
---|
[2c09826] | 1821 | /* then check if it's a question and just bring up the command prompt */ |
---|
| 1822 | if (owl_message_is_question(m)) { |
---|
| 1823 | owl_function_start_command(""); |
---|
| 1824 | return; |
---|
| 1825 | } |
---|
| 1826 | |
---|
[740d5f7] | 1827 | if((type == 0 && |
---|
| 1828 | (cmd=owl_perlconfig_message_call_method(m, "replycmd", 0, NULL))) || |
---|
| 1829 | (type == 1 && |
---|
| 1830 | (cmd=owl_perlconfig_message_call_method(m, "replysendercmd", 0, NULL)))) { |
---|
| 1831 | buff = cmd; |
---|
[d09e5a1] | 1832 | } |
---|
[1b6b2f3] | 1833 | |
---|
[e0540e4] | 1834 | if(!buff) { |
---|
| 1835 | owl_function_error("I don't know how to reply to that message."); |
---|
| 1836 | return; |
---|
| 1837 | } |
---|
[740d5f7] | 1838 | |
---|
[d09e5a1] | 1839 | if (enter) { |
---|
| 1840 | owl_history *hist = owl_global_get_cmd_history(&g); |
---|
| 1841 | owl_history_store(hist, buff); |
---|
| 1842 | owl_history_reset(hist); |
---|
| 1843 | owl_function_command_norv(buff); |
---|
| 1844 | } else { |
---|
| 1845 | owl_function_start_command(buff); |
---|
[7d4fbcd] | 1846 | } |
---|
[d09e5a1] | 1847 | owl_free(buff); |
---|
[7d4fbcd] | 1848 | } |
---|
| 1849 | } |
---|
| 1850 | |
---|
[e19eb97] | 1851 | void owl_function_zlocate(int argc, const char *const *argv, int auth) |
---|
[d54838d] | 1852 | { |
---|
[2527615] | 1853 | owl_fmtext fm; |
---|
[dca3b27] | 1854 | char *ptr; |
---|
| 1855 | char *result; |
---|
[2527615] | 1856 | int i; |
---|
| 1857 | |
---|
| 1858 | owl_fmtext_init_null(&fm); |
---|
[7d4fbcd] | 1859 | |
---|
[2527615] | 1860 | for (i=0; i<argc; i++) { |
---|
[dca3b27] | 1861 | ptr = long_zuser(argv[i]); |
---|
| 1862 | result = owl_zephyr_zlocate(ptr, auth); |
---|
| 1863 | owl_fmtext_append_normal(&fm, result); |
---|
| 1864 | owl_free(result); |
---|
[2527615] | 1865 | owl_free(ptr); |
---|
[7d4fbcd] | 1866 | } |
---|
| 1867 | |
---|
[2527615] | 1868 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 1869 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 1870 | } |
---|
| 1871 | |
---|
[5934b87] | 1872 | void owl_callback_command(owl_editwin *e) |
---|
| 1873 | { |
---|
| 1874 | char *rv; |
---|
| 1875 | const char *line = owl_editwin_get_text(e); |
---|
| 1876 | |
---|
| 1877 | rv = owl_function_command(line); |
---|
| 1878 | if (rv) { |
---|
| 1879 | owl_function_makemsg("%s", rv); |
---|
| 1880 | owl_free(rv); |
---|
| 1881 | } |
---|
| 1882 | } |
---|
| 1883 | |
---|
[e19eb97] | 1884 | void owl_function_start_command(const char *line) |
---|
[d54838d] | 1885 | { |
---|
[7d4fbcd] | 1886 | owl_editwin *tw; |
---|
[c394de8] | 1887 | owl_context *ctx; |
---|
[7d4fbcd] | 1888 | |
---|
[58d47ca] | 1889 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
[10b866d] | 1890 | |
---|
[7d4fbcd] | 1891 | owl_editwin_set_locktext(tw, "command: "); |
---|
| 1892 | |
---|
[47519e1b] | 1893 | owl_editwin_insert_string(tw, line); |
---|
[cf83b7a] | 1894 | |
---|
[4a41f16] | 1895 | ctx = owl_editcontext_new(OWL_CTX_EDITLINE, tw, "editline", |
---|
| 1896 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 1897 | owl_global_push_context_obj(&g, ctx); |
---|
[5934b87] | 1898 | owl_editwin_set_callback(tw, owl_callback_command); |
---|
[cf83b7a] | 1899 | } |
---|
| 1900 | |
---|
[9186c75] | 1901 | owl_editwin *owl_function_start_question(const char *line) |
---|
[cf83b7a] | 1902 | { |
---|
| 1903 | owl_editwin *tw; |
---|
[c394de8] | 1904 | owl_context *ctx; |
---|
[cf83b7a] | 1905 | |
---|
[58d47ca] | 1906 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
[cf83b7a] | 1907 | |
---|
| 1908 | owl_editwin_set_locktext(tw, line); |
---|
| 1909 | |
---|
[4a41f16] | 1910 | ctx = owl_editcontext_new(OWL_CTX_EDITRESPONSE, tw, "editresponse", |
---|
| 1911 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 1912 | owl_global_push_context_obj(&g, ctx); |
---|
[9186c75] | 1913 | return tw; |
---|
[7d4fbcd] | 1914 | } |
---|
| 1915 | |
---|
[9186c75] | 1916 | owl_editwin *owl_function_start_password(const char *line) |
---|
[453bd70] | 1917 | { |
---|
| 1918 | owl_editwin *tw; |
---|
[c394de8] | 1919 | owl_context *ctx; |
---|
[453bd70] | 1920 | |
---|
[58d47ca] | 1921 | tw = owl_global_set_typwin_active(&g, OWL_EDITWIN_STYLE_ONELINE, NULL); |
---|
| 1922 | |
---|
[453bd70] | 1923 | owl_editwin_set_echochar(tw, '*'); |
---|
| 1924 | |
---|
| 1925 | owl_editwin_set_locktext(tw, line); |
---|
| 1926 | |
---|
[4a41f16] | 1927 | ctx = owl_editcontext_new(OWL_CTX_EDITRESPONSE, tw, "editresponse", |
---|
| 1928 | owl_global_deactivate_editcontext, &g); |
---|
[c394de8] | 1929 | owl_global_push_context_obj(&g, ctx); |
---|
[9186c75] | 1930 | return tw; |
---|
[453bd70] | 1931 | } |
---|
| 1932 | |
---|
[e19eb97] | 1933 | char *owl_function_exec(int argc, const char *const *argv, const char *buff, int type) |
---|
[d54838d] | 1934 | { |
---|
[7d4fbcd] | 1935 | /* if type == 1 display in a popup |
---|
| 1936 | * if type == 2 display an admin messages |
---|
| 1937 | * if type == 0 return output |
---|
| 1938 | * else display in a popup |
---|
| 1939 | */ |
---|
[e19eb97] | 1940 | const char *redirect = " 2>&1 < /dev/null"; |
---|
[65b2173] | 1941 | char *newbuff; |
---|
[b7ee89b] | 1942 | char *out; |
---|
[7d4fbcd] | 1943 | FILE *p; |
---|
| 1944 | |
---|
[2a2bb60] | 1945 | #if OWL_STDERR_REDIR |
---|
| 1946 | redirect = " < /dev/null"; |
---|
| 1947 | #endif |
---|
| 1948 | |
---|
[7d4fbcd] | 1949 | if (argc<2) { |
---|
[ec6ff52] | 1950 | owl_function_error("Wrong number of arguments to the exec command"); |
---|
[7d4fbcd] | 1951 | return NULL; |
---|
| 1952 | } |
---|
| 1953 | |
---|
| 1954 | buff = skiptokens(buff, 1); |
---|
[36486be] | 1955 | newbuff = owl_sprintf("%s%s", buff, redirect); |
---|
[7d4fbcd] | 1956 | |
---|
[7ba9e0de] | 1957 | if (type == OWL_OUTPUT_POPUP) { |
---|
[afbf668] | 1958 | owl_popexec_new(newbuff); |
---|
[7d4fbcd] | 1959 | } else { |
---|
[b7ee89b] | 1960 | p = popen(newbuff, "r"); |
---|
| 1961 | out = owl_slurp(p); |
---|
[afbf668] | 1962 | pclose(p); |
---|
| 1963 | |
---|
[2cfc6d7] | 1964 | if (type == OWL_OUTPUT_RETURN) { |
---|
[b85c1c4] | 1965 | owl_free(newbuff); |
---|
[afbf668] | 1966 | return out; |
---|
[7ba9e0de] | 1967 | } else if (type == OWL_OUTPUT_ADMINMSG) { |
---|
[afbf668] | 1968 | owl_function_adminmsg(buff, out); |
---|
| 1969 | } |
---|
| 1970 | owl_free(out); |
---|
[7d4fbcd] | 1971 | } |
---|
[b85c1c4] | 1972 | owl_free(newbuff); |
---|
[7d4fbcd] | 1973 | return NULL; |
---|
| 1974 | } |
---|
| 1975 | |
---|
[e19eb97] | 1976 | char *owl_function_perl(int argc, const char *const *argv, const char *buff, int type) |
---|
[d54838d] | 1977 | { |
---|
[7d4fbcd] | 1978 | /* if type == 1 display in a popup |
---|
| 1979 | * if type == 2 display an admin messages |
---|
| 1980 | * if type == 0 return output |
---|
| 1981 | * else display in a popup |
---|
| 1982 | */ |
---|
| 1983 | char *perlout; |
---|
| 1984 | |
---|
| 1985 | if (argc<2) { |
---|
[ec6ff52] | 1986 | owl_function_error("Wrong number of arguments to perl command"); |
---|
[7d4fbcd] | 1987 | return NULL; |
---|
| 1988 | } |
---|
| 1989 | |
---|
| 1990 | /* consume first token (argv[0]) */ |
---|
| 1991 | buff = skiptokens(buff, 1); |
---|
| 1992 | |
---|
[f1e629d] | 1993 | perlout = owl_perlconfig_execute(buff); |
---|
[7d4fbcd] | 1994 | if (perlout) { |
---|
[7ba9e0de] | 1995 | if (type == OWL_OUTPUT_POPUP) { |
---|
[7d4fbcd] | 1996 | owl_function_popless_text(perlout); |
---|
[7ba9e0de] | 1997 | } else if (type == OWL_OUTPUT_ADMINMSG) { |
---|
[7d4fbcd] | 1998 | owl_function_adminmsg(buff, perlout); |
---|
[7ba9e0de] | 1999 | } else if (type == OWL_OUTPUT_RETURN) { |
---|
[7d4fbcd] | 2000 | return perlout; |
---|
| 2001 | } |
---|
| 2002 | owl_free(perlout); |
---|
| 2003 | } |
---|
| 2004 | return NULL; |
---|
| 2005 | } |
---|
| 2006 | |
---|
[5e0b690] | 2007 | /* Change the filter associated with the current view. |
---|
| 2008 | * This also figures out which message in the new filter |
---|
| 2009 | * should have the pointer. |
---|
| 2010 | */ |
---|
[e19eb97] | 2011 | void owl_function_change_currentview_filter(const char *filtname) |
---|
[c3ab155] | 2012 | { |
---|
| 2013 | owl_view *v; |
---|
| 2014 | owl_filter *f; |
---|
| 2015 | int curid=-1, newpos, curmsg; |
---|
[c08c70a] | 2016 | const owl_message *curm=NULL; |
---|
[c3ab155] | 2017 | |
---|
| 2018 | v=owl_global_get_current_view(&g); |
---|
| 2019 | |
---|
| 2020 | curmsg=owl_global_get_curmsg(&g); |
---|
| 2021 | if (curmsg==-1) { |
---|
| 2022 | owl_function_debugmsg("Hit the curmsg==-1 case in change_view"); |
---|
| 2023 | } else { |
---|
| 2024 | curm=owl_view_get_element(v, curmsg); |
---|
| 2025 | if (curm) { |
---|
| 2026 | curid=owl_message_get_id(curm); |
---|
| 2027 | owl_view_save_curmsgid(v, curid); |
---|
| 2028 | } |
---|
| 2029 | } |
---|
| 2030 | |
---|
| 2031 | f=owl_global_get_filter(&g, filtname); |
---|
| 2032 | if (!f) { |
---|
[ec6ff52] | 2033 | owl_function_error("Unknown filter %s", filtname); |
---|
[c3ab155] | 2034 | return; |
---|
| 2035 | } |
---|
| 2036 | |
---|
| 2037 | owl_view_new_filter(v, f); |
---|
| 2038 | |
---|
| 2039 | /* Figure out what to set the current message to. |
---|
| 2040 | * - If the view we're leaving has messages in it, go to the closest message |
---|
| 2041 | * to the last message pointed to in that view. |
---|
| 2042 | * - If the view we're leaving is empty, try to restore the position |
---|
| 2043 | * from the last time we were in the new view. */ |
---|
| 2044 | if (curm) { |
---|
| 2045 | newpos = owl_view_get_nearest_to_msgid(v, curid); |
---|
| 2046 | } else { |
---|
| 2047 | newpos = owl_view_get_nearest_to_saved(v); |
---|
| 2048 | } |
---|
| 2049 | |
---|
| 2050 | owl_global_set_curmsg(&g, newpos); |
---|
| 2051 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 2052 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2053 | owl_global_set_direction_downwards(&g); |
---|
| 2054 | } |
---|
[7d4fbcd] | 2055 | |
---|
[5e0b690] | 2056 | /* Create a new filter, or replace an existing one |
---|
| 2057 | * with a new definition. |
---|
| 2058 | */ |
---|
[e19eb97] | 2059 | void owl_function_create_filter(int argc, const char *const *argv) |
---|
[d54838d] | 2060 | { |
---|
[7d4fbcd] | 2061 | owl_filter *f; |
---|
[9e5c9f3] | 2062 | const owl_view *v; |
---|
[23fddad] | 2063 | int inuse = 0; |
---|
[7d4fbcd] | 2064 | |
---|
| 2065 | if (argc < 2) { |
---|
[ec6ff52] | 2066 | owl_function_error("Wrong number of arguments to filter command"); |
---|
[7d4fbcd] | 2067 | return; |
---|
| 2068 | } |
---|
| 2069 | |
---|
[3895e23] | 2070 | owl_function_debugmsg("owl_function_create_filter: starting to create filter named %s", argv[1]); |
---|
| 2071 | |
---|
[7d4fbcd] | 2072 | v=owl_global_get_current_view(&g); |
---|
| 2073 | |
---|
| 2074 | /* don't touch the all filter */ |
---|
| 2075 | if (!strcmp(argv[1], "all")) { |
---|
[ec6ff52] | 2076 | owl_function_error("You may not change the 'all' filter."); |
---|
[7d4fbcd] | 2077 | return; |
---|
| 2078 | } |
---|
| 2079 | |
---|
| 2080 | /* deal with the case of trying change the filter color */ |
---|
| 2081 | if (argc==4 && !strcmp(argv[2], "-c")) { |
---|
| 2082 | f=owl_global_get_filter(&g, argv[1]); |
---|
| 2083 | if (!f) { |
---|
[ec6ff52] | 2084 | owl_function_error("The filter '%s' does not exist.", argv[1]); |
---|
[7d4fbcd] | 2085 | return; |
---|
| 2086 | } |
---|
[601733d] | 2087 | if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { |
---|
[12c35df] | 2088 | owl_function_error("The color '%s' is not available.", argv[3]); |
---|
| 2089 | return; |
---|
| 2090 | } |
---|
[8fa9562] | 2091 | owl_filter_set_fgcolor(f, owl_util_string_to_color(argv[3])); |
---|
| 2092 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2093 | return; |
---|
| 2094 | } |
---|
| 2095 | if (argc==4 && !strcmp(argv[2], "-b")) { |
---|
| 2096 | f=owl_global_get_filter(&g, argv[1]); |
---|
| 2097 | if (!f) { |
---|
| 2098 | owl_function_error("The filter '%s' does not exist.", argv[1]); |
---|
| 2099 | return; |
---|
| 2100 | } |
---|
[601733d] | 2101 | if (owl_util_string_to_color(argv[3])==OWL_COLOR_INVALID) { |
---|
[8fa9562] | 2102 | owl_function_error("The color '%s' is not available.", argv[3]); |
---|
| 2103 | return; |
---|
| 2104 | } |
---|
| 2105 | owl_filter_set_bgcolor(f, owl_util_string_to_color(argv[3])); |
---|
[7d4fbcd] | 2106 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2107 | return; |
---|
| 2108 | } |
---|
| 2109 | |
---|
| 2110 | /* create the filter and check for errors */ |
---|
[23fddad] | 2111 | f = owl_filter_new(argv[1], argc-2, argv+2); |
---|
| 2112 | if (f == NULL) { |
---|
[40458b9] | 2113 | owl_function_error("Invalid filter"); |
---|
[7d4fbcd] | 2114 | return; |
---|
| 2115 | } |
---|
| 2116 | |
---|
| 2117 | /* if the named filter is in use by the current view, remember it */ |
---|
| 2118 | if (!strcmp(owl_view_get_filtname(v), argv[1])) { |
---|
| 2119 | inuse=1; |
---|
| 2120 | } |
---|
| 2121 | |
---|
| 2122 | /* if the named filter already exists, nuke it */ |
---|
| 2123 | if (owl_global_get_filter(&g, argv[1])) { |
---|
| 2124 | owl_global_remove_filter(&g, argv[1]); |
---|
| 2125 | } |
---|
| 2126 | |
---|
| 2127 | /* add the filter */ |
---|
| 2128 | owl_global_add_filter(&g, f); |
---|
| 2129 | |
---|
| 2130 | /* if it was in use by the current view then update */ |
---|
| 2131 | if (inuse) { |
---|
[3895e23] | 2132 | owl_function_change_currentview_filter(argv[1]); |
---|
[7d4fbcd] | 2133 | } |
---|
| 2134 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2135 | } |
---|
| 2136 | |
---|
[3895e23] | 2137 | /* If 'filtername' does not start with 'not-' create a filter named |
---|
| 2138 | * 'not-<filtername>' defined as "not filter <filtername>". If the |
---|
| 2139 | * filter 'not-<filtername>' already exists, do not overwrite it. If |
---|
| 2140 | * 'filtername' begins with 'not-' and a filter 'filtername' already |
---|
| 2141 | * exists, then do nothing. If the filter 'filtername' does not |
---|
| 2142 | * exist, create it and define it as 'not filter <filtername>' |
---|
| 2143 | * |
---|
| 2144 | * Returns the name of the negated filter, which the caller must free. |
---|
| 2145 | */ |
---|
[e19eb97] | 2146 | char *owl_function_create_negative_filter(const char *filtername) |
---|
[3895e23] | 2147 | { |
---|
| 2148 | char *newname; |
---|
[4542047] | 2149 | const owl_filter *tmpfilt; |
---|
[e19eb97] | 2150 | const char *argv[5]; |
---|
[3895e23] | 2151 | |
---|
| 2152 | owl_function_debugmsg("owl_function_create_negative_filter"); |
---|
| 2153 | |
---|
| 2154 | if (!strncmp(filtername, "not-", 4)) { |
---|
| 2155 | newname=owl_strdup(filtername+4); |
---|
| 2156 | } else { |
---|
| 2157 | newname=owl_sprintf("not-%s", filtername); |
---|
| 2158 | } |
---|
| 2159 | |
---|
| 2160 | tmpfilt=owl_global_get_filter(&g, newname); |
---|
| 2161 | if (!tmpfilt) { |
---|
| 2162 | argv[0]="filter"; /* anything is fine here */ |
---|
| 2163 | argv[1]=newname; |
---|
| 2164 | argv[2]="not"; |
---|
| 2165 | argv[3]="filter"; |
---|
| 2166 | argv[4]=filtername; |
---|
| 2167 | owl_function_create_filter(5, argv); |
---|
| 2168 | } |
---|
| 2169 | |
---|
| 2170 | owl_function_debugmsg("owl_function_create_negative_filter: returning with %s", newname); |
---|
| 2171 | return(newname); |
---|
| 2172 | } |
---|
| 2173 | |
---|
[c79a047] | 2174 | void owl_function_show_filters(void) |
---|
[d54838d] | 2175 | { |
---|
[4542047] | 2176 | const owl_filter *f; |
---|
[129e609] | 2177 | GList *fl; |
---|
[7d4fbcd] | 2178 | owl_fmtext fm; |
---|
| 2179 | |
---|
| 2180 | owl_fmtext_init_null(&fm); |
---|
| 2181 | |
---|
| 2182 | owl_fmtext_append_bold(&fm, "Filters:\n"); |
---|
| 2183 | |
---|
[129e609] | 2184 | for (fl = g.filterlist; fl; fl = g_list_next(fl)) { |
---|
| 2185 | f = fl->data; |
---|
[7d4fbcd] | 2186 | owl_fmtext_append_normal(&fm, " "); |
---|
| 2187 | if (owl_global_get_hascolors(&g)) { |
---|
[8fa9562] | 2188 | owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_fgcolor(f), owl_filter_get_bgcolor(f)); |
---|
[7d4fbcd] | 2189 | } else { |
---|
| 2190 | owl_fmtext_append_normal(&fm, owl_filter_get_name(f)); |
---|
| 2191 | } |
---|
| 2192 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 2193 | } |
---|
| 2194 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2195 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2196 | } |
---|
| 2197 | |
---|
[e19eb97] | 2198 | void owl_function_show_filter(const char *name) |
---|
[d54838d] | 2199 | { |
---|
[4542047] | 2200 | const owl_filter *f; |
---|
[cdc6ff1] | 2201 | char *buff, *tmp; |
---|
[7d4fbcd] | 2202 | |
---|
| 2203 | f=owl_global_get_filter(&g, name); |
---|
| 2204 | if (!f) { |
---|
[ec6ff52] | 2205 | owl_function_error("There is no filter named %s", name); |
---|
[7d4fbcd] | 2206 | return; |
---|
| 2207 | } |
---|
[cdc6ff1] | 2208 | tmp = owl_filter_print(f); |
---|
| 2209 | buff = owl_sprintf("%s: %s", owl_filter_get_name(f), tmp); |
---|
[7d4fbcd] | 2210 | owl_function_popless_text(buff); |
---|
[0504f63] | 2211 | owl_free(buff); |
---|
[cdc6ff1] | 2212 | owl_free(tmp); |
---|
[7d4fbcd] | 2213 | } |
---|
| 2214 | |
---|
[c79a047] | 2215 | void owl_function_show_zpunts(void) |
---|
[d54838d] | 2216 | { |
---|
[4542047] | 2217 | const owl_filter *f; |
---|
[77bced3] | 2218 | const owl_list *fl; |
---|
[7d4fbcd] | 2219 | char buff[5000]; |
---|
[0504f63] | 2220 | char *tmp; |
---|
[7d4fbcd] | 2221 | owl_fmtext fm; |
---|
| 2222 | int i, j; |
---|
| 2223 | |
---|
| 2224 | owl_fmtext_init_null(&fm); |
---|
| 2225 | |
---|
| 2226 | fl=owl_global_get_puntlist(&g); |
---|
| 2227 | j=owl_list_get_size(fl); |
---|
| 2228 | owl_fmtext_append_bold(&fm, "Active zpunt filters:\n"); |
---|
| 2229 | |
---|
| 2230 | for (i=0; i<j; i++) { |
---|
| 2231 | f=owl_list_get_element(fl, i); |
---|
[ce7b824] | 2232 | snprintf(buff, sizeof(buff), "[% 2d] ", i+1); |
---|
| 2233 | owl_fmtext_append_normal(&fm, buff); |
---|
[0504f63] | 2234 | tmp = owl_filter_print(f); |
---|
| 2235 | owl_fmtext_append_normal(&fm, tmp); |
---|
| 2236 | owl_free(tmp); |
---|
[7d4fbcd] | 2237 | } |
---|
| 2238 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2239 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2240 | } |
---|
| 2241 | |
---|
[3abf28b] | 2242 | /* Create a filter for a class, instance if one doesn't exist. If |
---|
| 2243 | * instance is NULL then catch all messgaes in the class. Returns the |
---|
| 2244 | * name of the filter, which the caller must free. |
---|
[66e409c] | 2245 | * If 'related' is nonzero, encompass unclasses and .d classes as well. |
---|
[3abf28b] | 2246 | */ |
---|
[66e409c] | 2247 | char *owl_function_classinstfilt(const char *c, const char *i, int related) |
---|
[d54838d] | 2248 | { |
---|
[7d4fbcd] | 2249 | owl_filter *f; |
---|
| 2250 | char *argbuff, *filtname; |
---|
[d54838d] | 2251 | char *tmpclass, *tmpinstance = NULL; |
---|
[7a20e4c] | 2252 | char *class, *instance = NULL; |
---|
[7d4fbcd] | 2253 | |
---|
[66e409c] | 2254 | if (related) { |
---|
| 2255 | class = owl_util_baseclass(c); |
---|
| 2256 | if (i) { |
---|
| 2257 | instance = owl_util_baseclass(i); |
---|
| 2258 | } |
---|
| 2259 | } else { |
---|
| 2260 | class = owl_strdup(c); |
---|
| 2261 | if (i) { |
---|
| 2262 | instance = owl_strdup(i); |
---|
| 2263 | } |
---|
[7a20e4c] | 2264 | } |
---|
| 2265 | |
---|
[7d4fbcd] | 2266 | /* name for the filter */ |
---|
| 2267 | if (!instance) { |
---|
[66e409c] | 2268 | filtname = owl_sprintf("%sclass-%s", related ? "related-" : "", class); |
---|
[7d4fbcd] | 2269 | } else { |
---|
[66e409c] | 2270 | filtname = owl_sprintf("%sclass-%s-instance-%s", related ? "related-" : "", class, instance); |
---|
[7d4fbcd] | 2271 | } |
---|
[ed2412d] | 2272 | /* downcase it */ |
---|
[28ee32b] | 2273 | { |
---|
| 2274 | char *temp = g_utf8_strdown(filtname, -1); |
---|
| 2275 | if (temp) { |
---|
| 2276 | owl_free(filtname); |
---|
| 2277 | filtname = temp; |
---|
| 2278 | } |
---|
| 2279 | } |
---|
[4099cf8] | 2280 | /* turn spaces, single quotes, and double quotes into dots */ |
---|
[e3d9c77] | 2281 | owl_text_tr(filtname, ' ', '.'); |
---|
[4099cf8] | 2282 | owl_text_tr(filtname, '\'', '.'); |
---|
| 2283 | owl_text_tr(filtname, '"', '.'); |
---|
[ed2412d] | 2284 | |
---|
[7d4fbcd] | 2285 | /* if it already exists then go with it. This lets users override */ |
---|
| 2286 | if (owl_global_get_filter(&g, filtname)) { |
---|
[ff426f9] | 2287 | goto done; |
---|
[7d4fbcd] | 2288 | } |
---|
| 2289 | |
---|
| 2290 | /* create the new filter */ |
---|
[995eb4b] | 2291 | tmpclass=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[12c35df] | 2292 | owl_text_tr(tmpclass, ' ', '.'); |
---|
[4099cf8] | 2293 | owl_text_tr(tmpclass, '\'', '.'); |
---|
| 2294 | owl_text_tr(tmpclass, '"', '.'); |
---|
[ed2412d] | 2295 | if (instance) { |
---|
[995eb4b] | 2296 | tmpinstance=owl_text_quote(instance, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[12c35df] | 2297 | owl_text_tr(tmpinstance, ' ', '.'); |
---|
[4099cf8] | 2298 | owl_text_tr(tmpinstance, '\'', '.'); |
---|
| 2299 | owl_text_tr(tmpinstance, '"', '.'); |
---|
[ed2412d] | 2300 | } |
---|
[a0e6082] | 2301 | |
---|
[66e409c] | 2302 | argbuff = owl_sprintf(related ? "class ^(un)*%s(\\.d)*$" : "class ^%s$", tmpclass); |
---|
[d54838d] | 2303 | if (tmpinstance) { |
---|
[a0e6082] | 2304 | char *tmp = argbuff; |
---|
[66e409c] | 2305 | argbuff = owl_sprintf(related ? "%s and ( instance ^(un)*%s(\\.d)*$ )" : "%s and instance ^%s$", tmp, tmpinstance); |
---|
[a0e6082] | 2306 | owl_free(tmp); |
---|
[7d4fbcd] | 2307 | } |
---|
[ed2412d] | 2308 | owl_free(tmpclass); |
---|
[d54838d] | 2309 | if (tmpinstance) owl_free(tmpinstance); |
---|
[7d4fbcd] | 2310 | |
---|
[23fddad] | 2311 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[7d4fbcd] | 2312 | |
---|
| 2313 | /* add it to the global list */ |
---|
| 2314 | owl_global_add_filter(&g, f); |
---|
| 2315 | |
---|
| 2316 | owl_free(argbuff); |
---|
[ff426f9] | 2317 | done: |
---|
[be5aa09] | 2318 | owl_free(class); |
---|
| 2319 | if (instance) { |
---|
| 2320 | owl_free(instance); |
---|
| 2321 | } |
---|
[ed2412d] | 2322 | return(filtname); |
---|
[7d4fbcd] | 2323 | } |
---|
| 2324 | |
---|
[3abf28b] | 2325 | /* Create a filter for personal zephyrs to or from the specified |
---|
| 2326 | * zephyr user. Includes login/logout notifications for the user. |
---|
| 2327 | * The name of the filter will be 'user-<user>'. If a filter already |
---|
| 2328 | * exists with this name, no new filter will be created. This allows |
---|
| 2329 | * the configuration to override this function. Returns the name of |
---|
| 2330 | * the filter, which the caller must free. |
---|
| 2331 | */ |
---|
[e19eb97] | 2332 | char *owl_function_zuserfilt(const char *user) |
---|
[d54838d] | 2333 | { |
---|
[7d4fbcd] | 2334 | owl_filter *f; |
---|
[1d12db24] | 2335 | char *argbuff, *longuser, *esclonguser, *shortuser, *filtname; |
---|
[7d4fbcd] | 2336 | |
---|
| 2337 | /* stick the local realm on if it's not there */ |
---|
[4b464a4] | 2338 | longuser=long_zuser(user); |
---|
| 2339 | shortuser=short_zuser(user); |
---|
[7d4fbcd] | 2340 | |
---|
| 2341 | /* name for the filter */ |
---|
[9a2ae6c] | 2342 | filtname=owl_sprintf("user-%s", shortuser); |
---|
[7d4fbcd] | 2343 | |
---|
| 2344 | /* if it already exists then go with it. This lets users override */ |
---|
| 2345 | if (owl_global_get_filter(&g, filtname)) { |
---|
[6cc3306] | 2346 | return filtname; |
---|
[7d4fbcd] | 2347 | } |
---|
| 2348 | |
---|
| 2349 | /* create the new-internal filter */ |
---|
[1d12db24] | 2350 | esclonguser = owl_text_quote(longuser, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2351 | |
---|
[9a2ae6c] | 2352 | argbuff=owl_sprintf("( type ^zephyr$ and filter personal and " |
---|
| 2353 | "( ( direction ^in$ and sender ^%1$s$ ) or ( direction ^out$ and " |
---|
| 2354 | "recipient ^%1$s$ ) ) ) or ( ( class ^login$ ) and ( sender ^%1$s$ ) )", |
---|
[1d12db24] | 2355 | esclonguser); |
---|
[7d4fbcd] | 2356 | |
---|
[23fddad] | 2357 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[7d4fbcd] | 2358 | |
---|
| 2359 | /* add it to the global list */ |
---|
| 2360 | owl_global_add_filter(&g, f); |
---|
| 2361 | |
---|
| 2362 | /* free stuff */ |
---|
| 2363 | owl_free(argbuff); |
---|
| 2364 | owl_free(longuser); |
---|
[1d12db24] | 2365 | owl_free(esclonguser); |
---|
[7d4fbcd] | 2366 | owl_free(shortuser); |
---|
[7360fab] | 2367 | |
---|
[ed2412d] | 2368 | return(filtname); |
---|
[7d4fbcd] | 2369 | } |
---|
| 2370 | |
---|
[3abf28b] | 2371 | /* Create a filter for AIM IM messages to or from the specified |
---|
| 2372 | * screenname. The name of the filter will be 'aimuser-<user>'. If a |
---|
| 2373 | * filter already exists with this name, no new filter will be |
---|
| 2374 | * created. This allows the configuration to override this function. |
---|
| 2375 | * Returns the name of the filter, which the caller must free. |
---|
| 2376 | */ |
---|
[e19eb97] | 2377 | char *owl_function_aimuserfilt(const char *user) |
---|
[3abf28b] | 2378 | { |
---|
| 2379 | owl_filter *f; |
---|
| 2380 | char *argbuff, *filtname; |
---|
[af9b92e] | 2381 | char *escuser; |
---|
[3abf28b] | 2382 | |
---|
| 2383 | /* name for the filter */ |
---|
[9a2ae6c] | 2384 | filtname=owl_sprintf("aimuser-%s", user); |
---|
[3abf28b] | 2385 | |
---|
| 2386 | /* if it already exists then go with it. This lets users override */ |
---|
| 2387 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2388 | return(owl_strdup(filtname)); |
---|
| 2389 | } |
---|
| 2390 | |
---|
| 2391 | /* create the new-internal filter */ |
---|
[af9b92e] | 2392 | escuser = owl_text_quote(user, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2393 | |
---|
[9a2ae6c] | 2394 | argbuff = owl_sprintf( |
---|
| 2395 | "( type ^aim$ and ( ( sender ^%1$s$ and recipient ^%2$s$ ) or " |
---|
| 2396 | "( sender ^%2$s$ and recipient ^%1$s$ ) ) )", |
---|
| 2397 | escuser, owl_global_get_aim_screenname_for_filters(&g)); |
---|
[3abf28b] | 2398 | |
---|
[23fddad] | 2399 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[3abf28b] | 2400 | |
---|
| 2401 | /* add it to the global list */ |
---|
| 2402 | owl_global_add_filter(&g, f); |
---|
| 2403 | |
---|
| 2404 | /* free stuff */ |
---|
| 2405 | owl_free(argbuff); |
---|
[af9b92e] | 2406 | owl_free(escuser); |
---|
[3abf28b] | 2407 | |
---|
| 2408 | return(filtname); |
---|
| 2409 | } |
---|
| 2410 | |
---|
[e19eb97] | 2411 | char *owl_function_typefilt(const char *type) |
---|
[d54838d] | 2412 | { |
---|
[f73e519] | 2413 | owl_filter *f; |
---|
[1d12db24] | 2414 | char *argbuff, *filtname, *esctype; |
---|
[f73e519] | 2415 | |
---|
| 2416 | /* name for the filter */ |
---|
| 2417 | filtname=owl_sprintf("type-%s", type); |
---|
| 2418 | |
---|
| 2419 | /* if it already exists then go with it. This lets users override */ |
---|
| 2420 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2421 | return filtname; |
---|
| 2422 | } |
---|
| 2423 | |
---|
| 2424 | /* create the new-internal filter */ |
---|
[1d12db24] | 2425 | esctype = owl_text_quote(type, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
| 2426 | |
---|
| 2427 | argbuff = owl_sprintf("type ^%s$", esctype); |
---|
[f73e519] | 2428 | |
---|
[23fddad] | 2429 | f = owl_filter_new_fromstring(filtname, argbuff); |
---|
[f73e519] | 2430 | |
---|
| 2431 | /* add it to the global list */ |
---|
| 2432 | owl_global_add_filter(&g, f); |
---|
| 2433 | |
---|
| 2434 | /* free stuff */ |
---|
| 2435 | owl_free(argbuff); |
---|
[1d12db24] | 2436 | owl_free(esctype); |
---|
[f73e519] | 2437 | |
---|
| 2438 | return filtname; |
---|
| 2439 | } |
---|
| 2440 | |
---|
[7d4fbcd] | 2441 | /* If flag is 1, marks for deletion. If flag is 0, |
---|
| 2442 | * unmarks for deletion. */ |
---|
[d54838d] | 2443 | void owl_function_delete_curview_msgs(int flag) |
---|
| 2444 | { |
---|
[9e5c9f3] | 2445 | const owl_view *v; |
---|
[7d4fbcd] | 2446 | int i, j; |
---|
| 2447 | |
---|
| 2448 | v=owl_global_get_current_view(&g); |
---|
| 2449 | j=owl_view_get_size(v); |
---|
| 2450 | for (i=0; i<j; i++) { |
---|
| 2451 | if (flag == 1) { |
---|
| 2452 | owl_message_mark_delete(owl_view_get_element(v, i)); |
---|
| 2453 | } else if (flag == 0) { |
---|
| 2454 | owl_message_unmark_delete(owl_view_get_element(v, i)); |
---|
| 2455 | } |
---|
| 2456 | } |
---|
| 2457 | |
---|
| 2458 | owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un"); |
---|
| 2459 | |
---|
| 2460 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2461 | } |
---|
| 2462 | |
---|
[ecaec21] | 2463 | static char *owl_function_smartfilter_cc(const owl_message *m) { |
---|
| 2464 | const char *ccs; |
---|
| 2465 | char *filtname; |
---|
| 2466 | char *text; |
---|
| 2467 | owl_filter *f; |
---|
| 2468 | |
---|
| 2469 | ccs = owl_message_get_attribute_value(m, "zephyr_ccs"); |
---|
| 2470 | |
---|
| 2471 | filtname = owl_sprintf("conversation-%s", ccs); |
---|
| 2472 | owl_text_tr(filtname, ' ', '-'); |
---|
| 2473 | |
---|
| 2474 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2475 | return filtname; |
---|
| 2476 | } |
---|
| 2477 | |
---|
| 2478 | text = owl_sprintf("type ^zephyr$ and filter personal and " |
---|
| 2479 | "zephyr_ccs ^%s%s%s$", |
---|
| 2480 | owl_getquoting(ccs), ccs, owl_getquoting(ccs)); |
---|
| 2481 | |
---|
| 2482 | f = owl_filter_new_fromstring(filtname, text); |
---|
| 2483 | |
---|
| 2484 | owl_global_add_filter(&g, f); |
---|
| 2485 | |
---|
| 2486 | owl_free(text); |
---|
| 2487 | |
---|
| 2488 | return filtname; |
---|
| 2489 | } |
---|
| 2490 | |
---|
[3abf28b] | 2491 | /* Create a filter based on the current message. Returns the name of |
---|
| 2492 | * a filter or null. The caller must free this name. |
---|
| 2493 | * |
---|
| 2494 | * if the curmsg is a personal zephyr return a filter name |
---|
[e6d989f] | 2495 | * to the zephyr conversation with that user. |
---|
[3abf28b] | 2496 | * If the curmsg is a zephyr class message, instance foo, recip *, |
---|
| 2497 | * return a filter name to the class, inst. |
---|
| 2498 | * If the curmsg is a zephyr class message and type==0 then |
---|
| 2499 | * return a filter name for just the class. |
---|
| 2500 | * If the curmsg is a zephyr class message and type==1 then |
---|
| 2501 | * return a filter name for the class and instance. |
---|
| 2502 | * If the curmsg is a personal AIM message returna filter |
---|
| 2503 | * name to the AIM conversation with that user |
---|
| 2504 | */ |
---|
[8a5b5a1] | 2505 | char *owl_function_smartfilter(int type, int invert_related) |
---|
[d54838d] | 2506 | { |
---|
[9e5c9f3] | 2507 | const owl_view *v; |
---|
[c08c70a] | 2508 | const owl_message *m; |
---|
[4b464a4] | 2509 | char *zperson, *filtname=NULL; |
---|
[66e409c] | 2510 | const char *argv[2]; |
---|
[8a5b5a1] | 2511 | int related = owl_global_is_narrow_related(&g) ^ invert_related; |
---|
| 2512 | |
---|
[7d4fbcd] | 2513 | v=owl_global_get_current_view(&g); |
---|
| 2514 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 2515 | |
---|
[5eeea3b] | 2516 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 2517 | owl_function_error("No message selected\n"); |
---|
[4b464a4] | 2518 | return(NULL); |
---|
[7d4fbcd] | 2519 | } |
---|
| 2520 | |
---|
[f73e519] | 2521 | /* very simple handling of admin messages for now */ |
---|
[4b464a4] | 2522 | if (owl_message_is_type_admin(m)) { |
---|
[3abf28b] | 2523 | return(owl_function_typefilt("admin")); |
---|
| 2524 | } |
---|
| 2525 | |
---|
[995eb4b] | 2526 | /* very simple handling of loopback messages for now */ |
---|
| 2527 | if (owl_message_is_type_loopback(m)) { |
---|
| 2528 | return(owl_function_typefilt("loopback")); |
---|
| 2529 | } |
---|
| 2530 | |
---|
[3abf28b] | 2531 | /* aim messages */ |
---|
| 2532 | if (owl_message_is_type_aim(m)) { |
---|
| 2533 | if (owl_message_is_direction_in(m)) { |
---|
| 2534 | filtname=owl_function_aimuserfilt(owl_message_get_sender(m)); |
---|
| 2535 | } else if (owl_message_is_direction_out(m)) { |
---|
| 2536 | filtname=owl_function_aimuserfilt(owl_message_get_recipient(m)); |
---|
| 2537 | } |
---|
| 2538 | return(filtname); |
---|
[7d4fbcd] | 2539 | } |
---|
| 2540 | |
---|
[4b464a4] | 2541 | /* narrow personal and login messages to the sender or recip as appropriate */ |
---|
[25729b2] | 2542 | if (owl_message_is_type_zephyr(m)) { |
---|
[0ef0e8f] | 2543 | if (owl_message_is_personal(m) || owl_message_is_loginout(m)) { |
---|
[ecaec21] | 2544 | if (owl_message_get_attribute_value(m, "zephyr_ccs") != NULL) { |
---|
| 2545 | return owl_function_smartfilter_cc(m); |
---|
| 2546 | } |
---|
| 2547 | |
---|
[4b464a4] | 2548 | if (owl_message_is_direction_in(m)) { |
---|
[25729b2] | 2549 | zperson=short_zuser(owl_message_get_sender(m)); |
---|
[4b464a4] | 2550 | } else { |
---|
[25729b2] | 2551 | zperson=short_zuser(owl_message_get_recipient(m)); |
---|
[4b464a4] | 2552 | } |
---|
[3abf28b] | 2553 | filtname=owl_function_zuserfilt(zperson); |
---|
[4b464a4] | 2554 | owl_free(zperson); |
---|
| 2555 | return(filtname); |
---|
[7d4fbcd] | 2556 | } |
---|
| 2557 | |
---|
[25729b2] | 2558 | /* narrow class MESSAGE, instance foo, recip * messages to class, inst */ |
---|
[ce74deb] | 2559 | if (!strcasecmp(owl_message_get_class(m), "message")) { |
---|
[66e409c] | 2560 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m), related); |
---|
[25729b2] | 2561 | return(filtname); |
---|
| 2562 | } |
---|
| 2563 | |
---|
| 2564 | /* otherwise narrow to the class */ |
---|
| 2565 | if (type==0) { |
---|
[66e409c] | 2566 | filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL, related); |
---|
[25729b2] | 2567 | } else if (type==1) { |
---|
[66e409c] | 2568 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m), related); |
---|
[25729b2] | 2569 | } |
---|
[4b464a4] | 2570 | return(filtname); |
---|
[7d4fbcd] | 2571 | } |
---|
| 2572 | |
---|
[25729b2] | 2573 | /* pass it off to perl */ |
---|
[66e409c] | 2574 | argv[0] = type ? "1" : "0"; |
---|
| 2575 | argv[1] = related ? "1" : "0"; |
---|
| 2576 | return owl_perlconfig_message_call_method(m, "smartfilter", 2, argv); |
---|
[7d4fbcd] | 2577 | } |
---|
| 2578 | |
---|
[d54838d] | 2579 | void owl_function_smartzpunt(int type) |
---|
| 2580 | { |
---|
[d36f2cb] | 2581 | /* Starts a zpunt command based on the current class,instance pair. |
---|
| 2582 | * If type=0, uses just class. If type=1, uses instance as well. */ |
---|
[9e5c9f3] | 2583 | const owl_view *v; |
---|
[c08c70a] | 2584 | const owl_message *m; |
---|
[e19eb97] | 2585 | const char *cmdprefix, *mclass, *minst; |
---|
[65b2173] | 2586 | char *cmd; |
---|
[d36f2cb] | 2587 | |
---|
| 2588 | v=owl_global_get_current_view(&g); |
---|
| 2589 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 2590 | |
---|
[5eeea3b] | 2591 | if (!m || owl_view_get_size(v)==0) { |
---|
[ec6ff52] | 2592 | owl_function_error("No message selected\n"); |
---|
[d36f2cb] | 2593 | return; |
---|
| 2594 | } |
---|
| 2595 | |
---|
| 2596 | /* for now we skip admin messages. */ |
---|
[4b464a4] | 2597 | if (owl_message_is_type_admin(m) |
---|
[5789230] | 2598 | || owl_message_is_loginout(m) |
---|
[4b464a4] | 2599 | || !owl_message_is_type_zephyr(m)) { |
---|
[ec6ff52] | 2600 | owl_function_error("smartzpunt doesn't support this message type."); |
---|
[d36f2cb] | 2601 | return; |
---|
| 2602 | } |
---|
| 2603 | |
---|
[cee1f25] | 2604 | mclass = owl_message_get_class(m); |
---|
| 2605 | minst = owl_message_get_instance(m); |
---|
[d36f2cb] | 2606 | if (!mclass || !*mclass || *mclass==' ' |
---|
| 2607 | || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal")) |
---|
| 2608 | || (type && (!minst || !*minst|| *minst==' '))) { |
---|
[ec6ff52] | 2609 | owl_function_error("smartzpunt can't safely do this for <%s,%s>", |
---|
[d36f2cb] | 2610 | mclass, minst); |
---|
| 2611 | } else { |
---|
| 2612 | cmdprefix = "start-command zpunt "; |
---|
[cee1f25] | 2613 | cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+10); |
---|
[d36f2cb] | 2614 | strcpy(cmd, cmdprefix); |
---|
[cee1f25] | 2615 | strcat(cmd, owl_getquoting(mclass)); |
---|
[d36f2cb] | 2616 | strcat(cmd, mclass); |
---|
[cee1f25] | 2617 | strcat(cmd, owl_getquoting(mclass)); |
---|
[d36f2cb] | 2618 | if (type) { |
---|
| 2619 | strcat(cmd, " "); |
---|
[cee1f25] | 2620 | strcat(cmd, owl_getquoting(minst)); |
---|
[d36f2cb] | 2621 | strcat(cmd, minst); |
---|
[cee1f25] | 2622 | strcat(cmd, owl_getquoting(minst)); |
---|
[d36f2cb] | 2623 | } else { |
---|
| 2624 | strcat(cmd, " *"); |
---|
| 2625 | } |
---|
| 2626 | owl_function_command(cmd); |
---|
| 2627 | owl_free(cmd); |
---|
| 2628 | } |
---|
| 2629 | } |
---|
| 2630 | |
---|
[5e0b690] | 2631 | /* Set the color of the current view's filter to |
---|
| 2632 | * be 'color' |
---|
| 2633 | */ |
---|
[e19eb97] | 2634 | void owl_function_color_current_filter(const char *fgcolor, const char *bgcolor) |
---|
[d54838d] | 2635 | { |
---|
[e19eb97] | 2636 | const char *name; |
---|
[7d4fbcd] | 2637 | |
---|
| 2638 | name=owl_view_get_filtname(owl_global_get_current_view(&g)); |
---|
[8fa9562] | 2639 | owl_function_color_filter(name, fgcolor, bgcolor); |
---|
[5e0b690] | 2640 | } |
---|
| 2641 | |
---|
| 2642 | /* Set the color of the filter 'filter' to be 'color'. If the color |
---|
| 2643 | * name does not exist, return -1, if the filter does not exist or is |
---|
| 2644 | * the "all" filter, return -2. Return 0 on success |
---|
| 2645 | */ |
---|
[e19eb97] | 2646 | int owl_function_color_filter(const char *filtname, const char *fgcolor, const char *bgcolor) |
---|
[5e0b690] | 2647 | { |
---|
| 2648 | owl_filter *f; |
---|
| 2649 | |
---|
| 2650 | f=owl_global_get_filter(&g, filtname); |
---|
[7d4fbcd] | 2651 | if (!f) { |
---|
[ec6ff52] | 2652 | owl_function_error("Unknown filter"); |
---|
[5e0b690] | 2653 | return(-2); |
---|
[7d4fbcd] | 2654 | } |
---|
| 2655 | |
---|
| 2656 | /* don't touch the all filter */ |
---|
[5e0b690] | 2657 | if (!strcmp(filtname, "all")) { |
---|
[ec6ff52] | 2658 | owl_function_error("You may not change the 'all' filter."); |
---|
[5e0b690] | 2659 | return(-2); |
---|
[7d4fbcd] | 2660 | } |
---|
| 2661 | |
---|
[601733d] | 2662 | if (owl_util_string_to_color(fgcolor)==OWL_COLOR_INVALID) { |
---|
[8fa9562] | 2663 | owl_function_error("No color named '%s' avilable.", fgcolor); |
---|
[5e0b690] | 2664 | return(-1); |
---|
[12c35df] | 2665 | } |
---|
[8fa9562] | 2666 | |
---|
| 2667 | |
---|
| 2668 | if (bgcolor != NULL) { |
---|
[601733d] | 2669 | if (owl_util_string_to_color(bgcolor)==OWL_COLOR_INVALID) { |
---|
[8fa9562] | 2670 | owl_function_error("No color named '%s' avilable.", bgcolor); |
---|
| 2671 | return(-1); |
---|
| 2672 | } |
---|
| 2673 | owl_filter_set_bgcolor(f, owl_util_string_to_color(bgcolor)); |
---|
| 2674 | } |
---|
| 2675 | owl_filter_set_fgcolor(f, owl_util_string_to_color(fgcolor)); |
---|
| 2676 | |
---|
[7d4fbcd] | 2677 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[5e0b690] | 2678 | return(0); |
---|
[7d4fbcd] | 2679 | } |
---|
| 2680 | |
---|
[c79a047] | 2681 | void owl_function_show_colors(void) |
---|
[d54838d] | 2682 | { |
---|
[7d4fbcd] | 2683 | owl_fmtext fm; |
---|
[c2c5c77] | 2684 | int i; |
---|
| 2685 | |
---|
[7d4fbcd] | 2686 | owl_fmtext_init_null(&fm); |
---|
[ca9142e] | 2687 | owl_fmtext_append_normal(&fm, "default: "); |
---|
[8fa9562] | 2688 | owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2689 | |
---|
| 2690 | owl_fmtext_append_normal(&fm,"red: "); |
---|
[8fa9562] | 2691 | owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2692 | |
---|
| 2693 | owl_fmtext_append_normal(&fm,"green: "); |
---|
[8fa9562] | 2694 | owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2695 | |
---|
| 2696 | owl_fmtext_append_normal(&fm,"yellow: "); |
---|
[8fa9562] | 2697 | owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2698 | |
---|
| 2699 | owl_fmtext_append_normal(&fm,"blue: "); |
---|
[8fa9562] | 2700 | owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2701 | |
---|
| 2702 | owl_fmtext_append_normal(&fm,"magenta: "); |
---|
[8fa9562] | 2703 | owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2704 | |
---|
| 2705 | owl_fmtext_append_normal(&fm,"cyan: "); |
---|
[8fa9562] | 2706 | owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN, OWL_COLOR_DEFAULT); |
---|
[ca9142e] | 2707 | |
---|
| 2708 | owl_fmtext_append_normal(&fm,"white: "); |
---|
[8fa9562] | 2709 | owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE, OWL_COLOR_DEFAULT); |
---|
[7d4fbcd] | 2710 | |
---|
[c2c5c77] | 2711 | for(i = 8; i < COLORS; ++i) { |
---|
| 2712 | char* str1 = owl_sprintf("%4i: ",i); |
---|
| 2713 | char* str2 = owl_sprintf("%i\n",i); |
---|
| 2714 | owl_fmtext_append_normal(&fm,str1); |
---|
| 2715 | owl_fmtext_append_normal_color(&fm, str2, i, OWL_COLOR_DEFAULT); |
---|
| 2716 | owl_free(str1); |
---|
| 2717 | owl_free(str2); |
---|
| 2718 | } |
---|
| 2719 | |
---|
[7d4fbcd] | 2720 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2721 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2722 | } |
---|
| 2723 | |
---|
[5bb6c21] | 2724 | /* add the given class, inst, recip to the punt list for filtering. |
---|
| 2725 | * if direction==0 then punt |
---|
| 2726 | * if direction==1 then unpunt |
---|
| 2727 | */ |
---|
[e19eb97] | 2728 | void owl_function_zpunt(const char *class, const char *inst, const char *recip, int direction) |
---|
[d54838d] | 2729 | { |
---|
[c894c15] | 2730 | char *puntexpr, *classexpr, *instexpr, *recipexpr; |
---|
[bc08664] | 2731 | char *quoted; |
---|
[7d4fbcd] | 2732 | |
---|
[5bb6c21] | 2733 | if (!strcmp(class, "*")) { |
---|
[c894c15] | 2734 | classexpr = owl_sprintf("class .*"); |
---|
[5bb6c21] | 2735 | } else { |
---|
[bc08664] | 2736 | quoted=owl_text_quote(class, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[cee1f25] | 2737 | owl_text_tr(quoted, ' ', '.'); |
---|
[4099cf8] | 2738 | owl_text_tr(quoted, '\'', '.'); |
---|
| 2739 | owl_text_tr(quoted, '"', '.'); |
---|
[c894c15] | 2740 | classexpr = owl_sprintf("class ^(un)*%s(\\.d)*$", quoted); |
---|
[bc08664] | 2741 | owl_free(quoted); |
---|
[5bb6c21] | 2742 | } |
---|
| 2743 | if (!strcmp(inst, "*")) { |
---|
[c894c15] | 2744 | instexpr = owl_sprintf(" and instance .*"); |
---|
[7d4fbcd] | 2745 | } else { |
---|
[bc08664] | 2746 | quoted=owl_text_quote(inst, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[cee1f25] | 2747 | owl_text_tr(quoted, ' ', '.'); |
---|
[4099cf8] | 2748 | owl_text_tr(quoted, '\'', '.'); |
---|
| 2749 | owl_text_tr(quoted, '"', '.'); |
---|
[c894c15] | 2750 | instexpr = owl_sprintf(" and instance ^(un)*%s(\\.d)*$", quoted); |
---|
[bc08664] | 2751 | owl_free(quoted); |
---|
[7d4fbcd] | 2752 | } |
---|
[c894c15] | 2753 | if (!strcmp(recip, "*")) { |
---|
| 2754 | recipexpr = owl_sprintf(""); |
---|
| 2755 | } else { |
---|
[e6c59ba] | 2756 | if(!strcmp(recip, "%me%")) { |
---|
| 2757 | recip = owl_zephyr_get_sender(); |
---|
| 2758 | } |
---|
[bc08664] | 2759 | quoted=owl_text_quote(recip, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH); |
---|
[cee1f25] | 2760 | owl_text_tr(quoted, ' ', '.'); |
---|
[4099cf8] | 2761 | owl_text_tr(quoted, '\'', '.'); |
---|
| 2762 | owl_text_tr(quoted, '"', '.'); |
---|
[7980fb2] | 2763 | recipexpr = owl_sprintf(" and recipient ^%s$", quoted); |
---|
[bc08664] | 2764 | owl_free(quoted); |
---|
[5bb6c21] | 2765 | } |
---|
[ce7b824] | 2766 | |
---|
[c894c15] | 2767 | puntexpr = owl_sprintf("%s %s %s", classexpr, instexpr, recipexpr); |
---|
| 2768 | owl_function_punt(puntexpr, direction); |
---|
| 2769 | owl_free(puntexpr); |
---|
| 2770 | owl_free(classexpr); |
---|
| 2771 | owl_free(instexpr); |
---|
| 2772 | owl_free(recipexpr); |
---|
[ce7b824] | 2773 | } |
---|
| 2774 | |
---|
[e19eb97] | 2775 | void owl_function_punt(const char *filter, int direction) |
---|
[ce7b824] | 2776 | { |
---|
| 2777 | owl_filter *f; |
---|
| 2778 | owl_list *fl; |
---|
[23fddad] | 2779 | int i, j; |
---|
[ce7b824] | 2780 | fl=owl_global_get_puntlist(&g); |
---|
| 2781 | |
---|
| 2782 | /* first, create the filter */ |
---|
| 2783 | owl_function_debugmsg("About to filter %s", filter); |
---|
[23fddad] | 2784 | f = owl_filter_new_fromstring("punt-filter", filter); |
---|
| 2785 | if (f == NULL) { |
---|
[ec6ff52] | 2786 | owl_function_error("Error creating filter for zpunt"); |
---|
[7d4fbcd] | 2787 | return; |
---|
| 2788 | } |
---|
| 2789 | |
---|
| 2790 | /* Check for an identical filter */ |
---|
| 2791 | j=owl_list_get_size(fl); |
---|
| 2792 | for (i=0; i<j; i++) { |
---|
| 2793 | if (owl_filter_equiv(f, owl_list_get_element(fl, i))) { |
---|
[ce7b824] | 2794 | owl_function_debugmsg("found an equivalent punt filter"); |
---|
[7d4fbcd] | 2795 | /* if we're punting, then just silently bow out on this duplicate */ |
---|
| 2796 | if (direction==0) { |
---|
[23fddad] | 2797 | owl_filter_delete(f); |
---|
[7d4fbcd] | 2798 | return; |
---|
| 2799 | } |
---|
| 2800 | |
---|
| 2801 | /* if we're unpunting, then remove this filter from the puntlist */ |
---|
| 2802 | if (direction==1) { |
---|
[23fddad] | 2803 | owl_filter_delete(owl_list_get_element(fl, i)); |
---|
[7d4fbcd] | 2804 | owl_list_remove_element(fl, i); |
---|
[23fddad] | 2805 | owl_filter_delete(f); |
---|
[7d4fbcd] | 2806 | return; |
---|
| 2807 | } |
---|
| 2808 | } |
---|
| 2809 | } |
---|
| 2810 | |
---|
[ce7b824] | 2811 | owl_function_debugmsg("punting"); |
---|
[7d4fbcd] | 2812 | /* If we're punting, add the filter to the global punt list */ |
---|
| 2813 | if (direction==0) { |
---|
| 2814 | owl_list_append_element(fl, f); |
---|
| 2815 | } |
---|
| 2816 | } |
---|
| 2817 | |
---|
[c79a047] | 2818 | void owl_function_show_keymaps(void) |
---|
[d54838d] | 2819 | { |
---|
[7d4fbcd] | 2820 | owl_list l; |
---|
| 2821 | owl_fmtext fm; |
---|
[afa200a] | 2822 | const owl_keymap *km; |
---|
[12bc46a] | 2823 | const owl_keyhandler *kh; |
---|
[1aee7d9] | 2824 | int i, numkm; |
---|
[e19eb97] | 2825 | const char *kmname; |
---|
[7d4fbcd] | 2826 | |
---|
[1aee7d9] | 2827 | kh = owl_global_get_keyhandler(&g); |
---|
[7d4fbcd] | 2828 | owl_fmtext_init_null(&fm); |
---|
| 2829 | owl_fmtext_append_bold(&fm, "Keymaps: "); |
---|
| 2830 | owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n"); |
---|
[1aee7d9] | 2831 | owl_keyhandler_get_keymap_names(kh, &l); |
---|
[7d4fbcd] | 2832 | owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary); |
---|
| 2833 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[1aee7d9] | 2834 | |
---|
| 2835 | numkm = owl_list_get_size(&l); |
---|
| 2836 | for (i=0; i<numkm; i++) { |
---|
| 2837 | kmname = owl_list_get_element(&l, i); |
---|
| 2838 | km = owl_keyhandler_get_keymap(kh, kmname); |
---|
| 2839 | owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n"); |
---|
[13ebf92] | 2840 | owl_keymap_get_details(km, &fm, 0); |
---|
[1aee7d9] | 2841 | } |
---|
| 2842 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 2843 | |
---|
[7d4fbcd] | 2844 | owl_function_popless_fmtext(&fm); |
---|
[bb0d439] | 2845 | owl_keyhandler_keymap_namelist_cleanup(&l); |
---|
[7ab0020] | 2846 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2847 | } |
---|
| 2848 | |
---|
[e19eb97] | 2849 | char *owl_function_keymap_summary(const char *name) |
---|
[d54838d] | 2850 | { |
---|
[afa200a] | 2851 | const owl_keymap *km |
---|
[7d4fbcd] | 2852 | = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
| 2853 | if (km) return owl_keymap_summary(km); |
---|
| 2854 | else return(NULL); |
---|
| 2855 | } |
---|
| 2856 | |
---|
| 2857 | /* TODO: implement for real */ |
---|
[e19eb97] | 2858 | void owl_function_show_keymap(const char *name) |
---|
[d54838d] | 2859 | { |
---|
[1fd0b25] | 2860 | owl_fmtext fm; |
---|
[afa200a] | 2861 | const owl_keymap *km; |
---|
[7d4fbcd] | 2862 | |
---|
| 2863 | owl_fmtext_init_null(&fm); |
---|
| 2864 | km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
| 2865 | if (km) { |
---|
[13ebf92] | 2866 | owl_keymap_get_details(km, &fm, 1); |
---|
[7d4fbcd] | 2867 | } else { |
---|
| 2868 | owl_fmtext_append_normal(&fm, "No such keymap...\n"); |
---|
| 2869 | } |
---|
| 2870 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2871 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2872 | } |
---|
| 2873 | |
---|
[e19eb97] | 2874 | void owl_function_help_for_command(const char *cmdname) |
---|
[d54838d] | 2875 | { |
---|
[1fd0b25] | 2876 | owl_fmtext fm; |
---|
[7d4fbcd] | 2877 | |
---|
| 2878 | owl_fmtext_init_null(&fm); |
---|
| 2879 | owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm); |
---|
| 2880 | owl_function_popless_fmtext(&fm); |
---|
[7ab0020] | 2881 | owl_fmtext_cleanup(&fm); |
---|
[7d4fbcd] | 2882 | } |
---|
[1fd0b25] | 2883 | |
---|
[2ec737f] | 2884 | void owl_function_set_search(const char *string) |
---|
[d54838d] | 2885 | { |
---|
[41c9a96] | 2886 | owl_regex re; |
---|
| 2887 | |
---|
| 2888 | if (string && owl_regex_create_quoted(&re, string) == 0) { |
---|
| 2889 | owl_global_set_search_re(&g, &re); |
---|
[5cbc929] | 2890 | owl_regex_cleanup(&re); |
---|
[41c9a96] | 2891 | } else { |
---|
| 2892 | owl_global_set_search_re(&g, NULL); |
---|
| 2893 | } |
---|
[2ec737f] | 2894 | } |
---|
[ab225e0] | 2895 | |
---|
[118c919] | 2896 | void owl_function_search_helper(int consider_current, int direction) |
---|
[d54838d] | 2897 | { |
---|
[1fd0b25] | 2898 | /* move to a message that contains the string. If direction is |
---|
| 2899 | * OWL_DIRECTION_DOWNWARDS then search fowards, if direction is |
---|
| 2900 | * OWL_DIRECTION_UPWARDS then search backwards. |
---|
| 2901 | * |
---|
[118c919] | 2902 | * If consider_current is true then it will stay on the |
---|
[9c1e61d4] | 2903 | * current message if it contains the string. |
---|
[1fd0b25] | 2904 | */ |
---|
| 2905 | |
---|
[9e5c9f3] | 2906 | const owl_view *v; |
---|
[1fd0b25] | 2907 | int viewsize, i, curmsg, start; |
---|
| 2908 | owl_message *m; |
---|
| 2909 | |
---|
| 2910 | v=owl_global_get_current_view(&g); |
---|
| 2911 | viewsize=owl_view_get_size(v); |
---|
| 2912 | curmsg=owl_global_get_curmsg(&g); |
---|
| 2913 | |
---|
| 2914 | if (viewsize==0) { |
---|
[ec6ff52] | 2915 | owl_function_error("No messages present"); |
---|
[1fd0b25] | 2916 | return; |
---|
| 2917 | } |
---|
| 2918 | |
---|
[118c919] | 2919 | if (consider_current) { |
---|
[1fd0b25] | 2920 | start=curmsg; |
---|
| 2921 | } else if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
|