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