=== modified file 'driver-csi.c' --- driver-csi.c 2008-10-07 21:22:59 +0000 +++ driver-csi.c 2008-10-06 22:53:25 +0000 @@ -141,6 +141,25 @@ free(csi); } +static inline void eatbytes(termkey_t *tk, size_t count) +{ + if(count >= tk->buffcount) { + tk->buffstart = 0; + tk->buffcount = 0; + return; + } + + tk->buffstart += count; + tk->buffcount -= count; + + size_t halfsize = tk->buffsize / 2; + + if(tk->buffstart > halfsize) { + memcpy(tk->buffer, tk->buffer + halfsize, halfsize); + tk->buffstart -= halfsize; + } +} + #define UTF8_INVALID 0xFFFD static int utf8_seqlen(int codepoint) @@ -256,7 +275,7 @@ do_codepoint(tk, '[', key); key->modifiers |= TERMKEY_KEYMOD_ALT; - (*tk->method.eatbytes)(tk, introlen); + eatbytes(tk, introlen); return TERMKEY_RES_KEY; } @@ -298,7 +317,7 @@ args++; - (*tk->method.eatbytes)(tk, csi_end + 1); + eatbytes(tk, csi_end + 1); if(args > 1 && arg[1] != -1) key->modifiers = arg[1] - 1; @@ -349,13 +368,13 @@ do_codepoint(tk, 'O', key); key->modifiers |= TERMKEY_KEYMOD_ALT; - (*tk->method.eatbytes)(tk, tk->buffcount); + eatbytes(tk, tk->buffcount); return TERMKEY_RES_KEY; } unsigned char cmd = CHARAT(introlen); - (*tk->method.eatbytes)(tk, introlen + 1); + eatbytes(tk, introlen + 1); if(cmd < 0x40 || cmd >= 0x80) return TERMKEY_SYM_UNKNOWN; @@ -403,7 +422,7 @@ return TERMKEY_RES_AGAIN; do_codepoint(tk, b0, key); - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); return TERMKEY_RES_KEY; } @@ -417,7 +436,7 @@ if(b1 == 0x1b) { do_codepoint(tk, b0, key); - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); return TERMKEY_RES_KEY; } @@ -429,7 +448,7 @@ case TERMKEY_RES_KEY: key->modifiers |= TERMKEY_KEYMOD_ALT; tk->buffstart--; - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); break; case TERMKEY_RES_NONE: @@ -449,7 +468,7 @@ else if(b0 < 0xa0) { // Single byte C0, G0 or C1 - C1 is never UTF-8 initial byte do_codepoint(tk, b0, key); - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); return TERMKEY_RES_KEY; } else if(tk->flags & TERMKEY_FLAG_UTF8) { @@ -463,7 +482,7 @@ if(b0 < 0xc0) { // Starts with a continuation byte - that's not right do_codepoint(tk, UTF8_INVALID, key); - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); return TERMKEY_RES_KEY; } else if(b0 < 0xe0) { @@ -488,7 +507,7 @@ } else { do_codepoint(tk, UTF8_INVALID, key); - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); return TERMKEY_RES_KEY; } @@ -499,7 +518,7 @@ unsigned char cb = CHARAT(b); if(cb < 0x80 || cb >= 0xc0) { do_codepoint(tk, UTF8_INVALID, key); - (*tk->method.eatbytes)(tk, b - 1); + eatbytes(tk, b - 1); return TERMKEY_RES_KEY; } @@ -518,7 +537,7 @@ codepoint = UTF8_INVALID; do_codepoint(tk, codepoint, key); - (*tk->method.eatbytes)(tk, nbytes); + eatbytes(tk, nbytes); return TERMKEY_RES_KEY; } else { @@ -530,7 +549,7 @@ key->utf8[0] = key->code.codepoint; key->utf8[1] = 0; - (*tk->method.eatbytes)(tk, 1); + eatbytes(tk, 1); return TERMKEY_RES_KEY; } === modified file 'termkey-internal.h' --- termkey-internal.h 2008-10-07 21:22:59 +0000 +++ termkey-internal.h 2008-10-06 22:36:14 +0000 @@ -33,12 +33,6 @@ struct termkey_driver driver; void *driver_info; - - // Now some "protected" methods for the driver to call but which we don't - // want exported as real symbols in the library - struct { - void (*eatbytes)(termkey_t *tk, size_t count); - } method; }; extern struct termkey_driver termkey_driver_csi; === modified file 'termkey.c' --- termkey.c 2008-10-07 21:22:59 +0000 +++ termkey.c 2008-10-07 02:17:06 +0000 @@ -13,9 +13,6 @@ NULL, }; -// Forwards for the "protected" methods -static void eatbytes(termkey_t *tk, size_t count); - termkey_t *termkey_new_full(int fd, int flags, size_t buffsize, int waittime) { termkey_t *tk = malloc(sizeof(*tk)); @@ -67,8 +64,6 @@ for(i = 0; i < tk->nkeynames; i++) tk->keynames[i] = NULL; - tk->method.eatbytes = &eatbytes; - for(i = 0; drivers[i]; i++) { void *driver_info = (*drivers[i]->new_driver)(tk); if(!driver_info) @@ -138,25 +133,6 @@ return tk->waittime; } -static void eatbytes(termkey_t *tk, size_t count) -{ - if(count >= tk->buffcount) { - tk->buffstart = 0; - tk->buffcount = 0; - return; - } - - tk->buffstart += count; - tk->buffcount -= count; - - size_t halfsize = tk->buffsize / 2; - - if(tk->buffstart > halfsize) { - memcpy(tk->buffer, tk->buffer + halfsize, halfsize); - tk->buffstart -= halfsize; - } -} - termkey_result termkey_getkey(termkey_t *tk, termkey_key *key) { return (*tk->driver.getkey)(tk, key);