[automaton] handle BEL (0x07) as string terminator #2225

pull/2236/head
nick black 3 years ago
parent 9c59ea5164
commit dfb32779b7

@ -156,18 +156,19 @@ esctrie_make_string(automaton* a, esctrie* e){
} }
e->trie[i] = esctrie_idx(a, newe); e->trie[i] = esctrie_idx(a, newe);
} }
if((e->trie[0x1b] = create_esctrie_node(a, 0)) == 0){ if((e->trie[0x07] = create_esctrie_node(a, NCKEY_INVALID)) == 0){
return NULL; return NULL;
} }
e = esctrie_from_idx(a, e->trie[0x1b]); esctrie* term = esctrie_from_idx(a, e->trie[0x07]);
if((e->trie['\\'] = create_esctrie_node(a, NCKEY_INVALID)) == 0){ if((e->trie[0x1b] = create_esctrie_node(a, 0)) == 0){
return NULL; return NULL;
} }
e = esctrie_from_idx(a, e->trie['\\']); e = esctrie_from_idx(a, e->trie[0x1b]);
e->ni.id = 0; e->trie['\\'] = esctrie_idx(a, term);
e->ntype = NODE_SPECIAL; term->ni.id = 0;
logdebug("made string: %p\n", e); term->ntype = NODE_SPECIAL;
return e; logdebug("made string: %u\n", esctrie_idx(a, term));
return term;
} }
static esctrie* static esctrie*
@ -502,21 +503,23 @@ int walk_automaton(automaton* a, struct inputctx* ictx, unsigned candidate,
return 0; return 0;
} }
if(e->ntype == NODE_STRING){ if(e->ntype == NODE_STRING){
if(candidate == 0x1b){ if(candidate == 0x1b || candidate == 0x07){
a->state = e->trie[candidate]; a->state = e->trie[candidate];
a->instring = 0; a->instring = 0;
} }
e = esctrie_from_idx(a, a->state);
if(e->ntype == NODE_FUNCTION){ // for the 0x07s of the world
return e->fxn(ictx);
}
return 0; return 0;
} }
if((a->state = e->trie[candidate]) == 0){ if((a->state = e->trie[candidate]) == 0){
if(isprint(candidate)){
if(esctrie_idx(a, e) == a->escapes){ if(esctrie_idx(a, e) == a->escapes){
memset(ni, 0, sizeof(*ni)); memset(ni, 0, sizeof(*ni));
ni->id = candidate; ni->id = candidate;
ni->alt = true; ni->alt = true;
return 1; return 1;
} }
}
loginfo("unexpected transition on %u[%u]\n", loginfo("unexpected transition on %u[%u]\n",
esctrie_idx(a, e), candidate); esctrie_idx(a, e), candidate);
return -1; return -1;

Loading…
Cancel
Save