st-title_parsing_fix-0.8.5.diff (3822B)
1 From 8446609384429bfc4342ede4b52ff42214ad2b77 Mon Sep 17 00:00:00 2001 2 From: Rizqi Nur Assyaufi <bandithijo@gmail.com> 3 Date: Mon, 18 Jul 2022 00:35:26 +0800 4 Subject: [PATCH] Fixes title parsing for st-0.8.5 5 6 In st, titles get truncated after the first ';' character, this patch 7 fixes that. 8 --- 9 st.c | 38 ++++++++++++++++++++------------------ 10 1 file changed, 20 insertions(+), 18 deletions(-) 11 12 diff --git a/st.c b/st.c 13 index 51049ba..a2e595c 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 @@ -1885,29 +1887,30 @@ 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 if (narg > 1) { 49 - xsettitle(strescseq.args[1]); 50 - xseticontitle(strescseq.args[1]); 51 + xsettitle(STRESCARGREST(1)); 52 + xseticontitle(STRESCARGREST(1)); 53 } 54 return; 55 case 1: 56 if (narg > 1) 57 - xseticontitle(strescseq.args[1]); 58 + xseticontitle(STRESCARGREST(1)); 59 return; 60 case 2: 61 if (narg > 1) 62 - xsettitle(strescseq.args[1]); 63 + xsettitle(STRESCARGREST(1)); 64 return; 65 case 52: 66 if (narg > 2 && allowwindowops) { 67 - dec = base64dec(strescseq.args[2]); 68 + dec = base64dec(STRESCARGJUST(2)); 69 if (dec) { 70 xsetsel(dec); 71 xclipcopy(); 72 @@ -1920,7 +1923,7 @@ strhandle(void) 73 if (narg < 2) 74 break; 75 76 - p = strescseq.args[1]; 77 + p = STRESCARGREST(1); 78 79 if (!strcmp(p, "?")) 80 osc_color_response(defaultfg, 10); 81 @@ -1933,7 +1936,7 @@ strhandle(void) 82 if (narg < 2) 83 break; 84 85 - p = strescseq.args[1]; 86 + p = STRESCARGREST(1); 87 88 if (!strcmp(p, "?")) 89 osc_color_response(defaultbg, 11); 90 @@ -1946,7 +1949,7 @@ strhandle(void) 91 if (narg < 2) 92 break; 93 94 - p = strescseq.args[1]; 95 + p = STRESCARGREST(1); 96 97 if (!strcmp(p, "?")) 98 osc_color_response(defaultcs, 12); 99 @@ -1958,10 +1961,10 @@ strhandle(void) 100 case 4: /* color set */ 101 if (narg < 3) 102 break; 103 - p = strescseq.args[2]; 104 + p = STRESCARGJUST(2); 105 /* FALLTHROUGH */ 106 case 104: /* color reset */ 107 - j = (narg > 1) ? atoi(strescseq.args[1]) : -1; 108 + j = (narg > 1) ? atoi(STRESCARGJUST(1)) : -1; 109 110 if (p && !strcmp(p, "?")) 111 osc4_color_response(j); 112 @@ -1981,7 +1984,7 @@ strhandle(void) 113 } 114 break; 115 case 'k': /* old title set compatibility */ 116 - xsettitle(strescseq.args[0]); 117 + xsettitle(strescseq.buf); 118 return; 119 case 'P': /* DCS -- Device Control String */ 120 case '_': /* APC -- Application Program Command */ 121 @@ -2000,18 +2003,17 @@ strparse(void) 122 char *p = strescseq.buf; 123 124 strescseq.narg = 0; 125 - strescseq.buf[strescseq.len] = '\0'; 126 127 if (*p == '\0') 128 return; 129 130 while (strescseq.narg < STR_ARG_SIZ) { 131 - strescseq.args[strescseq.narg++] = p; 132 while ((c = *p) != ';' && c != '\0') 133 - ++p; 134 + p++; 135 + strescseq.argp[strescseq.narg++] = p; 136 if (c == '\0') 137 return; 138 - *p++ = '\0'; 139 + p++; 140 } 141 } 142 143 -- 144 2.37.1 145