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