diff options
-rw-r--r-- | src/gui_mac.c | 152 | ||||
-rw-r--r-- | src/gui_photon.c | 143 | ||||
-rw-r--r-- | src/gui_w32.c | 140 | ||||
-rw-r--r-- | src/proto/term.pro | 1 | ||||
-rw-r--r-- | src/term.c | 280 | ||||
-rw-r--r-- | src/version.c | 2 |
6 files changed, 153 insertions, 565 deletions
diff --git a/src/gui_mac.c b/src/gui_mac.c index c87456e1f6..b3f76af700 100644 --- a/src/gui_mac.c +++ b/src/gui_mac.c @@ -3705,17 +3705,6 @@ gui_mch_free_font(GuiFont font) */ } - static int -hex_digit(int c) -{ - if (isdigit(c)) - return c - '0'; - c = TOLOWER_ASC(c); - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - return -1000; -} - /* * Return the Pixel value (color) for the given color name. This routine was * pretty much taken from example code in the Silicon Graphics OSF/Motif @@ -3728,146 +3717,13 @@ gui_mch_get_color(char_u *name) /* TODO: Add support for the new named color of MacOS 8 */ RGBColor MacColor; -// guicolor_T color = 0; - - typedef struct guicolor_tTable - { - char *name; - guicolor_T color; - } guicolor_tTable; - - /* - * The comment at the end of each line is the source - * (Mac, Window, Unix) and the number is the unix rgb.txt value - */ - static guicolor_tTable table[] = - { - {"Black", RGB(0x00, 0x00, 0x00)}, - {"darkgray", RGB(0x80, 0x80, 0x80)}, /*W*/ - {"darkgrey", RGB(0x80, 0x80, 0x80)}, /*W*/ - {"Gray", RGB(0xC0, 0xC0, 0xC0)}, /*W*/ - {"Grey", RGB(0xC0, 0xC0, 0xC0)}, /*W*/ - {"lightgray", RGB(0xE0, 0xE0, 0xE0)}, /*W*/ - {"lightgrey", RGB(0xE0, 0xE0, 0xE0)}, /*W*/ - {"gray10", RGB(0x1A, 0x1A, 0x1A)}, /*W*/ - {"grey10", RGB(0x1A, 0x1A, 0x1A)}, /*W*/ - {"gray20", RGB(0x33, 0x33, 0x33)}, /*W*/ - {"grey20", RGB(0x33, 0x33, 0x33)}, /*W*/ - {"gray30", RGB(0x4D, 0x4D, 0x4D)}, /*W*/ - {"grey30", RGB(0x4D, 0x4D, 0x4D)}, /*W*/ - {"gray40", RGB(0x66, 0x66, 0x66)}, /*W*/ - {"grey40", RGB(0x66, 0x66, 0x66)}, /*W*/ - {"gray50", RGB(0x7F, 0x7F, 0x7F)}, /*W*/ - {"grey50", RGB(0x7F, 0x7F, 0x7F)}, /*W*/ - {"gray60", RGB(0x99, 0x99, 0x99)}, /*W*/ - {"grey60", RGB(0x99, 0x99, 0x99)}, /*W*/ - {"gray70", RGB(0xB3, 0xB3, 0xB3)}, /*W*/ - {"grey70", RGB(0xB3, 0xB3, 0xB3)}, /*W*/ - {"gray80", RGB(0xCC, 0xCC, 0xCC)}, /*W*/ - {"grey80", RGB(0xCC, 0xCC, 0xCC)}, /*W*/ - {"gray90", RGB(0xE5, 0xE5, 0xE5)}, /*W*/ - {"grey90", RGB(0xE5, 0xE5, 0xE5)}, /*W*/ - {"white", RGB(0xFF, 0xFF, 0xFF)}, - {"darkred", RGB(0x80, 0x00, 0x00)}, /*W*/ - {"red", RGB(0xDD, 0x08, 0x06)}, /*M*/ - {"lightred", RGB(0xFF, 0xA0, 0xA0)}, /*W*/ - {"DarkBlue", RGB(0x00, 0x00, 0x80)}, /*W*/ - {"Blue", RGB(0x00, 0x00, 0xD4)}, /*M*/ - {"lightblue", RGB(0xA0, 0xA0, 0xFF)}, /*W*/ - {"DarkGreen", RGB(0x00, 0x80, 0x00)}, /*W*/ - {"Green", RGB(0x00, 0x64, 0x11)}, /*M*/ - {"lightgreen", RGB(0xA0, 0xFF, 0xA0)}, /*W*/ - {"DarkCyan", RGB(0x00, 0x80, 0x80)}, /*W ?0x307D7E */ - {"cyan", RGB(0x02, 0xAB, 0xEA)}, /*M*/ - {"lightcyan", RGB(0xA0, 0xFF, 0xFF)}, /*W*/ - {"darkmagenta", RGB(0x80, 0x00, 0x80)}, /*W*/ - {"magenta", RGB(0xF2, 0x08, 0x84)}, /*M*/ - {"lightmagenta",RGB(0xF0, 0xA0, 0xF0)}, /*W*/ - {"brown", RGB(0x80, 0x40, 0x40)}, /*W*/ - {"yellow", RGB(0xFC, 0xF3, 0x05)}, /*M*/ - {"lightyellow", RGB(0xFF, 0xFF, 0xA0)}, /*M*/ - {"darkyellow", RGB(0xBB, 0xBB, 0x00)}, /*U*/ - {"SeaGreen", RGB(0x2E, 0x8B, 0x57)}, /*W 0x4E8975 */ - {"orange", RGB(0xFC, 0x80, 0x00)}, /*W 0xF87A17 */ - {"Purple", RGB(0xA0, 0x20, 0xF0)}, /*W 0x8e35e5 */ - {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)}, /*W 0x737CA1 */ - {"Violet", RGB(0x8D, 0x38, 0xC9)}, /*U*/ - }; - - int r, g, b; - int i; - - if (name[0] == '#' && strlen((char *) name) == 7) - { - /* Name is in "#rrggbb" format */ - r = hex_digit(name[1]) * 16 + hex_digit(name[2]); - g = hex_digit(name[3]) * 16 + hex_digit(name[4]); - b = hex_digit(name[5]) * 16 + hex_digit(name[6]); - if (r < 0 || g < 0 || b < 0) - return INVALCOLOR; - return RGB(r, g, b); - } - else - { - if (STRICMP(name, "hilite") == 0) - { - LMGetHiliteRGB(&MacColor); - return (RGB(MacColor.red >> 8, MacColor.green >> 8, MacColor.blue >> 8)); - } - /* Check if the name is one of the colors we know */ - for (i = 0; i < sizeof(table) / sizeof(table[0]); i++) - if (STRICMP(name, table[i].name) == 0) - return table[i].color; - } - /* - * Last attempt. Look in the file "$VIM/rgb.txt". - */ + if (STRICMP(name, "hilite") == 0) { -#define LINE_LEN 100 - FILE *fd; - char line[LINE_LEN]; - char_u *fname; - - fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); - if (fname == NULL) - return INVALCOLOR; - - fd = fopen((char *)fname, "rt"); - vim_free(fname); - if (fd == NULL) - return INVALCOLOR; - - while (!feof(fd)) - { - int len; - int pos; - char *color; - - fgets(line, LINE_LEN, fd); - len = strlen(line); - - if (len <= 1 || line[len-1] != '\n') - continue; - - line[len-1] = '\0'; - - i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); - if (i != 3) - continue; - - color = line + pos; - - if (STRICMP(color, name) == 0) - { - fclose(fd); - return (guicolor_T) RGB(r, g, b); - } - } - fclose(fd); + LMGetHiliteRGB(&MacColor); + return (RGB(MacColor.red >> 8, MacColor.green >> 8, MacColor.blue >> 8)); } - - return INVALCOLOR; + return gui_get_color_cmn(name); } /* diff --git a/src/gui_photon.c b/src/gui_photon.c index 67ddc628a3..956c8e2060 100644 --- a/src/gui_photon.c +++ b/src/gui_photon.c @@ -1971,18 +1971,6 @@ gui_mch_new_colors(void) PtSetResource(gui.vimTextArea, Pt_ARG_FILL_COLOR, gui.back_pixel, 0); } - static int -hex_digit(int c) -{ - if (VIM_ISDIGIT(c)) - return c - '0'; - c = TOLOWER_ASC(c); - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - return -1000; -} - - /* * This should be split out into a separate file, * every port does basically the same thing. @@ -1994,136 +1982,7 @@ hex_digit(int c) guicolor_T gui_mch_get_color(char_u *name) { - int i; - int r, g, b; - - - typedef struct GuiColourTable - { - char *name; - guicolor_T colour; - } GuiColourTable; - - static GuiColourTable table[] = - { - {"Black", RGB(0x00, 0x00, 0x00)}, - {"DarkGray", RGB(0xA9, 0xA9, 0xA9)}, - {"DarkGrey", RGB(0xA9, 0xA9, 0xA9)}, - {"Gray", RGB(0xC0, 0xC0, 0xC0)}, - {"Grey", RGB(0xC0, 0xC0, 0xC0)}, - {"LightGray", RGB(0xD3, 0xD3, 0xD3)}, - {"LightGrey", RGB(0xD3, 0xD3, 0xD3)}, - {"Gray10", RGB(0x1A, 0x1A, 0x1A)}, - {"Grey10", RGB(0x1A, 0x1A, 0x1A)}, - {"Gray20", RGB(0x33, 0x33, 0x33)}, - {"Grey20", RGB(0x33, 0x33, 0x33)}, - {"Gray30", RGB(0x4D, 0x4D, 0x4D)}, - {"Grey30", RGB(0x4D, 0x4D, 0x4D)}, - {"Gray40", RGB(0x66, 0x66, 0x66)}, - {"Grey40", RGB(0x66, 0x66, 0x66)}, - {"Gray50", RGB(0x7F, 0x7F, 0x7F)}, - {"Grey50", RGB(0x7F, 0x7F, 0x7F)}, - {"Gray60", RGB(0x99, 0x99, 0x99)}, - {"Grey60", RGB(0x99, 0x99, 0x99)}, - {"Gray70", RGB(0xB3, 0xB3, 0xB3)}, - {"Grey70", RGB(0xB3, 0xB3, 0xB3)}, - {"Gray80", RGB(0xCC, 0xCC, 0xCC)}, - {"Grey80", RGB(0xCC, 0xCC, 0xCC)}, - {"Gray90", RGB(0xE5, 0xE5, 0xE5)}, - {"Grey90", RGB(0xE5, 0xE5, 0xE5)}, - {"White", RGB(0xFF, 0xFF, 0xFF)}, - {"DarkRed", RGB(0x80, 0x00, 0x00)}, - {"Red", RGB(0xFF, 0x00, 0x00)}, - {"LightRed", RGB(0xFF, 0xA0, 0xA0)}, - {"DarkBlue", RGB(0x00, 0x00, 0x80)}, - {"Blue", RGB(0x00, 0x00, 0xFF)}, - {"LightBlue", RGB(0xAD, 0xD8, 0xE6)}, - {"DarkGreen", RGB(0x00, 0x80, 0x00)}, - {"Green", RGB(0x00, 0xFF, 0x00)}, - {"LightGreen", RGB(0x90, 0xEE, 0x90)}, - {"DarkCyan", RGB(0x00, 0x80, 0x80)}, - {"Cyan", RGB(0x00, 0xFF, 0xFF)}, - {"LightCyan", RGB(0xE0, 0xFF, 0xFF)}, - {"DarkMagenta", RGB(0x80, 0x00, 0x80)}, - {"Magenta", RGB(0xFF, 0x00, 0xFF)}, - {"LightMagenta", RGB(0xFF, 0xA0, 0xFF)}, - {"Brown", RGB(0x80, 0x40, 0x40)}, - {"Yellow", RGB(0xFF, 0xFF, 0x00)}, - {"LightYellow", RGB(0xFF, 0xFF, 0xE0)}, - {"SeaGreen", RGB(0x2E, 0x8B, 0x57)}, - {"Orange", RGB(0xFF, 0xA5, 0x00)}, - {"Purple", RGB(0xA0, 0x20, 0xF0)}, - {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)}, - {"Violet", RGB(0xEE, 0x82, 0xEE)}, - }; - - /* is name #rrggbb format? */ - if (name[0] == '#' && STRLEN(name) == 7) - { - r = hex_digit(name[1]) * 16 + hex_digit(name[2]); - g = hex_digit(name[3]) * 16 + hex_digit(name[4]); - b = hex_digit(name[5]) * 16 + hex_digit(name[6]); - if (r < 0 || g < 0 || b < 0) - return INVALCOLOR; - return RGB(r, g, b); - } - - for (i = 0; i < ARRAY_LENGTH(table); i++) - { - if (STRICMP(name, table[i].name) == 0) - return table[i].colour; - } - - /* - * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt". - */ - { -#define LINE_LEN 100 - FILE *fd; - char line[LINE_LEN]; - char_u *fname; - - fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); - if (fname == NULL) - return INVALCOLOR; - - fd = fopen((char *)fname, "rt"); - vim_free(fname); - if (fd == NULL) - return INVALCOLOR; - - while (!feof(fd)) - { - int len; - int pos; - char *color; - - fgets(line, LINE_LEN, fd); - len = STRLEN(line); - - if (len <= 1 || line[len-1] != '\n') - continue; - - line[len-1] = '\0'; - - i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); - if (i != 3) - continue; - - color = line + pos; - - if (STRICMP(color, name) == 0) - { - fclose(fd); - return (guicolor_T)RGB(r, g, b); - } - } - - fclose(fd); - } - - - return INVALCOLOR; + return gui_get_color_cmn(name); } void diff --git a/src/gui_w32.c b/src/gui_w32.c index 543d5d5a12..82cad1cf3c 100644 --- a/src/gui_w32.c +++ b/src/gui_w32.c @@ -1555,16 +1555,6 @@ gui_mch_free_font(GuiFont font) DeleteObject((HFONT)font); } - static int -hex_digit(int c) -{ - if (VIM_ISDIGIT(c)) - return c - '0'; - c = TOLOWER_ASC(c); - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - return -1000; -} /* * Return the Pixel value (color) for the given color name. * Return INVALCOLOR for error. @@ -1572,65 +1562,6 @@ hex_digit(int c) guicolor_T gui_mch_get_color(char_u *name) { - typedef struct guicolor_tTable - { - char *name; - COLORREF color; - } guicolor_tTable; - - static guicolor_tTable table[] = - { - {"Black", RGB(0x00, 0x00, 0x00)}, - {"DarkGray", RGB(0xA9, 0xA9, 0xA9)}, - {"DarkGrey", RGB(0xA9, 0xA9, 0xA9)}, - {"Gray", RGB(0xC0, 0xC0, 0xC0)}, - {"Grey", RGB(0xC0, 0xC0, 0xC0)}, - {"LightGray", RGB(0xD3, 0xD3, 0xD3)}, - {"LightGrey", RGB(0xD3, 0xD3, 0xD3)}, - {"Gray10", RGB(0x1A, 0x1A, 0x1A)}, - {"Grey10", RGB(0x1A, 0x1A, 0x1A)}, - {"Gray20", RGB(0x33, 0x33, 0x33)}, - {"Grey20", RGB(0x33, 0x33, 0x33)}, - {"Gray30", RGB(0x4D, 0x4D, 0x4D)}, - {"Grey30", RGB(0x4D, 0x4D, 0x4D)}, - {"Gray40", RGB(0x66, 0x66, 0x66)}, - {"Grey40", RGB(0x66, 0x66, 0x66)}, - {"Gray50", RGB(0x7F, 0x7F, 0x7F)}, - {"Grey50", RGB(0x7F, 0x7F, 0x7F)}, - {"Gray60", RGB(0x99, 0x99, 0x99)}, - {"Grey60", RGB(0x99, 0x99, 0x99)}, - {"Gray70", RGB(0xB3, 0xB3, 0xB3)}, - {"Grey70", RGB(0xB3, 0xB3, 0xB3)}, - {"Gray80", RGB(0xCC, 0xCC, 0xCC)}, - {"Grey80", RGB(0xCC, 0xCC, 0xCC)}, - {"Gray90", RGB(0xE5, 0xE5, 0xE5)}, - {"Grey90", RGB(0xE5, 0xE5, 0xE5)}, - {"White", RGB(0xFF, 0xFF, 0xFF)}, - {"DarkRed", RGB(0x80, 0x00, 0x00)}, - {"Red", RGB(0xFF, 0x00, 0x00)}, - {"LightRed", RGB(0xFF, 0xA0, 0xA0)}, - {"DarkBlue", RGB(0x00, 0x00, 0x80)}, - {"Blue", RGB(0x00, 0x00, 0xFF)}, - {"LightBlue", RGB(0xAD, 0xD8, 0xE6)}, - {"DarkGreen", RGB(0x00, 0x80, 0x00)}, - {"Green", RGB(0x00, 0xFF, 0x00)}, - {"LightGreen", RGB(0x90, 0xEE, 0x90)}, - {"DarkCyan", RGB(0x00, 0x80, 0x80)}, - {"Cyan", RGB(0x00, 0xFF, 0xFF)}, - {"LightCyan", RGB(0xE0, 0xFF, 0xFF)}, - {"DarkMagenta", RGB(0x80, 0x00, 0x80)}, - {"Magenta", RGB(0xFF, 0x00, 0xFF)}, - {"LightMagenta", RGB(0xFF, 0xA0, 0xFF)}, - {"Brown", RGB(0x80, 0x40, 0x40)}, - {"Yellow", RGB(0xFF, 0xFF, 0x00)}, - {"LightYellow", RGB(0xFF, 0xFF, 0xE0)}, - {"DarkYellow", RGB(0xBB, 0xBB, 0x00)}, - {"SeaGreen", RGB(0x2E, 0x8B, 0x57)}, - {"Orange", RGB(0xFF, 0xA5, 0x00)}, - {"Purple", RGB(0xA0, 0x20, 0xF0)}, - {"SlateBlue", RGB(0x6A, 0x5A, 0xCD)}, - {"Violet", RGB(0xEE, 0x82, 0xEE)}, - }; typedef struct SysColorTable { @@ -1677,27 +1608,6 @@ gui_mch_get_color(char_u *name) {"SYS_WINDOWTEXT", COLOR_WINDOWTEXT} }; - int r, g, b; - int i; - - if (name[0] == '#' && STRLEN(name) == 7) - { - /* Name is in "#rrggbb" format */ - r = hex_digit(name[1]) * 16 + hex_digit(name[2]); - g = hex_digit(name[3]) * 16 + hex_digit(name[4]); - b = hex_digit(name[5]) * 16 + hex_digit(name[6]); - if (r < 0 || g < 0 || b < 0) - return INVALCOLOR; - return RGB(r, g, b); - } - else - { - /* Check if the name is one of the colors we know */ - for (i = 0; i < sizeof(table) / sizeof(table[0]); i++) - if (STRICMP(name, table[i].name) == 0) - return table[i].color; - } - /* * Try to look up a system colour. */ @@ -1705,55 +1615,7 @@ gui_mch_get_color(char_u *name) if (STRICMP(name, sys_table[i].name) == 0) return GetSysColor(sys_table[i].color); - /* - * Last attempt. Look in the file "$VIMRUNTIME/rgb.txt". - */ - { -#define LINE_LEN 100 - FILE *fd; - char line[LINE_LEN]; - char_u *fname; - - fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); - if (fname == NULL) - return INVALCOLOR; - - fd = mch_fopen((char *)fname, "rt"); - vim_free(fname); - if (fd == NULL) - return INVALCOLOR; - - while (!feof(fd)) - { - int len; - int pos; - char *color; - - fgets(line, LINE_LEN, fd); - len = (int)STRLEN(line); - - if (len <= 1 || line[len-1] != '\n') - continue; - - line[len-1] = '\0'; - - i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); - if (i != 3) - continue; - - color = line + pos; - - if (STRICMP(color, name) == 0) - { - fclose(fd); - return (guicolor_T) RGB(r, g, b); - } - } - - fclose(fd); - } - - return INVALCOLOR; + return gui_get_color_cmn(name); } /* * Return OK if the key with the termcap name "name" is supported. diff --git a/src/proto/term.pro b/src/proto/term.pro index cd2ca26d38..3984515446 100644 --- a/src/proto/term.pro +++ b/src/proto/term.pro @@ -65,4 +65,5 @@ void show_termcodes(void); int show_one_termcode(char_u *name, char_u *code, int printit); char_u *translate_mapping(char_u *str, int expmap); void update_tcap(int attr); +guicolor_T gui_get_color_cmn(char_u *name); /* vim: set ft=c : */ diff --git a/src/term.c b/src/term.c index f66236725a..a6faaa30af 100644 --- a/src/term.c +++ b/src/term.c @@ -1266,145 +1266,10 @@ static struct builtin_term builtin_termcaps[] = }; /* end of builtin_termcaps */ #if defined(FEAT_TERMTRUECOLOR) || defined(PROTO) -# define RGB(r, g, b) ((r<<16) | (g<<8) | (b)) -struct rgbcolor_table_S { - char_u *color_name; - guicolor_T color; -}; - -static struct rgbcolor_table_S rgb_table[] = { - {(char_u *)"black", RGB(0x00, 0x00, 0x00)}, - {(char_u *)"blue", RGB(0x00, 0x00, 0xFF)}, - {(char_u *)"brown", RGB(0xA5, 0x2A, 0x2A)}, - {(char_u *)"cyan", RGB(0x00, 0xFF, 0xFF)}, - {(char_u *)"darkblue", RGB(0x00, 0x00, 0x8B)}, - {(char_u *)"darkcyan", RGB(0x00, 0x8B, 0x8B)}, - {(char_u *)"darkgray", RGB(0xA9, 0xA9, 0xA9)}, - {(char_u *)"darkgreen", RGB(0x00, 0x64, 0x00)}, - {(char_u *)"darkgrey", RGB(0xA9, 0xA9, 0xA9)}, - {(char_u *)"darkmagenta", RGB(0x8B, 0x00, 0x8B)}, - {(char_u *)"darkred", RGB(0x8B, 0x00, 0x00)}, - {(char_u *)"darkyellow", RGB(0x8B, 0x8B, 0x00)}, /* No X11 */ - {(char_u *)"gray", RGB(0xBE, 0xBE, 0xBE)}, - {(char_u *)"gray10", RGB(0x1A, 0x1A, 0x1A)}, - {(char_u *)"gray20", RGB(0x33, 0x33, 0x33)}, - {(char_u *)"gray30", RGB(0x4D, 0x4D, 0x4D)}, - {(char_u *)"gray40", RGB(0x66, 0x66, 0x66)}, - {(char_u *)"gray50", RGB(0x7F, 0x7F, 0x7F)}, - {(char_u *)"gray60", RGB(0x99, 0x99, 0x99)}, - {(char_u *)"gray70", RGB(0xB3, 0xB3, 0xB3)}, - {(char_u *)"gray80", RGB(0xCC, 0xCC, 0xCC)}, - {(char_u *)"gray90", RGB(0xE5, 0xE5, 0xE5)}, - {(char_u *)"green", RGB(0x00, 0xFF, 0x00)}, - {(char_u *)"grey", RGB(0xBE, 0xBE, 0xBE)}, - {(char_u *)"grey10", RGB(0x1A, 0x1A, 0x1A)}, - {(char_u *)"grey20", RGB(0x33, 0x33, 0x33)}, - {(char_u *)"grey30", RGB(0x4D, 0x4D, 0x4D)}, - {(char_u *)"grey40", RGB(0x66, 0x66, 0x66)}, - {(char_u *)"grey50", RGB(0x7F, 0x7F, 0x7F)}, - {(char_u *)"grey60", RGB(0x99, 0x99, 0x99)}, - {(char_u *)"grey70", RGB(0xB3, 0xB3, 0xB3)}, - {(char_u *)"grey80", RGB(0xCC, 0xCC, 0xCC)}, - {(char_u *)"grey90", RGB(0xE5, 0xE5, 0xE5)}, - {(char_u *)"lightblue", RGB(0xAD, 0xD8, 0xE6)}, - {(char_u *)"lightcyan", RGB(0xE0, 0xFF, 0xFF)}, - {(char_u *)"lightgray", RGB(0xD3, 0xD3, 0xD3)}, - {(char_u *)"lightgreen", RGB(0x90, 0xEE, 0x90)}, - {(char_u *)"lightgrey", RGB(0xD3, 0xD3, 0xD3)}, - {(char_u *)"lightmagenta", RGB(0xFF, 0x8B, 0xFF)}, /* No X11 */ - {(char_u *)"lightred", RGB(0xFF, 0x8B, 0x8B)}, /* No X11 */ - {(char_u *)"lightyellow", RGB(0xFF, 0xFF, 0xE0)}, - {(char_u *)"magenta", RGB(0xFF, 0x00, 0xFF)}, - {(char_u *)"orange", RGB(0xFF, 0xA5, 0x00)}, - {(char_u *)"purple", RGB(0xA0, 0x20, 0xF0)}, - {(char_u *)"red", RGB(0xFF, 0x00, 0x00)}, - {(char_u *)"seagreen", RGB(0x2E, 0x8B, 0x57)}, - {(char_u *)"slateblue", RGB(0x6A, 0x5A, 0xCD)}, - {(char_u *)"violet", RGB(0xEE, 0x82, 0xEE)}, - {(char_u *)"white", RGB(0xFF, 0xFF, 0xFF)}, - {(char_u *)"yellow", RGB(0xFF, 0xFF, 0x00)}, -}; - - static int -hex_digit(int c) -{ - if (isdigit(c)) - return c - '0'; - c = TOLOWER_ASC(c); - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - return 0x1ffffff; -} - guicolor_T termtrue_mch_get_color(char_u *name) { - guicolor_T color; - int i; - - if (*name == '#' && strlen((char *) name) == 7) - { - color = RGB(((hex_digit(name[1])<<4) + hex_digit(name[2])), - ((hex_digit(name[3])<<4) + hex_digit(name[4])), - ((hex_digit(name[5])<<4) + hex_digit(name[6]))); - if (color > 0xffffff) - return INVALCOLOR; - return color; - } - else - { - /* Check if the name is one of the colors we know */ - for (i = 0; i < (int)(sizeof(rgb_table) / sizeof(rgb_table[0])); i++) - if (STRICMP(name, rgb_table[i].color_name) == 0) - return rgb_table[i].color; - } - - /* - * Last attempt. Look in the file "$VIM/rgb.txt". - */ - { -#define LINE_LEN 100 - FILE *fd; - char line[LINE_LEN]; - char_u *fname; - int r, g, b; - - fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); - if (fname == NULL) - return INVALCOLOR; - - fd = fopen((char *)fname, "rt"); - vim_free(fname); - if (fd == NULL) - return INVALCOLOR; - - while (!feof(fd)) - { - int len; - int pos; - - (void)fgets(line, LINE_LEN, fd); - len = strlen(line); - - if (len <= 1 || line[len-1] != '\n') - continue; - - line[len-1] = '\0'; - - i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); - if (i != 3) - continue; - - if (STRICMP(line + pos, name) == 0) - { - fclose(fd); - return (guicolor_T) RGB(r, g, b); - } - } - fclose(fd); - } - - return INVALCOLOR; + return gui_get_color_cmn(name); } guicolor_T @@ -6187,3 +6052,146 @@ update_tcap(int attr) } } #endif + +#if defined(FEAT_GUI) || defined(FEAT_TERMTRUECOLOR) || defined(PROTO) + static int +hex_digit(int c) +{ + if (isdigit(c)) + return c - '0'; + c = TOLOWER_ASC(c); + if (c >= 'a' && c <= 'f') + return c - 'a' + 10; + return 0x1ffffff; +} + + guicolor_T +gui_get_color_cmn(char_u *name) +{ +#define RGB(r, g, b) ((r<<16) | (g<<8) | (b)) +#define LINE_LEN 100 + FILE *fd; + char line[LINE_LEN]; + char_u *fname; + int r, g, b, i; + guicolor_T color; + + struct rgbcolor_table_S { + char_u *color_name; + guicolor_T color; + }; + + static struct rgbcolor_table_S rgb_table[] = { + {(char_u *)"black", RGB(0x00, 0x00, 0x00)}, + {(char_u *)"blue", RGB(0x00, 0x00, 0xFF)}, + {(char_u *)"brown", RGB(0xA5, 0x2A, 0x2A)}, + {(char_u *)"cyan", RGB(0x00, 0xFF, 0xFF)}, + {(char_u *)"darkblue", RGB(0x00, 0x00, 0x8B)}, + {(char_u *)"darkcyan", RGB(0x00, 0x8B, 0x8B)}, + {(char_u *)"darkgray", RGB(0xA9, 0xA9, 0xA9)}, + {(char_u *)"darkgreen", RGB(0x00, 0x64, 0x00)}, + {(char_u *)"darkgrey", RGB(0xA9, 0xA9, 0xA9)}, + {(char_u *)"darkmagenta", RGB(0x8B, 0x00, 0x8B)}, + {(char_u *)"darkred", RGB(0x8B, 0x00, 0x00)}, + {(char_u *)"darkyellow", RGB(0x8B, 0x8B, 0x00)}, /* No X11 */ + {(char_u *)"gray", RGB(0xBE, 0xBE, 0xBE)}, + {(char_u *)"gray10", RGB(0x1A, 0x1A, 0x1A)}, + {(char_u *)"gray20", RGB(0x33, 0x33, 0x33)}, + {(char_u *)"gray30", RGB(0x4D, 0x4D, 0x4D)}, + {(char_u *)"gray40", RGB(0x66, 0x66, 0x66)}, + {(char_u *)"gray50", RGB(0x7F, 0x7F, 0x7F)}, + {(char_u *)"gray60", RGB(0x99, 0x99, 0x99)}, + {(char_u *)"gray70", RGB(0xB3, 0xB3, 0xB3)}, + {(char_u *)"gray80", RGB(0xCC, 0xCC, 0xCC)}, + {(char_u *)"gray90", RGB(0xE5, 0xE5, 0xE5)}, + {(char_u *)"green", RGB(0x00, 0xFF, 0x00)}, + {(char_u *)"grey", RGB(0xBE, 0xBE, 0xBE)}, + {(char_u *)"grey10", RGB(0x1A, 0x1A, 0x1A)}, + {(char_u *)"grey20", RGB(0x33, 0x33, 0x33)}, + {(char_u *)"grey30", RGB(0x4D, 0x4D, 0x4D)}, + {(char_u *)"grey40", RGB(0x66, 0x66, 0x66)}, + {(char_u *)"grey50", RGB(0x7F, 0x7F, 0x7F)}, + {(char_u *)"grey60", RGB(0x99, 0x99, 0x99)}, + {(char_u *)"grey70", RGB(0xB3, 0xB3, 0xB3)}, + {(char_u *)"grey80", RGB(0xCC, 0xCC, 0xCC)}, + {(char_u *)"grey90", RGB(0xE5, 0xE5, 0xE5)}, + {(char_u *)"lightblue", RGB(0xAD, 0xD8, 0xE6)}, + {(char_u *)"lightcyan", RGB(0xE0, 0xFF, 0xFF)}, + {(char_u *)"lightgray", RGB(0xD3, 0xD3, 0xD3)}, + {(char_u *)"lightgreen", RGB(0x90, 0xEE, 0x90)}, + {(char_u *)"lightgrey", RGB(0xD3, 0xD3, 0xD3)}, + {(char_u *)"lightmagenta", RGB(0xFF, 0x8B, 0xFF)}, /* No X11 */ + {(char_u *)"lightred", RGB(0xFF, 0x8B, 0x8B)}, /* No X11 */ + {(char_u *)"lightyellow", RGB(0xFF, 0xFF, 0xE0)}, + {(char_u *)"magenta", RGB(0xFF, 0x00, 0xFF)}, + {(char_u *)"orange", RGB(0xFF, 0xA5, 0x00)}, + {(char_u *)"purple", RGB(0xA0, 0x20, 0xF0)}, + {(char_u *)"red", RGB(0xFF, 0x00, 0x00)}, + {(char_u *)"seagreen", RGB(0x2E, 0x8B, 0x57)}, + {(char_u *)"slateblue", RGB(0x6A, 0x5A, 0xCD)}, + {(char_u *)"violet", RGB(0xEE, 0x82, 0xEE)}, + {(char_u *)"white", RGB(0xFF, 0xFF, 0xFF)}, + {(char_u *)"yellow", RGB(0xFF, 0xFF, 0x00)}, + }; + + + if (name[0] == '#' && STRLEN(name) == 7) + { + /* Name is in "#rrggbb" format */ + color = RGB(((hex_digit(name[1]) << 4) + hex_digit(name[2])), + ((hex_digit(name[3]) << 4) + hex_digit(name[4])), + ((hex_digit(name[5]) << 4) + hex_digit(name[6]))); + if (color > 0xffffff) + return INVALCOLOR; + return color; + } + + /* Check if the name is one of the colors we know */ + for (i = 0; i < (int)(sizeof(rgb_table) / sizeof(rgb_table[0])); i++) + if (STRICMP(name, rgb_table[i].color_name) == 0) + return rgb_table[i].color; + + /* + * Last attempt. Look in the file "$VIM/rgb.txt". + */ + + fname = expand_env_save((char_u *)"$VIMRUNTIME/rgb.txt"); + if (fname == NULL) + return INVALCOLOR; + + fd = fopen((char *)fname, "rt"); + vim_free(fname); + if (fd == NULL) + { + if (p_verbose > 1) + verb_msg((char_u *)_("Cannot open $VIMRUNTIME/rgb.txt")); + return INVALCOLOR; + } + + while (!feof(fd)) + { + int len; + int pos; + + (void)fgets(line, LINE_LEN, fd); + len = strlen(line); + + if (len <= 1 || line[len - 1] != '\n') + continue; + + line[len - 1] = '\0'; + + i = sscanf(line, "%d %d %d %n", &r, &g, &b, &pos); + if (i != 3) + continue; + + if (STRICMP(line + pos, name) == 0) + { + fclose(fd); + return (guicolor_T) RGB(r, g, b); + } + } + fclose(fd); + return INVALCOLOR; +} +#endif diff --git a/src/version.c b/src/version.c index a2553e6938..8b713cad8b 100644 --- a/src/version.c +++ b/src/version.c @@ -754,6 +754,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1792, +/**/ 1791, /**/ 1790, |