mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-09 08:21:01 -04:00
dcs: xtgettcap: use custom put() handler
Grow buffer exponentially, since XTGETTCAP requests can, theoretically, be very large.
This commit is contained in:
parent
af88c19561
commit
67a228bf4b
1 changed files with 21 additions and 5 deletions
26
dcs.c
26
dcs.c
|
|
@ -16,17 +16,14 @@ ensure_size(struct terminal *term, size_t required_size)
|
||||||
if (required_size <= term->vt.dcs.size)
|
if (required_size <= term->vt.dcs.size)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
size_t new_size = (required_size + 127) / 128 * 128;
|
uint8_t *new_data = realloc(term->vt.dcs.data, required_size);
|
||||||
xassert(new_size > 0);
|
|
||||||
|
|
||||||
uint8_t *new_data = realloc(term->vt.dcs.data, new_size);
|
|
||||||
if (new_data == NULL) {
|
if (new_data == NULL) {
|
||||||
LOG_ERRNO("failed to increase size of DCS buffer");
|
LOG_ERRNO("failed to increase size of DCS buffer");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
term->vt.dcs.data = new_data;
|
term->vt.dcs.data = new_data;
|
||||||
term->vt.dcs.size = new_size;
|
term->vt.dcs.size = required_size;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -180,6 +177,24 @@ out:
|
||||||
free(name);
|
free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
xtgettcap_put(struct terminal *term, uint8_t c)
|
||||||
|
{
|
||||||
|
struct vt *vt = &term->vt;
|
||||||
|
|
||||||
|
/* Grow buffer expontentially */
|
||||||
|
if (vt->dcs.idx >= vt->dcs.size) {
|
||||||
|
size_t new_size = vt->dcs.size * 2;
|
||||||
|
if (new_size == 0)
|
||||||
|
new_size = 128;
|
||||||
|
|
||||||
|
if (!ensure_size(term, new_size))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
vt->dcs.data[vt->dcs.idx++] = c;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xtgettcap_unhook(struct terminal *term)
|
xtgettcap_unhook(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
|
@ -445,6 +460,7 @@ dcs_hook(struct terminal *term, uint8_t final)
|
||||||
case '+':
|
case '+':
|
||||||
switch (final) {
|
switch (final) {
|
||||||
case 'q': /* XTGETTCAP */
|
case 'q': /* XTGETTCAP */
|
||||||
|
term->vt.dcs.put_handler = &xtgettcap_put;
|
||||||
term->vt.dcs.unhook_handler = &xtgettcap_unhook;
|
term->vt.dcs.unhook_handler = &xtgettcap_unhook;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue