aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-12-05 23:55:44 +0000
committerPaul LeoNerd Evans <leonerd@leonerd.org.uk>2008-12-05 23:55:44 +0000
commit97a47e9b160907455831109549a320b5b3b4994d (patch)
treead60027e4512583a271421652cdc8368cdf2ab3c
parent43a99e64f249c166f9636646399429457bba5c92 (diff)
downloadtermo-97a47e9b160907455831109549a320b5b3b4994d.tar.gz
termo-97a47e9b160907455831109549a320b5b3b4994d.tar.xz
termo-97a47e9b160907455831109549a320b5b3b4994d.zip
Make common static function getkey(), roll functionallity of termkey_getkey{,_force}() into it
-rw-r--r--termkey.c148
1 files changed, 56 insertions, 92 deletions
diff --git a/termkey.c b/termkey.c
index 4e0bb5a..eb2e759 100644
--- a/termkey.c
+++ b/termkey.c
@@ -420,6 +420,59 @@ static void emit_codepoint(termkey_t *tk, long codepoint, termkey_key *key)
#define UTF8_INVALID 0xFFFD
+static termkey_result getkey(termkey_t *tk, termkey_key *key, int force)
+{
+ int again = 0;
+
+#ifdef DEBUG
+ fprintf(stderr, "getkey(force=%d): buffer ", force);
+ print_buffer(tk);
+ fprintf(stderr, "\n");
+#endif
+
+ termkey_result ret;
+ struct termkey_drivernode *p;
+ for(p = tk->drivers; p; p = p->next) {
+ ret = (p->driver->getkey)(tk, p->info, key, force);
+
+#ifdef DEBUG
+ fprintf(stderr, "Driver %s yields %s\n", p->driver->name, res2str(ret));
+#endif
+
+ switch(ret) {
+ case TERMKEY_RES_KEY:
+#ifdef DEBUG
+ print_key(tk, key); fprintf(stderr, "\n");
+#endif
+ /* fallthrough */
+ case TERMKEY_RES_EOF:
+ return ret;
+
+ case TERMKEY_RES_AGAIN:
+ if(!force)
+ again = 1;
+
+ /* fallthrough */
+ case TERMKEY_RES_NONE:
+ break;
+ }
+ }
+
+ if(again)
+ return TERMKEY_RES_AGAIN;
+
+ ret = getkey_simple(tk, key, force);
+
+#ifdef DEBUG
+ fprintf(stderr, "getkey_simple(force=%d) yields %s\n", force, res2str(ret));
+ if(ret == TERMKEY_RES_KEY) {
+ print_key(tk, key); fprintf(stderr, "\n");
+ }
+#endif
+
+ return ret;
+}
+
#define CHARAT(i) (tk->buffer[tk->buffstart + (i)])
static termkey_result getkey_simple(termkey_t *tk, termkey_key *key, int force)
@@ -447,11 +500,7 @@ static termkey_result getkey_simple(termkey_t *tk, termkey_key *key, int force)
tk->buffcount--;
// Run the full driver
- termkey_result metakey_result;
- if(force)
- metakey_result = termkey_getkey_force(tk, key);
- else
- metakey_result = termkey_getkey(tk, key);
+ termkey_result metakey_result = getkey(tk, key, force);
tk->buffstart--;
tk->buffcount++;
@@ -622,97 +671,12 @@ static const char *res2str(termkey_result res)
termkey_result termkey_getkey(termkey_t *tk, termkey_key *key)
{
- int again = 0;
-
-#ifdef DEBUG
- fprintf(stderr, "getkey(): buffer ");
- print_buffer(tk);
- fprintf(stderr, "\n");
-#endif
-
- termkey_result ret;
- struct termkey_drivernode *p;
- for(p = tk->drivers; p; p = p->next) {
- ret = (p->driver->getkey)(tk, p->info, key, 0);
-
-#ifdef DEBUG
- fprintf(stderr, "Driver %s yields %s\n", p->driver->name, res2str(ret));
-#endif
-
- switch(ret) {
- case TERMKEY_RES_KEY:
-#ifdef DEBUG
- print_key(tk, key); fprintf(stderr, "\n");
-#endif
- /* fallthrough */
- case TERMKEY_RES_EOF:
- return ret;
-
- case TERMKEY_RES_AGAIN:
- again = 1;
- /* fallthrough */
- case TERMKEY_RES_NONE:
- break;
- }
- }
-
- if(again)
- return TERMKEY_RES_AGAIN;
-
- ret = getkey_simple(tk, key, 0);
-
-#ifdef DEBUG
- fprintf(stderr, "getkey_simple(force=0) yields %s\n", res2str(ret));
- if(ret == TERMKEY_RES_KEY) {
- print_key(tk, key); fprintf(stderr, "\n");
- }
-#endif
-
- return ret;
+ return getkey(tk, key, 0);
}
termkey_result termkey_getkey_force(termkey_t *tk, termkey_key *key)
{
-#ifdef DEBUG
- fprintf(stderr, "getkey_force(): buffer ");
- print_buffer(tk);
- fprintf(stderr, "\n");
-#endif
-
- termkey_result ret;
- struct termkey_drivernode *p;
- for(p = tk->drivers; p; p = p->next) {
- ret = (p->driver->getkey)(tk, p->info, key, 1);
-
-#ifdef DEBUG
- fprintf(stderr, "Driver %s yields %s\n", p->driver->name, res2str(ret));
-#endif
-
- switch(ret) {
- case TERMKEY_RES_KEY:
-#ifdef DEBUG
- print_key(tk, key); fprintf(stderr, "\n");
-#endif
- /* fallthrough */
- case TERMKEY_RES_EOF:
- return ret;
-
- case TERMKEY_RES_AGAIN:
- case TERMKEY_RES_NONE:
- break;
- }
- }
-
- ret = getkey_simple(tk, key, 1);
-
-#ifdef DEBUG
- fprintf(stderr, "getkey_simple(force=1) yields %s\n", res2str(ret));
- if(ret == TERMKEY_RES_KEY) {
- print_key(tk, key); fprintf(stderr, "\n");
- }
-#endif
-
- return ret;
+ return getkey(tk, key, 1);
}
termkey_result termkey_waitkey(termkey_t *tk, termkey_key *key)