mirror of
https://github.com/dankamongmen/notcurses.git
synced 2024-11-20 03:25:47 +00:00
termdesc: factor out extract_paren_version, handle foot's XTVERSION #1798
This commit is contained in:
parent
44e85d2f05
commit
94947df1ad
@ -733,20 +733,27 @@ extract_version(query_state* qstate, const char* prefix){
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
extract_paren_version(query_state* qstate, const char* prefix){
|
||||||
|
if(qstate->runstring[qstate->stridx - 1] != ')'){
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
qstate->runstring[qstate->stridx - 1] = '\0';
|
||||||
|
extract_version(qstate, prefix);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
stash_string(query_state* inits){
|
stash_string(query_state* inits){
|
||||||
//fprintf(stderr, "string terminator after %d [%s]\n", inits->stringstate, inits->runstring);
|
//fprintf(stderr, "string terminator after %d [%s]\n", inits->stringstate, inits->runstring);
|
||||||
switch(inits->stringstate){
|
switch(inits->stringstate){
|
||||||
case STATE_XTVERSION1:{
|
case STATE_XTVERSION1:{
|
||||||
int version;
|
#define XTERMVT "XTerm("
|
||||||
if(sscanf(inits->runstring, "XTerm(%d)", &version) == 1){
|
if(strncmp(inits->runstring, XTERMVT, strlen(XTERMVT)) == 0){
|
||||||
// enough space for everything besides "XTerm()"
|
if(extract_paren_version(inits, XTERMVT) == 0){
|
||||||
size_t bytes = strlen(inits->runstring) - 7 + 1;
|
|
||||||
inits->version = malloc(bytes);
|
|
||||||
if(inits->version){
|
|
||||||
sprintf(inits->version, "%d", version); // FIXME replace with memcpy
|
|
||||||
}
|
|
||||||
inits->qterm = TERMINAL_XTERM;
|
inits->qterm = TERMINAL_XTERM;
|
||||||
|
}
|
||||||
|
#undef XTERMVT
|
||||||
}else if(strncmp(inits->runstring, "WezTerm ", strlen("WezTerm ")) == 0){
|
}else if(strncmp(inits->runstring, "WezTerm ", strlen("WezTerm ")) == 0){
|
||||||
extract_version(inits, "WezTerm ");
|
extract_version(inits, "WezTerm ");
|
||||||
inits->qterm = TERMINAL_WEZTERM;
|
inits->qterm = TERMINAL_WEZTERM;
|
||||||
@ -755,12 +762,16 @@ stash_string(query_state* inits){
|
|||||||
inits->qterm = TERMINAL_CONTOUR;
|
inits->qterm = TERMINAL_CONTOUR;
|
||||||
#define KITTYVT "kitty("
|
#define KITTYVT "kitty("
|
||||||
}else if(strncmp(inits->runstring, KITTYVT, strlen(KITTYVT)) == 0){
|
}else if(strncmp(inits->runstring, KITTYVT, strlen(KITTYVT)) == 0){
|
||||||
if(inits->runstring[inits->stridx - 1] == ')'){
|
if(extract_paren_version(inits, KITTYVT) == 0){
|
||||||
inits->runstring[inits->stridx - 1] = '\0';
|
|
||||||
extract_version(inits, "kitty(");
|
|
||||||
inits->qterm = TERMINAL_KITTY;
|
inits->qterm = TERMINAL_KITTY;
|
||||||
}
|
}
|
||||||
#undef KITTYVT
|
#undef KITTYVT
|
||||||
|
#define FOOTVT "foot("
|
||||||
|
}else if(strncmp(inits->runstring, FOOTVT, strlen(FOOTVT)) == 0){
|
||||||
|
if(extract_paren_version(inits, FOOTVT) == 0){
|
||||||
|
inits->qterm = TERMINAL_FOOT;
|
||||||
|
}
|
||||||
|
#undef FOOTVT
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}case STATE_XTGETTCAP_TERMNAME1:
|
}case STATE_XTGETTCAP_TERMNAME1:
|
||||||
|
Loading…
Reference in New Issue
Block a user