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