Ignore:
Timestamp:
Apr 25, 2006, 8:02:20 PM (15 years ago)
Author:
Sam Hocevar
Message:
  • Simplified _manage_modifiers() a bit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/cucul/import.c

    r881 r882  
    200200unsigned char _get_ansi_command(unsigned char const *buffer, int size);
    201201int _parse_tuple(unsigned int *ret, unsigned char const *buffer, int size);
    202 void _manage_modifiers(char c, int *fg, int *bg, int *save_fg, int *save_bg);
     202void _manage_modifiers(int i, int *fg, int *bg, int *save_fg, int *save_bg);
    203203
    204204static cucul_canvas_t *import_ansi(void const *data, unsigned int size)
     
    391391
    392392
    393 void _manage_modifiers(char c, int *fg, int *bg, int *save_fg, int *save_bg)
    394 {
    395     switch(c)
     393void _manage_modifiers(int i, int *fg, int *bg, int *save_fg, int *save_bg)
     394{
     395    static uint8_t const ansi2cucul[] =
     396    {
     397        CUCUL_COLOR_BLACK,
     398        CUCUL_COLOR_RED,
     399        CUCUL_COLOR_GREEN,
     400        CUCUL_COLOR_BROWN,
     401        CUCUL_COLOR_BLUE,
     402        CUCUL_COLOR_MAGENTA,
     403        CUCUL_COLOR_CYAN,
     404        CUCUL_COLOR_LIGHTGRAY
     405    };
     406
     407    if(i >= 30 && i <= 37)
     408        *fg = ansi2cucul[i - 30];
     409    else if(i == 39)
     410        *fg = CUCUL_COLOR_DEFAULT;
     411    else if(i >= 40 && i <= 47)
     412        *bg = ansi2cucul[i - 40];
     413    else if(i == 49)
     414        *bg = CUCUL_COLOR_DEFAULT;
     415    else if(i >= 90 && i <= 97)
     416        *fg = ansi2cucul[i - 90] + 8;
     417    else if(i >= 100 && i <= 107)
     418        *bg = ansi2cucul[i - 100] + 8;
     419    else switch(i)
    396420    {
    397421    case 0:
     
    399423        *bg = CUCUL_COLOR_DEFAULT;
    400424        break;
    401     case 1: // BOLD
     425    case 1: /* BOLD */
    402426        if(*fg < 8)
    403427            *fg += 8;
     
    423447        *bg = *save_bg;
    424448        break;
    425     case 30: *fg = CUCUL_COLOR_BLACK; break;
    426     case 31: *fg = CUCUL_COLOR_RED; break;
    427     case 32: *fg = CUCUL_COLOR_GREEN; break;
    428     case 33: *fg = CUCUL_COLOR_BROWN; break;
    429     case 34: *fg = CUCUL_COLOR_BLUE; break;
    430     case 35: *fg = CUCUL_COLOR_MAGENTA; break;
    431     case 36: *fg = CUCUL_COLOR_CYAN; break;
    432     case 37: *fg = CUCUL_COLOR_WHITE; break;
    433     case 39: *fg = CUCUL_COLOR_LIGHTGRAY; break;
    434     case 40: *bg = CUCUL_COLOR_BLACK; break;
    435     case 41: *bg = CUCUL_COLOR_RED; break;
    436     case 42: *bg = CUCUL_COLOR_GREEN; break;
    437     case 43: *bg = CUCUL_COLOR_BROWN; break;
    438     case 44: *bg = CUCUL_COLOR_BLUE; break;
    439     case 45: *bg = CUCUL_COLOR_MAGENTA; break;
    440     case 46: *bg = CUCUL_COLOR_CYAN; break;
    441     case 47: *bg = CUCUL_COLOR_WHITE; break;
    442     case 49: *bg = CUCUL_COLOR_BLACK; break;
    443 
    444     case 90: *fg = CUCUL_COLOR_DARKGRAY; break;
    445     case 91: *fg = CUCUL_COLOR_LIGHTRED; break;
    446     case 92: *fg = CUCUL_COLOR_LIGHTGREEN; break;
    447     case 93: *fg = CUCUL_COLOR_YELLOW; break;
    448     case 94: *fg = CUCUL_COLOR_LIGHTBLUE; break;
    449     case 95: *fg = CUCUL_COLOR_LIGHTMAGENTA; break;
    450     case 96: *fg = CUCUL_COLOR_LIGHTCYAN; break;
    451     case 97: *fg = CUCUL_COLOR_WHITE; break;
    452     case 100: *bg = CUCUL_COLOR_DARKGRAY; break;
    453     case 101: *bg = CUCUL_COLOR_LIGHTRED; break;
    454     case 102: *bg = CUCUL_COLOR_LIGHTGREEN; break;
    455     case 103: *bg = CUCUL_COLOR_YELLOW; break;
    456     case 104: *bg = CUCUL_COLOR_LIGHTBLUE; break;
    457     case 105: *bg = CUCUL_COLOR_LIGHTMAGENTA; break;
    458     case 106: *bg = CUCUL_COLOR_LIGHTCYAN; break;
    459     case 107: *bg = CUCUL_COLOR_WHITE; break;
    460 
    461449    default:
    462450        /*   printf("Unknow option to 'm' %d (%c)\n", c, IS_ALPHA(c)?c:'.'); */
Note: See TracChangeset for help on using the changeset viewer.