[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 */ |
---|
[09489b89] | 750 | owl_zephyr_shutdown(); |
---|
[7d4fbcd] | 751 | endwin(); |
---|
| 752 | owl_function_debugmsg("Quitting Owl"); |
---|
| 753 | exit(0); |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | |
---|
[d54838d] | 757 | void owl_function_makemsg(char *fmt, ...) |
---|
| 758 | { |
---|
[7d4fbcd] | 759 | va_list ap; |
---|
| 760 | char buff[2048]; |
---|
| 761 | |
---|
[0c502e9] | 762 | if (!owl_global_get_curs_msgwin(&g)) return; |
---|
| 763 | |
---|
[7d4fbcd] | 764 | va_start(ap, fmt); |
---|
| 765 | werase(owl_global_get_curs_msgwin(&g)); |
---|
| 766 | |
---|
| 767 | vsnprintf(buff, 2048, fmt, ap); |
---|
| 768 | owl_function_debugmsg("makemsg: %s", buff); |
---|
| 769 | waddstr(owl_global_get_curs_msgwin(&g), buff); |
---|
| 770 | wnoutrefresh(owl_global_get_curs_msgwin(&g)); |
---|
| 771 | owl_global_set_needrefresh(&g); |
---|
| 772 | va_end(ap); |
---|
| 773 | } |
---|
| 774 | |
---|
[d54838d] | 775 | void owl_function_errormsg(char *fmt, ...) |
---|
| 776 | { |
---|
[7d4fbcd] | 777 | va_list ap; |
---|
| 778 | char buff[2048]; |
---|
| 779 | |
---|
[0c502e9] | 780 | if (!owl_global_get_curs_msgwin(&g)) return; |
---|
| 781 | |
---|
[7d4fbcd] | 782 | va_start(ap, fmt); |
---|
| 783 | werase(owl_global_get_curs_msgwin(&g)); |
---|
| 784 | |
---|
| 785 | vsnprintf(buff, 2048, fmt, ap); |
---|
| 786 | owl_function_debugmsg("ERROR: %s", buff); |
---|
| 787 | waddstr(owl_global_get_curs_msgwin(&g), buff); |
---|
| 788 | waddstr(owl_global_get_curs_msgwin(&g), "ERROR: "); |
---|
| 789 | wnoutrefresh(owl_global_get_curs_msgwin(&g)); |
---|
| 790 | owl_global_set_needrefresh(&g); |
---|
| 791 | va_end(ap); |
---|
| 792 | } |
---|
| 793 | |
---|
| 794 | |
---|
[d54838d] | 795 | void owl_function_openurl() |
---|
| 796 | { |
---|
[7d4fbcd] | 797 | /* visit the first url in the current message */ |
---|
| 798 | owl_message *m; |
---|
| 799 | owl_view *v; |
---|
| 800 | char *ptr1, *ptr2, *text, url[LINE], tmpbuff[LINE]; |
---|
| 801 | int webbrowser; |
---|
| 802 | |
---|
| 803 | webbrowser = owl_global_get_webbrowser(&g); |
---|
| 804 | |
---|
| 805 | if (webbrowser < 0 || webbrowser == OWL_WEBBROWSER_NONE) { |
---|
| 806 | owl_function_makemsg("No browser selected"); |
---|
| 807 | return; |
---|
| 808 | } |
---|
| 809 | |
---|
| 810 | v=owl_global_get_current_view(&g); |
---|
| 811 | |
---|
[5eeea3b] | 812 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 813 | |
---|
| 814 | if (!m || owl_view_get_size(v)==0) { |
---|
[7d4fbcd] | 815 | owl_function_makemsg("No current message selected"); |
---|
| 816 | return; |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | text=owl_message_get_text(m); |
---|
| 820 | |
---|
| 821 | /* First look for a good URL */ |
---|
| 822 | if ((ptr1=strstr(text, "http://"))!=NULL) { |
---|
| 823 | ptr2=strpbrk(ptr1, " \n\t"); |
---|
| 824 | if (ptr2) { |
---|
| 825 | strncpy(url, ptr1, ptr2-ptr1+1); |
---|
| 826 | url[ptr2-ptr1+1]='\0'; |
---|
| 827 | } else { |
---|
| 828 | strcpy(url, ptr1); |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | /* if we had <http strip a trailing > */ |
---|
| 832 | if (ptr1>text && ptr1[-1]=='<') { |
---|
| 833 | if (url[strlen(url)-1]=='>') { |
---|
| 834 | url[strlen(url)-1]='\0'; |
---|
| 835 | } |
---|
| 836 | } |
---|
| 837 | } else if ((ptr1=strstr(text, "https://"))!=NULL) { |
---|
| 838 | /* Look for an https URL */ |
---|
| 839 | ptr2=strpbrk(ptr1, " \n\t"); |
---|
| 840 | if (ptr2) { |
---|
| 841 | strncpy(url, ptr1, ptr2-ptr1+1); |
---|
| 842 | url[ptr2-ptr1+1]='\0'; |
---|
| 843 | } else { |
---|
| 844 | strcpy(url, ptr1); |
---|
| 845 | } |
---|
| 846 | |
---|
| 847 | /* if we had <http strip a trailing > */ |
---|
| 848 | if (ptr1>text && ptr1[-1]=='<') { |
---|
| 849 | if (url[strlen(url)-1]=='>') { |
---|
| 850 | url[strlen(url)-1]='\0'; |
---|
| 851 | } |
---|
| 852 | } |
---|
| 853 | } else if ((ptr1=strstr(text, "www."))!=NULL) { |
---|
| 854 | /* if we can't find a real url look for www.something */ |
---|
| 855 | ptr2=strpbrk(ptr1, " \n\t"); |
---|
| 856 | if (ptr2) { |
---|
| 857 | strncpy(url, ptr1, ptr2-ptr1+1); |
---|
| 858 | url[ptr2-ptr1+1]='\0'; |
---|
| 859 | } else { |
---|
| 860 | strcpy(url, ptr1); |
---|
| 861 | } |
---|
| 862 | } else { |
---|
| 863 | owl_function_beep(); |
---|
| 864 | owl_function_makemsg("Could not find URL to open."); |
---|
| 865 | return; |
---|
| 866 | } |
---|
| 867 | |
---|
| 868 | /* Make sure there aren't any quotes or \'s in the url */ |
---|
| 869 | for (ptr1 = url; *ptr1; ptr1++) { |
---|
| 870 | if (*ptr1 == '"' || *ptr1 == '\\') { |
---|
| 871 | owl_function_beep(); |
---|
| 872 | owl_function_makemsg("URL contains invalid characters."); |
---|
| 873 | return; |
---|
| 874 | } |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | /* NOTE: There are potentially serious security issues here... */ |
---|
| 878 | |
---|
| 879 | /* open the page */ |
---|
| 880 | owl_function_makemsg("Opening %s", url); |
---|
| 881 | if (webbrowser == OWL_WEBBROWSER_NETSCAPE) { |
---|
| 882 | snprintf(tmpbuff, LINE, "netscape -remote \"openURL(%s)\" > /dev/null 2> /dev/null", url); |
---|
| 883 | system(tmpbuff); |
---|
| 884 | } else if (webbrowser == OWL_WEBBROWSER_GALEON) { |
---|
| 885 | snprintf(tmpbuff, LINE, "galeon \"%s\" > /dev/null 2> /dev/null &", url); |
---|
| 886 | system(tmpbuff); |
---|
[ae9e6be] | 887 | } else if (webbrowser == OWL_WEBBROWSER_OPERA) { |
---|
| 888 | snprintf(tmpbuff, LINE, "opera \"%s\" > /dev/null 2> /dev/null &", url); |
---|
| 889 | system(tmpbuff); |
---|
[7d4fbcd] | 890 | } |
---|
| 891 | } |
---|
| 892 | |
---|
[d54838d] | 893 | void owl_function_calculate_topmsg(int direction) |
---|
| 894 | { |
---|
[aa2f33b3] | 895 | int recwinlines, topmsg, curmsg; |
---|
[7d4fbcd] | 896 | owl_view *v; |
---|
| 897 | |
---|
| 898 | v=owl_global_get_current_view(&g); |
---|
[aa2f33b3] | 899 | curmsg=owl_global_get_curmsg(&g); |
---|
| 900 | topmsg=owl_global_get_topmsg(&g); |
---|
[7d4fbcd] | 901 | recwinlines=owl_global_get_recwin_lines(&g); |
---|
| 902 | |
---|
[f9c43ae] | 903 | /* |
---|
[7d4fbcd] | 904 | if (owl_view_get_size(v) < 1) { |
---|
| 905 | return; |
---|
| 906 | } |
---|
[f9c43ae] | 907 | */ |
---|
[aa2f33b3] | 908 | |
---|
| 909 | switch (owl_global_get_scrollmode(&g)) { |
---|
| 910 | case OWL_SCROLLMODE_TOP: |
---|
[f9c43ae] | 911 | topmsg = owl_function_calculate_topmsg_top(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 912 | break; |
---|
| 913 | case OWL_SCROLLMODE_NEARTOP: |
---|
[f9c43ae] | 914 | topmsg = owl_function_calculate_topmsg_neartop(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 915 | break; |
---|
| 916 | case OWL_SCROLLMODE_CENTER: |
---|
[f9c43ae] | 917 | topmsg = owl_function_calculate_topmsg_center(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 918 | break; |
---|
| 919 | case OWL_SCROLLMODE_PAGED: |
---|
[f9c43ae] | 920 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 0); |
---|
[aa2f33b3] | 921 | break; |
---|
| 922 | case OWL_SCROLLMODE_PAGEDCENTER: |
---|
[f9c43ae] | 923 | topmsg = owl_function_calculate_topmsg_paged(direction, v, curmsg, topmsg, recwinlines, 1); |
---|
[aa2f33b3] | 924 | break; |
---|
| 925 | case OWL_SCROLLMODE_NORMAL: |
---|
| 926 | default: |
---|
[f9c43ae] | 927 | topmsg = owl_function_calculate_topmsg_normal(direction, v, curmsg, topmsg, recwinlines); |
---|
[aa2f33b3] | 928 | } |
---|
[3a2daac] | 929 | owl_function_debugmsg("Calculated a topmsg of %i", topmsg); |
---|
[aa2f33b3] | 930 | owl_global_set_topmsg(&g, topmsg); |
---|
| 931 | } |
---|
| 932 | |
---|
| 933 | /* Returns what the new topmsg should be. |
---|
| 934 | * Passed the last direction of movement, |
---|
| 935 | * the current view, |
---|
| 936 | * the current message number in the view, |
---|
| 937 | * the top message currently being displayed, |
---|
| 938 | * and the number of lines in the recwin. |
---|
| 939 | */ |
---|
[d54838d] | 940 | int owl_function_calculate_topmsg_top(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
| 941 | { |
---|
[f9c43ae] | 942 | return(curmsg); |
---|
[aa2f33b3] | 943 | } |
---|
| 944 | |
---|
[d54838d] | 945 | int owl_function_calculate_topmsg_neartop(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
| 946 | { |
---|
[aa2f33b3] | 947 | if (curmsg>0 |
---|
| 948 | && (owl_message_get_numlines(owl_view_get_element(v, curmsg-1)) |
---|
| 949 | < recwinlines/2)) { |
---|
[f9c43ae] | 950 | return(curmsg-1); |
---|
[aa2f33b3] | 951 | } else { |
---|
[f9c43ae] | 952 | return(curmsg); |
---|
[aa2f33b3] | 953 | } |
---|
| 954 | } |
---|
| 955 | |
---|
[d54838d] | 956 | int owl_function_calculate_topmsg_center(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
| 957 | { |
---|
[aa2f33b3] | 958 | int i, last, lines; |
---|
| 959 | |
---|
| 960 | last = curmsg; |
---|
| 961 | lines = 0; |
---|
| 962 | for (i=curmsg-1; i>=0; i--) { |
---|
| 963 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 964 | if (lines > recwinlines/2) break; |
---|
| 965 | last = i; |
---|
| 966 | } |
---|
[f9c43ae] | 967 | return(last); |
---|
[aa2f33b3] | 968 | } |
---|
| 969 | |
---|
[d54838d] | 970 | int owl_function_calculate_topmsg_paged(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines, int center_on_page) |
---|
| 971 | { |
---|
[aa2f33b3] | 972 | int i, last, lines, savey; |
---|
| 973 | |
---|
| 974 | /* If we're off the top of the screen, scroll up such that the |
---|
| 975 | * curmsg is near the botton of the screen. */ |
---|
| 976 | if (curmsg < topmsg) { |
---|
| 977 | last = curmsg; |
---|
| 978 | lines = 0; |
---|
| 979 | for (i=curmsg; i>=0; i--) { |
---|
| 980 | lines += owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 981 | if (lines > recwinlines) break; |
---|
| 982 | last = i; |
---|
| 983 | } |
---|
| 984 | if (center_on_page) { |
---|
[f9c43ae] | 985 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
[aa2f33b3] | 986 | } else { |
---|
[f9c43ae] | 987 | return(last); |
---|
[aa2f33b3] | 988 | } |
---|
| 989 | } |
---|
| 990 | |
---|
| 991 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
| 992 | savey=0; |
---|
| 993 | for (i=topmsg; i<=curmsg; i++) { |
---|
| 994 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 995 | } |
---|
| 996 | |
---|
| 997 | /* if we're off the bottom of the screen, scroll down */ |
---|
| 998 | if (savey > recwinlines) { |
---|
| 999 | if (center_on_page) { |
---|
[f9c43ae] | 1000 | return(owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines)); |
---|
[aa2f33b3] | 1001 | } else { |
---|
[f9c43ae] | 1002 | return(curmsg); |
---|
[aa2f33b3] | 1003 | } |
---|
| 1004 | } |
---|
| 1005 | |
---|
| 1006 | /* else just stay as we are... */ |
---|
[f9c43ae] | 1007 | return(topmsg); |
---|
[aa2f33b3] | 1008 | } |
---|
| 1009 | |
---|
| 1010 | |
---|
[d54838d] | 1011 | int owl_function_calculate_topmsg_normal(int direction, owl_view *v, int curmsg, int topmsg, int recwinlines) |
---|
| 1012 | { |
---|
[aa2f33b3] | 1013 | int savey, j, i, foo, y; |
---|
[f9c43ae] | 1014 | |
---|
[88736cb] | 1015 | if (curmsg<0) return(topmsg); |
---|
| 1016 | |
---|
[f9c43ae] | 1017 | /* If we're off the top of the screen then center */ |
---|
| 1018 | if (curmsg<topmsg) { |
---|
| 1019 | topmsg=owl_function_calculate_topmsg_center(direction, v, curmsg, 0, recwinlines); |
---|
| 1020 | } |
---|
| 1021 | |
---|
[7d4fbcd] | 1022 | /* Find number of lines from top to bottom of curmsg (store in savey) */ |
---|
| 1023 | savey=0; |
---|
| 1024 | for (i=topmsg; i<=curmsg; i++) { |
---|
| 1025 | savey+=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1026 | } |
---|
| 1027 | |
---|
[f9c43ae] | 1028 | /* If we're off the bottom of the screen, set the topmsg to curmsg |
---|
| 1029 | * and scroll upwards */ |
---|
| 1030 | if (savey > recwinlines) { |
---|
| 1031 | topmsg=curmsg; |
---|
| 1032 | savey=owl_message_get_numlines(owl_view_get_element(v, i)); |
---|
| 1033 | direction=OWL_DIRECTION_UPWARDS; |
---|
[7d4fbcd] | 1034 | } |
---|
[f9c43ae] | 1035 | |
---|
[7d4fbcd] | 1036 | /* If our bottom line is less than 1/4 down the screen then scroll up */ |
---|
| 1037 | if (direction == OWL_DIRECTION_UPWARDS || direction == OWL_DIRECTION_NONE) { |
---|
| 1038 | if (savey < (recwinlines / 4)) { |
---|
| 1039 | y=0; |
---|
| 1040 | for (j=curmsg; j>=0; j--) { |
---|
| 1041 | foo=owl_message_get_numlines(owl_view_get_element(v, j)); |
---|
| 1042 | /* will we run the curmsg off the screen? */ |
---|
| 1043 | if ((foo+y) >= recwinlines) { |
---|
| 1044 | j++; |
---|
| 1045 | if (j>curmsg) j=curmsg; |
---|
| 1046 | break; |
---|
| 1047 | } |
---|
| 1048 | /* have saved 1/2 the screen space? */ |
---|
| 1049 | y+=foo; |
---|
| 1050 | if (y > (recwinlines / 2)) break; |
---|
| 1051 | } |
---|
| 1052 | if (j<0) j=0; |
---|
[f9c43ae] | 1053 | return(j); |
---|
[7d4fbcd] | 1054 | } |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | if (direction == OWL_DIRECTION_DOWNWARDS || direction == OWL_DIRECTION_NONE) { |
---|
| 1058 | /* If curmsg bottom line is more than 3/4 down the screen then scroll down */ |
---|
| 1059 | if (savey > ((recwinlines * 3)/4)) { |
---|
| 1060 | y=0; |
---|
| 1061 | /* count lines from the top until we can save 1/2 the screen size */ |
---|
| 1062 | for (j=topmsg; j<curmsg; j++) { |
---|
| 1063 | y+=owl_message_get_numlines(owl_view_get_element(v, j)); |
---|
| 1064 | if (y > (recwinlines / 2)) break; |
---|
| 1065 | } |
---|
| 1066 | if (j==curmsg) { |
---|
| 1067 | j--; |
---|
| 1068 | } |
---|
[f9c43ae] | 1069 | return(j+1); |
---|
[7d4fbcd] | 1070 | } |
---|
| 1071 | } |
---|
[aa2f33b3] | 1072 | |
---|
[f9c43ae] | 1073 | return(topmsg); |
---|
[7d4fbcd] | 1074 | } |
---|
| 1075 | |
---|
| 1076 | |
---|
[d54838d] | 1077 | void owl_function_resize() |
---|
| 1078 | { |
---|
[7d4fbcd] | 1079 | owl_global_set_resize_pending(&g); |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | |
---|
[d54838d] | 1083 | void owl_function_run_buffercommand() |
---|
| 1084 | { |
---|
[453bd70] | 1085 | char *buff, *ptr; |
---|
| 1086 | |
---|
[7d4fbcd] | 1087 | buff=owl_global_get_buffercommand(&g); |
---|
| 1088 | if (!strncmp(buff, "zwrite ", 7)) { |
---|
[ce7db4d] | 1089 | owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g))); |
---|
[d09e5a1] | 1090 | } else if (!strncmp(buff, "aimwrite ", 9)) { |
---|
| 1091 | owl_function_aimwrite(buff+9); |
---|
[453bd70] | 1092 | } else if (!strncmp(buff, "aimlogin ", 9)) { |
---|
| 1093 | ptr=owl_sprintf("%s %s", buff, owl_global_get_response(&g)); |
---|
| 1094 | owl_function_command(ptr); |
---|
| 1095 | owl_free(ptr); |
---|
[7d4fbcd] | 1096 | } |
---|
| 1097 | } |
---|
| 1098 | |
---|
[d54838d] | 1099 | void owl_function_debugmsg(char *fmt, ...) |
---|
| 1100 | { |
---|
[7d4fbcd] | 1101 | FILE *file; |
---|
| 1102 | time_t now; |
---|
| 1103 | char buff1[LINE], buff2[LINE]; |
---|
| 1104 | va_list ap; |
---|
| 1105 | va_start(ap, fmt); |
---|
| 1106 | |
---|
| 1107 | if (!owl_global_is_debug_fast(&g)) return; |
---|
| 1108 | |
---|
| 1109 | file=fopen(owl_global_get_debug_file(&g), "a"); |
---|
| 1110 | if (!file) return; |
---|
| 1111 | |
---|
| 1112 | now=time(NULL); |
---|
| 1113 | strcpy(buff1, ctime(&now)); |
---|
| 1114 | buff1[strlen(buff1)-1]='\0'; |
---|
| 1115 | |
---|
| 1116 | owl_global_get_runtime_string(&g, buff2); |
---|
| 1117 | |
---|
| 1118 | fprintf(file, "[%i - %s - %s]: ", (int) getpid(), buff1, buff2); |
---|
| 1119 | vfprintf(file, fmt, ap); |
---|
| 1120 | fprintf(file, "\n"); |
---|
| 1121 | fclose(file); |
---|
| 1122 | |
---|
| 1123 | va_end(ap); |
---|
| 1124 | } |
---|
| 1125 | |
---|
| 1126 | |
---|
[d54838d] | 1127 | void owl_function_refresh() |
---|
| 1128 | { |
---|
[7d4fbcd] | 1129 | owl_function_resize(); |
---|
| 1130 | } |
---|
| 1131 | |
---|
[d54838d] | 1132 | void owl_function_beep() |
---|
| 1133 | { |
---|
[7d4fbcd] | 1134 | if (owl_global_is_bell(&g)) { |
---|
| 1135 | beep(); |
---|
[b45293f] | 1136 | owl_global_set_needrefresh(&g); /* do we really need this? */ |
---|
[7d4fbcd] | 1137 | } |
---|
| 1138 | } |
---|
| 1139 | |
---|
| 1140 | |
---|
[d54838d] | 1141 | void owl_function_subscribe(char *class, char *inst, char *recip) |
---|
| 1142 | { |
---|
[7d4fbcd] | 1143 | int ret; |
---|
| 1144 | |
---|
| 1145 | ret=owl_zephyr_sub(class, inst, recip); |
---|
| 1146 | if (ret) { |
---|
| 1147 | owl_function_makemsg("Error subscribing."); |
---|
| 1148 | } else { |
---|
| 1149 | owl_function_makemsg("Subscribed."); |
---|
| 1150 | } |
---|
| 1151 | } |
---|
| 1152 | |
---|
| 1153 | |
---|
[d54838d] | 1154 | void owl_function_unsubscribe(char *class, char *inst, char *recip) |
---|
| 1155 | { |
---|
[7d4fbcd] | 1156 | int ret; |
---|
| 1157 | |
---|
| 1158 | ret=owl_zephyr_unsub(class, inst, recip); |
---|
| 1159 | if (ret) { |
---|
| 1160 | owl_function_makemsg("Error subscribing."); |
---|
| 1161 | } else { |
---|
| 1162 | owl_function_makemsg("Unsubscribed."); |
---|
| 1163 | } |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | |
---|
[d54838d] | 1167 | void owl_function_set_cursor(WINDOW *win) |
---|
| 1168 | { |
---|
[7d4fbcd] | 1169 | wnoutrefresh(win); |
---|
| 1170 | } |
---|
| 1171 | |
---|
| 1172 | |
---|
[d54838d] | 1173 | void owl_function_full_redisplay() |
---|
| 1174 | { |
---|
[7d4fbcd] | 1175 | redrawwin(owl_global_get_curs_recwin(&g)); |
---|
| 1176 | redrawwin(owl_global_get_curs_sepwin(&g)); |
---|
| 1177 | redrawwin(owl_global_get_curs_typwin(&g)); |
---|
| 1178 | redrawwin(owl_global_get_curs_msgwin(&g)); |
---|
| 1179 | |
---|
| 1180 | wnoutrefresh(owl_global_get_curs_recwin(&g)); |
---|
| 1181 | wnoutrefresh(owl_global_get_curs_sepwin(&g)); |
---|
| 1182 | wnoutrefresh(owl_global_get_curs_typwin(&g)); |
---|
| 1183 | wnoutrefresh(owl_global_get_curs_msgwin(&g)); |
---|
| 1184 | |
---|
| 1185 | sepbar(""); |
---|
| 1186 | owl_function_makemsg(""); |
---|
| 1187 | |
---|
| 1188 | owl_global_set_needrefresh(&g); |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | |
---|
[d54838d] | 1192 | void owl_function_popless_text(char *text) |
---|
| 1193 | { |
---|
[7d4fbcd] | 1194 | owl_popwin *pw; |
---|
| 1195 | owl_viewwin *v; |
---|
| 1196 | |
---|
| 1197 | pw=owl_global_get_popwin(&g); |
---|
| 1198 | v=owl_global_get_viewwin(&g); |
---|
| 1199 | |
---|
| 1200 | owl_popwin_up(pw); |
---|
| 1201 | owl_viewwin_init_text(v, owl_popwin_get_curswin(pw), |
---|
| 1202 | owl_popwin_get_lines(pw), owl_popwin_get_cols(pw), |
---|
| 1203 | text); |
---|
| 1204 | owl_popwin_refresh(pw); |
---|
| 1205 | owl_viewwin_redisplay(v, 0); |
---|
| 1206 | owl_global_set_needrefresh(&g); |
---|
| 1207 | } |
---|
| 1208 | |
---|
| 1209 | |
---|
[d54838d] | 1210 | void owl_function_popless_fmtext(owl_fmtext *fm) |
---|
| 1211 | { |
---|
[7d4fbcd] | 1212 | owl_popwin *pw; |
---|
| 1213 | owl_viewwin *v; |
---|
| 1214 | |
---|
| 1215 | pw=owl_global_get_popwin(&g); |
---|
| 1216 | v=owl_global_get_viewwin(&g); |
---|
| 1217 | |
---|
| 1218 | owl_popwin_up(pw); |
---|
| 1219 | owl_viewwin_init_fmtext(v, owl_popwin_get_curswin(pw), |
---|
| 1220 | owl_popwin_get_lines(pw), owl_popwin_get_cols(pw), |
---|
| 1221 | fm); |
---|
| 1222 | owl_popwin_refresh(pw); |
---|
| 1223 | owl_viewwin_redisplay(v, 0); |
---|
| 1224 | owl_global_set_needrefresh(&g); |
---|
| 1225 | } |
---|
| 1226 | |
---|
[d54838d] | 1227 | void owl_function_about() |
---|
| 1228 | { |
---|
[7d4fbcd] | 1229 | char buff[5000]; |
---|
| 1230 | |
---|
| 1231 | sprintf(buff, "This is owl version %s\n", OWL_VERSION_STRING); |
---|
| 1232 | strcat(buff, "\nOwl was written by James Kretchmar at the Massachusetts\n"); |
---|
| 1233 | strcat(buff, "Institute of Technology. The first version, 0.5, was\n"); |
---|
[bde7714] | 1234 | strcat(buff, "released in March 2002.\n"); |
---|
[7d4fbcd] | 1235 | strcat(buff, "\n"); |
---|
| 1236 | strcat(buff, "The name 'owl' was chosen in reference to the owls in the\n"); |
---|
| 1237 | strcat(buff, "Harry Potter novels, who are tasked with carrying messages\n"); |
---|
| 1238 | strcat(buff, "between Witches and Wizards.\n"); |
---|
| 1239 | strcat(buff, "\n"); |
---|
| 1240 | strcat(buff, "Copyright 2002 Massachusetts Institute of Technology\n"); |
---|
| 1241 | strcat(buff, "\n"); |
---|
| 1242 | strcat(buff, "Permission to use, copy, modify, and distribute this\n"); |
---|
| 1243 | strcat(buff, "software and its documentation for any purpose and without\n"); |
---|
| 1244 | strcat(buff, "fee is hereby granted, provided that the above copyright\n"); |
---|
| 1245 | strcat(buff, "notice and this permission notice appear in all copies\n"); |
---|
| 1246 | strcat(buff, "and in supporting documentation. No representation is\n"); |
---|
| 1247 | strcat(buff, "made about the suitability of this software for any\n"); |
---|
| 1248 | strcat(buff, "purpose. It is provided \"as is\" without express\n"); |
---|
| 1249 | strcat(buff, "or implied warranty.\n"); |
---|
| 1250 | owl_function_popless_text(buff); |
---|
| 1251 | } |
---|
| 1252 | |
---|
[d54838d] | 1253 | void owl_function_info() |
---|
| 1254 | { |
---|
[7d4fbcd] | 1255 | owl_message *m; |
---|
[5789230] | 1256 | owl_fmtext fm, attrfm; |
---|
[09489b89] | 1257 | char buff[10000]; |
---|
[7d4fbcd] | 1258 | owl_view *v; |
---|
[09489b89] | 1259 | #ifdef HAVE_LIBZEPHYR |
---|
| 1260 | ZNotice_t *n; |
---|
| 1261 | #endif |
---|
[7d4fbcd] | 1262 | |
---|
[d0d65df] | 1263 | owl_fmtext_init_null(&fm); |
---|
| 1264 | |
---|
[7d4fbcd] | 1265 | v=owl_global_get_current_view(&g); |
---|
[5eeea3b] | 1266 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 1267 | if (!m || owl_view_get_size(v)==0) { |
---|
[7d4fbcd] | 1268 | owl_function_makemsg("No message selected\n"); |
---|
| 1269 | return; |
---|
| 1270 | } |
---|
| 1271 | |
---|
[5789230] | 1272 | owl_fmtext_append_bold(&fm, "General Information:\n"); |
---|
| 1273 | owl_fmtext_append_normal(&fm, " Msg Id : "); |
---|
[d0d65df] | 1274 | sprintf(buff, "%i", owl_message_get_id(m)); |
---|
| 1275 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1276 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[df0d93a] | 1277 | |
---|
[5789230] | 1278 | owl_fmtext_append_normal(&fm, " Type : "); |
---|
[df0d93a] | 1279 | owl_fmtext_append_bold(&fm, owl_message_type_to_string(m)); |
---|
| 1280 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1281 | |
---|
[4b464a4] | 1282 | if (owl_message_is_direction_in(m)) { |
---|
[5789230] | 1283 | owl_fmtext_append_normal(&fm, " Direction : in\n"); |
---|
[4b464a4] | 1284 | } else if (owl_message_is_direction_out(m)) { |
---|
[5789230] | 1285 | owl_fmtext_append_normal(&fm, " Direction : out\n"); |
---|
[4b464a4] | 1286 | } else if (owl_message_is_direction_none(m)) { |
---|
[5789230] | 1287 | owl_fmtext_append_normal(&fm, " Direction : none\n"); |
---|
[4b464a4] | 1288 | } else { |
---|
[5789230] | 1289 | owl_fmtext_append_normal(&fm, " Direction : unknown\n"); |
---|
[4b464a4] | 1290 | } |
---|
[df0d93a] | 1291 | |
---|
[5789230] | 1292 | owl_fmtext_append_normal(&fm, " Time : "); |
---|
[d0d65df] | 1293 | owl_fmtext_append_normal(&fm, owl_message_get_timestr(m)); |
---|
| 1294 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[4b464a4] | 1295 | |
---|
[df0d93a] | 1296 | if (!owl_message_is_type_admin(m)) { |
---|
[5789230] | 1297 | owl_fmtext_append_normal(&fm, " Sender : "); |
---|
[df0d93a] | 1298 | owl_fmtext_append_normal(&fm, owl_message_get_sender(m)); |
---|
| 1299 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1300 | |
---|
[5789230] | 1301 | owl_fmtext_append_normal(&fm, " Recipient : "); |
---|
[df0d93a] | 1302 | owl_fmtext_append_normal(&fm, owl_message_get_recipient(m)); |
---|
| 1303 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1304 | } |
---|
| 1305 | |
---|
[0ff8fb57] | 1306 | if (owl_message_is_type_zephyr(m)) { |
---|
[5789230] | 1307 | owl_fmtext_append_bold(&fm, "\nZephyr Specific Information:\n"); |
---|
[0ff8fb57] | 1308 | |
---|
[5789230] | 1309 | owl_fmtext_append_normal(&fm, " Class : "); |
---|
[df0d93a] | 1310 | owl_fmtext_append_normal(&fm, owl_message_get_class(m)); |
---|
| 1311 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[5789230] | 1312 | owl_fmtext_append_normal(&fm, " Instance : "); |
---|
[df0d93a] | 1313 | owl_fmtext_append_normal(&fm, owl_message_get_instance(m)); |
---|
| 1314 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[5789230] | 1315 | owl_fmtext_append_normal(&fm, " Opcode : "); |
---|
[df0d93a] | 1316 | owl_fmtext_append_normal(&fm, owl_message_get_opcode(m)); |
---|
| 1317 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 1318 | |
---|
[5789230] | 1319 | owl_fmtext_append_normal(&fm, " Time : "); |
---|
[df0d93a] | 1320 | owl_fmtext_append_normal(&fm, owl_message_get_timestr(m)); |
---|
| 1321 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[09489b89] | 1322 | #ifdef HAVE_LIBZEPHYR |
---|
[d0d65df] | 1323 | if (owl_message_is_direction_in(m)) { |
---|
[09489b89] | 1324 | char *ptr, tmpbuff[1024]; |
---|
| 1325 | int i, j, fields, len; |
---|
| 1326 | |
---|
[d0d65df] | 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 | } |
---|
[09489b89] | 1398 | #endif |
---|
[7d4fbcd] | 1399 | } |
---|
[0ff8fb57] | 1400 | |
---|
| 1401 | if (owl_message_is_type_aim(m)) { |
---|
[5789230] | 1402 | owl_fmtext_append_bold(&fm, "\nAIM Specific Information:\n"); |
---|
[0ff8fb57] | 1403 | } |
---|
[5789230] | 1404 | |
---|
| 1405 | owl_fmtext_append_bold(&fm, "\nOwl Message Attributes:\n"); |
---|
| 1406 | owl_message_attributes_tofmtext(m, &attrfm); |
---|
| 1407 | owl_fmtext_append_fmtext(&fm, &attrfm); |
---|
[d0d65df] | 1408 | |
---|
| 1409 | owl_function_popless_fmtext(&fm); |
---|
[5789230] | 1410 | owl_fmtext_free(&fm); |
---|
| 1411 | owl_fmtext_free(&attrfm); |
---|
[7d4fbcd] | 1412 | } |
---|
| 1413 | |
---|
| 1414 | |
---|
[5639bf2] | 1415 | /* print the current message in a popup window. |
---|
| 1416 | * Use the 'default' style regardless of whatever |
---|
| 1417 | * style the user may be using |
---|
| 1418 | */ |
---|
[d54838d] | 1419 | void owl_function_curmsg_to_popwin() |
---|
| 1420 | { |
---|
[7d4fbcd] | 1421 | owl_popwin *pw; |
---|
| 1422 | owl_view *v; |
---|
| 1423 | owl_message *m; |
---|
[5639bf2] | 1424 | owl_style *s; |
---|
| 1425 | owl_fmtext fm; |
---|
[7d4fbcd] | 1426 | |
---|
[5639bf2] | 1427 | v=owl_global_get_current_view(&g); |
---|
| 1428 | s=owl_global_get_style_by_name(&g, "default"); |
---|
[7d4fbcd] | 1429 | pw=owl_global_get_popwin(&g); |
---|
| 1430 | |
---|
[5eeea3b] | 1431 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 1432 | |
---|
| 1433 | if (!m || owl_view_get_size(v)==0) { |
---|
[7d4fbcd] | 1434 | owl_function_makemsg("No current message"); |
---|
| 1435 | return; |
---|
| 1436 | } |
---|
| 1437 | |
---|
[5639bf2] | 1438 | owl_fmtext_init_null(&fm); |
---|
| 1439 | owl_style_get_formattext(s, &fm, m); |
---|
| 1440 | |
---|
| 1441 | owl_function_popless_fmtext(&fm); |
---|
| 1442 | owl_fmtext_free(&fm); |
---|
[7d4fbcd] | 1443 | } |
---|
| 1444 | |
---|
| 1445 | |
---|
[d54838d] | 1446 | void owl_function_page_curmsg(int step) |
---|
| 1447 | { |
---|
[7d4fbcd] | 1448 | /* scroll down or up within the current message IF the message is truncated */ |
---|
| 1449 | |
---|
| 1450 | int offset, curmsg, lines; |
---|
| 1451 | owl_view *v; |
---|
| 1452 | owl_message *m; |
---|
| 1453 | |
---|
| 1454 | offset=owl_global_get_curmsg_vert_offset(&g); |
---|
| 1455 | v=owl_global_get_current_view(&g); |
---|
| 1456 | curmsg=owl_global_get_curmsg(&g); |
---|
| 1457 | m=owl_view_get_element(v, curmsg); |
---|
[5eeea3b] | 1458 | if (!m || owl_view_get_size(v)==0) return; |
---|
[7d4fbcd] | 1459 | lines=owl_message_get_numlines(m); |
---|
| 1460 | |
---|
| 1461 | if (offset==0) { |
---|
| 1462 | /* Bail if the curmsg isn't the last one displayed */ |
---|
| 1463 | if (curmsg != owl_mainwin_get_last_msg(owl_global_get_mainwin(&g))) { |
---|
| 1464 | owl_function_makemsg("The entire message is already displayed"); |
---|
| 1465 | return; |
---|
| 1466 | } |
---|
| 1467 | |
---|
| 1468 | /* Bail if we're not truncated */ |
---|
| 1469 | if (!owl_mainwin_is_curmsg_truncated(owl_global_get_mainwin(&g))) { |
---|
| 1470 | owl_function_makemsg("The entire message is already displayed"); |
---|
| 1471 | return; |
---|
| 1472 | } |
---|
| 1473 | } |
---|
| 1474 | |
---|
| 1475 | |
---|
| 1476 | /* don't scroll past the last line */ |
---|
| 1477 | if (step>0) { |
---|
| 1478 | if (offset+step > lines-1) { |
---|
| 1479 | owl_global_set_curmsg_vert_offset(&g, lines-1); |
---|
| 1480 | } else { |
---|
| 1481 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
| 1482 | } |
---|
| 1483 | } |
---|
| 1484 | |
---|
| 1485 | /* would we be before the beginning of the message? */ |
---|
| 1486 | if (step<0) { |
---|
| 1487 | if (offset+step<0) { |
---|
| 1488 | owl_global_set_curmsg_vert_offset(&g, 0); |
---|
| 1489 | } else { |
---|
| 1490 | owl_global_set_curmsg_vert_offset(&g, offset+step); |
---|
| 1491 | } |
---|
| 1492 | } |
---|
| 1493 | |
---|
| 1494 | /* redisplay */ |
---|
| 1495 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 1496 | owl_global_set_needrefresh(&g); |
---|
| 1497 | } |
---|
| 1498 | |
---|
[d54838d] | 1499 | void owl_function_resize_typwin(int newsize) |
---|
| 1500 | { |
---|
[7d4fbcd] | 1501 | owl_global_set_typwin_lines(&g, newsize); |
---|
| 1502 | owl_function_resize(); |
---|
| 1503 | } |
---|
| 1504 | |
---|
[d54838d] | 1505 | void owl_function_typwin_grow() |
---|
| 1506 | { |
---|
[7d4fbcd] | 1507 | int i; |
---|
| 1508 | |
---|
| 1509 | i=owl_global_get_typwin_lines(&g); |
---|
| 1510 | owl_function_resize_typwin(i+1); |
---|
| 1511 | } |
---|
| 1512 | |
---|
[d54838d] | 1513 | void owl_function_typwin_shrink() |
---|
| 1514 | { |
---|
[7d4fbcd] | 1515 | int i; |
---|
| 1516 | |
---|
| 1517 | i=owl_global_get_typwin_lines(&g); |
---|
| 1518 | if (i>2) { |
---|
| 1519 | owl_function_resize_typwin(i-1); |
---|
| 1520 | } |
---|
| 1521 | } |
---|
| 1522 | |
---|
[d54838d] | 1523 | void owl_function_mainwin_pagedown() |
---|
| 1524 | { |
---|
[7d4fbcd] | 1525 | int i; |
---|
| 1526 | |
---|
| 1527 | i=owl_mainwin_get_last_msg(owl_global_get_mainwin(&g)); |
---|
| 1528 | if (i<0) return; |
---|
[f2e36b5] | 1529 | if (owl_mainwin_is_last_msg_truncated(owl_global_get_mainwin(&g)) |
---|
| 1530 | && (owl_global_get_curmsg(&g) < i) |
---|
| 1531 | && (i>0)) { |
---|
| 1532 | i--; |
---|
| 1533 | } |
---|
[7d4fbcd] | 1534 | owl_global_set_curmsg(&g, i); |
---|
| 1535 | owl_function_nextmsg(); |
---|
| 1536 | } |
---|
| 1537 | |
---|
[d54838d] | 1538 | void owl_function_mainwin_pageup() |
---|
| 1539 | { |
---|
[7d4fbcd] | 1540 | owl_global_set_curmsg(&g, owl_global_get_topmsg(&g)); |
---|
| 1541 | owl_function_prevmsg(); |
---|
| 1542 | } |
---|
| 1543 | |
---|
[d54838d] | 1544 | void owl_function_getsubs() |
---|
| 1545 | { |
---|
[09489b89] | 1546 | char *buff; |
---|
[7d4fbcd] | 1547 | |
---|
[09489b89] | 1548 | buff=owl_zephyr_getsubs(); |
---|
[7d4fbcd] | 1549 | |
---|
[09489b89] | 1550 | if (buff) { |
---|
| 1551 | owl_function_popless_text(buff); |
---|
| 1552 | } else { |
---|
| 1553 | owl_function_popless_text("Error getting subscriptions"); |
---|
[7d4fbcd] | 1554 | } |
---|
[09489b89] | 1555 | |
---|
[1c6c4d3] | 1556 | owl_free(buff); |
---|
[7d4fbcd] | 1557 | } |
---|
| 1558 | |
---|
| 1559 | #define PABUFLEN 5000 |
---|
[d54838d] | 1560 | void owl_function_printallvars() |
---|
| 1561 | { |
---|
[7d4fbcd] | 1562 | char buff[PABUFLEN], *pos, *name; |
---|
| 1563 | owl_list varnames; |
---|
| 1564 | int i, numvarnames, rem; |
---|
| 1565 | |
---|
| 1566 | pos = buff; |
---|
| 1567 | pos += sprintf(pos, "%-20s = %s\n", "VARIABLE", "VALUE"); |
---|
| 1568 | pos += sprintf(pos, "%-20s %s\n", "--------", "-----"); |
---|
| 1569 | owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); |
---|
| 1570 | rem = (buff+PABUFLEN)-pos-1; |
---|
| 1571 | numvarnames = owl_list_get_size(&varnames); |
---|
| 1572 | for (i=0; i<numvarnames; i++) { |
---|
| 1573 | name = owl_list_get_element(&varnames, i); |
---|
| 1574 | if (name && name[0]!='_') { |
---|
| 1575 | rem = (buff+PABUFLEN)-pos-1; |
---|
| 1576 | pos += snprintf(pos, rem, "\n%-20s = ", name); |
---|
| 1577 | rem = (buff+PABUFLEN)-pos-1; |
---|
| 1578 | owl_variable_get_tostring(owl_global_get_vardict(&g), name, pos, rem); |
---|
| 1579 | pos = buff+strlen(buff); |
---|
| 1580 | } |
---|
| 1581 | } |
---|
| 1582 | rem = (buff+PABUFLEN)-pos-1; |
---|
| 1583 | snprintf(pos, rem, "\n"); |
---|
| 1584 | owl_variable_dict_namelist_free(&varnames); |
---|
| 1585 | |
---|
| 1586 | owl_function_popless_text(buff); |
---|
| 1587 | } |
---|
| 1588 | |
---|
[d54838d] | 1589 | void owl_function_show_variables() |
---|
| 1590 | { |
---|
[7d4fbcd] | 1591 | owl_list varnames; |
---|
| 1592 | owl_fmtext fm; |
---|
| 1593 | int i, numvarnames; |
---|
| 1594 | char *varname; |
---|
| 1595 | |
---|
| 1596 | owl_fmtext_init_null(&fm); |
---|
| 1597 | owl_fmtext_append_bold(&fm, |
---|
| 1598 | "Variables: (use 'show variable <name>' for details)\n"); |
---|
| 1599 | owl_variable_dict_get_names(owl_global_get_vardict(&g), &varnames); |
---|
| 1600 | numvarnames = owl_list_get_size(&varnames); |
---|
| 1601 | for (i=0; i<numvarnames; i++) { |
---|
| 1602 | varname = owl_list_get_element(&varnames, i); |
---|
| 1603 | if (varname && varname[0]!='_') { |
---|
[aa2f33b3] | 1604 | owl_variable_describe(owl_global_get_vardict(&g), varname, &fm); |
---|
[7d4fbcd] | 1605 | } |
---|
| 1606 | } |
---|
| 1607 | owl_variable_dict_namelist_free(&varnames); |
---|
| 1608 | owl_function_popless_fmtext(&fm); |
---|
| 1609 | owl_fmtext_free(&fm); |
---|
| 1610 | } |
---|
| 1611 | |
---|
[d54838d] | 1612 | void owl_function_show_variable(char *name) |
---|
| 1613 | { |
---|
[7d4fbcd] | 1614 | owl_fmtext fm; |
---|
| 1615 | |
---|
| 1616 | owl_fmtext_init_null(&fm); |
---|
| 1617 | owl_variable_get_help(owl_global_get_vardict(&g), name, &fm); |
---|
| 1618 | owl_function_popless_fmtext(&fm); |
---|
| 1619 | owl_fmtext_free(&fm); |
---|
| 1620 | } |
---|
| 1621 | |
---|
| 1622 | /* note: this applies to global message list, not to view. |
---|
| 1623 | * If flag is 1, deletes. If flag is 0, undeletes. */ |
---|
[d54838d] | 1624 | void owl_function_delete_by_id(int id, int flag) |
---|
| 1625 | { |
---|
[7d4fbcd] | 1626 | owl_messagelist *ml; |
---|
| 1627 | owl_message *m; |
---|
| 1628 | ml = owl_global_get_msglist(&g); |
---|
| 1629 | m = owl_messagelist_get_by_id(ml, id); |
---|
| 1630 | if (m) { |
---|
| 1631 | if (flag == 1) { |
---|
| 1632 | owl_message_mark_delete(m); |
---|
| 1633 | } else if (flag == 0) { |
---|
| 1634 | owl_message_unmark_delete(m); |
---|
| 1635 | } |
---|
| 1636 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 1637 | owl_global_set_needrefresh(&g); |
---|
| 1638 | } else { |
---|
| 1639 | owl_function_makemsg("No message with id %d: unable to mark for (un)delete",id); |
---|
| 1640 | } |
---|
| 1641 | } |
---|
| 1642 | |
---|
[d54838d] | 1643 | void owl_function_delete_automsgs() |
---|
| 1644 | { |
---|
[7d4fbcd] | 1645 | /* mark for deletion all messages in the current view that match the |
---|
| 1646 | * 'trash' filter */ |
---|
| 1647 | |
---|
| 1648 | int i, j, count; |
---|
| 1649 | owl_message *m; |
---|
| 1650 | owl_view *v; |
---|
| 1651 | owl_filter *f; |
---|
| 1652 | |
---|
| 1653 | /* get the trash filter */ |
---|
| 1654 | f=owl_global_get_filter(&g, "trash"); |
---|
| 1655 | if (!f) { |
---|
| 1656 | owl_function_makemsg("No trash filter defined"); |
---|
| 1657 | return; |
---|
| 1658 | } |
---|
| 1659 | |
---|
| 1660 | v=owl_global_get_current_view(&g); |
---|
| 1661 | |
---|
| 1662 | count=0; |
---|
| 1663 | j=owl_view_get_size(v); |
---|
| 1664 | for (i=0; i<j; i++) { |
---|
| 1665 | m=owl_view_get_element(v, i); |
---|
| 1666 | if (owl_filter_message_match(f, m)) { |
---|
| 1667 | count++; |
---|
| 1668 | owl_message_mark_delete(m); |
---|
| 1669 | } |
---|
| 1670 | } |
---|
| 1671 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[1c6c4d3] | 1672 | owl_function_makemsg("%i messages marked for deletion", count); |
---|
[7d4fbcd] | 1673 | owl_global_set_needrefresh(&g); |
---|
| 1674 | } |
---|
| 1675 | |
---|
| 1676 | |
---|
[d54838d] | 1677 | void owl_function_status() |
---|
| 1678 | { |
---|
[7d4fbcd] | 1679 | char buff[5000]; |
---|
| 1680 | time_t start; |
---|
| 1681 | int up, days, hours, minutes; |
---|
| 1682 | |
---|
| 1683 | start=owl_global_get_starttime(&g); |
---|
| 1684 | |
---|
| 1685 | sprintf(buff, "Version: %s\n", OWL_VERSION_STRING); |
---|
| 1686 | sprintf(buff, "%sScreen size: %i lines, %i columns\n", buff, owl_global_get_lines(&g), owl_global_get_cols(&g)); |
---|
| 1687 | sprintf(buff, "%sStartup Arugments: %s\n", buff, owl_global_get_startupargs(&g)); |
---|
| 1688 | sprintf(buff, "%sStartup Time: %s", buff, ctime(&start)); |
---|
| 1689 | |
---|
| 1690 | up=owl_global_get_runtime(&g); |
---|
| 1691 | days=up/86400; |
---|
| 1692 | up-=days*86400; |
---|
| 1693 | hours=up/3600; |
---|
| 1694 | up-=hours*3600; |
---|
| 1695 | minutes=up/60; |
---|
| 1696 | up-=minutes*60; |
---|
| 1697 | sprintf(buff, "%sRun Time: %i days %2.2i:%2.2i:%2.2i\n", buff, days, hours, minutes, up); |
---|
| 1698 | |
---|
| 1699 | if (owl_global_get_hascolors(&g)) { |
---|
| 1700 | sprintf(buff, "%sColor: Yes, %i color pairs.\n", buff, owl_global_get_colorpairs(&g)); |
---|
| 1701 | } else { |
---|
| 1702 | strcat(buff, "Color: No.\n"); |
---|
| 1703 | } |
---|
[8262340] | 1704 | |
---|
| 1705 | sprintf(buff, "%sMemory Malloced: %i\n", buff, owl_global_get_malloced(&g)); |
---|
| 1706 | sprintf(buff, "%sMemory Freed: %i\n", buff, owl_global_get_freed(&g)); |
---|
| 1707 | sprintf(buff, "%sMemory In Use: %i\n", buff, owl_global_get_meminuse(&g)); |
---|
| 1708 | |
---|
[7d4fbcd] | 1709 | owl_function_popless_text(buff); |
---|
| 1710 | } |
---|
| 1711 | |
---|
[d54838d] | 1712 | void owl_function_show_term() |
---|
| 1713 | { |
---|
[7d4fbcd] | 1714 | owl_fmtext fm; |
---|
| 1715 | char buff[LINE]; |
---|
| 1716 | |
---|
| 1717 | owl_fmtext_init_null(&fm); |
---|
| 1718 | sprintf(buff, "Terminal Lines: %i\nTerminal Columns: %i\n", |
---|
| 1719 | owl_global_get_lines(&g), |
---|
| 1720 | owl_global_get_cols(&g)); |
---|
| 1721 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1722 | |
---|
| 1723 | if (owl_global_get_hascolors(&g)) { |
---|
| 1724 | owl_fmtext_append_normal(&fm, "Color: Yes\n"); |
---|
| 1725 | sprintf(buff, "Number of color pairs: %i\n", owl_global_get_colorpairs(&g)); |
---|
| 1726 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1727 | sprintf(buff, "Can change colors: %s\n", can_change_color() ? "yes" : "no"); |
---|
| 1728 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1729 | } else { |
---|
| 1730 | owl_fmtext_append_normal(&fm, "Color: No\n"); |
---|
| 1731 | } |
---|
| 1732 | |
---|
| 1733 | owl_function_popless_fmtext(&fm); |
---|
| 1734 | owl_fmtext_free(&fm); |
---|
| 1735 | } |
---|
| 1736 | |
---|
| 1737 | |
---|
[e7cc1c3] | 1738 | /* if type = 0 then normal reply. |
---|
| 1739 | * if type = 1 then it's a reply to sender |
---|
| 1740 | * if enter = 0 then allow the command to be edited |
---|
| 1741 | * if enter = 1 then don't wait for editing |
---|
| 1742 | */ |
---|
[d54838d] | 1743 | void owl_function_reply(int type, int enter) |
---|
| 1744 | { |
---|
[e50cd56] | 1745 | char *buff, *oldbuff; |
---|
[7d4fbcd] | 1746 | owl_message *m; |
---|
| 1747 | owl_filter *f; |
---|
| 1748 | |
---|
| 1749 | if (owl_view_get_size(owl_global_get_current_view(&g))==0) { |
---|
| 1750 | owl_function_makemsg("No message selected"); |
---|
| 1751 | } else { |
---|
[e50cd56] | 1752 | char *class, *inst, *to, *cc=NULL; |
---|
[7d4fbcd] | 1753 | |
---|
| 1754 | m=owl_view_get_element(owl_global_get_current_view(&g), owl_global_get_curmsg(&g)); |
---|
[5eeea3b] | 1755 | if (!m) { |
---|
| 1756 | owl_function_makemsg("No message selected"); |
---|
| 1757 | return; |
---|
| 1758 | } |
---|
| 1759 | |
---|
[7d4fbcd] | 1760 | /* first check if we catch the reply-lockout filter */ |
---|
| 1761 | f=owl_global_get_filter(&g, "reply-lockout"); |
---|
| 1762 | if (f) { |
---|
| 1763 | if (owl_filter_message_match(f, m)) { |
---|
| 1764 | owl_function_makemsg("Sorry, replies to this message have been disabled by the reply-lockout filter"); |
---|
| 1765 | return; |
---|
| 1766 | } |
---|
| 1767 | } |
---|
[4b464a4] | 1768 | |
---|
[d09e5a1] | 1769 | /* admin */ |
---|
| 1770 | if (owl_message_is_type_admin(m)) { |
---|
| 1771 | owl_function_makemsg("You cannot reply to an admin message"); |
---|
[d309eb3] | 1772 | return; |
---|
| 1773 | } |
---|
| 1774 | |
---|
[d09e5a1] | 1775 | /* zephyr */ |
---|
| 1776 | if (owl_message_is_type_zephyr(m)) { |
---|
| 1777 | /* for now we disable replies to zcrypt messages, since we can't |
---|
| 1778 | support an encrypted reply */ |
---|
| 1779 | if (!strcasecmp(owl_message_get_opcode(m), "crypt")) { |
---|
| 1780 | owl_function_makemsg("Replies to zcrypt messages are not enabled in this release"); |
---|
| 1781 | return; |
---|
| 1782 | } |
---|
| 1783 | |
---|
[e7cc1c3] | 1784 | /* if it's a zephyr we sent, send it out the same way again */ |
---|
[d09e5a1] | 1785 | if (owl_message_is_direction_out(m)) { |
---|
| 1786 | owl_function_zwrite_setup(owl_message_get_zwriteline(m)); |
---|
| 1787 | owl_global_set_buffercommand(&g, owl_message_get_zwriteline(m)); |
---|
| 1788 | return; |
---|
| 1789 | } |
---|
[e7cc1c3] | 1790 | |
---|
| 1791 | /* Special case a personal reply to a webzephyr user on a class */ |
---|
[1d3e925] | 1792 | if ((type==1) && !strcasecmp(owl_message_get_opcode(m), OWL_WEBZEPHYR_OPCODE)) { |
---|
| 1793 | class=OWL_WEBZEPHYR_CLASS; |
---|
[e7cc1c3] | 1794 | inst=owl_message_get_sender(m); |
---|
| 1795 | to=OWL_WEBZEPHYR_PRINCIPAL; |
---|
[1d3e925] | 1796 | } else if (!strcasecmp(owl_message_get_class(m), OWL_WEBZEPHYR_CLASS) && owl_message_is_loginout(m)) { |
---|
[f562355] | 1797 | /* Special case LOGIN/LOGOUT notifications on class "webzephyr" */ |
---|
[1d3e925] | 1798 | class=OWL_WEBZEPHYR_CLASS; |
---|
[e7cc1c3] | 1799 | inst=owl_message_get_instance(m); |
---|
| 1800 | to=OWL_WEBZEPHYR_PRINCIPAL; |
---|
[f562355] | 1801 | } else if (owl_message_is_loginout(m)) { |
---|
| 1802 | /* Normal LOGIN/LOGOUT messages */ |
---|
[7d4fbcd] | 1803 | class="MESSAGE"; |
---|
| 1804 | inst="PERSONAL"; |
---|
| 1805 | to=owl_message_get_sender(m); |
---|
| 1806 | } else if (type==1) { |
---|
[f562355] | 1807 | /* Personal reply */ |
---|
[7d4fbcd] | 1808 | class="MESSAGE"; |
---|
| 1809 | inst="PERSONAL"; |
---|
| 1810 | to=owl_message_get_sender(m); |
---|
| 1811 | } else { |
---|
[f562355] | 1812 | /* General reply */ |
---|
[7d4fbcd] | 1813 | class=owl_message_get_class(m); |
---|
| 1814 | inst=owl_message_get_instance(m); |
---|
| 1815 | to=owl_message_get_recipient(m); |
---|
[e50cd56] | 1816 | cc=owl_message_get_cc(m); |
---|
[7d4fbcd] | 1817 | if (!strcmp(to, "") || !strcmp(to, "*")) { |
---|
| 1818 | to=""; |
---|
| 1819 | } else if (to[0]=='@') { |
---|
| 1820 | /* leave it, to get the realm */ |
---|
| 1821 | } else { |
---|
| 1822 | to=owl_message_get_sender(m); |
---|
| 1823 | } |
---|
| 1824 | } |
---|
[d09e5a1] | 1825 | |
---|
[7d4fbcd] | 1826 | /* create the command line */ |
---|
[e50cd56] | 1827 | buff = owl_strdup("zwrite"); |
---|
[7d4fbcd] | 1828 | if (strcasecmp(class, "message")) { |
---|
[e50cd56] | 1829 | buff = owl_sprintf("%s -c %s%s%s", oldbuff=buff, owl_getquoting(class), class, owl_getquoting(class)); |
---|
| 1830 | owl_free(oldbuff); |
---|
[7d4fbcd] | 1831 | } |
---|
| 1832 | if (strcasecmp(inst, "personal")) { |
---|
[e50cd56] | 1833 | buff = owl_sprintf("%s -i %s%s%s", oldbuff=buff, owl_getquoting(inst), inst, owl_getquoting(inst)); |
---|
| 1834 | owl_free(oldbuff); |
---|
[7d4fbcd] | 1835 | } |
---|
| 1836 | if (*to != '\0') { |
---|
[f9c43ae] | 1837 | char *tmp, *oldtmp, *tmp2; |
---|
[601a9e0] | 1838 | tmp=short_zuser(to); |
---|
[e50cd56] | 1839 | if (cc) { |
---|
| 1840 | tmp = owl_util_uniq(oldtmp=tmp, cc, "-"); |
---|
| 1841 | owl_free(oldtmp); |
---|
| 1842 | buff = owl_sprintf("%s -C %s", oldbuff=buff, tmp); |
---|
| 1843 | owl_free(oldbuff); |
---|
| 1844 | } else { |
---|
[f9c43ae] | 1845 | if (owl_global_is_smartstrip(&g)) { |
---|
| 1846 | tmp2=tmp; |
---|
[7c8060d0] | 1847 | tmp=owl_util_smartstripped_user(tmp2); |
---|
[f9c43ae] | 1848 | owl_free(tmp2); |
---|
| 1849 | } |
---|
[e50cd56] | 1850 | buff = owl_sprintf("%s %s", oldbuff=buff, tmp); |
---|
| 1851 | owl_free(oldbuff); |
---|
| 1852 | } |
---|
[7d4fbcd] | 1853 | owl_free(tmp); |
---|
| 1854 | } |
---|
[e50cd56] | 1855 | if (cc) owl_free(cc); |
---|
[d09e5a1] | 1856 | } |
---|
[7d4fbcd] | 1857 | |
---|
[d09e5a1] | 1858 | /* aim */ |
---|
| 1859 | if (owl_message_is_type_aim(m)) { |
---|
[440ce01] | 1860 | if (owl_message_is_direction_out(m)) { |
---|
| 1861 | buff=owl_sprintf("aimwrite %s", owl_message_get_recipient(m)); |
---|
| 1862 | } else { |
---|
| 1863 | buff=owl_sprintf("aimwrite %s", owl_message_get_sender(m)); |
---|
| 1864 | } |
---|
[d09e5a1] | 1865 | } |
---|
[440ce01] | 1866 | |
---|
[d09e5a1] | 1867 | if (enter) { |
---|
| 1868 | owl_history *hist = owl_global_get_cmd_history(&g); |
---|
| 1869 | owl_history_store(hist, buff); |
---|
| 1870 | owl_history_reset(hist); |
---|
| 1871 | owl_function_command_norv(buff); |
---|
| 1872 | } else { |
---|
| 1873 | owl_function_start_command(buff); |
---|
[7d4fbcd] | 1874 | } |
---|
[d09e5a1] | 1875 | owl_free(buff); |
---|
[7d4fbcd] | 1876 | } |
---|
| 1877 | } |
---|
| 1878 | |
---|
[d54838d] | 1879 | void owl_function_zlocate(int argc, char **argv, int auth) |
---|
| 1880 | { |
---|
[2527615] | 1881 | owl_fmtext fm; |
---|
| 1882 | char *ptr, buff[LINE]; |
---|
| 1883 | int i; |
---|
| 1884 | |
---|
| 1885 | owl_fmtext_init_null(&fm); |
---|
[7d4fbcd] | 1886 | |
---|
[2527615] | 1887 | for (i=0; i<argc; i++) { |
---|
| 1888 | ptr=long_zuser(argv[i]); |
---|
| 1889 | owl_zephyr_zlocate(ptr, buff, auth); |
---|
| 1890 | owl_fmtext_append_normal(&fm, buff); |
---|
| 1891 | owl_free(ptr); |
---|
[7d4fbcd] | 1892 | } |
---|
| 1893 | |
---|
[2527615] | 1894 | owl_function_popless_fmtext(&fm); |
---|
| 1895 | owl_fmtext_free(&fm); |
---|
[7d4fbcd] | 1896 | } |
---|
| 1897 | |
---|
[d54838d] | 1898 | void owl_function_start_command(char *line) |
---|
| 1899 | { |
---|
[7d4fbcd] | 1900 | int i, j; |
---|
| 1901 | owl_editwin *tw; |
---|
| 1902 | |
---|
| 1903 | tw=owl_global_get_typwin(&g); |
---|
| 1904 | owl_global_set_typwin_active(&g); |
---|
[10b866d] | 1905 | owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, |
---|
| 1906 | owl_global_get_cmd_history(&g)); |
---|
| 1907 | |
---|
[7d4fbcd] | 1908 | owl_editwin_set_locktext(tw, "command: "); |
---|
| 1909 | owl_global_set_needrefresh(&g); |
---|
| 1910 | |
---|
| 1911 | j=strlen(line); |
---|
| 1912 | for (i=0; i<j; i++) { |
---|
| 1913 | owl_editwin_process_char(tw, line[i]); |
---|
| 1914 | } |
---|
| 1915 | owl_editwin_redisplay(tw, 0); |
---|
[cf83b7a] | 1916 | |
---|
| 1917 | owl_context_set_editline(owl_global_get_context(&g), tw); |
---|
| 1918 | owl_function_activate_keymap("editline"); |
---|
| 1919 | |
---|
| 1920 | } |
---|
| 1921 | |
---|
| 1922 | void owl_function_start_question(char *line) |
---|
| 1923 | { |
---|
| 1924 | owl_editwin *tw; |
---|
| 1925 | |
---|
| 1926 | tw=owl_global_get_typwin(&g); |
---|
| 1927 | owl_global_set_typwin_active(&g); |
---|
| 1928 | owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
| 1929 | |
---|
| 1930 | owl_editwin_set_locktext(tw, line); |
---|
| 1931 | owl_global_set_needrefresh(&g); |
---|
| 1932 | |
---|
| 1933 | owl_editwin_redisplay(tw, 0); |
---|
| 1934 | |
---|
| 1935 | owl_context_set_editresponse(owl_global_get_context(&g), tw); |
---|
| 1936 | owl_function_activate_keymap("editresponse"); |
---|
[7d4fbcd] | 1937 | } |
---|
| 1938 | |
---|
[453bd70] | 1939 | void owl_function_start_password(char *line) |
---|
| 1940 | { |
---|
| 1941 | owl_editwin *tw; |
---|
| 1942 | |
---|
| 1943 | tw=owl_global_get_typwin(&g); |
---|
| 1944 | owl_global_set_typwin_active(&g); |
---|
| 1945 | owl_editwin_new_style(tw, OWL_EDITWIN_STYLE_ONELINE, owl_global_get_cmd_history(&g)); |
---|
| 1946 | owl_editwin_set_echochar(tw, '*'); |
---|
| 1947 | |
---|
| 1948 | owl_editwin_set_locktext(tw, line); |
---|
| 1949 | owl_global_set_needrefresh(&g); |
---|
| 1950 | |
---|
| 1951 | owl_editwin_redisplay(tw, 0); |
---|
| 1952 | |
---|
| 1953 | owl_context_set_editresponse(owl_global_get_context(&g), tw); |
---|
| 1954 | owl_function_activate_keymap("editresponse"); |
---|
| 1955 | } |
---|
| 1956 | |
---|
[d54838d] | 1957 | char *owl_function_exec(int argc, char **argv, char *buff, int type) |
---|
| 1958 | { |
---|
[7d4fbcd] | 1959 | /* if type == 1 display in a popup |
---|
| 1960 | * if type == 2 display an admin messages |
---|
| 1961 | * if type == 0 return output |
---|
| 1962 | * else display in a popup |
---|
| 1963 | */ |
---|
| 1964 | char *newbuff, *redirect = " 2>&1 < /dev/null"; |
---|
| 1965 | char *out, buff2[1024]; |
---|
| 1966 | int size; |
---|
| 1967 | FILE *p; |
---|
| 1968 | |
---|
| 1969 | if (argc<2) { |
---|
[1fd0b25] | 1970 | owl_function_makemsg("Wrong number of arguments to the exec command"); |
---|
[7d4fbcd] | 1971 | return NULL; |
---|
| 1972 | } |
---|
| 1973 | |
---|
| 1974 | buff = skiptokens(buff, 1); |
---|
| 1975 | newbuff = owl_malloc(strlen(buff)+strlen(redirect)+1); |
---|
| 1976 | strcpy(newbuff, buff); |
---|
| 1977 | strcat(newbuff, redirect); |
---|
| 1978 | |
---|
| 1979 | p=popen(newbuff, "r"); |
---|
| 1980 | out=owl_malloc(1024); |
---|
| 1981 | size=1024; |
---|
| 1982 | strcpy(out, ""); |
---|
| 1983 | while (fgets(buff2, 1024, p)!=NULL) { |
---|
| 1984 | size+=1024; |
---|
| 1985 | out=owl_realloc(out, size); |
---|
| 1986 | strcat(out, buff2); |
---|
| 1987 | } |
---|
| 1988 | pclose(p); |
---|
| 1989 | |
---|
| 1990 | if (type==1) { |
---|
| 1991 | owl_function_popless_text(out); |
---|
| 1992 | } else if (type==0) { |
---|
| 1993 | return out; |
---|
| 1994 | } else if (type==2) { |
---|
| 1995 | owl_function_adminmsg(buff, out); |
---|
| 1996 | } else { |
---|
| 1997 | owl_function_popless_text(out); |
---|
| 1998 | } |
---|
| 1999 | owl_free(out); |
---|
| 2000 | return NULL; |
---|
| 2001 | } |
---|
| 2002 | |
---|
| 2003 | |
---|
[d54838d] | 2004 | char *owl_function_perl(int argc, char **argv, char *buff, int type) |
---|
| 2005 | { |
---|
[7d4fbcd] | 2006 | /* if type == 1 display in a popup |
---|
| 2007 | * if type == 2 display an admin messages |
---|
| 2008 | * if type == 0 return output |
---|
| 2009 | * else display in a popup |
---|
| 2010 | */ |
---|
| 2011 | char *perlout; |
---|
| 2012 | |
---|
| 2013 | if (argc<2) { |
---|
| 2014 | owl_function_makemsg("Wrong number of arguments to perl command"); |
---|
| 2015 | return NULL; |
---|
| 2016 | } |
---|
| 2017 | |
---|
| 2018 | /* consume first token (argv[0]) */ |
---|
| 2019 | buff = skiptokens(buff, 1); |
---|
| 2020 | |
---|
| 2021 | perlout = owl_config_execute(buff); |
---|
| 2022 | if (perlout) { |
---|
| 2023 | if (type==1) { |
---|
| 2024 | owl_function_popless_text(perlout); |
---|
| 2025 | } else if (type==2) { |
---|
| 2026 | owl_function_adminmsg(buff, perlout); |
---|
| 2027 | } else if (type==0) { |
---|
| 2028 | return perlout; |
---|
| 2029 | } else { |
---|
| 2030 | owl_function_popless_text(perlout); |
---|
| 2031 | } |
---|
| 2032 | owl_free(perlout); |
---|
| 2033 | } |
---|
| 2034 | return NULL; |
---|
| 2035 | } |
---|
| 2036 | |
---|
[c3ab155] | 2037 | #if 0 |
---|
| 2038 | void owl_function_change_view_old(char *filtname) |
---|
[d54838d] | 2039 | { |
---|
[7d4fbcd] | 2040 | owl_view *v; |
---|
| 2041 | owl_filter *f; |
---|
[f9c43ae] | 2042 | int curid=-1, newpos, curmsg; |
---|
| 2043 | owl_message *curm=NULL; |
---|
[7d4fbcd] | 2044 | |
---|
| 2045 | v=owl_global_get_current_view(&g); |
---|
[f9c43ae] | 2046 | curmsg=owl_global_get_curmsg(&g); |
---|
| 2047 | if (curmsg==-1) { |
---|
| 2048 | owl_function_debugmsg("Hit the curmsg==-1 case in change_view"); |
---|
| 2049 | } else { |
---|
| 2050 | curm=owl_view_get_element(v, curmsg); |
---|
| 2051 | if (curm) { |
---|
| 2052 | curid=owl_message_get_id(curm); |
---|
| 2053 | owl_view_save_curmsgid(v, curid); |
---|
| 2054 | } |
---|
[59cf91c] | 2055 | } |
---|
| 2056 | |
---|
[f9c43ae] | 2057 | /* grab the filter */; |
---|
[7d4fbcd] | 2058 | f=owl_global_get_filter(&g, filtname); |
---|
| 2059 | if (!f) { |
---|
| 2060 | owl_function_makemsg("Unknown filter"); |
---|
| 2061 | return; |
---|
| 2062 | } |
---|
| 2063 | |
---|
[f9c43ae] | 2064 | /* free the existing view and create a new one based on the filter */ |
---|
[7d4fbcd] | 2065 | owl_view_free(v); |
---|
| 2066 | owl_view_create(v, f); |
---|
| 2067 | |
---|
[f9c43ae] | 2068 | /* Figure out what to set the current message to. |
---|
| 2069 | * - If the view we're leaving has messages in it, go to the closest message |
---|
| 2070 | * to the last message pointed to in that view. |
---|
| 2071 | * - If the view we're leaving is empty, try to restore the position |
---|
| 2072 | * from the last time we were in the new view. */ |
---|
[59cf91c] | 2073 | if (curm) { |
---|
| 2074 | newpos = owl_view_get_nearest_to_msgid(v, curid); |
---|
| 2075 | } else { |
---|
| 2076 | newpos = owl_view_get_nearest_to_saved(v); |
---|
| 2077 | } |
---|
| 2078 | |
---|
| 2079 | owl_global_set_curmsg(&g, newpos); |
---|
| 2080 | |
---|
[f9c43ae] | 2081 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
[7d4fbcd] | 2082 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[f9c43ae] | 2083 | owl_global_set_direction_downwards(&g); |
---|
[7d4fbcd] | 2084 | } |
---|
[c3ab155] | 2085 | #endif |
---|
| 2086 | |
---|
| 2087 | void owl_function_change_view(char *filtname) |
---|
| 2088 | { |
---|
| 2089 | owl_view *v; |
---|
| 2090 | owl_filter *f; |
---|
| 2091 | int curid=-1, newpos, curmsg; |
---|
| 2092 | owl_message *curm=NULL; |
---|
| 2093 | |
---|
| 2094 | v=owl_global_get_current_view(&g); |
---|
| 2095 | |
---|
| 2096 | curmsg=owl_global_get_curmsg(&g); |
---|
| 2097 | if (curmsg==-1) { |
---|
| 2098 | owl_function_debugmsg("Hit the curmsg==-1 case in change_view"); |
---|
| 2099 | } else { |
---|
| 2100 | curm=owl_view_get_element(v, curmsg); |
---|
| 2101 | if (curm) { |
---|
| 2102 | curid=owl_message_get_id(curm); |
---|
| 2103 | owl_view_save_curmsgid(v, curid); |
---|
| 2104 | } |
---|
| 2105 | } |
---|
| 2106 | |
---|
| 2107 | f=owl_global_get_filter(&g, filtname); |
---|
| 2108 | if (!f) { |
---|
| 2109 | owl_function_makemsg("Unknown filter"); |
---|
| 2110 | return; |
---|
| 2111 | } |
---|
| 2112 | |
---|
| 2113 | owl_view_new_filter(v, f); |
---|
| 2114 | |
---|
| 2115 | /* Figure out what to set the current message to. |
---|
| 2116 | * - If the view we're leaving has messages in it, go to the closest message |
---|
| 2117 | * to the last message pointed to in that view. |
---|
| 2118 | * - If the view we're leaving is empty, try to restore the position |
---|
| 2119 | * from the last time we were in the new view. */ |
---|
| 2120 | if (curm) { |
---|
| 2121 | newpos = owl_view_get_nearest_to_msgid(v, curid); |
---|
| 2122 | } else { |
---|
| 2123 | newpos = owl_view_get_nearest_to_saved(v); |
---|
| 2124 | } |
---|
| 2125 | |
---|
| 2126 | owl_global_set_curmsg(&g, newpos); |
---|
| 2127 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 2128 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2129 | owl_global_set_direction_downwards(&g); |
---|
| 2130 | } |
---|
[7d4fbcd] | 2131 | |
---|
[d54838d] | 2132 | void owl_function_create_filter(int argc, char **argv) |
---|
| 2133 | { |
---|
[7d4fbcd] | 2134 | owl_filter *f; |
---|
| 2135 | owl_view *v; |
---|
| 2136 | int ret, inuse=0; |
---|
| 2137 | |
---|
| 2138 | if (argc < 2) { |
---|
| 2139 | owl_function_makemsg("Wrong number of arguments to filter command"); |
---|
| 2140 | return; |
---|
| 2141 | } |
---|
| 2142 | |
---|
| 2143 | v=owl_global_get_current_view(&g); |
---|
| 2144 | |
---|
| 2145 | /* don't touch the all filter */ |
---|
| 2146 | if (!strcmp(argv[1], "all")) { |
---|
| 2147 | owl_function_makemsg("You may not change the 'all' filter."); |
---|
| 2148 | return; |
---|
| 2149 | } |
---|
| 2150 | |
---|
| 2151 | /* deal with the case of trying change the filter color */ |
---|
| 2152 | if (argc==4 && !strcmp(argv[2], "-c")) { |
---|
| 2153 | f=owl_global_get_filter(&g, argv[1]); |
---|
| 2154 | if (!f) { |
---|
| 2155 | owl_function_makemsg("The filter '%s' does not exist.", argv[1]); |
---|
| 2156 | return; |
---|
| 2157 | } |
---|
| 2158 | owl_filter_set_color(f, owl_util_string_to_color(argv[3])); |
---|
| 2159 | owl_global_set_needrefresh(&g); |
---|
| 2160 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2161 | return; |
---|
| 2162 | } |
---|
| 2163 | |
---|
| 2164 | /* create the filter and check for errors */ |
---|
| 2165 | f=owl_malloc(sizeof(owl_filter)); |
---|
| 2166 | ret=owl_filter_init(f, argv[1], argc-2, argv+2); |
---|
| 2167 | if (ret==-1) { |
---|
| 2168 | owl_free(f); |
---|
| 2169 | owl_function_makemsg("Invalid filter syntax"); |
---|
| 2170 | return; |
---|
| 2171 | } |
---|
| 2172 | |
---|
| 2173 | /* if the named filter is in use by the current view, remember it */ |
---|
| 2174 | if (!strcmp(owl_view_get_filtname(v), argv[1])) { |
---|
| 2175 | inuse=1; |
---|
| 2176 | } |
---|
| 2177 | |
---|
| 2178 | /* if the named filter already exists, nuke it */ |
---|
| 2179 | if (owl_global_get_filter(&g, argv[1])) { |
---|
| 2180 | owl_global_remove_filter(&g, argv[1]); |
---|
| 2181 | } |
---|
| 2182 | |
---|
| 2183 | /* add the filter */ |
---|
| 2184 | owl_global_add_filter(&g, f); |
---|
| 2185 | |
---|
| 2186 | /* if it was in use by the current view then update */ |
---|
| 2187 | if (inuse) { |
---|
| 2188 | owl_function_change_view(argv[1]); |
---|
| 2189 | } |
---|
| 2190 | owl_global_set_needrefresh(&g); |
---|
| 2191 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2192 | } |
---|
| 2193 | |
---|
[d54838d] | 2194 | void owl_function_show_filters() |
---|
| 2195 | { |
---|
[7d4fbcd] | 2196 | owl_list *l; |
---|
| 2197 | owl_filter *f; |
---|
| 2198 | int i, j; |
---|
| 2199 | owl_fmtext fm; |
---|
| 2200 | |
---|
| 2201 | owl_fmtext_init_null(&fm); |
---|
| 2202 | |
---|
| 2203 | l=owl_global_get_filterlist(&g); |
---|
| 2204 | j=owl_list_get_size(l); |
---|
| 2205 | |
---|
| 2206 | owl_fmtext_append_bold(&fm, "Filters:\n"); |
---|
| 2207 | |
---|
| 2208 | for (i=0; i<j; i++) { |
---|
| 2209 | f=owl_list_get_element(l, i); |
---|
| 2210 | owl_fmtext_append_normal(&fm, " "); |
---|
| 2211 | if (owl_global_get_hascolors(&g)) { |
---|
| 2212 | owl_fmtext_append_normal_color(&fm, owl_filter_get_name(f), owl_filter_get_color(f)); |
---|
| 2213 | } else { |
---|
| 2214 | owl_fmtext_append_normal(&fm, owl_filter_get_name(f)); |
---|
| 2215 | } |
---|
| 2216 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 2217 | } |
---|
| 2218 | owl_function_popless_fmtext(&fm); |
---|
| 2219 | owl_fmtext_free(&fm); |
---|
| 2220 | } |
---|
| 2221 | |
---|
[d54838d] | 2222 | void owl_function_show_filter(char *name) |
---|
| 2223 | { |
---|
[7d4fbcd] | 2224 | owl_filter *f; |
---|
| 2225 | char buff[5000]; |
---|
| 2226 | |
---|
| 2227 | f=owl_global_get_filter(&g, name); |
---|
| 2228 | if (!f) { |
---|
| 2229 | owl_function_makemsg("There is no filter with that name"); |
---|
| 2230 | return; |
---|
| 2231 | } |
---|
| 2232 | owl_filter_print(f, buff); |
---|
| 2233 | owl_function_popless_text(buff); |
---|
| 2234 | } |
---|
| 2235 | |
---|
[d54838d] | 2236 | void owl_function_show_zpunts() |
---|
| 2237 | { |
---|
[7d4fbcd] | 2238 | owl_filter *f; |
---|
| 2239 | owl_list *fl; |
---|
| 2240 | char buff[5000]; |
---|
| 2241 | owl_fmtext fm; |
---|
| 2242 | int i, j; |
---|
| 2243 | |
---|
| 2244 | owl_fmtext_init_null(&fm); |
---|
| 2245 | |
---|
| 2246 | fl=owl_global_get_puntlist(&g); |
---|
| 2247 | j=owl_list_get_size(fl); |
---|
| 2248 | owl_fmtext_append_bold(&fm, "Active zpunt filters:\n"); |
---|
| 2249 | |
---|
| 2250 | for (i=0; i<j; i++) { |
---|
| 2251 | f=owl_list_get_element(fl, i); |
---|
| 2252 | owl_filter_print(f, buff); |
---|
| 2253 | owl_fmtext_append_normal(&fm, buff); |
---|
| 2254 | } |
---|
| 2255 | owl_function_popless_fmtext(&fm); |
---|
| 2256 | owl_fmtext_free(&fm); |
---|
| 2257 | } |
---|
| 2258 | |
---|
[3abf28b] | 2259 | /* Create a filter for a class, instance if one doesn't exist. If |
---|
| 2260 | * instance is NULL then catch all messgaes in the class. Returns the |
---|
| 2261 | * name of the filter, which the caller must free. |
---|
| 2262 | */ |
---|
| 2263 | char *owl_function_classinstfilt(char *class, char *instance) |
---|
[d54838d] | 2264 | { |
---|
[7d4fbcd] | 2265 | owl_list *fl; |
---|
| 2266 | owl_filter *f; |
---|
| 2267 | char *argbuff, *filtname; |
---|
[d54838d] | 2268 | char *tmpclass, *tmpinstance = NULL; |
---|
[7d4fbcd] | 2269 | int len; |
---|
| 2270 | |
---|
| 2271 | fl=owl_global_get_filterlist(&g); |
---|
| 2272 | |
---|
| 2273 | /* name for the filter */ |
---|
| 2274 | len=strlen(class)+30; |
---|
| 2275 | if (instance) len+=strlen(instance); |
---|
| 2276 | filtname=owl_malloc(len); |
---|
| 2277 | if (!instance) { |
---|
| 2278 | sprintf(filtname, "class-%s", class); |
---|
| 2279 | } else { |
---|
| 2280 | sprintf(filtname, "class-%s-instance-%s", class, instance); |
---|
| 2281 | } |
---|
[ed2412d] | 2282 | /* downcase it */ |
---|
[7d4fbcd] | 2283 | downstr(filtname); |
---|
[ed2412d] | 2284 | /* turn spaces into hyphens */ |
---|
| 2285 | owl_util_tr(filtname, ' ', '.'); |
---|
| 2286 | |
---|
[7d4fbcd] | 2287 | /* if it already exists then go with it. This lets users override */ |
---|
| 2288 | if (owl_global_get_filter(&g, filtname)) { |
---|
[ed2412d] | 2289 | return(filtname); |
---|
[7d4fbcd] | 2290 | } |
---|
| 2291 | |
---|
| 2292 | /* create the new filter */ |
---|
| 2293 | argbuff=owl_malloc(len+20); |
---|
[ed2412d] | 2294 | tmpclass=owl_strdup(class); |
---|
| 2295 | owl_util_tr(tmpclass, ' ', '.'); |
---|
| 2296 | if (instance) { |
---|
| 2297 | tmpinstance=owl_strdup(instance); |
---|
| 2298 | owl_util_tr(tmpinstance, ' ', '.'); |
---|
| 2299 | } |
---|
| 2300 | sprintf(argbuff, "( class ^%s$ )", tmpclass); |
---|
[d54838d] | 2301 | if (tmpinstance) { |
---|
[ed2412d] | 2302 | sprintf(argbuff, "%s and ( instance ^%s$ )", argbuff, tmpinstance); |
---|
[7d4fbcd] | 2303 | } |
---|
[ed2412d] | 2304 | owl_free(tmpclass); |
---|
[d54838d] | 2305 | if (tmpinstance) owl_free(tmpinstance); |
---|
[7d4fbcd] | 2306 | |
---|
| 2307 | f=owl_malloc(sizeof(owl_filter)); |
---|
| 2308 | owl_filter_init_fromstring(f, filtname, argbuff); |
---|
| 2309 | |
---|
| 2310 | /* add it to the global list */ |
---|
| 2311 | owl_global_add_filter(&g, f); |
---|
| 2312 | |
---|
| 2313 | owl_free(argbuff); |
---|
[ed2412d] | 2314 | return(filtname); |
---|
[7d4fbcd] | 2315 | } |
---|
| 2316 | |
---|
[3abf28b] | 2317 | /* Create a filter for personal zephyrs to or from the specified |
---|
| 2318 | * zephyr user. Includes login/logout notifications for the user. |
---|
| 2319 | * The name of the filter will be 'user-<user>'. If a filter already |
---|
| 2320 | * exists with this name, no new filter will be created. This allows |
---|
| 2321 | * the configuration to override this function. Returns the name of |
---|
| 2322 | * the filter, which the caller must free. |
---|
| 2323 | */ |
---|
| 2324 | char *owl_function_zuserfilt(char *user) |
---|
[d54838d] | 2325 | { |
---|
[7d4fbcd] | 2326 | owl_filter *f; |
---|
| 2327 | char *argbuff, *longuser, *shortuser, *filtname; |
---|
| 2328 | |
---|
| 2329 | /* stick the local realm on if it's not there */ |
---|
[4b464a4] | 2330 | longuser=long_zuser(user); |
---|
| 2331 | shortuser=short_zuser(user); |
---|
[7d4fbcd] | 2332 | |
---|
| 2333 | /* name for the filter */ |
---|
| 2334 | filtname=owl_malloc(strlen(shortuser)+20); |
---|
| 2335 | sprintf(filtname, "user-%s", shortuser); |
---|
| 2336 | |
---|
| 2337 | /* if it already exists then go with it. This lets users override */ |
---|
| 2338 | if (owl_global_get_filter(&g, filtname)) { |
---|
[3abf28b] | 2339 | return(owl_strdup(filtname)); |
---|
[7d4fbcd] | 2340 | } |
---|
| 2341 | |
---|
| 2342 | /* create the new-internal filter */ |
---|
| 2343 | f=owl_malloc(sizeof(owl_filter)); |
---|
| 2344 | |
---|
[4b464a4] | 2345 | argbuff=owl_malloc(strlen(longuser)+1000); |
---|
| 2346 | sprintf(argbuff, "( type ^zephyr$ and ( class ^message$ and instance ^personal$ and "); |
---|
| 2347 | sprintf(argbuff, "%s ( ( direction ^in$ and sender ^%s$ ) or ( direction ^out$ and recipient ^%s$ ) ) )", argbuff, longuser, longuser); |
---|
| 2348 | sprintf(argbuff, "%s or ( ( class ^login$ ) and ( sender ^%s$ ) ) )", argbuff, longuser); |
---|
[7d4fbcd] | 2349 | |
---|
| 2350 | owl_filter_init_fromstring(f, filtname, argbuff); |
---|
| 2351 | |
---|
| 2352 | /* add it to the global list */ |
---|
| 2353 | owl_global_add_filter(&g, f); |
---|
| 2354 | |
---|
| 2355 | /* free stuff */ |
---|
| 2356 | owl_free(argbuff); |
---|
| 2357 | owl_free(longuser); |
---|
| 2358 | owl_free(shortuser); |
---|
[7360fab] | 2359 | |
---|
[ed2412d] | 2360 | return(filtname); |
---|
[7d4fbcd] | 2361 | } |
---|
| 2362 | |
---|
[3abf28b] | 2363 | /* Create a filter for AIM IM messages to or from the specified |
---|
| 2364 | * screenname. The name of the filter will be 'aimuser-<user>'. If a |
---|
| 2365 | * filter already exists with this name, no new filter will be |
---|
| 2366 | * created. This allows the configuration to override this function. |
---|
| 2367 | * Returns the name of the filter, which the caller must free. |
---|
| 2368 | */ |
---|
| 2369 | char *owl_function_aimuserfilt(char *user) |
---|
| 2370 | { |
---|
| 2371 | owl_filter *f; |
---|
| 2372 | char *argbuff, *filtname; |
---|
| 2373 | |
---|
| 2374 | /* name for the filter */ |
---|
| 2375 | filtname=owl_malloc(strlen(user)+40); |
---|
| 2376 | sprintf(filtname, "aimuser-%s", user); |
---|
| 2377 | |
---|
| 2378 | /* if it already exists then go with it. This lets users override */ |
---|
| 2379 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2380 | return(owl_strdup(filtname)); |
---|
| 2381 | } |
---|
| 2382 | |
---|
| 2383 | /* create the new-internal filter */ |
---|
| 2384 | f=owl_malloc(sizeof(owl_filter)); |
---|
| 2385 | |
---|
| 2386 | argbuff=owl_malloc(1000); |
---|
| 2387 | sprintf(argbuff, |
---|
| 2388 | "( type ^aim$ and ( ( sender ^%s$ and recipient ^%s$ ) or ( sender ^%s$ and recipient ^%s$ ) ) )", |
---|
| 2389 | user, owl_global_get_aim_screenname(&g), owl_global_get_aim_screenname(&g), user); |
---|
| 2390 | |
---|
| 2391 | owl_filter_init_fromstring(f, filtname, argbuff); |
---|
| 2392 | |
---|
| 2393 | /* add it to the global list */ |
---|
| 2394 | owl_global_add_filter(&g, f); |
---|
| 2395 | |
---|
| 2396 | /* free stuff */ |
---|
| 2397 | owl_free(argbuff); |
---|
| 2398 | |
---|
| 2399 | return(filtname); |
---|
| 2400 | } |
---|
| 2401 | |
---|
| 2402 | char *owl_function_typefilt(char *type) |
---|
[d54838d] | 2403 | { |
---|
[f73e519] | 2404 | owl_filter *f; |
---|
| 2405 | char *argbuff, *filtname; |
---|
| 2406 | |
---|
| 2407 | /* name for the filter */ |
---|
| 2408 | filtname=owl_sprintf("type-%s", type); |
---|
| 2409 | |
---|
| 2410 | /* if it already exists then go with it. This lets users override */ |
---|
| 2411 | if (owl_global_get_filter(&g, filtname)) { |
---|
| 2412 | return filtname; |
---|
| 2413 | } |
---|
| 2414 | |
---|
| 2415 | /* create the new-internal filter */ |
---|
| 2416 | f=owl_malloc(sizeof(owl_filter)); |
---|
| 2417 | |
---|
| 2418 | argbuff = owl_sprintf("type ^%s$", type); |
---|
| 2419 | |
---|
| 2420 | owl_filter_init_fromstring(f, filtname, argbuff); |
---|
| 2421 | |
---|
| 2422 | /* add it to the global list */ |
---|
| 2423 | owl_global_add_filter(&g, f); |
---|
| 2424 | |
---|
| 2425 | /* free stuff */ |
---|
| 2426 | owl_free(argbuff); |
---|
| 2427 | |
---|
| 2428 | return filtname; |
---|
| 2429 | } |
---|
| 2430 | |
---|
[7d4fbcd] | 2431 | /* If flag is 1, marks for deletion. If flag is 0, |
---|
| 2432 | * unmarks for deletion. */ |
---|
[d54838d] | 2433 | void owl_function_delete_curview_msgs(int flag) |
---|
| 2434 | { |
---|
[7d4fbcd] | 2435 | owl_view *v; |
---|
| 2436 | int i, j; |
---|
| 2437 | |
---|
| 2438 | v=owl_global_get_current_view(&g); |
---|
| 2439 | j=owl_view_get_size(v); |
---|
| 2440 | for (i=0; i<j; i++) { |
---|
| 2441 | if (flag == 1) { |
---|
| 2442 | owl_message_mark_delete(owl_view_get_element(v, i)); |
---|
| 2443 | } else if (flag == 0) { |
---|
| 2444 | owl_message_unmark_delete(owl_view_get_element(v, i)); |
---|
| 2445 | } |
---|
| 2446 | } |
---|
| 2447 | |
---|
| 2448 | owl_function_makemsg("%i messages marked for %sdeletion", j, flag?"":"un"); |
---|
| 2449 | |
---|
| 2450 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2451 | } |
---|
| 2452 | |
---|
[3abf28b] | 2453 | /* Create a filter based on the current message. Returns the name of |
---|
| 2454 | * a filter or null. The caller must free this name. |
---|
| 2455 | * |
---|
| 2456 | * if the curmsg is a personal zephyr return a filter name |
---|
| 2457 | * to the zephyr converstaion with that user. |
---|
| 2458 | * If the curmsg is a zephyr class message, instance foo, recip *, |
---|
| 2459 | * return a filter name to the class, inst. |
---|
| 2460 | * If the curmsg is a zephyr class message and type==0 then |
---|
| 2461 | * return a filter name for just the class. |
---|
| 2462 | * If the curmsg is a zephyr class message and type==1 then |
---|
| 2463 | * return a filter name for the class and instance. |
---|
| 2464 | * If the curmsg is a personal AIM message returna filter |
---|
| 2465 | * name to the AIM conversation with that user |
---|
| 2466 | */ |
---|
[d54838d] | 2467 | char *owl_function_smartfilter(int type) |
---|
| 2468 | { |
---|
[7d4fbcd] | 2469 | owl_view *v; |
---|
| 2470 | owl_message *m; |
---|
[4b464a4] | 2471 | char *zperson, *filtname=NULL; |
---|
[7d4fbcd] | 2472 | |
---|
| 2473 | v=owl_global_get_current_view(&g); |
---|
| 2474 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 2475 | |
---|
[5eeea3b] | 2476 | if (!m || owl_view_get_size(v)==0) { |
---|
[7d4fbcd] | 2477 | owl_function_makemsg("No message selected\n"); |
---|
[4b464a4] | 2478 | return(NULL); |
---|
[7d4fbcd] | 2479 | } |
---|
| 2480 | |
---|
[f73e519] | 2481 | /* very simple handling of admin messages for now */ |
---|
[4b464a4] | 2482 | if (owl_message_is_type_admin(m)) { |
---|
[3abf28b] | 2483 | return(owl_function_typefilt("admin")); |
---|
| 2484 | } |
---|
| 2485 | |
---|
| 2486 | /* aim messages */ |
---|
| 2487 | if (owl_message_is_type_aim(m)) { |
---|
| 2488 | if (owl_message_is_direction_in(m)) { |
---|
| 2489 | filtname=owl_function_aimuserfilt(owl_message_get_sender(m)); |
---|
| 2490 | } else if (owl_message_is_direction_out(m)) { |
---|
| 2491 | filtname=owl_function_aimuserfilt(owl_message_get_recipient(m)); |
---|
| 2492 | } |
---|
| 2493 | return(filtname); |
---|
[7d4fbcd] | 2494 | } |
---|
| 2495 | |
---|
[4b464a4] | 2496 | /* narrow personal and login messages to the sender or recip as appropriate */ |
---|
[5789230] | 2497 | if (owl_message_is_personal(m) || owl_message_is_loginout(m)) { |
---|
[4b464a4] | 2498 | if (owl_message_is_type_zephyr(m)) { |
---|
| 2499 | if (owl_message_is_direction_in(m)) { |
---|
| 2500 | zperson=short_zuser(owl_message_get_sender(m)); |
---|
| 2501 | } else { |
---|
| 2502 | zperson=short_zuser(owl_message_get_recipient(m)); |
---|
| 2503 | } |
---|
[3abf28b] | 2504 | filtname=owl_function_zuserfilt(zperson); |
---|
[4b464a4] | 2505 | owl_free(zperson); |
---|
| 2506 | return(filtname); |
---|
[7d4fbcd] | 2507 | } |
---|
[4b464a4] | 2508 | return(NULL); |
---|
[7d4fbcd] | 2509 | } |
---|
| 2510 | |
---|
| 2511 | /* narrow class MESSAGE, instance foo, recip * messages to class, inst */ |
---|
[3abf28b] | 2512 | if (!strcasecmp(owl_message_get_class(m), "message") && !owl_message_is_personal(m)) { |
---|
| 2513 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m)); |
---|
[4b464a4] | 2514 | return(filtname); |
---|
[7d4fbcd] | 2515 | } |
---|
| 2516 | |
---|
| 2517 | /* otherwise narrow to the class */ |
---|
| 2518 | if (type==0) { |
---|
[3abf28b] | 2519 | filtname=owl_function_classinstfilt(owl_message_get_class(m), NULL); |
---|
[7d4fbcd] | 2520 | } else if (type==1) { |
---|
[3abf28b] | 2521 | filtname=owl_function_classinstfilt(owl_message_get_class(m), owl_message_get_instance(m)); |
---|
[7d4fbcd] | 2522 | } |
---|
[4b464a4] | 2523 | return(filtname); |
---|
[7d4fbcd] | 2524 | } |
---|
| 2525 | |
---|
[d54838d] | 2526 | void owl_function_smartzpunt(int type) |
---|
| 2527 | { |
---|
[d36f2cb] | 2528 | /* Starts a zpunt command based on the current class,instance pair. |
---|
| 2529 | * If type=0, uses just class. If type=1, uses instance as well. */ |
---|
| 2530 | owl_view *v; |
---|
| 2531 | owl_message *m; |
---|
| 2532 | char *cmd, *cmdprefix, *mclass, *minst; |
---|
| 2533 | |
---|
| 2534 | v=owl_global_get_current_view(&g); |
---|
| 2535 | m=owl_view_get_element(v, owl_global_get_curmsg(&g)); |
---|
| 2536 | |
---|
[5eeea3b] | 2537 | if (!m || owl_view_get_size(v)==0) { |
---|
[d36f2cb] | 2538 | owl_function_makemsg("No message selected\n"); |
---|
| 2539 | return; |
---|
| 2540 | } |
---|
| 2541 | |
---|
| 2542 | /* for now we skip admin messages. */ |
---|
[4b464a4] | 2543 | if (owl_message_is_type_admin(m) |
---|
[5789230] | 2544 | || owl_message_is_loginout(m) |
---|
[4b464a4] | 2545 | || !owl_message_is_type_zephyr(m)) { |
---|
[d36f2cb] | 2546 | owl_function_makemsg("smartzpunt doesn't support this message type."); |
---|
| 2547 | return; |
---|
| 2548 | } |
---|
| 2549 | |
---|
| 2550 | mclass = owl_message_get_class(m); |
---|
| 2551 | minst = owl_message_get_instance(m); |
---|
| 2552 | if (!mclass || !*mclass || *mclass==' ' |
---|
| 2553 | || (!strcasecmp(mclass, "message") && !strcasecmp(minst, "personal")) |
---|
| 2554 | || (type && (!minst || !*minst|| *minst==' '))) { |
---|
| 2555 | owl_function_makemsg("smartzpunt can't safely do this for <%s,%s>", |
---|
| 2556 | mclass, minst); |
---|
| 2557 | } else { |
---|
| 2558 | cmdprefix = "start-command zpunt "; |
---|
| 2559 | cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+3); |
---|
| 2560 | strcpy(cmd, cmdprefix); |
---|
| 2561 | strcat(cmd, mclass); |
---|
| 2562 | if (type) { |
---|
| 2563 | strcat(cmd, " "); |
---|
| 2564 | strcat(cmd, minst); |
---|
| 2565 | } else { |
---|
| 2566 | strcat(cmd, " *"); |
---|
| 2567 | } |
---|
| 2568 | owl_function_command(cmd); |
---|
| 2569 | owl_free(cmd); |
---|
| 2570 | } |
---|
| 2571 | } |
---|
| 2572 | |
---|
| 2573 | |
---|
| 2574 | |
---|
[d54838d] | 2575 | void owl_function_color_current_filter(char *color) |
---|
| 2576 | { |
---|
[7d4fbcd] | 2577 | owl_filter *f; |
---|
| 2578 | char *name; |
---|
| 2579 | |
---|
| 2580 | name=owl_view_get_filtname(owl_global_get_current_view(&g)); |
---|
| 2581 | f=owl_global_get_filter(&g, name); |
---|
| 2582 | if (!f) { |
---|
| 2583 | owl_function_makemsg("Unknown filter"); |
---|
| 2584 | return; |
---|
| 2585 | } |
---|
| 2586 | |
---|
| 2587 | /* don't touch the all filter */ |
---|
| 2588 | if (!strcmp(name, "all")) { |
---|
| 2589 | owl_function_makemsg("You may not change the 'all' filter."); |
---|
| 2590 | return; |
---|
| 2591 | } |
---|
| 2592 | |
---|
| 2593 | /* deal with the case of trying change the filter color */ |
---|
| 2594 | owl_filter_set_color(f, owl_util_string_to_color(color)); |
---|
| 2595 | owl_global_set_needrefresh(&g); |
---|
| 2596 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2597 | } |
---|
| 2598 | |
---|
[d54838d] | 2599 | void owl_function_show_colors() |
---|
| 2600 | { |
---|
[7d4fbcd] | 2601 | owl_fmtext fm; |
---|
| 2602 | |
---|
| 2603 | owl_fmtext_init_null(&fm); |
---|
| 2604 | owl_fmtext_append_normal_color(&fm, "default\n", OWL_COLOR_DEFAULT); |
---|
| 2605 | owl_fmtext_append_normal_color(&fm, "red\n", OWL_COLOR_RED); |
---|
| 2606 | owl_fmtext_append_normal_color(&fm, "green\n", OWL_COLOR_GREEN); |
---|
| 2607 | owl_fmtext_append_normal_color(&fm, "yellow\n", OWL_COLOR_YELLOW); |
---|
| 2608 | owl_fmtext_append_normal_color(&fm, "blue\n", OWL_COLOR_BLUE); |
---|
| 2609 | owl_fmtext_append_normal_color(&fm, "magenta\n", OWL_COLOR_MAGENTA); |
---|
| 2610 | owl_fmtext_append_normal_color(&fm, "cyan\n", OWL_COLOR_CYAN); |
---|
| 2611 | owl_fmtext_append_normal_color(&fm, "white\n", OWL_COLOR_WHITE); |
---|
| 2612 | |
---|
| 2613 | owl_function_popless_fmtext(&fm); |
---|
| 2614 | owl_fmtext_free(&fm); |
---|
| 2615 | } |
---|
| 2616 | |
---|
[5bb6c21] | 2617 | /* add the given class, inst, recip to the punt list for filtering. |
---|
| 2618 | * if direction==0 then punt |
---|
| 2619 | * if direction==1 then unpunt |
---|
| 2620 | */ |
---|
[d54838d] | 2621 | void owl_function_zpunt(char *class, char *inst, char *recip, int direction) |
---|
| 2622 | { |
---|
[7d4fbcd] | 2623 | owl_filter *f; |
---|
| 2624 | owl_list *fl; |
---|
| 2625 | char *buff; |
---|
| 2626 | int ret, i, j; |
---|
| 2627 | |
---|
| 2628 | fl=owl_global_get_puntlist(&g); |
---|
| 2629 | |
---|
| 2630 | /* first, create the filter */ |
---|
| 2631 | f=malloc(sizeof(owl_filter)); |
---|
| 2632 | buff=malloc(strlen(class)+strlen(inst)+strlen(recip)+100); |
---|
[5bb6c21] | 2633 | strcpy(buff, "class"); |
---|
| 2634 | if (!strcmp(class, "*")) { |
---|
| 2635 | strcat(buff, " .*"); |
---|
| 2636 | } else { |
---|
| 2637 | sprintf(buff, "%s ^%s$", buff, class); |
---|
| 2638 | } |
---|
| 2639 | if (!strcmp(inst, "*")) { |
---|
| 2640 | strcat(buff, " and instance .*"); |
---|
[7d4fbcd] | 2641 | } else { |
---|
[5bb6c21] | 2642 | sprintf(buff, "%s and instance ^%s$", buff, inst); |
---|
[7d4fbcd] | 2643 | } |
---|
[5bb6c21] | 2644 | if (strcmp(recip, "*")) { |
---|
| 2645 | sprintf(buff, "%s and recipient ^%s$", buff, recip); |
---|
| 2646 | } |
---|
| 2647 | |
---|
[7d4fbcd] | 2648 | owl_function_debugmsg("About to filter %s", buff); |
---|
| 2649 | ret=owl_filter_init_fromstring(f, "punt-filter", buff); |
---|
| 2650 | owl_free(buff); |
---|
| 2651 | if (ret) { |
---|
| 2652 | owl_function_makemsg("Error creating filter for zpunt"); |
---|
| 2653 | owl_filter_free(f); |
---|
| 2654 | return; |
---|
| 2655 | } |
---|
| 2656 | |
---|
| 2657 | /* Check for an identical filter */ |
---|
| 2658 | j=owl_list_get_size(fl); |
---|
| 2659 | for (i=0; i<j; i++) { |
---|
| 2660 | if (owl_filter_equiv(f, owl_list_get_element(fl, i))) { |
---|
| 2661 | /* if we're punting, then just silently bow out on this duplicate */ |
---|
| 2662 | if (direction==0) { |
---|
| 2663 | owl_filter_free(f); |
---|
| 2664 | return; |
---|
| 2665 | } |
---|
| 2666 | |
---|
| 2667 | /* if we're unpunting, then remove this filter from the puntlist */ |
---|
| 2668 | if (direction==1) { |
---|
| 2669 | owl_filter_free(owl_list_get_element(fl, i)); |
---|
| 2670 | owl_list_remove_element(fl, i); |
---|
| 2671 | return; |
---|
| 2672 | } |
---|
| 2673 | } |
---|
| 2674 | } |
---|
| 2675 | |
---|
| 2676 | /* If we're punting, add the filter to the global punt list */ |
---|
| 2677 | if (direction==0) { |
---|
| 2678 | owl_list_append_element(fl, f); |
---|
| 2679 | } |
---|
| 2680 | } |
---|
| 2681 | |
---|
[d54838d] | 2682 | void owl_function_activate_keymap(char *keymap) |
---|
| 2683 | { |
---|
[7d4fbcd] | 2684 | if (!owl_keyhandler_activate(owl_global_get_keyhandler(&g), keymap)) { |
---|
| 2685 | owl_function_makemsg("Unable to activate keymap '%s'", keymap); |
---|
| 2686 | } |
---|
| 2687 | } |
---|
| 2688 | |
---|
| 2689 | |
---|
[d54838d] | 2690 | void owl_function_show_keymaps() |
---|
| 2691 | { |
---|
[7d4fbcd] | 2692 | owl_list l; |
---|
| 2693 | owl_fmtext fm; |
---|
[1aee7d9] | 2694 | owl_keymap *km; |
---|
| 2695 | owl_keyhandler *kh; |
---|
| 2696 | int i, numkm; |
---|
| 2697 | char *kmname; |
---|
[7d4fbcd] | 2698 | |
---|
[1aee7d9] | 2699 | kh = owl_global_get_keyhandler(&g); |
---|
[7d4fbcd] | 2700 | owl_fmtext_init_null(&fm); |
---|
| 2701 | owl_fmtext_append_bold(&fm, "Keymaps: "); |
---|
| 2702 | owl_fmtext_append_normal(&fm, "(use 'show keymap <name>' for details)\n"); |
---|
[1aee7d9] | 2703 | owl_keyhandler_get_keymap_names(kh, &l); |
---|
[7d4fbcd] | 2704 | owl_fmtext_append_list(&fm, &l, "\n", owl_function_keymap_summary); |
---|
| 2705 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[1aee7d9] | 2706 | |
---|
| 2707 | numkm = owl_list_get_size(&l); |
---|
| 2708 | for (i=0; i<numkm; i++) { |
---|
| 2709 | kmname = owl_list_get_element(&l, i); |
---|
| 2710 | km = owl_keyhandler_get_keymap(kh, kmname); |
---|
| 2711 | owl_fmtext_append_bold(&fm, "\n\n----------------------------------------------------------------------------------------------------\n\n"); |
---|
| 2712 | owl_keymap_get_details(km, &fm); |
---|
| 2713 | } |
---|
| 2714 | owl_fmtext_append_normal(&fm, "\n"); |
---|
| 2715 | |
---|
[7d4fbcd] | 2716 | owl_function_popless_fmtext(&fm); |
---|
| 2717 | owl_keyhandler_keymap_namelist_free(&l); |
---|
| 2718 | owl_fmtext_free(&fm); |
---|
| 2719 | } |
---|
| 2720 | |
---|
[d54838d] | 2721 | char *owl_function_keymap_summary(void *name) |
---|
| 2722 | { |
---|
[7d4fbcd] | 2723 | owl_keymap *km |
---|
| 2724 | = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
| 2725 | if (km) return owl_keymap_summary(km); |
---|
| 2726 | else return(NULL); |
---|
| 2727 | } |
---|
| 2728 | |
---|
| 2729 | /* TODO: implement for real */ |
---|
[d54838d] | 2730 | void owl_function_show_keymap(char *name) |
---|
| 2731 | { |
---|
[1fd0b25] | 2732 | owl_fmtext fm; |
---|
[7d4fbcd] | 2733 | owl_keymap *km; |
---|
| 2734 | |
---|
| 2735 | owl_fmtext_init_null(&fm); |
---|
| 2736 | km = owl_keyhandler_get_keymap(owl_global_get_keyhandler(&g), name); |
---|
| 2737 | if (km) { |
---|
| 2738 | owl_keymap_get_details(km, &fm); |
---|
| 2739 | } else { |
---|
| 2740 | owl_fmtext_append_normal(&fm, "No such keymap...\n"); |
---|
| 2741 | } |
---|
| 2742 | owl_function_popless_fmtext(&fm); |
---|
| 2743 | owl_fmtext_free(&fm); |
---|
| 2744 | } |
---|
| 2745 | |
---|
[d54838d] | 2746 | void owl_function_help_for_command(char *cmdname) |
---|
| 2747 | { |
---|
[1fd0b25] | 2748 | owl_fmtext fm; |
---|
[7d4fbcd] | 2749 | |
---|
| 2750 | owl_fmtext_init_null(&fm); |
---|
| 2751 | owl_cmd_get_help(owl_global_get_cmddict(&g), cmdname, &fm); |
---|
| 2752 | owl_function_popless_fmtext(&fm); |
---|
| 2753 | owl_fmtext_free(&fm); |
---|
| 2754 | } |
---|
[1fd0b25] | 2755 | |
---|
[d54838d] | 2756 | void owl_function_search_start(char *string, int direction) |
---|
| 2757 | { |
---|
[1fd0b25] | 2758 | /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */ |
---|
| 2759 | owl_global_set_search_active(&g, string); |
---|
| 2760 | owl_function_search_helper(0, direction); |
---|
| 2761 | } |
---|
| 2762 | |
---|
[d54838d] | 2763 | void owl_function_search_continue(int direction) |
---|
| 2764 | { |
---|
[1fd0b25] | 2765 | /* direction is OWL_DIRECTION_DOWNWARDS or OWL_DIRECTION_UPWARDS */ |
---|
| 2766 | owl_function_search_helper(1, direction); |
---|
| 2767 | } |
---|
| 2768 | |
---|
[d54838d] | 2769 | void owl_function_search_helper(int mode, int direction) |
---|
| 2770 | { |
---|
[1fd0b25] | 2771 | /* move to a message that contains the string. If direction is |
---|
| 2772 | * OWL_DIRECTION_DOWNWARDS then search fowards, if direction is |
---|
| 2773 | * OWL_DIRECTION_UPWARDS then search backwards. |
---|
| 2774 | * |
---|
| 2775 | * If mode==0 then it will stay on the current message if it |
---|
| 2776 | * contains the string. |
---|
| 2777 | */ |
---|
| 2778 | |
---|
| 2779 | owl_view *v; |
---|
| 2780 | int viewsize, i, curmsg, start; |
---|
| 2781 | owl_message *m; |
---|
| 2782 | |
---|
| 2783 | v=owl_global_get_current_view(&g); |
---|
| 2784 | viewsize=owl_view_get_size(v); |
---|
| 2785 | curmsg=owl_global_get_curmsg(&g); |
---|
| 2786 | |
---|
| 2787 | if (viewsize==0) { |
---|
| 2788 | owl_function_makemsg("No messages present"); |
---|
| 2789 | return; |
---|
| 2790 | } |
---|
| 2791 | |
---|
| 2792 | if (mode==0) { |
---|
| 2793 | start=curmsg; |
---|
| 2794 | } else if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
| 2795 | start=curmsg+1; |
---|
| 2796 | } else { |
---|
| 2797 | start=curmsg-1; |
---|
| 2798 | } |
---|
| 2799 | |
---|
| 2800 | /* bounds check */ |
---|
| 2801 | if (start>=viewsize || start<0) { |
---|
| 2802 | owl_function_makemsg("No further matches found"); |
---|
| 2803 | return; |
---|
| 2804 | } |
---|
| 2805 | |
---|
| 2806 | for (i=start; i<viewsize && i>=0;) { |
---|
| 2807 | m=owl_view_get_element(v, i); |
---|
| 2808 | if (owl_message_search(m, owl_global_get_search_string(&g))) { |
---|
| 2809 | owl_global_set_curmsg(&g, i); |
---|
| 2810 | owl_function_calculate_topmsg(direction); |
---|
| 2811 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 2812 | if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
| 2813 | owl_global_set_direction_downwards(&g); |
---|
| 2814 | } else { |
---|
| 2815 | owl_global_set_direction_upwards(&g); |
---|
| 2816 | } |
---|
| 2817 | return; |
---|
| 2818 | } |
---|
| 2819 | if (direction==OWL_DIRECTION_DOWNWARDS) { |
---|
| 2820 | i++; |
---|
| 2821 | } else { |
---|
| 2822 | i--; |
---|
| 2823 | } |
---|
| 2824 | } |
---|
[37c27cf] | 2825 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[1fd0b25] | 2826 | owl_function_makemsg("No matches found"); |
---|
| 2827 | } |
---|
| 2828 | |
---|
| 2829 | |
---|
| 2830 | /* strips formatting from ztext and returns the unformatted text. |
---|
| 2831 | * caller is responsible for freeing. */ |
---|
[d54838d] | 2832 | char *owl_function_ztext_stylestrip(char *zt) |
---|
| 2833 | { |
---|
[1fd0b25] | 2834 | owl_fmtext fm; |
---|
| 2835 | char *plaintext; |
---|
| 2836 | |
---|
| 2837 | owl_fmtext_init_null(&fm); |
---|
| 2838 | owl_fmtext_append_ztext(&fm, zt); |
---|
| 2839 | plaintext = owl_fmtext_print_plain(&fm); |
---|
| 2840 | owl_fmtext_free(&fm); |
---|
| 2841 | return(plaintext); |
---|
| 2842 | } |
---|
[42abb10] | 2843 | |
---|
[aa5f725] | 2844 | /* Popup a buddylisting. If file is NULL use the default .anyone */ |
---|
| 2845 | void owl_function_buddylist(int aim, int zephyr, char *file) |
---|
[d54838d] | 2846 | { |
---|
[09489b89] | 2847 | int i, j; |
---|
[42abb10] | 2848 | owl_fmtext fm; |
---|
[aa5f725] | 2849 | owl_buddylist *b; |
---|
[09489b89] | 2850 | #ifdef HAVE_LIBZEPHYR |
---|
| 2851 | char *ourfile, *tmp, buff[LINE], *line; |
---|
| 2852 | ZLocations_t location[200]; |
---|
| 2853 | FILE *f; |
---|
| 2854 | int numlocs, ret; |
---|
| 2855 | #endif |
---|
[42abb10] | 2856 | |
---|
[aa5f725] | 2857 | owl_fmtext_init_null(&fm); |
---|
[42abb10] | 2858 | |
---|
[aa5f725] | 2859 | if (aim && owl_global_is_aimloggedin(&g)) { |
---|
| 2860 | b=owl_global_get_buddylist(&g); |
---|
[42abb10] | 2861 | |
---|
[aa5f725] | 2862 | owl_fmtext_append_bold(&fm, "AIM users logged in:\n"); |
---|
| 2863 | j=owl_buddylist_get_size(b); |
---|
| 2864 | for (i=0; i<j; i++) { |
---|
| 2865 | owl_fmtext_append_normal(&fm, " "); |
---|
| 2866 | owl_fmtext_append_normal(&fm, owl_buddylist_get_buddy(b, i)); |
---|
| 2867 | owl_fmtext_append_normal(&fm, "\n"); |
---|
[42abb10] | 2868 | } |
---|
[aa5f725] | 2869 | } |
---|
[42abb10] | 2870 | |
---|
[09489b89] | 2871 | #ifdef HAVE_LIBZEPHYR |
---|
[aa5f725] | 2872 | if (zephyr) { |
---|
| 2873 | if (file==NULL) { |
---|
| 2874 | tmp=owl_global_get_homedir(&g); |
---|
| 2875 | if (!tmp) { |
---|
| 2876 | owl_function_makemsg("Could not determine home directory"); |
---|
| 2877 | return; |
---|
| 2878 | } |
---|
| 2879 | ourfile=owl_malloc(strlen(tmp)+50); |
---|
| 2880 | sprintf(ourfile, "%s/.anyone", owl_global_get_homedir(&g)); |
---|
| 2881 | } else { |
---|
| 2882 | ourfile=owl_strdup(file); |
---|
[42abb10] | 2883 | } |
---|
[aa5f725] | 2884 | |
---|
| 2885 | f=fopen(ourfile, "r"); |
---|
| 2886 | if (!f) { |
---|
| 2887 | owl_function_makemsg("Error opening file %s: %s", |
---|
| 2888 | ourfile, |
---|
| 2889 | strerror(errno) ? strerror(errno) : ""); |
---|
| 2890 | return; |
---|
| 2891 | } |
---|
[09489b89] | 2892 | |
---|
[aa5f725] | 2893 | owl_fmtext_append_bold(&fm, "Zephyr users logged in:\n"); |
---|
| 2894 | |
---|
| 2895 | while (fgets(buff, LINE, f)!=NULL) { |
---|
| 2896 | /* ignore comments, blank lines etc. */ |
---|
| 2897 | if (buff[0]=='#') continue; |
---|
| 2898 | if (buff[0]=='\n') continue; |
---|
| 2899 | if (buff[0]=='\0') continue; |
---|
| 2900 | |
---|
| 2901 | /* strip the \n */ |
---|
| 2902 | buff[strlen(buff)-1]='\0'; |
---|
| 2903 | |
---|
| 2904 | /* ingore from # on */ |
---|
| 2905 | tmp=strchr(buff, '#'); |
---|
| 2906 | if (tmp) tmp[0]='\0'; |
---|
| 2907 | |
---|
| 2908 | /* ingore from SPC */ |
---|
| 2909 | tmp=strchr(buff, ' '); |
---|
| 2910 | if (tmp) tmp[0]='\0'; |
---|
| 2911 | |
---|
| 2912 | /* stick on the local realm. */ |
---|
| 2913 | if (!strchr(buff, '@')) { |
---|
| 2914 | strcat(buff, "@"); |
---|
| 2915 | strcat(buff, ZGetRealm()); |
---|
[42abb10] | 2916 | } |
---|
[aa5f725] | 2917 | |
---|
| 2918 | ret=ZLocateUser(buff, &numlocs, ZAUTH); |
---|
| 2919 | if (ret!=ZERR_NONE) { |
---|
| 2920 | owl_function_makemsg("Error getting location for %s", buff); |
---|
| 2921 | continue; |
---|
| 2922 | } |
---|
| 2923 | |
---|
| 2924 | numlocs=200; |
---|
| 2925 | ret=ZGetLocations(location, &numlocs); |
---|
| 2926 | if (ret==0) { |
---|
| 2927 | for (i=0; i<numlocs; i++) { |
---|
| 2928 | line=malloc(strlen(location[i].host)+strlen(location[i].time)+strlen(location[i].tty)+100); |
---|
| 2929 | tmp=short_zuser(buff); |
---|
| 2930 | sprintf(line, " %-10.10s %-24.24s %-12.12s %20.20s\n", |
---|
| 2931 | tmp, |
---|
| 2932 | location[i].host, |
---|
| 2933 | location[i].tty, |
---|
| 2934 | location[i].time); |
---|
| 2935 | owl_fmtext_append_normal(&fm, line); |
---|
| 2936 | owl_free(tmp); |
---|
| 2937 | } |
---|
| 2938 | if (numlocs>=200) { |
---|
| 2939 | owl_fmtext_append_normal(&fm, " Too many locations found for this user, truncating.\n"); |
---|
| 2940 | } |
---|
[42abb10] | 2941 | } |
---|
| 2942 | } |
---|
[aa5f725] | 2943 | fclose(f); |
---|
| 2944 | owl_free(ourfile); |
---|
[42abb10] | 2945 | } |
---|
[09489b89] | 2946 | #endif |
---|
[aa5f725] | 2947 | |
---|
[42abb10] | 2948 | owl_function_popless_fmtext(&fm); |
---|
| 2949 | owl_fmtext_free(&fm); |
---|
| 2950 | } |
---|
[2adaf1d] | 2951 | |
---|
[d54838d] | 2952 | void owl_function_dump(char *filename) |
---|
| 2953 | { |
---|
[2adaf1d] | 2954 | int i, j, count; |
---|
| 2955 | owl_message *m; |
---|
| 2956 | owl_view *v; |
---|
| 2957 | FILE *file; |
---|
| 2958 | /* struct stat sbuf; */ |
---|
| 2959 | |
---|
| 2960 | v=owl_global_get_current_view(&g); |
---|
| 2961 | |
---|
| 2962 | /* in the future make it ask yes/no */ |
---|
| 2963 | /* |
---|
| 2964 | ret=stat(filename, &sbuf); |
---|
| 2965 | if (!ret) { |
---|
| 2966 | ret=owl_function_askyesno("File exists, continue? [Y/n]"); |
---|
| 2967 | if (!ret) return; |
---|
| 2968 | } |
---|
| 2969 | */ |
---|
| 2970 | |
---|
| 2971 | file=fopen(filename, "w"); |
---|
| 2972 | if (!file) { |
---|
| 2973 | owl_function_makemsg("Error opening file"); |
---|
| 2974 | return; |
---|
| 2975 | } |
---|
| 2976 | |
---|
| 2977 | count=0; |
---|
| 2978 | j=owl_view_get_size(v); |
---|
| 2979 | for (i=0; i<j; i++) { |
---|
| 2980 | m=owl_view_get_element(v, i); |
---|
| 2981 | fputs(owl_message_get_text(m), file); |
---|
| 2982 | } |
---|
| 2983 | fclose(file); |
---|
| 2984 | } |
---|
[8f44c6b] | 2985 | |
---|
| 2986 | |
---|
| 2987 | |
---|
[801c7cb] | 2988 | void owl_function_do_newmsgproc(void) |
---|
| 2989 | { |
---|
[8f44c6b] | 2990 | if (owl_global_get_newmsgproc(&g) && strcmp(owl_global_get_newmsgproc(&g), "")) { |
---|
| 2991 | /* if there's a process out there, we need to check on it */ |
---|
| 2992 | if (owl_global_get_newmsgproc_pid(&g)) { |
---|
| 2993 | owl_function_debugmsg("Checking on newmsgproc pid==%i", owl_global_get_newmsgproc_pid(&g)); |
---|
| 2994 | owl_function_debugmsg("Waitpid return is %i", waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)); |
---|
| 2995 | waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG); |
---|
| 2996 | if (waitpid(owl_global_get_newmsgproc_pid(&g), NULL, WNOHANG)==-1) { |
---|
| 2997 | /* it exited */ |
---|
| 2998 | owl_global_set_newmsgproc_pid(&g, 0); |
---|
| 2999 | owl_function_debugmsg("newmsgproc exited"); |
---|
| 3000 | } else { |
---|
| 3001 | owl_function_debugmsg("newmsgproc did not exit"); |
---|
| 3002 | } |
---|
| 3003 | } |
---|
| 3004 | |
---|
| 3005 | /* if it exited, fork & exec a new one */ |
---|
| 3006 | if (owl_global_get_newmsgproc_pid(&g)==0) { |
---|
| 3007 | int i, myargc; |
---|
| 3008 | i=fork(); |
---|
| 3009 | if (i) { |
---|
| 3010 | /* parent set the child's pid */ |
---|
| 3011 | owl_global_set_newmsgproc_pid(&g, i); |
---|
| 3012 | owl_function_debugmsg("I'm the parent and I started a new newmsgproc with pid %i", i); |
---|
| 3013 | } else { |
---|
| 3014 | /* child exec's the program */ |
---|
| 3015 | char **parsed; |
---|
| 3016 | parsed=owl_parseline(owl_global_get_newmsgproc(&g), &myargc); |
---|
[d54838d] | 3017 | if (myargc < 0) { |
---|
| 3018 | owl_function_debugmsg("Could not parse newmsgproc '%s': unbalanced quotes?", owl_global_get_newmsgproc(&g)); |
---|
| 3019 | } |
---|
| 3020 | if (myargc <= 0) { |
---|
| 3021 | _exit(127); |
---|
| 3022 | } |
---|
| 3023 | parsed=realloc(parsed, sizeof(*parsed) * (myargc+1)); |
---|
| 3024 | parsed[myargc] = NULL; |
---|
[8f44c6b] | 3025 | |
---|
[d54838d] | 3026 | owl_function_debugmsg("About to exec \"%s\" with %d arguments", parsed[0], myargc); |
---|
[8f44c6b] | 3027 | |
---|
[d54838d] | 3028 | execvp(parsed[0], parsed); |
---|
[8f44c6b] | 3029 | |
---|
| 3030 | |
---|
| 3031 | /* was there an error exec'ing? */ |
---|
[d54838d] | 3032 | owl_function_debugmsg("Cannot run newmsgproc '%s': cannot exec '%s': %s", |
---|
| 3033 | owl_global_get_newmsgproc(&g), parsed[0], strerror(errno)); |
---|
[8f44c6b] | 3034 | _exit(127); |
---|
| 3035 | } |
---|
| 3036 | } |
---|
| 3037 | } |
---|
| 3038 | } |
---|
[ecd5dc5] | 3039 | |
---|
[2824f79] | 3040 | /* print the xterm escape sequence to raise the window */ |
---|
[801c7cb] | 3041 | void owl_function_xterm_raise(void) |
---|
| 3042 | { |
---|
[e9b1f60] | 3043 | printf("\033[5t"); |
---|
[ecd5dc5] | 3044 | } |
---|
| 3045 | |
---|
[2824f79] | 3046 | /* print the xterm escape sequence to deiconify the window */ |
---|
[801c7cb] | 3047 | void owl_function_xterm_deiconify(void) |
---|
| 3048 | { |
---|
[e9b1f60] | 3049 | printf("\033[1t"); |
---|
[ecd5dc5] | 3050 | } |
---|
[38cf544c] | 3051 | |
---|
| 3052 | /* Add the specified command to the startup file. Eventually this |
---|
| 3053 | * should be clever, and rewriting settings that will obviosly |
---|
| 3054 | * override earlier settings with 'set' 'bindkey' and 'alias' |
---|
[2824f79] | 3055 | * commands. For now though we just remove any line that would |
---|
| 3056 | * duplicate this one and then append this line to the end of |
---|
| 3057 | * startupfile. |
---|
[38cf544c] | 3058 | */ |
---|
| 3059 | void owl_function_addstartup(char *buff) |
---|
| 3060 | { |
---|
| 3061 | FILE *file; |
---|
| 3062 | char *filename; |
---|
| 3063 | |
---|
| 3064 | filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE); |
---|
| 3065 | file=fopen(filename, "a"); |
---|
| 3066 | if (!file) { |
---|
| 3067 | owl_function_makemsg("Error opening startupfile for new command"); |
---|
[378fa14] | 3068 | owl_free(filename); |
---|
[38cf544c] | 3069 | return; |
---|
| 3070 | } |
---|
[2824f79] | 3071 | |
---|
| 3072 | /* delete earlier copies */ |
---|
| 3073 | owl_util_file_deleteline(filename, buff, 1); |
---|
[378fa14] | 3074 | owl_free(filename); |
---|
[2824f79] | 3075 | |
---|
| 3076 | /* add this line */ |
---|
[38cf544c] | 3077 | fprintf(file, "%s\n", buff); |
---|
[2824f79] | 3078 | |
---|
[38cf544c] | 3079 | fclose(file); |
---|
| 3080 | } |
---|
| 3081 | |
---|
| 3082 | /* Remove the specified command from the startup file. */ |
---|
| 3083 | void owl_function_delstartup(char *buff) |
---|
| 3084 | { |
---|
| 3085 | char *filename; |
---|
| 3086 | filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE); |
---|
| 3087 | owl_util_file_deleteline(filename, buff, 1); |
---|
| 3088 | owl_free(filename); |
---|
| 3089 | } |
---|
| 3090 | |
---|
| 3091 | void owl_function_execstartup(void) |
---|
| 3092 | { |
---|
| 3093 | FILE *file; |
---|
| 3094 | char *filename; |
---|
| 3095 | char buff[LINE]; |
---|
| 3096 | |
---|
| 3097 | filename=owl_sprintf("%s/%s", owl_global_get_homedir(&g), OWL_STARTUP_FILE); |
---|
| 3098 | file=fopen(filename, "r"); |
---|
| 3099 | owl_free(filename); |
---|
| 3100 | if (!file) { |
---|
| 3101 | /* just fail silently if it doesn't exist */ |
---|
| 3102 | return; |
---|
| 3103 | } |
---|
| 3104 | while (fgets(buff, LINE, file)!=NULL) { |
---|
| 3105 | buff[strlen(buff)-1]='\0'; |
---|
| 3106 | owl_function_command(buff); |
---|
| 3107 | } |
---|
| 3108 | fclose(file); |
---|
| 3109 | } |
---|
[c3ab155] | 3110 | |
---|
[ef56a67] | 3111 | |
---|
| 3112 | void owl_function_change_style(owl_view *v, char *stylename) |
---|
| 3113 | { |
---|
[f1cbb7a] | 3114 | owl_style *s; |
---|
| 3115 | |
---|
| 3116 | s=owl_global_get_style_by_name(&g, stylename); |
---|
| 3117 | if (!s) { |
---|
| 3118 | owl_function_makemsg("No style named %s", stylename); |
---|
| 3119 | return; |
---|
| 3120 | } |
---|
| 3121 | owl_view_set_style(v, s); |
---|
[ef56a67] | 3122 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
| 3123 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 3124 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
| 3125 | |
---|
| 3126 | } |
---|
| 3127 | |
---|
[c3ab155] | 3128 | void owl_function_toggleoneline() |
---|
| 3129 | { |
---|
[ef56a67] | 3130 | owl_view *v; |
---|
| 3131 | owl_style *s; |
---|
[c3ab155] | 3132 | |
---|
[ef56a67] | 3133 | v=owl_global_get_current_view(&g); |
---|
| 3134 | s=owl_view_get_style(v); |
---|
[c3ab155] | 3135 | |
---|
[ef56a67] | 3136 | if (!owl_style_matches_name(s, "oneline")) { |
---|
| 3137 | owl_function_change_style(v, "oneline"); |
---|
[c3ab155] | 3138 | } else { |
---|
[ef56a67] | 3139 | owl_function_change_style(v, owl_global_get_default_style(&g)); |
---|
[c3ab155] | 3140 | } |
---|
[ef56a67] | 3141 | |
---|
| 3142 | owl_messagelist_invalidate_formats(owl_global_get_msglist(&g)); |
---|
| 3143 | owl_function_calculate_topmsg(OWL_DIRECTION_DOWNWARDS); |
---|
| 3144 | owl_mainwin_redisplay(owl_global_get_mainwin(&g)); |
---|
[c3ab155] | 3145 | } |
---|