diff -ur mc-4.8.11.orig/lib/tty/color-internal.c mc-4.8.11/lib/tty/color-internal.c
old
|
new
|
|
94 | 94 | /*** file scope functions ************************************************************************/ |
95 | 95 | /* --------------------------------------------------------------------------------------------- */ |
96 | 96 | |
| 97 | static inline int |
| 98 | parse_hex_digit (char c) |
| 99 | { |
| 100 | if (c >= '0' && c <= '9') |
| 101 | return c - '0'; |
| 102 | c |= 0x20; |
| 103 | if (c >= 'a' && c <= 'f') |
| 104 | return c - 'a' + 10; |
| 105 | return -1; |
| 106 | } |
| 107 | |
97 | 108 | static int |
98 | | parse_256_color_name (const char *color_name) |
| 109 | parse_256_or_true_color_name (const char *color_name) |
99 | 110 | { |
100 | 111 | int i; |
101 | 112 | char dummy; |
… |
… |
|
117 | 128 | { |
118 | 129 | return 16 + 36 * (color_name[3] - '0') + 6 * (color_name[4] - '0') + (color_name[5] - '0'); |
119 | 130 | } |
| 131 | if (color_name[0] == '#') |
| 132 | { |
| 133 | int h[6]; |
| 134 | color_name++; |
| 135 | if (strlen(color_name) != 3 && strlen(color_name) != 6) |
| 136 | return -1; |
| 137 | for (i = 0; color_name[i] != '\0'; i++) { |
| 138 | h[i] = parse_hex_digit (color_name[i]); |
| 139 | if (h[i] == -1) |
| 140 | return -1; |
| 141 | } |
| 142 | if (i == 3) |
| 143 | i = (h[0] << 20) | (h[0] << 16) | (h[1] << 12) | (h[1] << 8) | (h[2] << 4) | h[2]; |
| 144 | else |
| 145 | i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5]; |
| 146 | return (1 << 24) | i; |
| 147 | } |
120 | 148 | return -1; |
121 | 149 | } |
122 | 150 | |
… |
… |
|
150 | 178 | } |
151 | 179 | return color_N_names[idx - 16]; |
152 | 180 | } |
| 181 | /* Create and return strings in "#rrggbb" format for true color. */ |
| 182 | if (idx & (1 << 24)) |
| 183 | { |
| 184 | // FIXME: The allocated string is not free()d. |
| 185 | // Not trivial to fix, needs some refactoring. |
| 186 | gchar *rgb = g_try_malloc(8); |
| 187 | sprintf(rgb, "#%06X", idx & 0xFFFFFF); |
| 188 | return rgb; |
| 189 | } |
153 | 190 | return "default"; |
154 | 191 | } |
155 | 192 | |
… |
… |
|
165 | 202 | for (i = 0; color_table[i].name != NULL; i++) |
166 | 203 | if (strcmp (color_name, color_table[i].name) == 0) |
167 | 204 | return color_table[i].value; |
168 | | return parse_256_color_name (color_name); |
| 205 | return parse_256_or_true_color_name (color_name); |
169 | 206 | } |
170 | 207 | return -1; |
171 | 208 | } |