Changeset b2b0773 for fmtext.c


Ignore:
Timestamp:
Jun 9, 2003, 10:54:18 AM (18 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
Branches:
master, barnowl_perlaim, debian, owl, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
6bf73ce
Parents:
d559df9
Message:
Changes to help build on OSX
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    rd559df9 rb2b0773  
    55static const char fileIdent[] = "$Id$";
    66
     7/* initialize an fmtext with no data */
    78void owl_fmtext_init_null(owl_fmtext *f)
    89{
     
    1516}
    1617
    17 
     18/* Internal function.  Set the attribute 'attr' from index 'first' to
     19 * index 'last'
     20 */
    1821void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last)
    1922{
     
    2427}
    2528
     29/* Internal function.  Add the attribute 'attr' to the existing
     30 * attributes from index 'first' to index 'last'
     31 */
    2632void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last)
    2733{
     
    3238}
    3339
     40/* Internal function.  Set the color to be 'color' from index 'first'
     41 * to index 'last
     42 */
    3443void _owl_fmtext_set_color(owl_fmtext *f, int color, int first, int last)
    3544{
     
    4049}
    4150
    42 
     51/* append text to the end of 'f' with attribute 'attr' and color
     52 * 'color'
     53 */
    4354void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int color)
    4455{
     
    5667}
    5768
    58 
     69/* Append normal, uncolored text 'text' to 'f' */
    5970void owl_fmtext_append_normal(owl_fmtext *f, char *text)
    6071{
     
    6273}
    6374
     75/* Append normal text 'text' to 'f' with color 'color' */
    6476void owl_fmtext_append_normal_color(owl_fmtext *f, char *text, int color)
    6577{
     
    6779}
    6880
    69 
     81/* Append bold text 'text' to 'f' */
    7082void owl_fmtext_append_bold(owl_fmtext *f, char *text)
    7183{
     
    7385}
    7486
    75 
     87/* Append reverse video text 'text' to 'f' */
    7688void owl_fmtext_append_reverse(owl_fmtext *f, char *text)
    7789{
     
    7991}
    8092
    81 
     93/* Append reversed and bold, uncolored text 'text' to 'f' */
    8294void owl_fmtext_append_reversebold(owl_fmtext *f, char *text)
    8395{
     
    8597}
    8698
    87 
     99/* Add the attribute 'attr' to all text in 'f' */
    88100void owl_fmtext_addattr(owl_fmtext *f, int attr)
    89101{
     
    97109}
    98110
     111/* Anywhere the color is NOT ALREDY SET, set the color to 'color'.
     112 * Other colors are left unchanged
     113 */
    99114void owl_fmtext_colorize(owl_fmtext *f, int color)
    100115{
     
    108123}
    109124
    110 
     125/* Append the text 'text' to 'f' and interpret the zephyr style
     126 * formatting syntax to set appropriate attributes.
     127 */
    111128void owl_fmtext_append_ztext(owl_fmtext *f, char *text)
    112129{
     
    293310    }
    294311  }
    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 */
    300317void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop)
    301318{
     
    316333}
    317334
     335/* append fmtext 'in' to 'f' */
    318336void owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in)
    319337{
     
    322340}
    323341
     342/* Append 'nspaces' number of spaces to the end of 'f' */
    324343void owl_fmtext_append_spaces(owl_fmtext *f, int nspaces)
    325344{
     
    358377}
    359378
    360 
    361 /* caller is responsible for freeing */
     379/* Return a plain version of the fmtext.  Caller is responsible for
     380 * freeing the return
     381 */
    362382char *owl_fmtext_print_plain(owl_fmtext *f)
    363383{
    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 */
    368390void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w)
    369391{
     
    422444
    423445
     446/* start with line 'aline' (where the first line is 0) and print
     447 * 'lines' number of lines into 'out'
     448 */
    424449int owl_fmtext_truncate_lines(owl_fmtext *in, int aline, int lines, owl_fmtext *out)
    425450{
    426   /* start with line aline (where the first line is 0) and print
    427    *  'lines' lines
    428    */
    429451  char *ptr1, *ptr2;
    430452  int i, offset;
     
    445467
    446468  for (i=0; i<lines; i++) {
    447     ptr2=strchr(ptr1, '\n');
    448469    offset=ptr1-in->textbuff;
     470    ptr2=strchr(ptr1, '\n'); /* this is a valgrind suspicious line */
    449471    if (!ptr2) {
    450       _owl_fmtext_append_fmtext(out, in, offset, in->textlen-1);
     472      _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1);
    451473      return(-1);
    452474    }
     
    457479}
    458480
    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 */
    462486void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
    463487{
     
    504528}
    505529
    506 
     530/* Return the number of lines in 'f' */
    507531int owl_fmtext_num_lines(owl_fmtext *f)
    508532{
     
    522546}
    523547
    524 
    525548char *owl_fmtext_get_text(owl_fmtext *f)
    526549{
     
    536559}
    537560
     561/* Free all memory allocated by the object */
    538562void owl_fmtext_free(owl_fmtext *f)
    539563{
     
    543567}
    544568
    545 
     569/* Make a copy of the fmtext 'src' into 'dst' */
    546570void owl_fmtext_copy(owl_fmtext *dst, owl_fmtext *src)
    547571{
     572  int mallocsize;
     573
     574  if (src->textlen==0) {
     575    mallocsize=5;
     576  } else {
     577    mallocsize=src->textlen+2;
     578  }
    548579  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);
    552583  memcpy(dst->textbuff, src->textbuff, src->textlen);
    553584  memcpy(dst->fmbuff, src->fmbuff, src->textlen);
     
    555586}
    556587
    557 
    558588/* 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.
    560590 */
    561591int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string)
     
    582612}
    583613
    584 /* return 1 if the string is found, 0 if not.  This is case
    585  *  insensitive
     614/* return 1 if the string is found, 0 if not.  This is a case
     615 *  insensitive search.
    586616 */
    587617int owl_fmtext_search(owl_fmtext *f, char *string)
Note: See TracChangeset for help on using the changeset viewer.