Changeset 1fd0b25 for fmtext.c


Ignore:
Timestamp:
Aug 17, 2002, 10:31:35 AM (22 years ago)
Author:
James M. Kretchmar <kretch@mit.edu>
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:
37c27cf
Parents:
8509c08
Message:
Added the 'search' command.
'/' is a keybinding for 'search'
'?' is a keybinding for 'search -r'
Fixed stristr, which was completely broken
renamed owl_fmtext_ztext_stylestrip to owl_function_ztext_styletsrip
     and put it in functions.c
File:
1 edited

Legend:

Unmodified
Added
Removed
  • fmtext.c

    re1c4636 r1fd0b25  
    1919  for (i=first; i<=last; i++) {
    2020    f->fmbuff[i]=(unsigned char) attr;
     21  }
     22}
     23
     24void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last) {
     25  int i;
     26  for (i=first; i<=last; i++) {
     27    f->fmbuff[i]|=(unsigned char) attr;
    2128  }
    2229}
     
    332339}
    333340
    334 /* strips formatting from ztext and returns the unformatted text.
    335  * caller is responsible for freeing. */
    336 char *owl_fmtext_ztext_stylestrip(char *zt) {
    337   owl_fmtext fm;
    338   char *plaintext;
    339 
    340   owl_fmtext_init_null(&fm);
    341   owl_fmtext_append_ztext(&fm, zt);
    342   plaintext = owl_fmtext_print_plain(&fm);
    343   owl_fmtext_free(&fm);
    344   return(plaintext);
    345 }
    346 
    347341
    348342void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) {
     
    516510  memcpy(dst->colorbuff, src->colorbuff, src->textlen);
    517511}
     512
     513
     514int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string) {
     515  /* highlight all instance of "string".  Return the number of
     516   * instances found.  This is case insensitive. */
     517
     518  int found, len;
     519  char *ptr1, *ptr2;
     520
     521  len=strlen(string);
     522  found=0;
     523  ptr1=f->textbuff;
     524  while (ptr1-f->textbuff <= f->textlen) {
     525    ptr2=stristr(ptr1, string);
     526    if (!ptr2) return(found);
     527
     528    found++;
     529    _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE,
     530                         ptr2 - f->textbuff,
     531                         ptr2 - f->textbuff + len - 1);
     532
     533    ptr1=ptr2+len;
     534  }
     535  return(found);
     536}
     537
     538int owl_fmtext_search(owl_fmtext *f, char *string) {
     539  /* return 1 if the string is found, 0 if not.  This is case
     540   *  insensitive */
     541
     542  if (stristr(f->textbuff, string)) return(1);
     543  return(0);
     544}
Note: See TracChangeset for help on using the changeset viewer.