- Timestamp:
- Jun 9, 2003, 10:54:18 AM (22 years ago)
- Branches:
- master, barnowl_perlaim, debian, owl, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 6bf73ce
- Parents:
- d559df9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fmtext.c
rd559df9 rb2b0773 5 5 static const char fileIdent[] = "$Id$"; 6 6 7 /* initialize an fmtext with no data */ 7 8 void owl_fmtext_init_null(owl_fmtext *f) 8 9 { … … 15 16 } 16 17 17 18 /* Internal function. Set the attribute 'attr' from index 'first' to 19 * index 'last' 20 */ 18 21 void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last) 19 22 { … … 24 27 } 25 28 29 /* Internal function. Add the attribute 'attr' to the existing 30 * attributes from index 'first' to index 'last' 31 */ 26 32 void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last) 27 33 { … … 32 38 } 33 39 40 /* Internal function. Set the color to be 'color' from index 'first' 41 * to index 'last 42 */ 34 43 void _owl_fmtext_set_color(owl_fmtext *f, int color, int first, int last) 35 44 { … … 40 49 } 41 50 42 51 /* append text to the end of 'f' with attribute 'attr' and color 52 * 'color' 53 */ 43 54 void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int color) 44 55 { … … 56 67 } 57 68 58 69 /* Append normal, uncolored text 'text' to 'f' */ 59 70 void owl_fmtext_append_normal(owl_fmtext *f, char *text) 60 71 { … … 62 73 } 63 74 75 /* Append normal text 'text' to 'f' with color 'color' */ 64 76 void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int color) 65 77 { … … 67 79 } 68 80 69 81 /* Append bold text 'text' to 'f' */ 70 82 void owl_fmtext_append_bold(owl_fmtext *f, char *text) 71 83 { … … 73 85 } 74 86 75 87 /* Append reverse video text 'text' to 'f' */ 76 88 void owl_fmtext_append_reverse(owl_fmtext *f, char *text) 77 89 { … … 79 91 } 80 92 81 93 /* Append reversed and bold, uncolored text 'text' to 'f' */ 82 94 void owl_fmtext_append_reversebold(owl_fmtext *f, char *text) 83 95 { … … 85 97 } 86 98 87 99 /* Add the attribute 'attr' to all text in 'f' */ 88 100 void owl_fmtext_addattr(owl_fmtext *f, int attr) 89 101 { … … 97 109 } 98 110 111 /* Anywhere the color is NOT ALREDY SET, set the color to 'color'. 112 * Other colors are left unchanged 113 */ 99 114 void owl_fmtext_colorize(owl_fmtext *f, int color) 100 115 { … … 108 123 } 109 124 110 125 /* Append the text 'text' to 'f' and interpret the zephyr style 126 * formatting syntax to set appropriate attributes. 127 */ 111 128 void owl_fmtext_append_ztext(owl_fmtext *f, char *text) 112 129 { … … 293 310 } 294 311 } 295 296 } 297 298 /* This is used internally to fmtext. Use owl_fmtext_append_fmtext() 299 * (no initial underscore) externally */312 } 313 314 /* Internal function. Append text from 'in' between index 'start' and 315 * 'stop' to the end of 'f' 316 */ 300 317 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) 301 318 { … … 316 333 } 317 334 335 /* append fmtext 'in' to 'f' */ 318 336 void owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in) 319 337 { … … 322 340 } 323 341 342 /* Append 'nspaces' number of spaces to the end of 'f' */ 324 343 void owl_fmtext_append_spaces(owl_fmtext *f, int nspaces) 325 344 { … … 358 377 } 359 378 360 361 /* caller is responsible for freeing */ 379 /* Return a plain version of the fmtext. Caller is responsible for 380 * freeing the return 381 */ 362 382 char *owl_fmtext_print_plain(owl_fmtext *f) 363 383 { 364 return owl_strdup(f->textbuff); 365 } 366 367 384 return(owl_strdup(f->textbuff)); 385 } 386 387 /* add the formatted text to the curses window 'w'. The window 'w' 388 * must already be initiatlized with curses 389 */ 368 390 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 369 391 { … … 422 444 423 445 446 /* start with line 'aline' (where the first line is 0) and print 447 * 'lines' number of lines into 'out' 448 */ 424 449 int owl_fmtext_truncate_lines(owl_fmtext *in, int aline, int lines, owl_fmtext *out) 425 450 { 426 /* start with line aline (where the first line is 0) and print427 * 'lines' lines428 */429 451 char *ptr1, *ptr2; 430 452 int i, offset; … … 445 467 446 468 for (i=0; i<lines; i++) { 447 ptr2=strchr(ptr1, '\n');448 469 offset=ptr1-in->textbuff; 470 ptr2=strchr(ptr1, '\n'); /* this is a valgrind suspicious line */ 449 471 if (!ptr2) { 450 _owl_fmtext_append_fmtext(out, in, offset, in->textlen-1);472 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1); 451 473 return(-1); 452 474 } … … 457 479 } 458 480 459 460 /* the first column is column 0 */ 461 /* the message is expected to end in a new line for now */ 481 /* Truncate the message so that each line begins at column 'acol' and 482 * ends at 'bcol' or sooner. The first column is number 0. The new 483 * message is placed in 'out'. The message is * expected to end in a 484 * new line for now 485 */ 462 486 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out) 463 487 { … … 504 528 } 505 529 506 530 /* Return the number of lines in 'f' */ 507 531 int owl_fmtext_num_lines(owl_fmtext *f) 508 532 { … … 522 546 } 523 547 524 525 548 char *owl_fmtext_get_text(owl_fmtext *f) 526 549 { … … 536 559 } 537 560 561 /* Free all memory allocated by the object */ 538 562 void owl_fmtext_free(owl_fmtext *f) 539 563 { … … 543 567 } 544 568 545 569 /* Make a copy of the fmtext 'src' into 'dst' */ 546 570 void owl_fmtext_copy(owl_fmtext *dst, owl_fmtext *src) 547 571 { 572 int mallocsize; 573 574 if (src->textlen==0) { 575 mallocsize=5; 576 } else { 577 mallocsize=src->textlen+2; 578 } 548 579 dst->textlen=src->textlen; 549 dst->textbuff=owl_malloc( src->textlen+5);550 dst->fmbuff=owl_malloc( src->textlen+5);551 dst->colorbuff=owl_malloc( src->textlen+5);580 dst->textbuff=owl_malloc(mallocsize); /* valgrind suspcious line */ 581 dst->fmbuff=owl_malloc(mallocsize); 582 dst->colorbuff=owl_malloc(mallocsize); 552 583 memcpy(dst->textbuff, src->textbuff, src->textlen); 553 584 memcpy(dst->fmbuff, src->fmbuff, src->textlen); … … 555 586 } 556 587 557 558 588 /* highlight all instance of "string". Return the number of 559 * instances found. This is case insensitive.589 * instances found. This is a case insensitive search. 560 590 */ 561 591 int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string) … … 582 612 } 583 613 584 /* return 1 if the string is found, 0 if not. This is case585 * insensitive 614 /* return 1 if the string is found, 0 if not. This is a case 615 * insensitive search. 586 616 */ 587 617 int owl_fmtext_search(owl_fmtext *f, char *string)
Note: See TracChangeset
for help on using the changeset viewer.