diff options
Diffstat (limited to 'src/osc')
| -rw-r--r-- | src/osc/clipboard.c | 33 | ||||
| -rw-r--r-- | src/osc/dispatch.c | 3 |
2 files changed, 25 insertions, 11 deletions
diff --git a/src/osc/clipboard.c b/src/osc/clipboard.c index a5ac59d..4f550ba 100644 --- a/src/osc/clipboard.c +++ b/src/osc/clipboard.c @@ -3,21 +3,36 @@ #include <stdlib.h> #include <string.h> -static int b64_val(char c) +static const int8_t b64_lut[256] = { + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, + -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, + -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, +}; + +static inline int b64_val(char c) { - if (c >= 'A' && c <= 'Z') return c - 'A'; - if (c >= 'a' && c <= 'z') return c - 'a' + 26; - if (c >= '0' && c <= '9') return c - '0' + 52; - if (c == '+') return 62; - if (c == '/') return 63; - return -1; + return b64_lut[(unsigned char)c]; } static bool b64_decode(const char *s, size_t n, char *out, size_t *out_len) { size_t pad = 0; - while (pad < n && s[n - pad - 1] == '=') - pad++; + if (n > 0 && s[n - 1] == '=') { + pad = (n > 1 && s[n - 2] == '=') ? ((n > 2 && s[n - 3] == '=') ? 3 : 2) : 1; + } n -= pad; if (pad > 2 || (pad && n % 4 + pad != 4)) return false; diff --git a/src/osc/dispatch.c b/src/osc/dispatch.c index 4cf986e..74863ed 100644 --- a/src/osc/dispatch.c +++ b/src/osc/dispatch.c @@ -135,8 +135,7 @@ static void osc4_handle(struct term *t, const char *params) static void osc104_handle(struct term *t, const char *params) { if (!*params) { - for (int i = 0; i < 256; i++) - term_palette_reset(&t->palette, i); + term_palette_reset_all(&t->palette); return; } const char *p = params; |
