=== modified file 'driver-csi.c' --- driver-csi.c 2008-12-10 00:23:47 +0000 +++ driver-csi.c 2008-11-12 13:02:30 +0000 @@ -148,7 +148,7 @@ #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 termkey_result getkey_csi(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force) { size_t csi_end = introlen; @@ -164,7 +164,7 @@ (*tk->method.emit_codepoint)(tk, '[', key); key->modifiers |= TERMKEY_KEYMOD_ALT; - *nbytep = introlen; + (*tk->method.eat_bytes)(tk, introlen); return TERMKEY_RES_KEY; } @@ -263,12 +263,12 @@ } } - *nbytep = csi_end + 1; + (*tk->method.eat_bytes)(tk, csi_end + 1); 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 termkey_result getkey_ss3(termkey_t *tk, termkey_csi *csi, size_t introlen, termkey_key *key, int force) { if(tk->buffcount < introlen + 1) { if(!force) @@ -276,7 +276,7 @@ (*tk->method.emit_codepoint)(tk, 'O', key); key->modifiers |= TERMKEY_KEYMOD_ALT; - *nbytep = tk->buffcount; + (*tk->method.eat_bytes)(tk, tk->buffcount); return TERMKEY_RES_KEY; } @@ -312,12 +312,12 @@ return TERMKEY_RES_NONE; } - *nbytep = introlen + 1; + (*tk->method.eat_bytes)(tk, introlen + 1); return TERMKEY_RES_KEY; } -static termkey_result peekkey(termkey_t *tk, void *info, termkey_key *key, int force, size_t *nbytep) +static termkey_result getkey(termkey_t *tk, void *info, termkey_key *key, int force) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -328,16 +328,16 @@ unsigned char b0 = CHARAT(0); if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == '[') { - return peekkey_csi(tk, csi, 2, key, force, nbytep); + return getkey_csi(tk, csi, 2, key, force); } else if(b0 == 0x1b && tk->buffcount > 1 && CHARAT(1) == 'O') { - return peekkey_ss3(tk, csi, 2, key, force, nbytep); + return getkey_ss3(tk, csi, 2, key, force); } else if(b0 == 0x8f) { - return peekkey_ss3(tk, csi, 1, key, force, nbytep); + return getkey_ss3(tk, csi, 1, key, force); } else if(b0 == 0x9b) { - return peekkey_csi(tk, csi, 1, key, force, nbytep); + return getkey_csi(tk, csi, 1, key, force); } else return TERMKEY_RES_NONE; @@ -426,5 +426,5 @@ .new_driver = new_driver, .free_driver = free_driver, - .peekkey = peekkey, + .getkey = getkey, }; === modified file 'driver-ti.c' --- driver-ti.c 2008-12-10 00:23:47 +0000 +++ driver-ti.c 2008-12-03 20:19:15 +0000 @@ -260,7 +260,7 @@ #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 termkey_result getkey(termkey_t *tk, void *info, termkey_key *key, int force) { termkey_ti *ti = info; @@ -282,7 +282,7 @@ key->type = nk->key.type; key->code.sym = nk->key.sym; key->modifiers = nk->key.modifier_set; - *nbytep = pos; + (*tk->method.eat_bytes)(tk, pos); return TERMKEY_RES_KEY; } } @@ -456,5 +456,5 @@ .start_driver = start_driver, .stop_driver = stop_driver, - .peekkey = peekkey, + .getkey = getkey, }; === modified file 'termkey-internal.h' --- termkey-internal.h 2008-12-10 00:23:47 +0000 +++ termkey-internal.h 2008-11-09 19:58:11 +0000 @@ -13,7 +13,7 @@ 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); + termkey_result (*getkey)(termkey_t *tk, void *info, termkey_key *key, int force); }; struct keyinfo { @@ -56,8 +56,9 @@ // Now some "protected" methods for the driver to call but which we don't // want exported as real symbols in the library struct { + void (*eat_bytes)(termkey_t *tk, size_t count); 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); + termkey_result (*getkey_simple)(termkey_t *tk, termkey_key *key, int force); } method; }; === modified file 'termkey.c' --- termkey.c 2008-12-10 00:23:47 +0000 +++ termkey.c 2008-12-06 00:03:48 +0000 @@ -32,9 +32,9 @@ }; // Forwards for the "protected" methods -// static void eat_bytes(termkey_t *tk, size_t count); +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 termkey_result getkey_simple(termkey_t *tk, termkey_key *key, int force); 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); @@ -163,8 +163,9 @@ for(i = 0; i < 32; i++) tk->c0[i].sym = TERMKEY_SYM_NONE; + tk->method.eat_bytes = &eat_bytes; tk->method.emit_codepoint = &emit_codepoint; - tk->method.peekkey_simple = &peekkey_simple; + tk->method.getkey_simple = &getkey_simple; for(i = 0; keynames[i].name; i++) termkey_register_keyname(tk, keynames[i].sym, keynames[i].name); @@ -412,7 +413,7 @@ #define UTF8_INVALID 0xFFFD -static termkey_result peekkey(termkey_t *tk, termkey_key *key, int force, size_t *nbytep) +static termkey_result getkey(termkey_t *tk, termkey_key *key, int force) { int again = 0; @@ -425,7 +426,7 @@ 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); + ret = (p->driver->getkey)(tk, p->info, key, force); #ifdef DEBUG fprintf(stderr, "Driver %s yields %s\n", p->driver->name, res2str(ret)); @@ -463,7 +464,7 @@ if(again) return TERMKEY_RES_AGAIN; - ret = peekkey_simple(tk, key, force, nbytep); + ret = getkey_simple(tk, key, force); #ifdef DEBUG fprintf(stderr, "getkey_simple(force=%d) yields %s\n", force, res2str(ret)); @@ -477,7 +478,7 @@ #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 termkey_result getkey_simple(termkey_t *tk, termkey_key *key, int force) { if(tk->buffcount == 0) return tk->is_closed ? TERMKEY_RES_EOF : TERMKEY_RES_NONE; @@ -493,7 +494,7 @@ return TERMKEY_RES_AGAIN; (*tk->method.emit_codepoint)(tk, b0, key); - *nbytep = 1; + (*tk->method.eat_bytes)(tk, 1); return TERMKEY_RES_KEY; } @@ -502,7 +503,7 @@ tk->buffcount--; // Run the full driver - termkey_result metakey_result = peekkey(tk, key, force, nbytep); + termkey_result metakey_result = getkey(tk, key, force); tk->buffstart--; tk->buffcount++; @@ -510,7 +511,7 @@ switch(metakey_result) { case TERMKEY_RES_KEY: key->modifiers |= TERMKEY_KEYMOD_ALT; - (*nbytep)++; + (*tk->method.eat_bytes)(tk, 1); break; case TERMKEY_RES_NONE: @@ -524,7 +525,7 @@ else if(b0 < 0xa0) { // Single byte C0, G0 or C1 - C1 is never UTF-8 initial byte (*tk->method.emit_codepoint)(tk, b0, key); - *nbytep = 1; + (*tk->method.eat_bytes)(tk, 1); return TERMKEY_RES_KEY; } else if(tk->flags & TERMKEY_FLAG_UTF8) { @@ -538,7 +539,7 @@ if(b0 < 0xc0) { // Starts with a continuation byte - that's not right (*tk->method.emit_codepoint)(tk, UTF8_INVALID, key); - *nbytep = 1; + (*tk->method.eat_bytes)(tk, 1); return TERMKEY_RES_KEY; } else if(b0 < 0xe0) { @@ -563,7 +564,7 @@ } else { (*tk->method.emit_codepoint)(tk, UTF8_INVALID, key); - *nbytep = 1; + (*tk->method.eat_bytes)(tk, 1); return TERMKEY_RES_KEY; } @@ -577,7 +578,7 @@ * arrive later, they'll be invalid too. */ (*tk->method.emit_codepoint)(tk, UTF8_INVALID, key); - *nbytep = tk->buffcount; + (*tk->method.eat_bytes)(tk, tk->buffcount); return TERMKEY_RES_KEY; } @@ -585,7 +586,7 @@ unsigned char cb = CHARAT(b); if(cb < 0x80 || cb >= 0xc0) { (*tk->method.emit_codepoint)(tk, UTF8_INVALID, key); - *nbytep = b - 1; + (*tk->method.eat_bytes)(tk, b - 1); return TERMKEY_RES_KEY; } @@ -604,7 +605,7 @@ codepoint = UTF8_INVALID; (*tk->method.emit_codepoint)(tk, codepoint, key); - *nbytep = nbytes; + (*tk->method.eat_bytes)(tk, nbytes); return TERMKEY_RES_KEY; } else { @@ -616,7 +617,7 @@ key->utf8[0] = key->code.codepoint; key->utf8[1] = 0; - *nbytep = 1; + (*tk->method.eat_bytes)(tk, 1); return TERMKEY_RES_KEY; } @@ -673,24 +674,12 @@ termkey_result termkey_getkey(termkey_t *tk, termkey_key *key) { - size_t nbytes = 0; - termkey_result ret = peekkey(tk, key, 0, &nbytes); - - if(ret == TERMKEY_RES_KEY) - eat_bytes(tk, nbytes); - - return ret; + return getkey(tk, key, 0); } termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key) { - size_t nbytes = 0; - termkey_result ret = peekkey(tk, key, 1, &nbytes); - - if(ret == TERMKEY_RES_KEY) - eat_bytes(tk, nbytes); - - return ret; + return getkey(tk, key, 1); } termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key)