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