Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
automaton.h
Go to the documentation of this file.
1#ifndef NOTCURSES_AUTOMATON
2#define NOTCURSES_AUTOMATON
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
8#include <stdint.h>
9
10struct ncinput;
11struct esctrie;
12struct inputctx;
13
14typedef int (*triefunc)(struct inputctx*);
15
16// the state necessary for matching input against our automaton of control
17// sequences. we *do not* match the bulk UTF-8 input. we match online (i.e.
18// we can be passed a byte at a time). initialize with all zeroes.
19typedef struct automaton {
20 unsigned escapes; // head Esc node of trie
21 int used; // bytes consumed thus far
22 int instring; // are we in an ST-terminated string?
23 unsigned state;
24 const unsigned char* matchstart; // beginning of active match
25 // we keep a node pool not to save time when allocating, but because
26 // trying to free the automaton without reference counting otherwise
27 // sucks worse than three bitches in a bitchboat.
28 unsigned poolsize;
29 unsigned poolused;
32
33// wipe out all storage internal to |a| (but not |a| itself).
35
36int inputctx_add_input_escape(automaton* a, const char* esc,
37 uint32_t special, unsigned modifiers);
38
39int inputctx_add_cflow(automaton* a, const char* csi, triefunc fxn)
40 __attribute__ ((nonnull (1, 2)));
41
42int walk_automaton(automaton* a, struct inputctx* ictx, unsigned candidate,
43 struct ncinput* ni)
44 __attribute__ ((nonnull (1, 2, 4)));
45
46uint32_t esctrie_id(const struct esctrie* e);
47
48#ifdef __cplusplus
49}
50#endif
51
52#endif
int inputctx_add_input_escape(automaton *a, const char *esc, uint32_t special, unsigned modifiers)
Definition automaton.c:513
int int uint32_t esctrie_id(const struct esctrie *e)
int inputctx_add_cflow(automaton *a, const char *csi, triefunc fxn) __attribute__((nonnull(1
int(* triefunc)(struct inputctx *)
Definition automaton.h:14
int int walk_automaton(automaton *a, struct inputctx *ictx, unsigned candidate, struct ncinput *ni) __attribute__((nonnull(1
void input_free_esctrie(automaton *a)
Definition automaton.c:81
__attribute__((nonnull(1, 2))) static inline int egcpool_stash(egcpool *pool
struct esctrie * nodepool
Definition automaton.h:30
unsigned state
Definition automaton.h:23
unsigned escapes
Definition automaton.h:20
unsigned poolsize
Definition automaton.h:28
unsigned poolused
Definition automaton.h:29
const unsigned char * matchstart
Definition automaton.h:24
int instring
Definition automaton.h:22
triefunc fxn
Definition automaton.c:31
ncinput ni
Definition automaton.c:30
Definition in.c:52
static escape_e e
Definition termdesc.h:224