protect initdata, notcurses_getvec()

pull/2166/head
nick black 3 years ago
parent 1630a1629f
commit 5f00466b38
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC

@ -321,6 +321,7 @@ static int
stash_string(inputctx* ictx){
struct initial_responses* inits = ictx->initdata;
//fprintf(stderr, "string terminator after %d [%s]\n", inits->stringstate, inits->runstring);
if(inits){
switch(ictx->stringstate){
case STATE_XTVERSION1:{
static const struct {
@ -386,6 +387,7 @@ stash_string(inputctx* ictx){
//fprintf(stderr, "invalid string [%s] stashed %d\n", inits->runstring, inits->stringstate);
break;
}
}
ictx->runstring[0] = '\0';
ictx->stridx = 0;
return 0;
@ -451,8 +453,10 @@ pump_control_read(inputctx* ictx, unsigned char c){
break;
case STATE_APC:
if(c == 'G'){
if(ictx->initdata){
ictx->initdata->kitty_graphics = true;
}
}
ictx->state = STATE_APC_DRAIN;
break;
case STATE_APC_DRAIN:
@ -503,12 +507,14 @@ pump_control_read(inputctx* ictx, unsigned char c){
// SDA yields up Alacritty's crate version, but it doesn't unambiguously
// identify Alacritty. If we've got any other version information, skip
// directly to STATE_SDA_DRAIN, rather than doing STATE_SDA_VER.
if(ictx->initdata){
if(ictx->initdata->qterm || ictx->initdata->version){
loginfo("Identified terminal already; ignoring DA2\n");
ictx->state = STATE_SDA_DRAIN;
}else{
ictx->state = STATE_SDA;
}
}
}else if(isdigit(c)){
ictx->numeric = 0;
if(ruts_numeric(&ictx->numeric, c)){
@ -562,16 +568,22 @@ pump_control_read(inputctx* ictx, unsigned char c){
ictx->state = STATE_NULL;
}else if(c == 't'){
//fprintf(stderr, "CELLS X: %d\n", ictx->numeric);
if(ictx->initdata){
ictx->initdata->dimx = ictx->numeric;
ictx->initdata->dimy = ictx->p2;
}
ictx->state = STATE_NULL;
}else if(c == ';'){
if(ictx->p2 == 4){
if(ictx->initdata){
ictx->initdata->pixy = ictx->numeric;
ictx->state = STATE_PIXELS_WIDTH;
}
ictx->numeric = 0;
}else if(ictx->p2 == 8){
if(ictx->initdata){
ictx->initdata->dimy = ictx->numeric;
}
ictx->state = STATE_CELLS_WIDTH;
ictx->numeric = 0;
}else{
@ -588,8 +600,10 @@ pump_control_read(inputctx* ictx, unsigned char c){
return -1;
}
}else if(c == 't'){
if(ictx->initdata){
ictx->initdata->pixx = ictx->numeric;
loginfo("got pixel geometry: %d/%d\n", ictx->initdata->pixy, ictx->initdata->pixx);
}
ictx->state = STATE_NULL;
}else{
ictx->state = STATE_NULL;
@ -601,8 +615,10 @@ pump_control_read(inputctx* ictx, unsigned char c){
return -1;
}
}else if(c == 't'){
if(ictx->initdata){
ictx->initdata->dimx = ictx->numeric;
loginfo("got cell geometry: %d/%d\n", ictx->initdata->dimy, ictx->initdata->dimx);
}
ictx->state = STATE_NULL;
}else{
ictx->state = STATE_NULL;
@ -722,12 +738,14 @@ pump_control_read(inputctx* ictx, unsigned char c){
case STATE_SDA_VER:
if(c == ';'){
ictx->state = STATE_SDA_DRAIN;
if(ictx->initdata){
loginfo("Got DA2 Pv: %u\n", ictx->numeric);
// if a version was set, we couldn't have arrived here. alacritty
// writes its crate version here, in an encoded form. nothing else
// necessarily does, though, so allow failure. this value will be
// interpreted as the version only if TERM indicates alacritty.
ictx->initdata->version = set_sda_version(ictx);
}
}else if(ruts_numeric(&ictx->numeric, c)){
return -1;
}
@ -807,8 +825,10 @@ pump_control_read(inputctx* ictx, unsigned char c){
}
}else if(c == 'S'){
if(ictx->p2 == 1){
if(ictx->initdata){
ictx->initdata->color_registers = ictx->numeric;
loginfo("sixel color registers: %d\n", ictx->initdata->color_registers);
}
ictx->numeric = 0;
}
ictx->state = STATE_NULL;
@ -836,9 +856,11 @@ pump_control_read(inputctx* ictx, unsigned char c){
return -1;
}
}else if(c == 'S'){
if(ictx->initdata){
ictx->initdata->sixelx = ictx->p4;
ictx->initdata->sixely = ictx->numeric;
loginfo("max sixel geometry: %dx%d\n", ictx->initdata->sixely, ictx->initdata->sixelx);
}
}else if(c >= 0x40 && c <= 0x7E){
ictx->state = STATE_NULL;
if(c == 'c'){
@ -848,7 +870,9 @@ pump_control_read(inputctx* ictx, unsigned char c){
break;
case STATE_APPSYNC_REPORT:
if(ictx->numeric == '2'){
if(ictx->initdata){
ictx->initdata->appsync_supported = 1;
}
ictx->state = STATE_APPSYNC_REPORT_DRAIN;
}
break;
@ -1174,6 +1198,23 @@ uint32_t notcurses_get(notcurses* nc, const struct timespec* ts, ncinput* ni){
return r;
}
int notcurses_getvec(notcurses* n, const struct timespec* ts,
ncinput* ni, int vcount){
for(int v = 0 ; v < vcount ; ++v){
// FIXME need to manage ts; right now, we could delay up to ts * vcount!
uint32_t u = notcurses_get(n, ts, &ni[v]);
if(u == (uint32_t)-1){
if(v == 0){
return -1;
}
return v;
}else if(u == 0){
return v;
}
}
return vcount;
}
uint32_t ncdirect_get(ncdirect* n, const struct timespec* ts, ncinput* ni){
return internal_get(n->tcache.ictx, ts, ni, 0, 0);
}

Loading…
Cancel
Save