Skip to content

Commit

Permalink
[automaton] handle BEL (0x07) as string terminator #2225
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Oct 3, 2021
1 parent 9c59ea5 commit dfb3277
Showing 1 changed file with 19 additions and 16 deletions.
35 changes: 19 additions & 16 deletions src/lib/automaton.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,19 @@ esctrie_make_string(automaton* a, esctrie* e){
}
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;
}
e = esctrie_from_idx(a, e->trie[0x1b]);
if((e->trie['\\'] = create_esctrie_node(a, NCKEY_INVALID)) == 0){
esctrie* term = esctrie_from_idx(a, e->trie[0x07]);
if((e->trie[0x1b] = create_esctrie_node(a, 0)) == 0){
return NULL;
}
e = esctrie_from_idx(a, e->trie['\\']);
e->ni.id = 0;
e->ntype = NODE_SPECIAL;
logdebug("made string: %p\n", e);
return e;
e = esctrie_from_idx(a, e->trie[0x1b]);
e->trie['\\'] = esctrie_idx(a, term);
term->ni.id = 0;
term->ntype = NODE_SPECIAL;
logdebug("made string: %u\n", esctrie_idx(a, term));
return term;
}

static esctrie*
Expand Down Expand Up @@ -502,20 +503,22 @@ int walk_automaton(automaton* a, struct inputctx* ictx, unsigned candidate,
return 0;
}
if(e->ntype == NODE_STRING){
if(candidate == 0x1b){
if(candidate == 0x1b || candidate == 0x07){
a->state = e->trie[candidate];
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;
}
if((a->state = e->trie[candidate]) == 0){
if(isprint(candidate)){
if(esctrie_idx(a, e) == a->escapes){
memset(ni, 0, sizeof(*ni));
ni->id = candidate;
ni->alt = true;
return 1;
}
if(esctrie_idx(a, e) == a->escapes){
memset(ni, 0, sizeof(*ni));
ni->id = candidate;
ni->alt = true;
return 1;
}
loginfo("unexpected transition on %u[%u]\n",
esctrie_idx(a, e), candidate);
Expand Down

0 comments on commit dfb3277

Please sign in to comment.