aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
Diffstat (limited to 'st.c')
-rw-r--r--st.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/st.c b/st.c
index 1e4196e..d7bd32a 100644
--- a/st.c
+++ b/st.c
@@ -198,6 +198,8 @@ static char utf8encodebyte(Rune, size_t);
198static char *utf8strchr(char *s, Rune u); 198static char *utf8strchr(char *s, Rune u);
199static size_t utf8validate(Rune *, size_t); 199static size_t utf8validate(Rune *, size_t);
200 200
201static char *base64dec(const char *);
202
201static ssize_t xwrite(int, const char *, size_t); 203static ssize_t xwrite(int, const char *, size_t);
202static void *xrealloc(void *, size_t); 204static void *xrealloc(void *, size_t);
203 205
@@ -369,6 +371,48 @@ utf8validate(Rune *u, size_t i)
369 return i; 371 return i;
370} 372}
371 373
374static const char base64_digits[] = {
375 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
376 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 0, 0, 0,
377 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, -1, 0, 0, 0, 0, 1,
378 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
379 22, 23, 24, 25, 0, 0, 0, 0, 0, 0, 26, 27, 28, 29, 30, 31, 32, 33, 34,
380 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 0,
381 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
382 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
383 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
384 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
385 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
386 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
387};
388
389char *
390base64dec(const char *src)
391{
392 size_t in_len = strlen(src);
393 char *result, *dst;
394
395 if (in_len % 4)
396 return NULL;
397 result = dst = xmalloc(in_len / 4 * 3 + 1);
398 while (*src) {
399 int a = base64_digits[(unsigned char) *src++];
400 int b = base64_digits[(unsigned char) *src++];
401 int c = base64_digits[(unsigned char) *src++];
402 int d = base64_digits[(unsigned char) *src++];
403
404 *dst++ = (a << 2) | ((b & 0x30) >> 4);
405 if (c == -1)
406 break;
407 *dst++ = ((b & 0x0f) << 4) | ((c & 0x3c) >> 2);
408 if (d == -1)
409 break;
410 *dst++ = ((c & 0x03) << 6) | d;
411 }
412 *dst = '\0';
413 return result;
414}
415
372void 416void
373selinit(void) 417selinit(void)
374{ 418{
@@ -1820,6 +1864,19 @@ strhandle(void)
1820 if (narg > 1) 1864 if (narg > 1)
1821 xsettitle(strescseq.args[1]); 1865 xsettitle(strescseq.args[1]);
1822 return; 1866 return;
1867 case 52:
1868 if (narg > 2) {
1869 char *dec;
1870
1871 dec = base64dec(strescseq.args[2]);
1872 if (dec) {
1873 xsetsel(dec, CurrentTime);
1874 clipcopy(NULL);
1875 } else {
1876 fprintf(stderr, "erresc: invalid base64\n");
1877 }
1878 }
1879 return;
1823 case 4: /* color set */ 1880 case 4: /* color set */
1824 if (narg < 3) 1881 if (narg < 3)
1825 break; 1882 break;