From be998cef1b8a46391956dc212ef3bf1351da0f3a Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Wed, 15 Jul 2009 20:40:44 +0100 Subject: Renamed all type names to CamelCaseNames for visual distinctness, separate from variables/functions --- Makefile | 2 +- demo-async.c | 8 ++-- demo.c | 6 +-- driver-csi.c | 44 ++++++++++----------- driver-ti.c | 42 ++++++++++---------- termkey-internal.h | 34 ++++++++-------- termkey.c | 100 +++++++++++++++++++++++------------------------ termkey.h.in | 65 ++++++++++++++++-------------- termkey_advisereadable.3 | 2 +- termkey_get_fd.3 | 2 +- termkey_get_keyname.3 | 2 +- termkey_getkey.3.sh | 12 +++--- termkey_keyname2sym.3 | 2 +- termkey_new.3 | 6 +-- termkey_set_flags.3 | 4 +- termkey_set_waittime.3 | 4 +- termkey_snprint_key.3 | 4 +- termkey_waitkey.3.sh | 4 +- 18 files changed, 175 insertions(+), 168 deletions(-) diff --git a/Makefile b/Makefile index 31a5840..e1c75de 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ CFLAGS?= CFLAGS_DEBUG= VERSION_MAJOR=0 -VERSION_MINOR=2 +VERSION_MINOR=3 SONAME=libtermkey.so.$(VERSION_MAJOR) diff --git a/demo-async.c b/demo-async.c index 2574faa..9b48434 100644 --- a/demo-async.c +++ b/demo-async.c @@ -3,7 +3,7 @@ #include "termkey.h" -static void on_key(termkey_t *tk, termkey_key *key) +static void on_key(TermKey *tk, TermKeyKey *key) { char buffer[50]; termkey_snprint_key(tk, buffer, sizeof buffer, key, TERMKEY_FORMAT_VIM); @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) { TERMKEY_CHECK_VERSION; - termkey_t *tk = termkey_new(0, 0); + TermKey *tk = termkey_new(0, 0); if(!tk) { fprintf(stderr, "Cannot allocate termkey instance\n"); @@ -26,8 +26,8 @@ int main(int argc, char *argv[]) fd.fd = 0; /* the file descriptor we passed to termkey_new() */ fd.events = POLLIN; - termkey_result ret; - termkey_key key; + TermKeyResult ret; + TermKeyKey key; int running = 1; int nextwait = -1; diff --git a/demo.c b/demo.c index c39c38e..54845ad 100644 --- a/demo.c +++ b/demo.c @@ -7,15 +7,15 @@ int main(int argc, char *argv[]) TERMKEY_CHECK_VERSION; char buffer[50]; - termkey_t *tk = termkey_new(0, 0); + TermKey *tk = termkey_new(0, 0); if(!tk) { fprintf(stderr, "Cannot allocate termkey instance\n"); exit(1); } - termkey_result ret; - termkey_key key; + TermKeyResult ret; + TermKeyKey key; while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) { termkey_snprint_key(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_VIM); diff --git a/driver-csi.c b/driver-csi.c index 75f9874..be05b6c 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -5,7 +5,7 @@ #include typedef struct { - termkey_t *tk; + TermKey *tk; // There are 64 codes 0x40 - 0x7F struct keyinfo csi_ss3s[64]; @@ -14,17 +14,17 @@ typedef struct { int ncsifuncs; struct keyinfo *csifuncs; -} termkey_csi; +} TermKeyCsi; -static termkey_keysym register_csi_ss3(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name); -static termkey_keysym register_ss3kpalt(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name, char kpalt); -static termkey_keysym register_csifunc(termkey_csi *csi, termkey_type type, termkey_keysym sym, int number, const char *name); +static TermKeySym register_csi_ss3(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, unsigned char cmd, const char *name); +static TermKeySym register_ss3kpalt(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, unsigned char cmd, const char *name, char kpalt); +static TermKeySym register_csifunc(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int number, const char *name); -static termkey_keysym register_csi_ss3_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name); -static termkey_keysym register_ss3kpalt_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt); -static termkey_keysym register_csifunc_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name); +static TermKeySym register_csi_ss3_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name); +static TermKeySym register_ss3kpalt_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt); +static TermKeySym register_csifunc_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, int number, const char *name); -static void *new_driver(termkey_t *tk, const char *term) +static void *new_driver(TermKey *tk, const char *term) { if(strncmp(term, "xterm", 5) == 0) { // We want "xterm" or "xtermc" or "xterm-..." @@ -43,7 +43,7 @@ static void *new_driver(termkey_t *tk, const char *term) // Excellent - we'll continue - termkey_csi *csi = malloc(sizeof *csi); + TermKeyCsi *csi = malloc(sizeof *csi); if(!csi) return NULL; @@ -139,7 +139,7 @@ abort_free_csi: static void free_driver(void *info) { - termkey_csi *csi = info; + TermKeyCsi *csi = info; free(csi->csifuncs); csi->csifuncs = NULL; @@ -148,7 +148,7 @@ static void free_driver(void *info) #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static termkey_result peekkey_csi(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force, size_t *nbytep) +static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep) { size_t csi_end = introlen; @@ -268,7 +268,7 @@ static termkey_result peekkey_csi(termkey_t *tk, termkey_csi *csi, size_t introl return TERMKEY_RES_KEY; } -static termkey_result peekkey_ss3(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force, size_t *nbytep) +static TermKeyResult peekkey_ss3(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep) { if(tk->buffcount < introlen + 1) { if(!force) @@ -317,12 +317,12 @@ static termkey_result peekkey_ss3(termkey_t *tk, termkey_csi *csi, size_t introl return TERMKEY_RES_KEY; } -static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytep) +static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytep) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; - termkey_csi *csi = info; + TermKeyCsi *csi = info; // Now we're sure at least 1 byte is valid unsigned char b0 = CHARAT(0); @@ -343,12 +343,12 @@ static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int f return TERMKEY_RES_NONE; } -static termkey_keysym register_csi_ss3(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name) +static TermKeySym register_csi_ss3(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, unsigned char cmd, const char *name) { return register_csi_ss3_full(csi, type, sym, 0, 0, cmd, name); } -static termkey_keysym register_csi_ss3_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name) +static TermKeySym register_csi_ss3_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name) { if(cmd < 0x40 || cmd >= 0x80) { fprintf(stderr, "Cannot register CSI/SS3 key at cmd 0x%02x - out of bounds\n", cmd); @@ -366,12 +366,12 @@ static termkey_keysym register_csi_ss3_full(termkey_csi *csi, termkey_type type, return sym; } -static termkey_keysym register_ss3kpalt(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name, char kpalt) +static TermKeySym register_ss3kpalt(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, unsigned char cmd, const char *name, char kpalt) { return register_ss3kpalt_full(csi, type, sym, 0, 0, cmd, name, kpalt); } -static termkey_keysym register_ss3kpalt_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt) +static TermKeySym register_ss3kpalt_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char cmd, const char *name, char kpalt) { if(cmd < 0x40 || cmd >= 0x80) { fprintf(stderr, "Cannot register SS3 key at cmd 0x%02x - out of bounds\n", cmd); @@ -390,12 +390,12 @@ static termkey_keysym register_ss3kpalt_full(termkey_csi *csi, termkey_type type return sym; } -static termkey_keysym register_csifunc(termkey_csi *csi, termkey_type type, termkey_keysym sym, int number, const char *name) +static TermKeySym register_csifunc(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int number, const char *name) { return register_csifunc_full(csi, type, sym, 0, 0, number, name); } -static termkey_keysym register_csifunc_full(termkey_csi *csi, termkey_type type, termkey_keysym sym, int modifier_set, int modifier_mask, int number, const char *name) +static TermKeySym register_csifunc_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, int number, const char *name) { if(name) sym = termkey_register_keyname(csi->tk, sym, name); @@ -420,7 +420,7 @@ static termkey_keysym register_csifunc_full(termkey_csi *csi, termkey_type type, return sym; } -struct termkey_driver termkey_driver_csi = { +struct TermKeyDriver termkey_driver_csi = { .name = "CSI", .new_driver = new_driver, diff --git a/driver-ti.c b/driver-ti.c index 098c526..7d4c047 100644 --- a/driver-ti.c +++ b/driver-ti.c @@ -39,18 +39,18 @@ struct trie_node_arr { }; typedef struct { - termkey_t *tk; + TermKey *tk; struct trie_node *root; char *start_string; char *stop_string; -} termkey_ti; +} TermKeyTI; -static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmask, int *modsetp); -static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset); +static int funcname2keysym(const char *funcname, TermKeyType *typep, TermKeySym *symp, int *modmask, int *modsetp); +static int register_seq(TermKeyTI *ti, const char *seq, TermKeyType type, TermKeySym sym, int modmask, int modset); -static struct trie_node *new_node_key(termkey_type type, termkey_keysym sym, int modmask, int modset) +static struct trie_node *new_node_key(TermKeyType type, TermKeySym sym, int modmask, int modset) { struct trie_node_key *n = malloc(sizeof(*n)); if(!n) @@ -150,7 +150,7 @@ static struct trie_node *compress_trie(struct trie_node *n) return n; } -static void *new_driver(termkey_t *tk, const char *term) +static void *new_driver(TermKey *tk, const char *term) { int err; @@ -159,7 +159,7 @@ static void *new_driver(termkey_t *tk, const char *term) if(setupterm((char*)term, 1, &err) != OK) return NULL; - termkey_ti *ti = malloc(sizeof *ti); + TermKeyTI *ti = malloc(sizeof *ti); if(!ti) return NULL; @@ -180,8 +180,8 @@ static void *new_driver(termkey_t *tk, const char *term) if(!value || value == (char*)-1) continue; - termkey_type type; - termkey_keysym sym; + TermKeyType type; + TermKeySym sym; int mask = 0; int set = 0; @@ -220,9 +220,9 @@ abort_free_ti: return NULL; } -static void start_driver(termkey_t *tk, void *info) +static void start_driver(TermKey *tk, void *info) { - termkey_ti *ti = info; + TermKeyTI *ti = info; /* The terminfo database will contain keys in application cursor key mode. * We may need to enable that mode @@ -233,9 +233,9 @@ static void start_driver(termkey_t *tk, void *info) } } -static void stop_driver(termkey_t *tk, void *info) +static void stop_driver(TermKey *tk, void *info) { - termkey_ti *ti = info; + TermKeyTI *ti = info; if(ti->stop_string) { // Can't call putp or tputs because they suck and don't give us fd control @@ -245,7 +245,7 @@ static void stop_driver(termkey_t *tk, void *info) static void free_driver(void *info) { - termkey_ti *ti = info; + TermKeyTI *ti = info; free_trie(ti->root); @@ -260,9 +260,9 @@ static void free_driver(void *info) #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytep) +static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytep) { - termkey_ti *ti = info; + TermKeyTI *ti = info; if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -297,8 +297,8 @@ static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int f static struct { const char *funcname; - termkey_type type; - termkey_keysym sym; + TermKeyType type; + TermKeySym sym; int mods; } funcs[] = { @@ -348,7 +348,7 @@ static struct { { NULL }, }; -static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmaskp, int *modsetp) +static int funcname2keysym(const char *funcname, TermKeyType *typep, TermKeySym *symp, int *modmaskp, int *modsetp) { // Binary search @@ -395,7 +395,7 @@ static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_ke return 0; } -static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset) +static int register_seq(TermKeyTI *ti, const char *seq, TermKeyType type, TermKeySym sym, int modmask, int modset) { int pos = 0; struct trie_node *p = ti->root; @@ -447,7 +447,7 @@ static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, term return 1; } -struct termkey_driver termkey_driver_ti = { +struct TermKeyDriver termkey_driver_ti = { .name = "terminfo", .new_driver = new_driver, diff --git a/termkey-internal.h b/termkey-internal.h index dce83a6..8286c36 100644 --- a/termkey-internal.h +++ b/termkey-internal.h @@ -6,31 +6,31 @@ #include #include -struct termkey_driver +struct TermKeyDriver { const char *name; - void *(*new_driver)(termkey_t *tk, const char *term); + void *(*new_driver)(TermKey *tk, const char *term); void (*free_driver)(void *info); - void (*start_driver)(termkey_t *tk, void *info); - void (*stop_driver)(termkey_t *tk, void *info); - termkey_result (*peekkey)(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytes); + void (*start_driver)(TermKey *tk, void *info); + void (*stop_driver)(TermKey *tk, void *info); + TermKeyResult (*peekkey)(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytes); }; struct keyinfo { - termkey_type type; - termkey_keysym sym; + TermKeyType type; + TermKeySym sym; int modifier_mask; int modifier_set; }; -struct termkey_drivernode; -struct termkey_drivernode { - struct termkey_driver *driver; +struct TermKeyDriverNode; +struct TermKeyDriverNode { + struct TermKeyDriver *driver; void *info; - struct termkey_drivernode *next; + struct TermKeyDriverNode *next; }; -struct termkey { +struct _TermKey { int fd; int flags; unsigned char *buffer; @@ -51,17 +51,17 @@ struct termkey { // There are 32 C0 codes struct keyinfo c0[32]; - struct termkey_drivernode *drivers; + struct TermKeyDriverNode *drivers; // Now some "protected" methods for the driver to call but which we don't // want exported as real symbols in the library struct { - void (*emit_codepoint)(termkey_t *tk, long codepoint, termkey_key *key); - termkey_result (*peekkey_simple)(termkey_t *tk, termkey_key *key, int force, size_t *nbytes); + void (*emit_codepoint)(TermKey *tk, long codepoint, TermKeyKey *key); + TermKeyResult (*peekkey_simple)(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes); } method; }; -extern struct termkey_driver termkey_driver_csi; -extern struct termkey_driver termkey_driver_ti; +extern struct TermKeyDriver termkey_driver_csi; +extern struct TermKeyDriver termkey_driver_ti; #endif diff --git a/termkey.c b/termkey.c index 394c1a8..da4397d 100644 --- a/termkey.c +++ b/termkey.c @@ -25,22 +25,22 @@ void termkey_check_version(int major, int minor) // Happy } -static struct termkey_driver *drivers[] = { +static struct TermKeyDriver *drivers[] = { &termkey_driver_ti, &termkey_driver_csi, NULL, }; // Forwards for the "protected" methods -// static void eat_bytes(termkey_t *tk, size_t count); -static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key); -static termkey_result peekkey_simple(termkey_t *tk, termkey_key *key, int force, size_t *nbytes); +// static void eat_bytes(TermKey *tk, size_t count); +static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key); +static TermKeyResult peekkey_simple(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes); -static termkey_keysym register_c0(termkey_t *tk, termkey_keysym sym, unsigned char ctrl, const char *name); -static termkey_keysym register_c0_full(termkey_t *tk, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name); +static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, const char *name); +static TermKeySym register_c0_full(TermKey *tk, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name); static struct { - termkey_keysym sym; + TermKeySym sym; const char *name; } keynames[] = { { TERMKEY_SYM_NONE, "NONE" }, @@ -109,9 +109,9 @@ static struct { /* We might expose this as public API one day, when the ideas are finalised. * As yet it isn't public, so keep it static */ -static termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) +static TermKey *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) { - termkey_t *tk = malloc(sizeof(*tk)); + TermKey *tk = malloc(sizeof(*tk)); if(!tk) return NULL; @@ -176,7 +176,7 @@ static termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waitt const char *term = getenv("TERM"); - struct termkey_drivernode *tail = NULL; + struct TermKeyDriverNode *tail = NULL; for(i = 0; drivers[i]; i++) { void *info = (*drivers[i]->new_driver)(tk, term); @@ -187,7 +187,7 @@ static termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waitt fprintf(stderr, "Loading the %s driver\n", drivers[i]->name); #endif - struct termkey_drivernode *thisdrv = malloc(sizeof(*thisdrv)); + struct TermKeyDriverNode *thisdrv = malloc(sizeof(*thisdrv)); if(!thisdrv) goto abort_free_drivers; @@ -221,7 +221,7 @@ static termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waitt } } - struct termkey_drivernode *p; + struct TermKeyDriverNode *p; for(p = tk->drivers; p; p = p->next) if(p->driver->start_driver) (*p->driver->start_driver)(tk, p->info); @@ -231,7 +231,7 @@ static termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waitt abort_free_drivers: for(p = tk->drivers; p; ) { (*p->driver->free_driver)(p->info); - struct termkey_drivernode *next = p->next; + struct TermKeyDriverNode *next = p->next; free(p); p = next; } @@ -248,20 +248,20 @@ abort_free_tk: return NULL; } -termkey_t *termkey_new(int fd, int flags) +TermKey *termkey_new(int fd, int flags) { return termkey_new_full(fd, flags, 256, 50); } -void termkey_free(termkey_t *tk) +void termkey_free(TermKey *tk) { free(tk->buffer); tk->buffer = NULL; free(tk->keynames); tk->keynames = NULL; - struct termkey_drivernode *p; + struct TermKeyDriverNode *p; for(p = tk->drivers; p; ) { (*p->driver->free_driver)(p->info); - struct termkey_drivernode *next = p->next; + struct TermKeyDriverNode *next = p->next; free(p); p = next; } @@ -269,9 +269,9 @@ void termkey_free(termkey_t *tk) free(tk); } -void termkey_destroy(termkey_t *tk) +void termkey_destroy(TermKey *tk) { - struct termkey_drivernode *p; + struct TermKeyDriverNode *p; for(p = tk->drivers; p; p = p->next) if(p->driver->stop_driver) (*p->driver->stop_driver)(tk, p->info); @@ -282,32 +282,32 @@ void termkey_destroy(termkey_t *tk) termkey_free(tk); } -int termkey_get_fd(termkey_t *tk) +int termkey_get_fd(TermKey *tk) { return tk->fd; } -int termkey_get_flags(termkey_t *tk) +int termkey_get_flags(TermKey *tk) { return tk->flags; } -void termkey_set_flags(termkey_t *tk, int newflags) +void termkey_set_flags(TermKey *tk, int newflags) { tk->flags = newflags; } -void termkey_set_waittime(termkey_t *tk, int msec) +void termkey_set_waittime(TermKey *tk, int msec) { tk->waittime = msec; } -int termkey_get_waittime(termkey_t *tk) +int termkey_get_waittime(TermKey *tk) { return tk->waittime; } -static void eat_bytes(termkey_t *tk, size_t count) +static void eat_bytes(TermKey *tk, size_t count) { if(count >= tk->buffcount) { tk->buffstart = 0; @@ -329,7 +329,7 @@ static inline unsigned int utf8_seqlen(long codepoint) return 6; } -static void fill_utf8(termkey_key *key) +static void fill_utf8(TermKeyKey *key) { long codepoint = key->code.codepoint; int nbytes = utf8_seqlen(codepoint); @@ -354,7 +354,7 @@ static void fill_utf8(termkey_key *key) } } -static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key) +static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key) { if(codepoint < 0x20) { // C0 range @@ -421,7 +421,7 @@ static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key) #define UTF8_INVALID 0xFFFD -static termkey_result peekkey(termkey_t *tk, termkey_key *key, int force, size_t *nbytep) +static TermKeyResult peekkey(TermKey *tk, TermKeyKey *key, int force, size_t *nbytep) { int again = 0; @@ -431,8 +431,8 @@ static termkey_result peekkey(termkey_t *tk, termkey_key *key, int force, size_t fprintf(stderr, "\n"); #endif - termkey_result ret; - struct termkey_drivernode *p; + TermKeyResult ret; + struct TermKeyDriverNode *p; for(p = tk->drivers; p; p = p->next) { ret = (p->driver->peekkey)(tk, p->info, key, force, nbytep); @@ -486,7 +486,7 @@ static termkey_result peekkey(termkey_t *tk, termkey_key *key, int force, size_t #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static termkey_result peekkey_simple(termkey_t *tk, termkey_key *key, int force, size_t *nbytep) +static TermKeyResult peekkey_simple(TermKey *tk, TermKeyKey *key, int force, size_t *nbytep) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -511,7 +511,7 @@ static termkey_result peekkey_simple(termkey_t *tk, termkey_key *key, int force, tk->buffcount--; // Run the full driver - termkey_result metakey_result = peekkey(tk, key, force, nbytep); + TermKeyResult metakey_result = peekkey(tk, key, force, nbytep); tk->buffstart--; tk->buffcount++; @@ -632,7 +632,7 @@ static termkey_result peekkey_simple(termkey_t *tk, termkey_key *key, int force, } #ifdef DEBUG -static void print_buffer(termkey_t *tk) +static void print_buffer(TermKey *tk) { int i; for(i = 0; i < tk->buffcount && i < 20; i++) @@ -641,7 +641,7 @@ static void print_buffer(termkey_t *tk) fprintf(stderr, "..."); } -static void print_key(termkey_t *tk, termkey_key *key) +static void print_key(TermKey *tk, TermKeyKey *key) { switch(key->type) { case TERMKEY_TYPE_UNICODE: @@ -663,7 +663,7 @@ static void print_key(termkey_t *tk, termkey_key *key) m & ~(TERMKEY_KEYMOD_CTRL|TERMKEY_KEYMOD_ALT|TERMKEY_KEYMOD_SHIFT)); } -static const char *res2str(termkey_result res) +static const char *res2str(TermKeyResult res) { switch(res) { case TERMKEY_RES_KEY: @@ -680,10 +680,10 @@ static const char *res2str(termkey_result res) } #endif -termkey_result termkey_getkey(termkey_t *tk, termkey_key *key) +TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key) { size_t nbytes = 0; - termkey_result ret = peekkey(tk, key, 0, &nbytes); + TermKeyResult ret = peekkey(tk, key, 0, &nbytes); if(ret == TERMKEY_RES_KEY) eat_bytes(tk, nbytes); @@ -696,10 +696,10 @@ termkey_result termkey_getkey(termkey_t *tk, termkey_key *key) return ret; } -termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key) +TermKeyResult termkey_getkey_force(TermKey *tk, TermKeyKey *key) { size_t nbytes = 0; - termkey_result ret = peekkey(tk, key, 1, &nbytes); + TermKeyResult ret = peekkey(tk, key, 1, &nbytes); if(ret == TERMKEY_RES_KEY) eat_bytes(tk, nbytes); @@ -707,10 +707,10 @@ termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key) return ret; } -termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key) +TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key) { while(1) { - termkey_result ret = termkey_getkey(tk, key); + TermKeyResult ret = termkey_getkey(tk, key); switch(ret) { case TERMKEY_RES_KEY: @@ -750,7 +750,7 @@ termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key) /* UNREACHABLE */ } -void termkey_pushinput(termkey_t *tk, unsigned char *input, size_t inputlen) +void termkey_pushinput(TermKey *tk, unsigned char *input, size_t inputlen) { if(tk->buffstart + tk->buffcount + inputlen > tk->buffsize) { while(tk->buffstart + tk->buffcount + inputlen > tk->buffsize) @@ -766,7 +766,7 @@ void termkey_pushinput(termkey_t *tk, unsigned char *input, size_t inputlen) tk->buffcount += inputlen; } -termkey_result termkey_advisereadable(termkey_t *tk) +TermKeyResult termkey_advisereadable(TermKey *tk) { unsigned char buffer[64]; // Smaller than the default size ssize_t len = read(tk->fd, buffer, sizeof buffer); @@ -783,7 +783,7 @@ termkey_result termkey_advisereadable(termkey_t *tk) } } -termkey_keysym termkey_register_keyname(termkey_t *tk, termkey_keysym sym, const char *name) +TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name) { if(!sym) sym = tk->nkeynames; @@ -805,7 +805,7 @@ termkey_keysym termkey_register_keyname(termkey_t *tk, termkey_keysym sym, const return sym; } -const char *termkey_get_keyname(termkey_t *tk, termkey_keysym sym) +const char *termkey_get_keyname(TermKey *tk, TermKeySym sym) { if(sym == TERMKEY_SYM_UNKNOWN) return "UNKNOWN"; @@ -816,12 +816,12 @@ const char *termkey_get_keyname(termkey_t *tk, termkey_keysym sym) return "UNKNOWN"; } -termkey_keysym termkey_keyname2sym(termkey_t *tk, const char *keyname) +TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname) { /* We store an array, so we can't do better than a linear search. Doesn't * matter because user won't be calling this too often */ - termkey_keysym sym; + TermKeySym sym; for(sym = 0; sym < tk->nkeynames; sym++) if(tk->keynames[sym] && strcmp(keyname, tk->keynames[sym]) == 0) @@ -830,12 +830,12 @@ termkey_keysym termkey_keyname2sym(termkey_t *tk, const char *keyname) return TERMKEY_SYM_UNKNOWN; } -static termkey_keysym register_c0(termkey_t *tk, termkey_keysym sym, unsigned char ctrl, const char *name) +static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, const char *name) { return register_c0_full(tk, sym, 0, 0, ctrl, name); } -static termkey_keysym register_c0_full(termkey_t *tk, termkey_keysym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name) +static TermKeySym register_c0_full(TermKey *tk, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name) { if(ctrl >= 0x20) { fprintf(stderr, "Cannot register C0 key at ctrl 0x%02x - out of bounds\n", ctrl); @@ -852,7 +852,7 @@ static termkey_keysym register_c0_full(termkey_t *tk, termkey_keysym sym, int mo return sym; } -size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format) +size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format) { size_t pos = 0; size_t l = 0; diff --git a/termkey.h.in b/termkey.h.in index cbf895d..eebfeff 100644 --- a/termkey.h.in +++ b/termkey.h.in @@ -84,20 +84,20 @@ typedef enum { TERMKEY_SYM_KPEQUALS, // et cetera ad nauseum -} termkey_sym; +} TermKeySym; typedef enum { TERMKEY_TYPE_UNICODE, TERMKEY_TYPE_FUNCTION, TERMKEY_TYPE_KEYSYM -} termkey_type; +} TermKeyType; typedef enum { TERMKEY_RES_NONE, TERMKEY_RES_KEY, TERMKEY_RES_EOF, TERMKEY_RES_AGAIN, -} termkey_result; +} TermKeyResult; enum { TERMKEY_KEYMOD_SHIFT = 1 << 0, @@ -105,23 +105,21 @@ enum { TERMKEY_KEYMOD_CTRL = 1 << 2, }; -typedef int termkey_keysym; - typedef struct { - termkey_type type; + TermKeyType type; union { - long codepoint; // TERMKEY_TYPE_UNICODE - int number; // TERMKEY_TYPE_FUNCTION - termkey_keysym sym; // TERMKEY_TYPE_KEYSYM + long codepoint; // TERMKEY_TYPE_UNICODE + int number; // TERMKEY_TYPE_FUNCTION + TermKeySym sym; // TERMKEY_TYPE_KEYSYM } code; int modifiers; /* Any Unicode character can be UTF-8 encoded in no more than 6 bytes, plus * terminating NUL */ char utf8[7]; -} termkey_key; +} TermKeyKey; -typedef struct termkey termkey_t; +typedef struct _TermKey TermKey; enum { TERMKEY_FLAG_NOINTERPRET = 1 << 0, // Do not interpret C0//G1 codes if possible @@ -133,42 +131,51 @@ enum { void termkey_check_version(int major, int minor); -termkey_t *termkey_new(int fd, int flags); -void termkey_free(termkey_t *tk); -void termkey_destroy(termkey_t *tk); +TermKey *termkey_new(int fd, int flags); +void termkey_free(TermKey *tk); +void termkey_destroy(TermKey *tk); -int termkey_get_fd(termkey_t *tk); +int termkey_get_fd(TermKey *tk); -int termkey_get_flags(termkey_t *tk); -void termkey_set_flags(termkey_t *tk, int newflags); +int termkey_get_flags(TermKey *tk); +void termkey_set_flags(TermKey *tk, int newflags); -void termkey_set_waittime(termkey_t *tk, int msec); -int termkey_get_waittime(termkey_t *tk); +void termkey_set_waittime(TermKey *tk, int msec); +int termkey_get_waittime(TermKey *tk); -termkey_result termkey_getkey(termkey_t *tk, termkey_key *key); -termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key); -termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key); +TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key); +TermKeyResult termkey_getkey_force(TermKey *tk, TermKeyKey *key); +TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key); -void termkey_pushinput(termkey_t *tk, unsigned char *input, size_t inputlen); +void termkey_pushinput(TermKey *tk, unsigned char *input, size_t inputlen); -termkey_result termkey_advisereadable(termkey_t *tk); +TermKeyResult termkey_advisereadable(TermKey *tk); -termkey_keysym termkey_register_keyname(termkey_t *tk, termkey_keysym sym, const char *name); -const char *termkey_get_keyname(termkey_t *tk, termkey_keysym sym); +TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name); +const char *termkey_get_keyname(TermKey *tk, TermKeySym sym); -termkey_keysym termkey_keyname2sym(termkey_t *tk, const char *keyname); +TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname); typedef enum { TERMKEY_FORMAT_LONGMOD = 1 << 0, // Shift-... instead of S-... TERMKEY_FORMAT_CARETCTRL = 1 << 1, // ^X instead of C-X TERMKEY_FORMAT_ALTISMETA = 1 << 2, // Meta- or M- instead of Alt- or A- TERMKEY_FORMAT_WRAPBRACKET = 1 << 3, // Wrap special keys in brackets like -} termkey_format; +} TermKeyFormat; // Some useful combinations #define TERMKEY_FORMAT_VIM (TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_WRAPBRACKET) -size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format); +size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format); + +// Legacy name typedefs + +typedef TermKeySym termkey_keysym; +typedef TermKeyType termkey_type; +typedef TermKeyResult termkey_result; +typedef TermKeyKey termkey_key; + +typedef TermKey termkey_t; #endif diff --git a/termkey_advisereadable.3 b/termkey_advisereadable.3 index 2fe831c..ee434f6 100644 --- a/termkey_advisereadable.3 +++ b/termkey_advisereadable.3 @@ -5,7 +5,7 @@ termkey_advisereadable \- read more bytes from the underlying terminal .nf .B #include .sp -.BI "termkey_result termkey_advisereadable(termkey_t *" tk ); +.BI "TermKeyResult termkey_advisereadable(TermKey *" tk ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_get_fd.3 b/termkey_get_fd.3 index 653e1cf..5e648d6 100644 --- a/termkey_get_fd.3 +++ b/termkey_get_fd.3 @@ -5,7 +5,7 @@ termkey_get_fd \- obtain the file descriptor for the terminal .nf .B #include .sp -.BI "int termkey_get_fd(termkey_t *" tk ); +.BI "int termkey_get_fd(TermKey *" tk ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_get_keyname.3 b/termkey_get_keyname.3 index 62dc1d2..e945727 100644 --- a/termkey_get_keyname.3 +++ b/termkey_get_keyname.3 @@ -5,7 +5,7 @@ termkey_get_keyname \- return a string name for a symbolic key .nf .B #include .sp -.BI "const char *termkey_get_keyname(termkey_t *" tk ", termkey_keysym " sym ); +.BI "const char *termkey_get_keyname(TermKey *" tk ", TermKeySym " sym ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_getkey.3.sh b/termkey_getkey.3.sh index 33e7f23..83ef9db 100644 --- a/termkey_getkey.3.sh +++ b/termkey_getkey.3.sh @@ -7,9 +7,9 @@ termkey_getkey, termkey_getkey_force \- retrieve the next key event .nf .B #include .sp -.BI "termkey_result termkey_getkey(termkey_t *" tk ", termkey_key *" key ); +.BI "TermKeyResult termkey_getkey(TermKey *" tk ", TermKeyKey *" key ); .br -.BI "termkey_result termkey_getkey_force(termkey_t *" tk ", termkey_key *" key ); +.BI "TermKeyResult termkey_getkey_force(TermKey *" tk ", TermKeyKey *" key ); .fi .sp Link with \fI-ltermkey\fP. @@ -33,20 +33,20 @@ no bytes are waiting in the buffer. .PP Neither of these functions will block or perform any IO operations on the underlying filehandle. To use the instance in an asynchronous program, see \fBtermkey_advisereadable\fP(3). For a blocking call suitable for use in a synchronous program, use \fBtermkey_waitkey\fP(3) instead of \fBtermkey_getkey\fP(). .PP -The \fItermkey_key\fP structure is defined as follows: +The \fITermKeyKey\fP structure is defined as follows: .PP .in +4n .nf typedef struct { - termkey_type type; + TermKeyType type; union { long codepoint; /* TERMKEY_TYPE_UNICODE */ int number; /* TERMKEY_TYPE_FUNCTION */ - termkey_keysym sym; /* TERMKEY_TYPE_KEYSYM */ + TermKeySym sym; /* TERMKEY_TYPE_KEYSYM */ } code; int modifiers; char utf8[7]; -} termkey_key; +} TermKeyKey; .fi .in .PP diff --git a/termkey_keyname2sym.3 b/termkey_keyname2sym.3 index aba22f4..9aa72be 100644 --- a/termkey_keyname2sym.3 +++ b/termkey_keyname2sym.3 @@ -5,7 +5,7 @@ termkey_keyname2sym \- look up a symbolic key value for a string name .nf .B #include .sp -.BI "termkey_keysym termkey_keyname2sym(termkey_t *" tk ", const char *" keyname ); +.BI "TermKeySym termkey_keyname2sym(TermKey *" tk ", const char *" keyname ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_new.3 b/termkey_new.3 index 4d099ff..4a7f774 100644 --- a/termkey_new.3 +++ b/termkey_new.3 @@ -7,14 +7,14 @@ termkey_new, termkey_destroy \- create or destroy new termkey instance .sp .BI "TERMKEY_CHECK_VERSION;" .br -.BI "termkey_tk *termkey_new(int " fd ", int " flags ); +.BI "TermKey *termkey_new(int " fd ", int " flags ); .br -.BI "void termkey_destroy(termkey_t *" tk ); +.BI "void termkey_destroy(TermKey *" tk ); .fi .sp Link with \fI\-ltermkey\fP. .SH DESCRIPTION -\fBtermkey_new\fP() creates a new termkey instance connected to the file handle opened by \fIfd\fP using the \fIflags\fP. The \fBtermkey_tk\fP structure should be considered opaque; its contents are not intended for use outside of the library. +\fBtermkey_new\fP() creates a new termkey instance connected to the file handle opened by \fIfd\fP using the \fIflags\fP. The \fBTermKey\fP structure should be considered opaque; its contents are not intended for use outside of the library. .PP \fBtermkey_destroy\fP() destroys the given instance and releases any resources controlled by it. It will not close the underlying filehandle given as the \fIfd\fP argument to \fBtermkey_new\fP(). .PP diff --git a/termkey_set_flags.3 b/termkey_set_flags.3 index 6365a91..c6f47a6 100644 --- a/termkey_set_flags.3 +++ b/termkey_set_flags.3 @@ -5,9 +5,9 @@ termkey_set_flags, termkey_get_flags \- control the operational flags .nf .B #include .sp -.BI "void termkey_set_flags(termkey_t *" tk ", int " newflags ); +.BI "void termkey_set_flags(TermKey *" tk ", int " newflags ); .br -.BI "int termkey_get_flags(termkey_t *" tk ); +.BI "int termkey_get_flags(TermKey *" tk ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_set_waittime.3 b/termkey_set_waittime.3 index 87fc82b..da2d013 100644 --- a/termkey_set_waittime.3 +++ b/termkey_set_waittime.3 @@ -5,9 +5,9 @@ termkey_set_waittime, termkey_get_waittime \- control the wait time for multibyt .nf .B #include .sp -.BI "void termkey_set_waittime(termkey_t *" tk ", int " msec ); +.BI "void termkey_set_waittime(TermKey *" tk ", int " msec ); .br -.BI "int termkey_get_waittime(termkey_t *" tk ); +.BI "int termkey_get_waittime(TermKey *" tk ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_snprint_key.3 b/termkey_snprint_key.3 index 4c67f9d..5a66392 100644 --- a/termkey_snprint_key.3 +++ b/termkey_snprint_key.3 @@ -5,8 +5,8 @@ termkey_snprint_key \- format a string representing a key event .nf .B #include .sp -.BI "size_t termkey_snprint_key(termkey_t *" tk ", char *" buffer ", size_t " len ", -.BI " termkey_key " key ", termkey_format " format ); +.BI "size_t termkey_snprint_key(TermKey *" tk ", char *" buffer ", size_t " len ", +.BI " TermKeyKey " key ", TermKeyFormat " format ); .fi .sp Link with \fI-ltermkey\fP. diff --git a/termkey_waitkey.3.sh b/termkey_waitkey.3.sh index 7dda316..8a2a072 100644 --- a/termkey_waitkey.3.sh +++ b/termkey_waitkey.3.sh @@ -7,14 +7,14 @@ termkey_waitkey \- wait for and retrieve the next key event .nf .B #include .sp -.BI "termkey_result termkey_waitkey(termkey_t *" tk ", termkey_key *" key ); +.BI "TermKeyResult termkey_waitkey(TermKey *" tk ", TermKeyKey *" key ); .fi .sp Link with \fI-ltermkey\fP. .SH DESCRIPTION \fBtermkey_waitkey\fP attempts to retrieve a single keypress event from the buffer, and put it in the structure referred to by \fIkey\fP. If successful it will return \fBTERMKEY_RES_KEY\fP to indicate that the structure now contains a new keypress event. If nothing is in the buffer it will block until one is available. If no events are ready and the input stream is now closed, will return \fBTERMKEY_RES_EOF\fP. .PP -For details of the \fBtermkey_key\fP structure, see \fBtermkey_getkey\fP(3). +For details of the \fBTermKeyKey\fP structure, see \fBtermkey_getkey\fP(3). .PP Some keypresses generate multiple bytes from the terminal. Because there may be network or other delays between the terminal and an application using termkey, \fBtermkey_waitkey\fP() will attempt to wait for the remaining bytes to arrive if it detects the start of a multibyte sequence. If no more bytes arrive within a certain time, then the bytes will be reported as they stand, even if this results in interpreting a partially-complete Escape sequence as a literal Escape key followed by some normal letters or other symbols. The amount of time to wait can be set by \fBtermkey_set_waittime\fP(3). .SH "RETURN VALUE" -- cgit v1.2.3-70-g09d2