Ejemplo n.º 1
0
/* This is a bit of a hack, because regexec doesn't have an 'n'
 * version. */
static int _re_memcompare(const owl_regex *re, const char *string, int start, int end)
{
  int ans;
  char *tmp = g_strndup(string + start, end - start);
  ans = owl_regex_compare(re, tmp, NULL, NULL);
  g_free(tmp);
  return !ans;
}
Ejemplo n.º 2
0
/* return 1 if the string is found, 0 if not.  This is a case
 *  insensitive search.
 */
int owl_fmtext_search(const owl_fmtext *f, const owl_regex *re)
{
  if (owl_regex_compare(re, f->textbuff, NULL, NULL) == 0) return(1);
  return(0);
}
Ejemplo n.º 3
0
/* add the formatted text to the curses window 'w'.  The window 'w'
 * must already be initiatlized with curses
 */
static void _owl_fmtext_curs_waddstr(const owl_fmtext *f, WINDOW *w, int do_search)
{
  /* char *tmpbuff; */
  /* int position, trans1, trans2, trans3, len, lastsame; */
  char *s, *p;
  char attr;
  short fg, bg, pair = 0;
  
  if (w==NULL) {
    owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr.");
    return;
  }

  s = f->textbuff;
  /* Set default attributes. */
  attr = f->default_attrs;
  fg = f->default_fgcolor;
  bg = f->default_bgcolor;
  _owl_fmtext_wattrset(w, attr);
  _owl_fmtext_update_colorpair(fg, bg, &pair);
  _owl_fmtext_wcolor_set(w, pair);

  /* Find next possible format character. */
  p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
  while(p) {
    if (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
      /* Deal with all text from last insert to here. */
      char tmp;
   
      tmp = p[0];
      p[0] = '\0';
      if (owl_global_is_search_active(&g)) {
	/* Search is active, so highlight search results. */
	char tmp2;
	int start, end;
	while (owl_regex_compare(owl_global_get_search_re(&g), s, &start, &end) == 0) {
	  /* Prevent an infinite loop matching the empty string. */
	  if (end == 0)
	    break;

	  /* Found search string, highlight it. */

	  tmp2 = s[start];
	  s[start] = '\0';
	  waddstr(w, s);
	  s[start] = tmp2;

	  _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE);
	  _owl_fmtext_wcolor_set(w, pair);
	  
	  tmp2 = s[end];
	  s[end] = '\0';
	  waddstr(w, s + start);
	  s[end] = tmp2;

	  _owl_fmtext_wattrset(w, attr);
	  _owl_fmtext_wcolor_set(w, pair);

	  s += end;
	}
      }
      /* Deal with remaining part of string. */
      waddstr(w, s);
      p[0] = tmp;

      /* Deal with new attributes. Initialize to defaults, then
	 process all consecutive formatting characters. */
      attr = f->default_attrs;
      fg = f->default_fgcolor;
      bg = f->default_bgcolor;
      while (owl_fmtext_is_format_char(g_utf8_get_char(p))) {
	_owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg);
	p = g_utf8_next_char(p);
      }
      _owl_fmtext_wattrset(w, attr | f->default_attrs);
      if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor;
      if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor;
      _owl_fmtext_update_colorpair(fg, bg, &pair);
      _owl_fmtext_wcolor_set(w, pair);

      /* Advance to next non-formatting character. */
      s = p;
      p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    }
    else {
      p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8);
    }
  }
  if (s) {
    waddstr(w, s);
  }
  wbkgdset(w, 0);
}