Notcurses 3.0.13
a blingful library for TUIs and character graphics
Loading...
Searching...
No Matches
automaton.h File Reference
#include <stdint.h>
Include dependency graph for automaton.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  automaton
 

Typedefs

typedef int(* triefunc) (struct inputctx *)
 
typedef struct automaton automaton
 

Functions

void input_free_esctrie (automaton *a)
 
int inputctx_add_input_escape (automaton *a, const char *esc, uint32_t special, unsigned modifiers)
 
int inputctx_add_cflow (automaton *a, const char *csi, triefunc fxn) __attribute__((nonnull(1
 
int int walk_automaton (automaton *a, struct inputctx *ictx, unsigned candidate, struct ncinput *ni) __attribute__((nonnull(1
 
int int uint32_t esctrie_id (const struct esctrie *e)
 

Typedef Documentation

◆ automaton

typedef struct automaton automaton

◆ triefunc

typedef int(* triefunc) (struct inputctx *)

Definition at line 14 of file automaton.h.

Function Documentation

◆ esctrie_id()

int int uint32_t esctrie_id ( const struct esctrie e)

◆ input_free_esctrie()

void input_free_esctrie ( automaton a)

Definition at line 81 of file automaton.c.

81 {
82 a->escapes = 0;
83 a->poolsize = 0;
84 for(unsigned i = 0 ; i < a->poolused ; ++i){
85 free(a->nodepool[i].trie);
86 }
87 free(a->nodepool);
88 a->poolused = 0;
89 a->nodepool = NULL;
90}
free(duplicated)
struct esctrie * nodepool
Definition automaton.h:30
unsigned escapes
Definition automaton.h:20
unsigned poolsize
Definition automaton.h:28
unsigned poolused
Definition automaton.h:29
unsigned * trie
Definition automaton.c:23
return NULL
Definition termdesc.h:229
Here is the call graph for this function:

◆ inputctx_add_cflow()

int inputctx_add_cflow ( automaton a,
const char *  csi,
triefunc  fxn 
)

◆ inputctx_add_input_escape()

int inputctx_add_input_escape ( automaton a,
const char *  esc,
uint32_t  special,
unsigned  modifiers 
)

Definition at line 513 of file automaton.c.

514 {
515 if(esc[0] != NCKEY_ESC || strlen(esc) < 2){ // assume ESC prefix + content
516 logerror("not an escape (0x%x)", special);
517 return -1;
518 }
519 esctrie* eptr = insert_path(a, esc + 1);
520 if(eptr == NULL){
521 return -1;
522 }
523 // it appears that multiple keys can be mapped to the same escape string. as
524 // an example, see "kend" and "kc1" in st ("simple term" from suckless) :/.
525 if(eptr->ni.id){ // already had one here!
526 if(eptr->ni.id != special){
527 logwarn("already added escape (got 0x%x, wanted 0x%x)", eptr->ni.id, special);
528 }
529 }else{
530 eptr->ni.id = special;
531 eptr->ni.shift = modifiers & NCKEY_MOD_SHIFT;
532 eptr->ni.ctrl = modifiers & NCKEY_MOD_CTRL;
533 eptr->ni.alt = modifiers & NCKEY_MOD_ALT;
534 eptr->ni.y = 0;
535 eptr->ni.x = 0;
536 eptr->ni.modifiers = modifiers;
537 logdebug("added 0x%08x to %u", special, esctrie_idx(a, eptr));
538 }
539 return 0;
540}
#define logerror(fmt,...)
Definition logging.h:32
#define logdebug(fmt,...)
Definition logging.h:52
#define logwarn(fmt,...)
Definition logging.h:37
#define NCKEY_MOD_SHIFT
Definition nckeys.h:219
#define NCKEY_MOD_CTRL
Definition nckeys.h:221
#define NCKEY_ESC
Definition nckeys.h:196
#define NCKEY_MOD_ALT
Definition nckeys.h:220
ncinput ni
Definition automaton.c:30
bool alt
Definition notcurses.h:1214
bool ctrl
Definition notcurses.h:1216
uint32_t id
Definition notcurses.h:1210
bool shift
Definition notcurses.h:1215
unsigned modifiers
Definition notcurses.h:1219

◆ walk_automaton()

int int walk_automaton ( automaton a,
struct inputctx ictx,
unsigned  candidate,
struct ncinput ni 
)