aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidpkj <davidpenkow1@gmail.com>2023-02-15 10:46:52 +0100
committerdavidpkj <davidpenkow1@gmail.com>2023-02-15 11:03:30 +0100
commitc3e41d43a70789dc007c4896f8da69209e3f68d1 (patch)
tree3e56e98b8d1ad98be7b491f59777b1a8be2a3f54
parent354bf243ff0b3e93e890f3ee34cb85ba95135e8d (diff)
Patch: title_parsing_fix-0.8.5
-rw-r--r--st.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/st.c b/st.c
index ee318d5..57b4203 100644
--- a/st.c
+++ b/st.c
@@ -44,6 +44,8 @@
#define ISCONTROLC1(c) (BETWEEN(c, 0x80, 0x9f))
#define ISCONTROL(c) (ISCONTROLC0(c) || ISCONTROLC1(c))
#define ISDELIM(u) (u && wcschr(worddelimiters, u))
+#define STRESCARGREST(n) ((n) == 0 ? strescseq.buf : strescseq.argp[(n)-1] + 1)
+#define STRESCARGJUST(n) (*(strescseq.argp[n]) = '\0', STRESCARGREST(n))
#define TLINE(y) ( \
(y) < term.scr ? term.hist[(term.histi + (y) - term.scr + 1 + HISTSIZE) % HISTSIZE] \
@@ -176,7 +178,7 @@ typedef struct {
char *buf; /* allocated raw string */
size_t siz; /* allocation size */
size_t len; /* raw string length */
- char *args[STR_ARG_SIZ];
+ char *argp[STR_ARG_SIZ]; /* pointers to the end of nth argument */
int narg; /* nb of args */
} STREscape;
@@ -2124,29 +2126,30 @@ strhandle(void)
};
term.esc &= ~(ESC_STR_END|ESC_STR);
- strparse();
- par = (narg = strescseq.narg) ? atoi(strescseq.args[0]) : 0;
+ strescseq.buf[strescseq.len] = '\0';
switch (strescseq.type) {
case ']': /* OSC -- Operating System Command */
+ strparse();
+ par = (narg = strescseq.narg) ? atoi(STRESCARGJUST(0)) : 0;
switch (par) {
case 0:
if (narg > 1) {
- xsettitle(strescseq.args[1]);
- xseticontitle(strescseq.args[1]);
+ xsettitle(STRESCARGREST(1));
+ xseticontitle(STRESCARGREST(1));
}
return;
case 1:
if (narg > 1)
- xseticontitle(strescseq.args[1]);
+ xseticontitle(STRESCARGREST(1));
return;
case 2:
if (narg > 1)
- xsettitle(strescseq.args[1]);
+ xsettitle(STRESCARGREST(1));
return;
case 52:
if (narg > 2 && allowwindowops) {
- dec = base64dec(strescseq.args[2]);
+ dec = base64dec(STRESCARGJUST(2));
if (dec) {
xsetsel(dec);
xclipcopy();
@@ -2160,7 +2163,7 @@ strhandle(void)
case 12:
if (narg < 2)
break;
- p = strescseq.args[1];
+ p = STRESCARGREST(1);
if ((j = par - 10) < 0 || j >= LEN(osc_table))
break; /* shouldn't be possible */
@@ -2176,10 +2179,10 @@ strhandle(void)
case 4: /* color set */
if (narg < 3)
break;
- p = strescseq.args[2];
+ p = STRESCARGJUST(2);
/* FALLTHROUGH */
case 104: /* color reset */
- j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
+ j = (narg > 1) ? atoi(STRESCARGJUST(1)) : -1;
if (p && !strcmp(p, "?")) {
osc_color_response(j, 0, 1);
@@ -2201,7 +2204,7 @@ strhandle(void)
}
break;
case 'k': /* old title set compatibility */
- xsettitle(strescseq.args[0]);
+ xsettitle(strescseq.buf);
return;
case 'P': /* DCS -- Device Control String */
case '_': /* APC -- Application Program Command */
@@ -2220,18 +2223,17 @@ strparse(void)
char *p = strescseq.buf;
strescseq.narg = 0;
- strescseq.buf[strescseq.len] = '\0';
if (*p == '\0')
return;
while (strescseq.narg < STR_ARG_SIZ) {
- strescseq.args[strescseq.narg++] = p;
while ((c = *p) != ';' && c != '\0')
- ++p;
+ p++;
+ strescseq.argp[strescseq.narg++] = p;
if (c == '\0')
return;
- *p++ = '\0';
+ p++;
}
}