/* Internal function. Scan for attribute characters. */ static void _owl_fmtext_scan_attributes(const owl_fmtext *f, int start, char *attr, short *fgcolor, short *bgcolor) { const char *p; p = strchr(f->textbuff, OWL_FMTEXT_UC_STARTBYTE_UTF8); while (p && p < f->textbuff + start) { _owl_fmtext_update_attributes(g_utf8_get_char(p), attr, fgcolor, bgcolor); p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); } }
/* 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); }
/* add the formatted text to the curses window 'w'. The window 'w' * must already be initiatlized with curses */ void _owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) /*noproto*/ { /* char *tmpbuff; */ /* int position, trans1, trans2, trans3, len, lastsame; */ char *s, *p; char attr; short fg, bg, pair; int search_results, search_len; if (w==NULL) { owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr."); return; } search_results = (do_search ? owl_fmtext_search(f, owl_global_get_search_string(&g)) : 0); search_len = (search_results ? strlen(owl_global_get_search_string(&g)) : 0); 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 (search_results) { /* Search is active, so highlight search results. */ char tmp2, *ss; ss = stristr(s, owl_global_get_search_string(&g)); while (ss) { /* Found search string, highlight it. */ tmp2 = ss[0]; ss[0] = '\0'; waddstr(w, s); ss[0] = tmp2; _owl_fmtext_wattrset(w, attr ^ OWL_FMTEXT_ATTR_REVERSE); _owl_fmtext_wcolor_set(w, pair); tmp2 = ss[search_len]; ss[search_len] = '\0'; waddstr(w, ss); ss[search_len] = tmp2; _owl_fmtext_wattrset(w, attr); _owl_fmtext_wcolor_set(w, pair); s = ss + search_len; ss = stristr(s, owl_global_get_search_string(&g)); } } /* 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 (p && 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); } }