aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--st.c57
-rw-r--r--st.info1
-rw-r--r--win.h1
-rw-r--r--x.c1
4 files changed, 59 insertions, 1 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;
diff --git a/st.info b/st.info
index 13cc8eb..0b928af 100644
--- a/st.info
+++ b/st.info
@@ -189,6 +189,7 @@ st| simpleterm,
189 Se, 189 Se,
190 Ss, 190 Ss,
191 Tc, 191 Tc,
192 Ms=\E]52;%p1%s;%p2%s\007,
192 193
193st-256color| simpleterm with 256 colors, 194st-256color| simpleterm with 256 colors,
194 use=st, 195 use=st,
diff --git a/win.h b/win.h
index d684797..428111c 100644
--- a/win.h
+++ b/win.h
@@ -27,3 +27,4 @@ void xunloadfonts(void);
27void xresize(int, int); 27void xresize(int, int);
28void xselpaste(void); 28void xselpaste(void);
29unsigned long xwinid(void); 29unsigned long xwinid(void);
30void xsetsel(char *, Time);
diff --git a/x.c b/x.c
index 6474a01..743b084 100644
--- a/x.c
+++ b/x.c
@@ -88,7 +88,6 @@ static void xclear(int, int, int, int);
88static void xdrawcursor(void); 88static void xdrawcursor(void);
89static int xgeommasktogravity(int); 89static int xgeommasktogravity(int);
90static int xloadfont(Font *, FcPattern *); 90static int xloadfont(Font *, FcPattern *);
91static void xsetsel(char *, Time);
92static void xunloadfont(Font *); 91static void xunloadfont(Font *);
93 92
94static void expose(XEvent *); 93static void expose(XEvent *);