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