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