=== modified file 'Makefile' --- Makefile 2009-07-15 19:40:44 +0000 +++ Makefile 2008-12-15 20:49:59 +0000 @@ -4,7 +4,7 @@ CFLAGS_DEBUG= VERSION_MAJOR=0 -VERSION_MINOR=3 +VERSION_MINOR=2 SONAME=libtermkey.so.$(VERSION_MAJOR) === modified file 'demo-async.c' --- demo-async.c 2009-07-15 19:40:44 +0000 +++ demo-async.c 2008-12-08 22:54:14 +0000 @@ -3,7 +3,7 @@ #include "termkey.h" -static void on_key(TermKey *tk, TermKeyKey *key) +static void on_key(termkey_t *tk, termkey_key *key) { char buffer[50]; termkey_snprint_key(tk, buffer, sizeof buffer, key, TERMKEY_FORMAT_VIM); @@ -14,7 +14,7 @@ { TERMKEY_CHECK_VERSION; - TermKey *tk = termkey_new(0, 0); + termkey_t *tk = termkey_new(0, 0); if(!tk) { fprintf(stderr, "Cannot allocate termkey instance\n"); @@ -26,8 +26,8 @@ fd.fd = 0; /* the file descriptor we passed to termkey_new() */ fd.events = POLLIN; - TermKeyResult ret; - TermKeyKey key; + termkey_result ret; + termkey_key key; int running = 1; int nextwait = -1; === modified file 'demo.c' --- demo.c 2009-07-15 19:40:44 +0000 +++ demo.c 2008-12-08 22:54:14 +0000 @@ -7,15 +7,15 @@ TERMKEY_CHECK_VERSION; char buffer[50]; - TermKey *tk = termkey_new(0, 0); + termkey_t *tk = termkey_new(0, 0); if(!tk) { fprintf(stderr, "Cannot allocate termkey instance\n"); exit(1); } - TermKeyResult ret; - TermKeyKey key; + termkey_result ret; + termkey_key key; while((ret = termkey_waitkey(tk, &key)) != TERMKEY_RES_EOF) { termkey_snprint_key(tk, buffer, sizeof buffer, &key, TERMKEY_FORMAT_VIM); === modified file 'driver-csi.c' --- driver-csi.c 2009-07-15 19:40:44 +0000 +++ driver-csi.c 2008-12-10 00:23:47 +0000 @@ -5,7 +5,7 @@ #include typedef struct { - TermKey *tk; + termkey_t *tk; // There are 64 codes 0x40 - 0x7F struct keyinfo csi_ss3s[64]; @@ -14,17 +14,17 @@ int ncsifuncs; struct keyinfo *csifuncs; -} TermKeyCsi; - -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 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 *tk, const char *term) +} termkey_csi; + +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 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 void *new_driver(termkey_t *tk, const char *term) { if(strncmp(term, "xterm", 5) == 0) { // We want "xterm" or "xtermc" or "xterm-..." @@ -43,7 +43,7 @@ // Excellent - we'll continue - TermKeyCsi *csi = malloc(sizeof *csi); + termkey_csi *csi = malloc(sizeof *csi); if(!csi) return NULL; @@ -139,7 +139,7 @@ static void free_driver(void *info) { - TermKeyCsi *csi = info; + termkey_csi *csi = info; free(csi->csifuncs); csi->csifuncs = NULL; @@ -148,7 +148,7 @@ #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static TermKeyResult peekkey_csi(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep) +static termkey_result peekkey_csi(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force, size_t *nbytep) { size_t csi_end = introlen; @@ -268,7 +268,7 @@ return TERMKEY_RES_KEY; } -static TermKeyResult peekkey_ss3(TermKey *tk, TermKeyCsi *csi, size_t introlen, TermKeyKey *key, int force, size_t *nbytep) +static termkey_result peekkey_ss3(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force, size_t *nbytep) { if(tk->buffcount < introlen + 1) { if(!force) @@ -317,12 +317,12 @@ return TERMKEY_RES_KEY; } -static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytep) +static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytep) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; - TermKeyCsi *csi = info; + termkey_csi *csi = info; // Now we're sure at least 1 byte is valid unsigned char b0 = CHARAT(0); @@ -343,12 +343,12 @@ return TERMKEY_RES_NONE; } -static TermKeySym register_csi_ss3(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, unsigned char cmd, const char *name) +static termkey_keysym register_csi_ss3(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name) { return register_csi_ss3_full(csi, type, sym, 0, 0, cmd, 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 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) { 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 @@ return sym; } -static TermKeySym register_ss3kpalt(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, unsigned char cmd, const char *name, char kpalt) +static termkey_keysym register_ss3kpalt(termkey_csi *csi, termkey_type type, termkey_keysym sym, unsigned char cmd, const char *name, char kpalt) { return register_ss3kpalt_full(csi, type, sym, 0, 0, cmd, name, 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) +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) { if(cmd < 0x40 || cmd >= 0x80) { fprintf(stderr, "Cannot register SS3 key at cmd 0x%02x - out of bounds\n", cmd); @@ -390,12 +390,12 @@ return sym; } -static TermKeySym register_csifunc(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int number, const char *name) +static termkey_keysym register_csifunc(termkey_csi *csi, termkey_type type, termkey_keysym sym, int number, const char *name) { return register_csifunc_full(csi, type, sym, 0, 0, number, name); } -static TermKeySym register_csifunc_full(TermKeyCsi *csi, TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, int number, const char *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) { if(name) sym = termkey_register_keyname(csi->tk, sym, name); @@ -420,7 +420,7 @@ return sym; } -struct TermKeyDriver termkey_driver_csi = { +struct termkey_driver termkey_driver_csi = { .name = "CSI", .new_driver = new_driver, === modified file 'driver-ti.c' --- driver-ti.c 2009-07-15 19:40:44 +0000 +++ driver-ti.c 2008-12-10 00:23:47 +0000 @@ -39,18 +39,18 @@ }; typedef struct { - TermKey *tk; + termkey_t *tk; struct trie_node *root; char *start_string; char *stop_string; -} TermKeyTI; - -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(TermKeyType type, TermKeySym sym, int modmask, int modset) +} termkey_ti; + +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 struct trie_node *new_node_key(termkey_type type, termkey_keysym sym, int modmask, int modset) { struct trie_node_key *n = malloc(sizeof(*n)); if(!n) @@ -150,7 +150,7 @@ return n; } -static void *new_driver(TermKey *tk, const char *term) +static void *new_driver(termkey_t *tk, const char *term) { int err; @@ -159,7 +159,7 @@ if(setupterm((char*)term, 1, &err) != OK) return NULL; - TermKeyTI *ti = malloc(sizeof *ti); + termkey_ti *ti = malloc(sizeof *ti); if(!ti) return NULL; @@ -180,8 +180,8 @@ if(!value || value == (char*)-1) continue; - TermKeyType type; - TermKeySym sym; + termkey_type type; + termkey_keysym sym; int mask = 0; int set = 0; @@ -220,9 +220,9 @@ return NULL; } -static void start_driver(TermKey *tk, void *info) +static void start_driver(termkey_t *tk, void *info) { - TermKeyTI *ti = info; + termkey_ti *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 stop_driver(TermKey *tk, void *info) +static void stop_driver(termkey_t *tk, void *info) { - TermKeyTI *ti = info; + termkey_ti *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 free_driver(void *info) { - TermKeyTI *ti = info; + termkey_ti *ti = info; free_trie(ti->root); @@ -260,9 +260,9 @@ #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static TermKeyResult peekkey(TermKey *tk, void *info, TermKeyKey *key, int force, size_t *nbytep) +static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytep) { - TermKeyTI *ti = info; + termkey_ti *ti = info; if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -297,8 +297,8 @@ static struct { const char *funcname; - TermKeyType type; - TermKeySym sym; + termkey_type type; + termkey_keysym sym; int mods; } funcs[] = { @@ -348,7 +348,7 @@ { NULL }, }; -static int funcname2keysym(const char *funcname, TermKeyType *typep, TermKeySym *symp, int *modmaskp, int *modsetp) +static int funcname2keysym(const char *funcname, termkey_type *typep, termkey_keysym *symp, int *modmaskp, int *modsetp) { // Binary search @@ -395,7 +395,7 @@ return 0; } -static int register_seq(TermKeyTI *ti, const char *seq, TermKeyType type, TermKeySym sym, int modmask, int modset) +static int register_seq(termkey_ti *ti, const char *seq, termkey_type type, termkey_keysym sym, int modmask, int modset) { int pos = 0; struct trie_node *p = ti->root; @@ -447,7 +447,7 @@ return 1; } -struct TermKeyDriver termkey_driver_ti = { +struct termkey_driver termkey_driver_ti = { .name = "terminfo", .new_driver = new_driver, === modified file 'termkey-internal.h' --- termkey-internal.h 2009-07-15 19:40:44 +0000 +++ termkey-internal.h 2008-12-10 00:23:47 +0000 @@ -6,31 +6,31 @@ #include #include -struct TermKeyDriver +struct termkey_driver { const char *name; - void *(*new_driver)(TermKey *tk, const char *term); + void *(*new_driver)(termkey_t *tk, const char *term); void (*free_driver)(void *info); - 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); + 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); }; struct keyinfo { - TermKeyType type; - TermKeySym sym; + termkey_type type; + termkey_keysym sym; int modifier_mask; int modifier_set; }; -struct TermKeyDriverNode; -struct TermKeyDriverNode { - struct TermKeyDriver *driver; +struct termkey_drivernode; +struct termkey_drivernode { + struct termkey_driver *driver; void *info; - struct TermKeyDriverNode *next; + struct termkey_drivernode *next; }; -struct _TermKey { +struct termkey { int fd; int flags; unsigned char *buffer; @@ -51,17 +51,17 @@ // There are 32 C0 codes struct keyinfo c0[32]; - struct TermKeyDriverNode *drivers; + struct termkey_drivernode *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 *tk, long codepoint, TermKeyKey *key); - TermKeyResult (*peekkey_simple)(TermKey *tk, TermKeyKey *key, int force, size_t *nbytes); + 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); } method; }; -extern struct TermKeyDriver termkey_driver_csi; -extern struct TermKeyDriver termkey_driver_ti; +extern struct termkey_driver termkey_driver_csi; +extern struct termkey_driver termkey_driver_ti; #endif === modified file 'termkey.c' --- termkey.c 2009-07-15 19:40:44 +0000 +++ termkey.c 2008-12-10 01:34:40 +0000 @@ -25,22 +25,22 @@ // Happy } -static struct TermKeyDriver *drivers[] = { +static struct termkey_driver *drivers[] = { &termkey_driver_ti, &termkey_driver_csi, NULL, }; // Forwards for the "protected" methods -// 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 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 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 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 struct { - TermKeySym sym; + termkey_keysym sym; const char *name; } keynames[] = { { TERMKEY_SYM_NONE, "NONE" }, @@ -109,9 +109,9 @@ /* 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 *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) +static termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) { - TermKey *tk = malloc(sizeof(*tk)); + termkey_t *tk = malloc(sizeof(*tk)); if(!tk) return NULL; @@ -176,7 +176,7 @@ const char *term = getenv("TERM"); - struct TermKeyDriverNode *tail = NULL; + struct termkey_drivernode *tail = NULL; for(i = 0; drivers[i]; i++) { void *info = (*drivers[i]->new_driver)(tk, term); @@ -187,7 +187,7 @@ fprintf(stderr, "Loading the %s driver\n", drivers[i]->name); #endif - struct TermKeyDriverNode *thisdrv = malloc(sizeof(*thisdrv)); + struct termkey_drivernode *thisdrv = malloc(sizeof(*thisdrv)); if(!thisdrv) goto abort_free_drivers; @@ -221,7 +221,7 @@ } } - struct TermKeyDriverNode *p; + struct termkey_drivernode *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 @@ abort_free_drivers: for(p = tk->drivers; p; ) { (*p->driver->free_driver)(p->info); - struct TermKeyDriverNode *next = p->next; + struct termkey_drivernode *next = p->next; free(p); p = next; } @@ -248,20 +248,20 @@ return NULL; } -TermKey *termkey_new(int fd, int flags) +termkey_t *termkey_new(int fd, int flags) { return termkey_new_full(fd, flags, 256, 50); } -void termkey_free(TermKey *tk) +void termkey_free(termkey_t *tk) { free(tk->buffer); tk->buffer = NULL; free(tk->keynames); tk->keynames = NULL; - struct TermKeyDriverNode *p; + struct termkey_drivernode *p; for(p = tk->drivers; p; ) { (*p->driver->free_driver)(p->info); - struct TermKeyDriverNode *next = p->next; + struct termkey_drivernode *next = p->next; free(p); p = next; } @@ -269,9 +269,9 @@ free(tk); } -void termkey_destroy(TermKey *tk) +void termkey_destroy(termkey_t *tk) { - struct TermKeyDriverNode *p; + struct termkey_drivernode *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 @@ termkey_free(tk); } -int termkey_get_fd(TermKey *tk) +int termkey_get_fd(termkey_t *tk) { return tk->fd; } -int termkey_get_flags(TermKey *tk) +int termkey_get_flags(termkey_t *tk) { return tk->flags; } -void termkey_set_flags(TermKey *tk, int newflags) +void termkey_set_flags(termkey_t *tk, int newflags) { tk->flags = newflags; } -void termkey_set_waittime(TermKey *tk, int msec) +void termkey_set_waittime(termkey_t *tk, int msec) { tk->waittime = msec; } -int termkey_get_waittime(TermKey *tk) +int termkey_get_waittime(termkey_t *tk) { return tk->waittime; } -static void eat_bytes(TermKey *tk, size_t count) +static void eat_bytes(termkey_t *tk, size_t count) { if(count >= tk->buffcount) { tk->buffstart = 0; @@ -329,7 +329,7 @@ return 6; } -static void fill_utf8(TermKeyKey *key) +static void fill_utf8(termkey_key *key) { long codepoint = key->code.codepoint; int nbytes = utf8_seqlen(codepoint); @@ -354,7 +354,7 @@ } } -static void emit_codepoint(TermKey *tk, long codepoint, TermKeyKey *key) +static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key) { if(codepoint < 0x20) { // C0 range @@ -421,7 +421,7 @@ #define UTF8_INVALID 0xFFFD -static TermKeyResult peekkey(TermKey *tk, TermKeyKey *key, int force, size_t *nbytep) +static termkey_result peekkey(termkey_t *tk, termkey_key *key, int force, size_t *nbytep) { int again = 0; @@ -431,8 +431,8 @@ fprintf(stderr, "\n"); #endif - TermKeyResult ret; - struct TermKeyDriverNode *p; + termkey_result ret; + struct termkey_drivernode *p; for(p = tk->drivers; p; p = p->next) { ret = (p->driver->peekkey)(tk, p->info, key, force, nbytep); @@ -486,7 +486,7 @@ #define CHARAT(i) (tk->buffer[tk->buffstart + (i)]) -static TermKeyResult peekkey_simple(TermKey *tk, TermKeyKey *key, int force, size_t *nbytep) +static termkey_result peekkey_simple(termkey_t *tk, termkey_key *key, int force, size_t *nbytep) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -511,7 +511,7 @@ tk->buffcount--; // Run the full driver - TermKeyResult metakey_result = peekkey(tk, key, force, nbytep); + termkey_result metakey_result = peekkey(tk, key, force, nbytep); tk->buffstart--; tk->buffcount++; @@ -632,7 +632,7 @@ } #ifdef DEBUG -static void print_buffer(TermKey *tk) +static void print_buffer(termkey_t *tk) { int i; for(i = 0; i < tk->buffcount && i < 20; i++) @@ -641,7 +641,7 @@ fprintf(stderr, "..."); } -static void print_key(TermKey *tk, TermKeyKey *key) +static void print_key(termkey_t *tk, termkey_key *key) { switch(key->type) { case TERMKEY_TYPE_UNICODE: @@ -663,7 +663,7 @@ m & ~(TERMKEY_KEYMOD_CTRL|TERMKEY_KEYMOD_ALT|TERMKEY_KEYMOD_SHIFT)); } -static const char *res2str(TermKeyResult res) +static const char *res2str(termkey_result res) { switch(res) { case TERMKEY_RES_KEY: @@ -680,10 +680,10 @@ } #endif -TermKeyResult termkey_getkey(TermKey *tk, TermKeyKey *key) +termkey_result termkey_getkey(termkey_t *tk, termkey_key *key) { size_t nbytes = 0; - TermKeyResult ret = peekkey(tk, key, 0, &nbytes); + termkey_result ret = peekkey(tk, key, 0, &nbytes); if(ret == TERMKEY_RES_KEY) eat_bytes(tk, nbytes); @@ -696,10 +696,10 @@ return ret; } -TermKeyResult termkey_getkey_force(TermKey *tk, TermKeyKey *key) +termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key) { size_t nbytes = 0; - TermKeyResult ret = peekkey(tk, key, 1, &nbytes); + termkey_result ret = peekkey(tk, key, 1, &nbytes); if(ret == TERMKEY_RES_KEY) eat_bytes(tk, nbytes); @@ -707,10 +707,10 @@ return ret; } -TermKeyResult termkey_waitkey(TermKey *tk, TermKeyKey *key) +termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key) { while(1) { - TermKeyResult ret = termkey_getkey(tk, key); + termkey_result ret = termkey_getkey(tk, key); switch(ret) { case TERMKEY_RES_KEY: @@ -750,7 +750,7 @@ /* UNREACHABLE */ } -void termkey_pushinput(TermKey *tk, unsigned char *input, size_t inputlen) +void termkey_pushinput(termkey_t *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 @@ tk->buffcount += inputlen; } -TermKeyResult termkey_advisereadable(TermKey *tk) +termkey_result termkey_advisereadable(termkey_t *tk) { unsigned char buffer[64]; // Smaller than the default size ssize_t len = read(tk->fd, buffer, sizeof buffer); @@ -783,7 +783,7 @@ } } -TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name) +termkey_keysym termkey_register_keyname(termkey_t *tk, termkey_keysym sym, const char *name) { if(!sym) sym = tk->nkeynames; @@ -805,7 +805,7 @@ return sym; } -const char *termkey_get_keyname(TermKey *tk, TermKeySym sym) +const char *termkey_get_keyname(termkey_t *tk, termkey_keysym sym) { if(sym == TERMKEY_SYM_UNKNOWN) return "UNKNOWN"; @@ -816,12 +816,12 @@ return "UNKNOWN"; } -TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname) +termkey_keysym termkey_keyname2sym(termkey_t *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 */ - TermKeySym sym; + termkey_keysym sym; for(sym = 0; sym < tk->nkeynames; sym++) if(tk->keynames[sym] && strcmp(keyname, tk->keynames[sym]) == 0) @@ -830,12 +830,12 @@ return TERMKEY_SYM_UNKNOWN; } -static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, const char *name) +static termkey_keysym register_c0(termkey_t *tk, termkey_keysym sym, unsigned char ctrl, const char *name) { return register_c0_full(tk, sym, 0, 0, ctrl, name); } -static TermKeySym register_c0_full(TermKey *tk, TermKeySym sym, int modifier_set, int modifier_mask, 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) { if(ctrl >= 0x20) { fprintf(stderr, "Cannot register C0 key at ctrl 0x%02x - out of bounds\n", ctrl); @@ -852,7 +852,7 @@ return sym; } -size_t termkey_snprint_key(TermKey *tk, char *buffer, size_t len, TermKeyKey *key, TermKeyFormat format) +size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format) { size_t pos = 0; size_t l = 0; === modified file 'termkey.h.in' --- termkey.h.in 2009-07-15 19:40:44 +0000 +++ termkey.h.in 2008-12-02 00:56:43 +0000 @@ -84,20 +84,20 @@ TERMKEY_SYM_KPEQUALS, // et cetera ad nauseum -} TermKeySym; +} termkey_sym; typedef enum { TERMKEY_TYPE_UNICODE, TERMKEY_TYPE_FUNCTION, TERMKEY_TYPE_KEYSYM -} TermKeyType; +} termkey_type; typedef enum { TERMKEY_RES_NONE, TERMKEY_RES_KEY, TERMKEY_RES_EOF, TERMKEY_RES_AGAIN, -} TermKeyResult; +} termkey_result; enum { TERMKEY_KEYMOD_SHIFT = 1 << 0, @@ -105,21 +105,23 @@ TERMKEY_KEYMOD_CTRL = 1 << 2, }; +typedef int termkey_keysym; + typedef struct { - TermKeyType type; + termkey_type type; union { - long codepoint; // TERMKEY_TYPE_UNICODE - int number; // TERMKEY_TYPE_FUNCTION - TermKeySym sym; // TERMKEY_TYPE_KEYSYM + long codepoint; // TERMKEY_TYPE_UNICODE + int number; // TERMKEY_TYPE_FUNCTION + termkey_keysym 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]; -} TermKeyKey; +} termkey_key; -typedef struct _TermKey TermKey; +typedef struct termkey termkey_t; enum { TERMKEY_FLAG_NOINTERPRET = 1 << 0, // Do not interpret C0//G1 codes if possible @@ -131,51 +133,42 @@ void termkey_check_version(int major, int minor); -TermKey *termkey_new(int fd, int flags); -void termkey_free(TermKey *tk); -void termkey_destroy(TermKey *tk); - -int termkey_get_fd(TermKey *tk); - -int termkey_get_flags(TermKey *tk); -void termkey_set_flags(TermKey *tk, int newflags); - -void termkey_set_waittime(TermKey *tk, int msec); -int termkey_get_waittime(TermKey *tk); - -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 *tk, unsigned char *input, size_t inputlen); - -TermKeyResult termkey_advisereadable(TermKey *tk); - -TermKeySym termkey_register_keyname(TermKey *tk, TermKeySym sym, const char *name); -const char *termkey_get_keyname(TermKey *tk, TermKeySym sym); - -TermKeySym termkey_keyname2sym(TermKey *tk, const char *keyname); +termkey_t *termkey_new(int fd, int flags); +void termkey_free(termkey_t *tk); +void termkey_destroy(termkey_t *tk); + +int termkey_get_fd(termkey_t *tk); + +int termkey_get_flags(termkey_t *tk); +void termkey_set_flags(termkey_t *tk, int newflags); + +void termkey_set_waittime(termkey_t *tk, int msec); +int termkey_get_waittime(termkey_t *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); + +void termkey_pushinput(termkey_t *tk, unsigned char *input, size_t inputlen); + +termkey_result termkey_advisereadable(termkey_t *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); + +termkey_keysym termkey_keyname2sym(termkey_t *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 -} TermKeyFormat; +} termkey_format; // Some useful combinations #define TERMKEY_FORMAT_VIM (TERMKEY_FORMAT_ALTISMETA|TERMKEY_FORMAT_WRAPBRACKET) -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; +size_t termkey_snprint_key(termkey_t *tk, char *buffer, size_t len, termkey_key *key, termkey_format format); #endif === modified file 'termkey_advisereadable.3' --- termkey_advisereadable.3 2009-07-15 19:40:44 +0000 +++ termkey_advisereadable.3 2008-11-06 20:29:50 +0000 @@ -5,7 +5,7 @@ .nf .B #include .sp -.BI "TermKeyResult termkey_advisereadable(TermKey *" tk ); +.BI "termkey_result termkey_advisereadable(termkey_t *" tk ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_get_fd.3' --- termkey_get_fd.3 2009-07-15 19:40:44 +0000 +++ termkey_get_fd.3 2008-12-02 23:06:08 +0000 @@ -5,7 +5,7 @@ .nf .B #include .sp -.BI "int termkey_get_fd(TermKey *" tk ); +.BI "int termkey_get_fd(termkey_t *" tk ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_get_keyname.3' --- termkey_get_keyname.3 2009-07-15 19:40:44 +0000 +++ termkey_get_keyname.3 2008-12-02 00:56:43 +0000 @@ -5,7 +5,7 @@ .nf .B #include .sp -.BI "const char *termkey_get_keyname(TermKey *" tk ", TermKeySym " sym ); +.BI "const char *termkey_get_keyname(termkey_t *" tk ", termkey_keysym " sym ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_getkey.3.sh' --- termkey_getkey.3.sh 2009-07-15 19:40:44 +0000 +++ termkey_getkey.3.sh 2008-12-10 01:03:43 +0000 @@ -7,9 +7,9 @@ .nf .B #include .sp -.BI "TermKeyResult termkey_getkey(TermKey *" tk ", TermKeyKey *" key ); +.BI "termkey_result termkey_getkey(termkey_t *" tk ", termkey_key *" key ); .br -.BI "TermKeyResult termkey_getkey_force(TermKey *" tk ", TermKeyKey *" key ); +.BI "termkey_result termkey_getkey_force(termkey_t *" tk ", termkey_key *" key ); .fi .sp Link with \fI-ltermkey\fP. @@ -33,20 +33,20 @@ .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 \fITermKeyKey\fP structure is defined as follows: +The \fItermkey_key\fP structure is defined as follows: .PP .in +4n .nf typedef struct { - TermKeyType type; + termkey_type type; union { long codepoint; /* TERMKEY_TYPE_UNICODE */ int number; /* TERMKEY_TYPE_FUNCTION */ - TermKeySym sym; /* TERMKEY_TYPE_KEYSYM */ + termkey_keysym sym; /* TERMKEY_TYPE_KEYSYM */ } code; int modifiers; char utf8[7]; -} TermKeyKey; +} termkey_key; .fi .in .PP === modified file 'termkey_keyname2sym.3' --- termkey_keyname2sym.3 2009-07-15 19:40:44 +0000 +++ termkey_keyname2sym.3 2008-12-02 00:56:43 +0000 @@ -5,7 +5,7 @@ .nf .B #include .sp -.BI "TermKeySym termkey_keyname2sym(TermKey *" tk ", const char *" keyname ); +.BI "termkey_keysym termkey_keyname2sym(termkey_t *" tk ", const char *" keyname ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_new.3' --- termkey_new.3 2009-07-15 19:40:44 +0000 +++ termkey_new.3 2008-12-01 22:36:14 +0000 @@ -7,14 +7,14 @@ .sp .BI "TERMKEY_CHECK_VERSION;" .br -.BI "TermKey *termkey_new(int " fd ", int " flags ); +.BI "termkey_tk *termkey_new(int " fd ", int " flags ); .br -.BI "void termkey_destroy(TermKey *" tk ); +.BI "void termkey_destroy(termkey_t *" 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\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_tk\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 === modified file 'termkey_set_flags.3' --- termkey_set_flags.3 2009-07-15 19:40:44 +0000 +++ termkey_set_flags.3 2008-11-10 22:29:21 +0000 @@ -5,9 +5,9 @@ .nf .B #include .sp -.BI "void termkey_set_flags(TermKey *" tk ", int " newflags ); +.BI "void termkey_set_flags(termkey_t *" tk ", int " newflags ); .br -.BI "int termkey_get_flags(TermKey *" tk ); +.BI "int termkey_get_flags(termkey_t *" tk ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_set_waittime.3' --- termkey_set_waittime.3 2009-07-15 19:40:44 +0000 +++ termkey_set_waittime.3 2008-11-06 20:29:50 +0000 @@ -5,9 +5,9 @@ .nf .B #include .sp -.BI "void termkey_set_waittime(TermKey *" tk ", int " msec ); +.BI "void termkey_set_waittime(termkey_t *" tk ", int " msec ); .br -.BI "int termkey_get_waittime(TermKey *" tk ); +.BI "int termkey_get_waittime(termkey_t *" tk ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_snprint_key.3' --- termkey_snprint_key.3 2009-07-15 19:40:44 +0000 +++ termkey_snprint_key.3 2008-11-06 00:02:41 +0000 @@ -5,8 +5,8 @@ .nf .B #include .sp -.BI "size_t termkey_snprint_key(TermKey *" tk ", char *" buffer ", size_t " len ", -.BI " TermKeyKey " key ", TermKeyFormat " format ); +.BI "size_t termkey_snprint_key(termkey_t *" tk ", char *" buffer ", size_t " len ", +.BI " termkey_key " key ", termkey_format " format ); .fi .sp Link with \fI-ltermkey\fP. === modified file 'termkey_waitkey.3.sh' --- termkey_waitkey.3.sh 2009-07-15 19:40:44 +0000 +++ termkey_waitkey.3.sh 2008-12-10 01:03:43 +0000 @@ -7,14 +7,14 @@ .nf .B #include .sp -.BI "TermKeyResult termkey_waitkey(TermKey *" tk ", TermKeyKey *" key ); +.BI "termkey_result termkey_waitkey(termkey_t *" tk ", termkey_key *" 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 \fBTermKeyKey\fP structure, see \fBtermkey_getkey\fP(3). +For details of the \fBtermkey_key\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"