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