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