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