- Timestamp:
- Mar 28, 2007, 10:54:33 PM (17 years ago)
- Branches:
- master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 7f33c18
- Parents:
- af9b92e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fmtext.c
ra387d12e rc2c5c77 12 12 f->textbuff=owl_malloc(5); 13 13 f->fmbuff=owl_malloc(5); 14 f->fgcolorbuff=owl_malloc(5 );15 f->bgcolorbuff=owl_malloc(5 );14 f->fgcolorbuff=owl_malloc(5 * sizeof(short)); 15 f->bgcolorbuff=owl_malloc(5 * sizeof(short)); 16 16 f->textbuff[0]=0; 17 17 f->fmbuff[0]=OWL_FMTEXT_ATTR_NONE; … … 60 60 int i; 61 61 for (i=first; i<=last; i++) { 62 f->fgcolorbuff[i]=( unsigned char)color;62 f->fgcolorbuff[i]=(short)color; 63 63 } 64 64 } … … 68 68 int i; 69 69 for (i=first; i<=last; i++) { 70 f->bgcolorbuff[i]=( unsigned char)color;70 f->bgcolorbuff[i]=(short)color; 71 71 } 72 72 } … … 77 77 f->textbuff=owl_realloc(f->textbuff, newlen+1); 78 78 f->fmbuff=owl_realloc(f->fmbuff, newlen+1); 79 f->fgcolorbuff=owl_realloc(f->fgcolorbuff, newlen+1);80 f->bgcolorbuff=owl_realloc(f->bgcolorbuff, newlen+1);79 f->fgcolorbuff=owl_realloc(f->fgcolorbuff, (newlen+1) * sizeof(short)); 80 f->bgcolorbuff=owl_realloc(f->bgcolorbuff, (newlen+1) * sizeof(short)); 81 81 f->bufflen = newlen+1; 82 82 } … … 151 151 j=f->textlen; 152 152 for(i=0; i<j; i++) { 153 if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = color;153 if (f->fgcolorbuff[i]==OWL_COLOR_DEFAULT) f->fgcolorbuff[i] = (short)color; 154 154 } 155 155 } … … 162 162 j=f->textlen; 163 163 for(i=0; i<j; i++) { 164 if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = color;164 if (f->bgcolorbuff[i]==OWL_COLOR_DEFAULT) f->bgcolorbuff[i] = (short)color; 165 165 } 166 166 } … … 230 230 /* find the last char with the current format and color */ 231 231 trans1=owl_util_find_trans(f->fmbuff+position, len-position); 232 trans2=owl_util_find_trans (f->fgcolorbuff+position, len-position);233 trans3=owl_util_find_trans (f->bgcolorbuff+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 234 235 235 lastsame = (trans1 < trans2) ? trans1 : trans2; … … 252 252 /* warning, this is sort of a hack */ 253 253 if (owl_global_get_hascolors(&g)) { 254 int fg, bg; 255 short pair; 254 short fg, bg, pair; 256 255 fg = f->fgcolorbuff[position]; 257 256 bg = f->bgcolorbuff[position]; … … 259 258 pair = owl_fmtext_get_colorpair(fg, bg); 260 259 if (pair != -1) { 261 w attron(w, COLOR_PAIR(pair));260 wcolor_set(w,pair,NULL); 262 261 } 263 262 } … … 402 401 dst->textbuff=owl_malloc(mallocsize); 403 402 dst->fmbuff=owl_malloc(mallocsize); 404 dst->fgcolorbuff=owl_malloc(mallocsize );405 dst->bgcolorbuff=owl_malloc(mallocsize );403 dst->fgcolorbuff=owl_malloc(mallocsize * sizeof(short)); 404 dst->bgcolorbuff=owl_malloc(mallocsize * sizeof(short)); 406 405 memcpy(dst->textbuff, src->textbuff, src->textlen+1); 407 406 memcpy(dst->fmbuff, src->fmbuff, src->textlen); 408 memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen );409 memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen );407 memcpy(dst->fgcolorbuff, src->fgcolorbuff, src->textlen * sizeof(short)); 408 memcpy(dst->bgcolorbuff, src->bgcolorbuff, src->textlen * sizeof(short)); 410 409 } 411 410 … … 678 677 { 679 678 // This could be a bitarray if we wanted to save memory. 680 int i, j, colors; 681 cpmgr->next = COLORS; 682 683 colors = COLORS + 1; // 1 to account for "default". 684 cpmgr->pairs = owl_malloc(colors * sizeof(int*)); 685 for(i = 0; i < colors; i++) { 686 // Because we're going to have a pair set for any fg and the 687 // default bg, we don't need to account for default here. 688 cpmgr->pairs[i] = owl_malloc(COLORS * sizeof(int)); 689 for(j = 0; j < COLORS; j++) { 679 short i, j; 680 cpmgr->next = 8; 681 682 // The test is <= because we allocate COLORS+1 entries. 683 cpmgr->pairs = owl_malloc((COLORS+1) * sizeof(short*)); 684 for(i = 0; i <= COLORS; i++) { 685 cpmgr->pairs[i] = owl_malloc((COLORS+1) * sizeof(short)); 686 for(j = 0; j <= COLORS; j++) { 690 687 cpmgr->pairs[i][j] = -1; 691 688 } 689 } 690 for(i = 0; i < 8; i++) { 691 short fg, bg; 692 pair_content(i, &fg, &bg); 693 cpmgr->pairs[fg+1][bg+1] = i; 692 694 } 693 695 } … … 696 698 void owl_fmtext_reset_colorpairs() 697 699 { 698 int i, j, colors;700 short i, j; 699 701 owl_colorpair_mgr *cpmgr = owl_global_get_colorpair_mgr(&g); 700 cpmgr->next = COLORS;701 702 colors = COLORS + 1; // 1 to account for "default".703 for(i = 0; i < colors; i++) {704 for(j = 0; j < COLORS; j++) {702 cpmgr->next = 8; 703 704 // The test is <= because we allocated COLORS+1 entries. 705 for(i = 0; i <= COLORS; i++) { 706 for(j = 0; j <= COLORS; j++) { 705 707 cpmgr->pairs[i][j] = -1; 706 708 } 709 } 710 for(i = 0; i < 8; i++) { 711 short fg, bg; 712 pair_content(i, &fg, &bg); 713 cpmgr->pairs[fg+1][bg+1] = i; 707 714 } 708 715 } … … 723 730 #endif 724 731 725 if (bg == default_bg) { 726 // default bg -> use color pairs initialized by owl.c 727 pair = fg; 728 } else { 729 // looking for a pair we already set up for this draw. 730 cpmgr = owl_global_get_colorpair_mgr(&g); 731 pair = cpmgr->pairs[fg+1][bg]; 732 if (!(pair != -1 && pair < cpmgr->next)) { 733 // If we didn't find a pair, search for a free one to assign. 734 // Skip the first COLORS, since they're static. 735 // If we ever get 256 color curses, this will need more thought. 736 pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1; 737 if (pair != -1) { 738 // We found a free pair, initialize it. 739 init_pair(pair, fg, bg); 740 cpmgr->pairs[fg+1][bg] = pair; 741 cpmgr->next++; 742 } else { 743 // We still don't have a pair, drop the background color. Too bad. 744 pair = fg; 745 } 732 // looking for a pair we already set up for this draw. 733 cpmgr = owl_global_get_colorpair_mgr(&g); 734 pair = cpmgr->pairs[fg+1][bg+1]; 735 if (!(pair != -1 && pair < cpmgr->next)) { 736 /* owl_global_set_needrefresh(&g);*/ 737 // If we didn't find a pair, search for a free one to assign. 738 pair = (cpmgr->next < COLOR_PAIRS) ? cpmgr->next : -1; 739 if (pair != -1) { 740 // We found a free pair, initialize it. 741 init_pair(pair, fg, bg); 742 cpmgr->pairs[fg+1][bg+1] = pair; 743 cpmgr->next++; 744 } 745 else if (bg != OWL_COLOR_DEFAULT) { 746 // We still don't have a pair, drop the background color. Too bad. 747 owl_function_debugmsg("colorpairs: color shortage - dropping background color."); 748 pair = owl_fmtext_get_colorpair(fg, OWL_COLOR_DEFAULT); 749 } 750 else { 751 // We still don't have a pair, defaults all around. 752 owl_function_debugmsg("colorpairs: color shortage - dropping foreground and background color."); 753 pair = 0; 746 754 } 747 755 }
Note: See TracChangeset
for help on using the changeset viewer.