Changes in fmtext.c [5376a95:fa3290d]
Legend:
- Unmodified
- Added
- Removed
-
fmtext.c
r5376a95 rfa3290d 8 8 void owl_fmtext_init_null(owl_fmtext *f) 9 9 { 10 f->textlen = 0; 11 f->bufflen = 5; 12 f->textbuff = owl_malloc(5); 13 f->textbuff[0] = 0; 14 f->default_attrs = OWL_FMTEXT_ATTR_NONE; 15 f->default_fgcolor = OWL_COLOR_DEFAULT; 16 f->default_fgcolor = OWL_COLOR_DEFAULT; 10 f->textlen=0; 11 f->bufflen=5; 12 f->textbuff=owl_malloc(5); 13 f->fmbuff=owl_malloc(5); 14 f->fgcolorbuff=owl_malloc(5 * sizeof(short)); 15 f->bgcolorbuff=owl_malloc(5 * sizeof(short)); 16 f->textbuff[0]=0; 17 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; 18 f->fgcolorbuff[0]=OWL_COLOR_DEFAULT; 19 f->bgcolorbuff[0]=OWL_COLOR_DEFAULT; 17 20 } 18 21 … … 21 24 void owl_fmtext_clear(owl_fmtext *f) 22 25 { 23 f->textlen = 0; 24 f->textbuff[0] = 0; 25 f->default_attrs = OWL_FMTEXT_ATTR_NONE; 26 f->default_fgcolor = OWL_COLOR_DEFAULT; 27 f->default_fgcolor = OWL_COLOR_DEFAULT; 26 f->textlen = 0; 27 f->textbuff[0] = 0; 28 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; 29 f->fgcolorbuff[0]=OWL_COLOR_DEFAULT; 30 f->bgcolorbuff[0]=OWL_COLOR_DEFAULT; 31 } 32 33 /* Internal function. Set the attribute 'attr' from index 'first' to 34 * index 'last' 35 */ 36 void _owl_fmtext_set_attr(owl_fmtext *f, int attr, int first, int last) 37 { 38 int i; 39 for (i=first; i<=last; i++) { 40 f->fmbuff[i]=(unsigned char) attr; 41 } 42 } 43 44 /* Internal function. Add the attribute 'attr' to the existing 45 * attributes from index 'first' to index 'last' 46 */ 47 void _owl_fmtext_add_attr(owl_fmtext *f, int attr, int first, int last) 48 { 49 int i; 50 for (i=first; i<=last; i++) { 51 f->fmbuff[i]|=(unsigned char) attr; 52 } 53 } 54 55 /* Internal function. Set the color to be 'color' from index 'first' 56 * to index 'last 57 */ 58 void _owl_fmtext_set_fgcolor(owl_fmtext *f, int color, int first, int last) 59 { 60 int i; 61 for (i=first; i<=last; i++) { 62 f->fgcolorbuff[i]=(short)color; 63 } 64 } 65 66 void _owl_fmtext_set_bgcolor(owl_fmtext *f, int color, int first, int last) 67 { 68 int i; 69 for (i=first; i<=last; i++) { 70 f->bgcolorbuff[i]=(short)color; 71 } 28 72 } 29 73 … … 31 75 { 32 76 if(newlen + 1 > f->bufflen) { 33 f->textbuff = owl_realloc(f->textbuff, newlen + 1); 77 f->textbuff=owl_realloc(f->textbuff, newlen+1); 78 f->fmbuff=owl_realloc(f->fmbuff, newlen+1); 79 f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short)); 80 f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short)); 34 81 f->bufflen = newlen+1; 35 82 } 36 83 } 37 84 38 int _owl_fmtext_is_format_char(gunichar c) /*noproto*/39 {40 if ((c & ~OWL_FMTEXT_UC_ATTR_MASK) == OWL_FMTEXT_UC_ATTR) return 1;41 if ((c & ~(OWL_FMTEXT_UC_ALLCOLOR_MASK)) == OWL_FMTEXT_UC_COLOR_BASE) return 1;42 return 0;43 }44 85 /* append text to the end of 'f' with attribute 'attr' and color 45 86 * 'color' 46 87 */ 47 void owl_fmtext_append_attr(owl_fmtext *f, char *text, char attr, short fgcolor, short bgcolor) 48 { 49 char attrbuff[6]; 50 int newlen, a = 0, fg = 0, bg = 0; 51 52 if (attr != OWL_FMTEXT_ATTR_NONE) a=1; 53 if (fgcolor != OWL_COLOR_DEFAULT) fg=1; 54 if (bgcolor != OWL_COLOR_DEFAULT) bg=1; 55 56 /* Plane-16 characters in UTF-8 are 4 bytes long. */ 57 newlen = strlen(f->textbuff) + strlen(text) + (8 * (a + fg + bg)); 88 void owl_fmtext_append_attr(owl_fmtext *f, char *text, int attr, int fgcolor, int bgcolor) 89 { 90 int newlen; 91 newlen=strlen(f->textbuff)+strlen(text); 58 92 _owl_fmtext_realloc(f, newlen); 59 60 /* Set attributes */61 if (a) {62 memset(attrbuff,0,6);63 g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);64 strcat(f->textbuff, attrbuff);65 }66 if (fg) {67 memset(attrbuff,0,6);68 g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);69 strcat(f->textbuff, attrbuff);70 }71 if (bg) {72 memset(attrbuff,0,6);73 g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);74 strcat(f->textbuff, attrbuff);75 }76 93 77 94 strcat(f->textbuff, text); 78 79 /* Reset attributes */ 80 if (bg) strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT); 81 if (fg) strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT); 82 if (a) strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE); 95 _owl_fmtext_set_attr(f, attr, f->textlen, newlen); 96 _owl_fmtext_set_fgcolor(f, fgcolor, f->textlen, newlen); 97 _owl_fmtext_set_bgcolor(f, bgcolor, f->textlen, newlen); 83 98 f->textlen=newlen; 84 99 } … … 114 129 } 115 130 116 /* Add the attribute 'attr' to the default atts for thetext in 'f' */117 void owl_fmtext_addattr(owl_fmtext *f, charattr)131 /* Add the attribute 'attr' to all text in 'f' */ 132 void owl_fmtext_addattr(owl_fmtext *f, int attr) 118 133 { 119 134 /* add the attribute to all text */ 120 f->default_attrs |= attr; 121 } 122 123 /* Set the default foreground color for this fmtext to 'color'. 124 * Only affects text that is colored default. 135 int i, j; 136 137 j=f->textlen; 138 for (i=0; i<j; i++) { 139 f->fmbuff[i] |= attr; 140 } 141 } 142 143 /* Anywhere the color is NOT ALREDY SET, set the color to 'color'. 144 * Other colors are left unchanged 125 145 */ 126 146 void owl_fmtext_colorize(owl_fmtext *f, int color) 127 147 { 128 f->default_fgcolor = color; 129 } 130 131 /* Set the default foreground color for this fmtext to 'color'. 132 * Only affects text that is colored default. 133 */ 148 /* everywhere the fgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */ 149 int i, j; 150 151 j=f->textlen; 152 for(i=0; i<j; i++) { 153 if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color; 154 } 155 } 156 134 157 void owl_fmtext_colorizebg(owl_fmtext *f, int color) 135 158 { 136 f->default_bgcolor = color; 137 } 138 139 /* Internal function. Parse attrbute character. */ 140 void _owl_fmtext_update_attributes(gunichar c, char *attr, short *fgcolor, short *bgcolor) /*noproto*/ 141 { 142 if ((c & OWL_FMTEXT_UC_ATTR) == OWL_FMTEXT_UC_ATTR) { 143 *attr = c & OWL_FMTEXT_UC_ATTR_MASK; 144 } 145 else if ((c & OWL_FMTEXT_UC_FGCOLOR) == OWL_FMTEXT_UC_FGCOLOR) { 146 *fgcolor = (c == OWL_FMTEXT_UC_FGDEFAULT 147 ? OWL_COLOR_DEFAULT 148 : c & OWL_FMTEXT_UC_COLOR_MASK); 149 } 150 else if ((c & OWL_FMTEXT_UC_BGCOLOR) == OWL_FMTEXT_UC_BGCOLOR) { 151 *bgcolor = (c == OWL_FMTEXT_UC_BGDEFAULT 152 ? OWL_COLOR_DEFAULT 153 : c & OWL_FMTEXT_UC_COLOR_MASK); 154 } 155 } 156 157 /* Internal function. Scan for attribute characters. */ 158 void _owl_fmtext_scan_attributes(owl_fmtext *f, int start, char *attr, short *fgcolor, short *bgcolor) /*noproto*/ 159 { 160 char *p; 161 p = strchr(f->textbuff, OWL_FMTEXT_UC_STARTBYTE_UTF8); 162 while (p && p < f->textbuff + start) { 163 _owl_fmtext_update_attributes(g_utf8_get_char(p), attr, fgcolor, bgcolor); 164 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 165 } 166 } 159 /* everywhere the bgcolor is OWL_COLOR_DEFAULT, change it to be 'color' */ 160 int i, j; 161 162 j=f->textlen; 163 for(i=0; i<j; i++) { 164 if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color; 165 } 166 } 167 167 168 168 /* Internal function. Append text from 'in' between index 'start' and 169 169 * 'stop' to the end of 'f' 170 170 */ 171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) /*noproto*/ 172 { 173 char attrbuff[6]; 174 int newlen, a = 0, fg = 0, bg = 0; 175 char attr = 0; 176 short fgcolor = OWL_COLOR_DEFAULT; 177 short bgcolor = OWL_COLOR_DEFAULT; 178 179 _owl_fmtext_scan_attributes(in, start, &attr, &fgcolor, &bgcolor); 180 if (attr != OWL_FMTEXT_ATTR_NONE) a=1; 181 if (fgcolor != OWL_COLOR_DEFAULT) fg=1; 182 if (bgcolor != OWL_COLOR_DEFAULT) bg=1; 183 184 /* We will reset to defaults after appending the text. We may need 185 to set initial attributes. */ 186 newlen=strlen(f->textbuff)+(stop-start+1) + (4 * (a + fg + bg)) + 12; 171 void _owl_fmtext_append_fmtext(owl_fmtext *f, owl_fmtext *in, int start, int stop) 172 { 173 int newlen, i; 174 175 newlen=strlen(f->textbuff)+(stop-start+1); 187 176 _owl_fmtext_realloc(f, newlen); 188 177 189 if (a) {190 memset(attrbuff,0,6);191 g_unichar_to_utf8(OWL_FMTEXT_UC_ATTR | attr, attrbuff);192 strcat(f->textbuff, attrbuff);193 }194 if (fg) {195 memset(attrbuff,0,6);196 g_unichar_to_utf8(OWL_FMTEXT_UC_FGCOLOR | fgcolor, attrbuff);197 strcat(f->textbuff, attrbuff);198 }199 if (bg) {200 memset(attrbuff,0,6);201 g_unichar_to_utf8(OWL_FMTEXT_UC_BGCOLOR | bgcolor, attrbuff);202 strcat(f->textbuff, attrbuff);203 }204 205 178 strncat(f->textbuff, in->textbuff+start, stop-start+1); 206 207 /* Reset attributes */208 strcat(f->textbuff, OWL_FMTEXT_UTF8_BGDEFAULT);209 strcat(f->textbuff, OWL_FMTEXT_UTF8_FGDEFAULT);210 strcat(f->textbuff, OWL_FMTEXT_UTF8_ATTR_NONE);211 212 179 f->textbuff[newlen]='\0'; 180 for (i=start; i<=stop; i++) { 181 f->fmbuff[f->textlen+(i-start)]=in->fmbuff[i]; 182 f->fgcolorbuff[f->textlen+(i-start)]=in->fgcolorbuff[i]; 183 f->bgcolorbuff[f->textlen+(i-start)]=in->bgcolorbuff[i]; 184 } 213 185 f->textlen=newlen; 214 186 } … … 235 207 char *owl_fmtext_print_plain(owl_fmtext *f) 236 208 { 237 return owl_strip_format_chars(f->textbuff); 238 } 239 240 void _owl_fmtext_wattrset(WINDOW *w, int attrs) /*noproto*/ 241 { 242 wattrset(w, A_NORMAL); 243 if (attrs & OWL_FMTEXT_ATTR_BOLD) wattron(w, A_BOLD); 244 if (attrs & OWL_FMTEXT_ATTR_REVERSE) wattron(w, A_REVERSE); 245 if (attrs & OWL_FMTEXT_ATTR_UNDERLINE) wattron(w, A_UNDERLINE); 246 } 209 return(owl_strdup(f->textbuff)); 210 } 211 247 212 /* add the formatted text to the curses window 'w'. The window 'w' 248 213 * must already be initiatlized with curses 249 214 */ 250 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w, int do_search) 251 { 252 /* char *tmpbuff; */ 253 /* int position, trans1, trans2, trans3, len, lastsame; */ 254 char *s, *p; 255 char attr; 256 short fg, bg; 257 int search_results, search_len; 258 215 void owl_fmtext_curs_waddstr(owl_fmtext *f, WINDOW *w) 216 { 217 char *tmpbuff; 218 int position, trans1, trans2, trans3, len, lastsame; 219 259 220 if (w==NULL) { 260 221 owl_function_debugmsg("Hit a null window in owl_fmtext_curs_waddstr."); … … 262 223 } 263 224 264 search_results = (do_search 265 ? owl_fmtext_search(f, owl_global_get_search_string(&g)) 266 : NULL); 267 if (search_results) search_len = strlen(owl_global_get_search_string(&g)); 268 s = f->textbuff; 269 /* Set default attributes. */ 270 attr = f->default_attrs; 271 fg = f->default_fgcolor; 272 bg = f->default_bgcolor; 273 _owl_fmtext_wattrset(w, attr); 274 if (owl_global_get_hascolors(&g)) { 275 short pair; 276 pair = owl_fmtext_get_colorpair(fg, bg); 277 if (pair != -1) { 278 wcolor_set(w,pair,NULL); 279 } 280 } 281 282 /* Find next possible format character. */ 283 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 284 while(p) { 285 if (_owl_fmtext_is_format_char(g_utf8_get_char(p))) { 286 /* Deal with all text from last insert to here. */ 287 char tmp; 288 289 tmp = p[0]; 290 p[0] = '\0'; 291 if (search_results) { 292 /* Search is active, so highlight search results. */ 293 char tmp2, *ss; 294 ss = stristr(s, owl_global_get_search_string(&g)); 295 while (ss) { 296 /* Found search string, highlight it. */ 297 298 tmp2 = ss[0]; 299 ss[0] = '\0'; 300 waddstr(w, s); 301 ss[0] = tmp2; 302 303 _owl_fmtext_wattrset(w,attr ^ A_REVERSE); 304 305 tmp2 = ss[search_len]; 306 ss[search_len] = '\0'; 307 waddstr(w, ss); 308 ss[search_len] = tmp2; 309 310 _owl_fmtext_wattrset(w,attr); 311 312 s = ss + search_len; 313 ss = stristr(s, owl_global_get_search_string(&g)); 314 } 315 } 316 /* Deal with remaining part of string. */ 317 waddstr(w, s); 318 p[0] = tmp; 319 320 /* Deal with new attributes. Initialize to defaults, then 321 process all consecutive formatting characters. */ 322 attr = f->default_attrs; 323 fg = f->default_fgcolor; 324 bg = f->default_bgcolor; 325 while (p && _owl_fmtext_is_format_char(g_utf8_get_char(p))) { 326 _owl_fmtext_update_attributes(g_utf8_get_char(p), &attr, &fg, &bg); 327 p = g_utf8_next_char(p); 328 } 329 _owl_fmtext_wattrset(w, attr | f->default_attrs); 330 if (owl_global_get_hascolors(&g)) { 331 if (fg == OWL_COLOR_DEFAULT) fg = f->default_fgcolor; 332 if (bg == OWL_COLOR_DEFAULT) bg = f->default_bgcolor; 333 short pair; 334 pair = owl_fmtext_get_colorpair(fg, bg); 335 if (pair != -1) { 336 wcolor_set(w,pair,NULL); 337 } 338 } 339 /* Advance to next non-formatting character. */ 340 s = p; 341 p = strchr(s, OWL_FMTEXT_UC_STARTBYTE_UTF8); 342 } 343 else { 344 p = strchr(p+1, OWL_FMTEXT_UC_STARTBYTE_UTF8); 345 } 346 } 347 if (s) { 348 waddstr(w, s); 349 } 225 tmpbuff=owl_malloc(f->textlen+10); 226 227 position=0; 228 len=f->textlen; 229 while (position<=len) { 230 /* find the last char with the current format and color */ 231 trans1=owl_util_find_trans(f->fmbuff+position, len-position); 232 trans2=owl_util_find_trans_short(f->fgcolorbuff+position, len-position); 233 trans3=owl_util_find_trans_short(f->bgcolorbuff+position, len-position); 234 235 lastsame = (trans1 < trans2) ? trans1 : trans2; 236 lastsame = (lastsame < trans3) ? lastsame : trans3; 237 lastsame += position; 238 239 /* set the format */ 240 wattrset(w, A_NORMAL); 241 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_BOLD) { 242 wattron(w, A_BOLD); 243 } 244 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_REVERSE) { 245 wattron(w, A_REVERSE); 246 } 247 if (f->fmbuff[position] & OWL_FMTEXT_ATTR_UNDERLINE) { 248 wattron(w, A_UNDERLINE); 249 } 250 251 /* set the color */ 252 /* warning, this is sort of a hack */ 253 if (owl_global_get_hascolors(&g)) { 254 short fg, bg, pair; 255 fg = f->fgcolorbuff[position]; 256 bg = f->bgcolorbuff[position]; 257 258 pair = owl_fmtext_get_colorpair(fg, bg); 259 if (pair != -1) { 260 wcolor_set(w,pair,NULL); 261 } 262 } 263 264 /* add the text */ 265 strncpy(tmpbuff, f->textbuff + position, lastsame-position+1); 266 tmpbuff[lastsame-position+1]='\0'; 267 waddstr(w, tmpbuff); 268 269 position=lastsame+1; 270 } 271 owl_free(tmpbuff); 350 272 } 351 273 … … 360 282 361 283 /* find the starting line */ 362 ptr1 = in->textbuff; 363 for (i = 0; i < aline; i++) { 364 ptr1 = strchr(ptr1, '\n'); 365 if (!ptr1) return(-1); 366 ptr1++; 367 } 368 284 ptr1=in->textbuff; 285 if (aline!=0) { 286 for (i=0; i<aline; i++) { 287 ptr1=strchr(ptr1, '\n'); 288 if (!ptr1) return(-1); 289 ptr1++; 290 } 291 } 369 292 /* ptr1 now holds the starting point */ 370 293 371 294 /* copy in the next 'lines' lines */ 372 if (lines <1) return(-1);373 374 for (i = 0; i <lines; i++) {375 offset = ptr1 -in->textbuff;376 ptr2 =strchr(ptr1, '\n');295 if (lines<1) return(-1); 296 297 for (i=0; i<lines; i++) { 298 offset=ptr1-in->textbuff; 299 ptr2=strchr(ptr1, '\n'); 377 300 if (!ptr2) { 378 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen) -1);301 _owl_fmtext_append_fmtext(out, in, offset, (in->textlen)-1); 379 302 return(-1); 380 303 } 381 _owl_fmtext_append_fmtext(out, in, offset, (ptr2 - ptr1) +offset);382 ptr1 = ptr2 +1;304 _owl_fmtext_append_fmtext(out, in, offset, (ptr2-ptr1)+offset); 305 ptr1=ptr2+1; 383 306 } 384 307 return(0); … … 392 315 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out) 393 316 { 394 char *ptr _s, *ptr_e, *ptr_c, *last;395 int col, st, padding, chwidth;317 char *ptr1, *ptr2, *last; 318 int len, offset; 396 319 397 320 last=in->textbuff+in->textlen-1; 398 ptr _s=in->textbuff;399 while (ptr _s <=last) {400 ptr _e=strchr(ptr_s, '\n');401 if (!ptr _e) {321 ptr1=in->textbuff; 322 while (ptr1<=last) { 323 ptr2=strchr(ptr1, '\n'); 324 if (!ptr2) { 402 325 /* but this shouldn't happen if we end in a \n */ 403 326 break; 404 327 } 405 328 406 if (ptr _e == ptr_s) {329 if (ptr2==ptr1) { 407 330 owl_fmtext_append_normal(out, "\n"); 408 ++ptr_s;331 ptr1++; 409 332 continue; 410 333 } 411 334 412 col = 0; 413 st = 0; 414 padding = 0; 415 ptr_c = ptr_s; 416 while(col <= bcol && ptr_c < ptr_e) { 417 gunichar c = g_utf8_get_char(ptr_c); 418 if (!_owl_fmtext_is_format_char(c)) { 419 chwidth = wcwidth(c); 420 421 if (col + chwidth > bcol) 422 break; 423 if (col >= acol) { 424 if (st == 0) { 425 ptr_s = ptr_c; 426 padding = col - acol; 427 ++st; 428 } 429 } 430 col += chwidth; 431 chwidth = 0; 432 } 433 ptr_c = g_utf8_next_char(ptr_c); 434 } 435 if (st) { 436 /* lead padding */ 437 owl_fmtext_append_spaces(out, padding); 438 if (ptr_c[0] & 0x80) { 439 if (col + chwidth == bcol) 440 ptr_c = g_utf8_next_char(ptr_c); 441 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - 1 - in->textbuff); 442 owl_fmtext_append_normal(out, "\n"); 443 } 444 else { 445 _owl_fmtext_append_fmtext(out, in, ptr_s - in->textbuff, ptr_c - in->textbuff); 446 } 447 } 448 else { 335 /* we need to check that we won't run over here */ 336 len=bcol-acol; 337 if (len > (ptr2-(ptr1+acol))) { 338 /* the whole line fits with room to spare, don't take a full 'len' */ 339 len=ptr2-(ptr1+acol); 340 } 341 if (len>last-ptr1) { 342 /* the whole rest of the text fits with room to spare, adjust for it */ 343 len-=(last-ptr1); 344 } 345 if (len<=0) { 346 /* saftey check */ 449 347 owl_fmtext_append_normal(out, "\n"); 450 } 451 ptr_s = g_utf8_next_char(ptr_e); 348 ptr1=ptr2+1; 349 continue; 350 } 351 352 offset=ptr1-in->textbuff; 353 _owl_fmtext_append_fmtext(out, in, offset+acol, offset+acol+len); 354 355 ptr1=ptr2+1; 452 356 } 453 357 } … … 477 381 478 382 /* set the charater at 'index' to be 'char'. If index is out of 479 * bounds don't do anything. If c or char at index is not ASCII, don't 480 * do anything because it's not UTF-8 safe. */ 481 void owl_fmtext_set_char(owl_fmtext *f, int index, char ch) 383 * bounds don't do anything */ 384 void owl_fmtext_set_char(owl_fmtext *f, int index, int ch) 482 385 { 483 386 if ((index < 0) || (index > f->textlen-1)) return; 484 /* NOT ASCII*/485 if (f->textbuff[index] & 0x80 || ch & 0x80) return;486 387 f->textbuff[index]=ch; 487 388 } … … 499 400 dst->textlen=src->textlen; 500 401 dst->textbuff=owl_malloc(mallocsize); 402 dst->fmbuff=owl_malloc(mallocsize); 403 dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short)); 404 dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short)); 501 405 memcpy(dst->textbuff, src->textbuff, src->textlen+1); 502 dst->default_attrs = src->default_attrs; 503 dst->default_fgcolor = src->default_fgcolor; 504 dst->default_bgcolor = src->default_bgcolor; 406 memcpy(dst->fmbuff, src->fmbuff, src->textlen); 407 memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short)); 408 memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short)); 409 } 410 411 /* highlight all instances of "string". Return the number of 412 * instances found. This is a case insensitive search. 413 */ 414 int owl_fmtext_search_and_highlight(owl_fmtext *f, char *string) 415 { 416 417 int found, len; 418 char *ptr1, *ptr2; 419 420 len=strlen(string); 421 found=0; 422 ptr1=f->textbuff; 423 while (ptr1-f->textbuff <= f->textlen) { 424 ptr2=stristr(ptr1, string); 425 if (!ptr2) return(found); 426 427 found++; 428 _owl_fmtext_add_attr(f, OWL_FMTEXT_ATTR_REVERSE, 429 ptr2 - f->textbuff, 430 ptr2 - f->textbuff + len - 1); 431 432 ptr1=ptr2+len; 433 } 434 return(found); 505 435 } 506 436 … … 510 440 int owl_fmtext_search(owl_fmtext *f, char *string) 511 441 { 442 512 443 if (stristr(f->textbuff, string)) return(1); 513 444 return(0); … … 750 681 { 751 682 if (f->textbuff) owl_free(f->textbuff); 683 if (f->fmbuff) owl_free(f->fmbuff); 684 if (f->fgcolorbuff) owl_free(f->fgcolorbuff); 685 if (f->bgcolorbuff) owl_free(f->bgcolorbuff); 752 686 } 753 687
Note: See TracChangeset
for help on using the changeset viewer.