st-title_parsing_fix-0.8.4.diff (3026B)
1 From 6585da1be120d86316e4a9d620e9dfdfb3755822 Mon Sep 17 00:00:00 2001 2 From: Ashish Kumar Yadav <ashishkumar.yadav@students.iiserpune.ac.in> 3 Date: Wed, 4 Aug 2021 18:21:01 +0530 4 Subject: [PATCH] Fixes title parsing 5 6 In st, titles get truncated after the first ';' character, this patch 7 fixes that. 8 --- 9 st.c | 26 ++++++++++++++------------ 10 1 file changed, 14 insertions(+), 12 deletions(-) 11 12 diff --git a/st.c b/st.c 13 index 76b7e0d..8c68218 100644 14 --- a/st.c 15 +++ b/st.c 16 @@ -42,6 +42,8 @@ 17 #define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f)) 18 #define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c)) 19 #define ISDELIM(u) (u && wcschr(worddelimiters, u)) 20 +#define STRESCARGREST(n) ((n) == 0 ? strescseq.buf : strescseq.argp[(n)-1] + 1) 21 +#define STRESCARGJUST(n) (*(strescseq.argp[n]) = '\0', STRESCARGREST(n)) 22 23 enum term_mode { 24 MODE_WRAP = 1 << 0, 25 @@ -148,7 +150,7 @@ typedef struct { 26 char *buf; /* allocated raw string */ 27 size_t siz; /* allocation size */ 28 size_t len; /* raw string length */ 29 - char *args[STR_ARG_SIZ]; 30 + char *argp[STR_ARG_SIZ]; /* pointers to the end of nth argument */ 31 int narg; /* nb of args */ 32 } STREscape; 33 34 @@ -1846,21 +1848,22 @@ strhandle(void) 35 int j, narg, par; 36 37 term.esc &= ~(ESC_STR_END|ESC_STR); 38 - strparse(); 39 - par = (narg = strescseq.narg) ? atoi(strescseq.args[0]) : 0; 40 + strescseq.buf[strescseq.len] = '\0'; 41 42 switch (strescseq.type) { 43 case ']': /* OSC -- Operating System Command */ 44 + strparse(); 45 + par = (narg = strescseq.narg) ? atoi(STRESCARGJUST(0)) : 0; 46 switch (par) { 47 case 0: 48 case 1: 49 case 2: 50 if (narg > 1) 51 - xsettitle(strescseq.args[1]); 52 + xsettitle(STRESCARGREST(1)); 53 return; 54 case 52: 55 if (narg > 2 && allowwindowops) { 56 - dec = base64dec(strescseq.args[2]); 57 + dec = base64dec(STRESCARGJUST(2)); 58 if (dec) { 59 xsetsel(dec); 60 xclipcopy(); 61 @@ -1872,10 +1875,10 @@ strhandle(void) 62 case 4: /* color set */ 63 if (narg < 3) 64 break; 65 - p = strescseq.args[2]; 66 + p = STRESCARGJUST(2); 67 /* FALLTHROUGH */ 68 case 104: /* color reset, here p = NULL */ 69 - j = (narg > 1) ? atoi(strescseq.args[1]) : -1; 70 + j = (narg > 1) ? atoi(STRESCARGJUST(1)) : -1; 71 if (xsetcolorname(j, p)) { 72 if (par == 104 && narg <= 1) 73 return; /* color reset without parameter */ 74 @@ -1892,7 +1895,7 @@ strhandle(void) 75 } 76 break; 77 case 'k': /* old title set compatibility */ 78 - xsettitle(strescseq.args[0]); 79 + xsettitle(strescseq.buf); 80 return; 81 case 'P': /* DCS -- Device Control String */ 82 case '_': /* APC -- Application Program Command */ 83 @@ -1911,18 +1914,17 @@ strparse(void) 84 char *p = strescseq.buf; 85 86 strescseq.narg = 0; 87 - strescseq.buf[strescseq.len] = '\0'; 88 89 if (*p == '\0') 90 return; 91 92 while (strescseq.narg < STR_ARG_SIZ) { 93 - strescseq.args[strescseq.narg++] = p; 94 while ((c = *p) != ';' && c != '\0') 95 - ++p; 96 + p++; 97 + strescseq.argp[strescseq.narg++] = p; 98 if (c == '\0') 99 return; 100 - *p++ = '\0'; 101 + p++; 102 } 103 } 104 105 -- 106 2.32.0 107