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