diff options
author | bptato <nincsnevem662@gmail.com> | 2021-02-02 21:14:46 +0000 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-02-02 21:14:46 +0000 |
commit | e4570e8b6e17382e1cc4984684f861524d5b02f4 (patch) | |
tree | 37b0dc1979c6f020f0c2095891a2bba796b306b0 /etc.c | |
parent | Avoid having external programs download images (diff) | |
download | w3m-e4570e8b6e17382e1cc4984684f861524d5b02f4.tar.gz w3m-e4570e8b6e17382e1cc4984684f861524d5b02f4.zip |
Support iTerm2 graphics protocol, replace encodeB with base64_encode
Diffstat (limited to 'etc.c')
-rw-r--r-- | etc.c | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -2004,3 +2004,62 @@ void (*mySignal(int signal_number, void (*action) (int))) (int) { return (signal(signal_number, action)); #endif } + +static char Base64Table[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + +const char * +base64_encode(const unsigned char *src, int len) +{ + unsigned char *w, *at; + const unsigned char *in, *endw; + int j, k; + + k = len; + if (k % 3) + k += 3 - (k % 3); + k = k / 3 * 4; + + if (k < len) + return ""; + + w = GC_MALLOC_ATOMIC(k); + w[k] = 0; + + at = w; + in = src; + + endw = src + len - 2; + + while (in < endw) { + j = *in++; + j = j << 8 | *in++; + j = j << 8 | *in++; + + *at++ = Base64Table[(j >> 18) & 0x3f]; + *at++ = Base64Table[(j >> 12) & 0x3f]; + *at++ = Base64Table[(j >> 6) & 0x3f]; + *at++ = Base64Table[j & 0x3f]; + } + + if (in - src - len) { + if (in - src - len == 1) { + j = *in++; + j = j << 8; + j = j << 8; + *at++ = Base64Table[(j >> 18) & 0x3f]; + *at++ = Base64Table[(j >> 12) & 0x3f]; + *at++ = '='; + *at++ = '='; + } else { + j = *in++; + j = j << 8 | *in++; + j = j << 8; + *at++ = Base64Table[(j >> 18) & 0x3f]; + *at++ = Base64Table[(j >> 12) & 0x3f]; + *at++ = Base64Table[(j >> 6) & 0x3f]; + *at++ = '='; + } + } + return w; +} |