From 2b219f615a4d4663790ef0cdd935899fd4e090ce Mon Sep 17 00:00:00 2001 From: Alexey Gladkov Date: Sat, 30 Mar 2013 18:07:55 +0400 Subject: [PATCH] Add lk_get_key function Signed-off-by: Alexey Gladkov --- src/libkeymap/dump.c | 10 +++++----- src/libkeymap/keymap/kmap.h | 1 + src/libkeymap/kmap.c | 21 ++++++++++++++++++++- src/libkeymap/loadkeys.c | 6 +++--- src/libkeymap/summary.c | 2 +- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/libkeymap/dump.c b/src/libkeymap/dump.c index 732b3a8..ce640f5 100644 --- a/src/libkeymap/dump.c +++ b/src/libkeymap/dump.c @@ -65,7 +65,7 @@ lk_dump_bkeymap(struct keymap *kmap) for (i = 0; i < MAX_NR_KEYMAPS; i++) { if (kmap->key_map[i]) { for (j = 0; j < NR_KEYS / 2; j++) { - v = kmap->key_map[i][j]; + v = lk_get_key(kmap, i, j); if (write(1, &v, 2) == -1) goto fail; } @@ -130,7 +130,7 @@ lk_dump_ctable(struct keymap *kmap, FILE *fd) for (j = 0; j < NR_KEYS; j++) { if (!(j % 8)) fprintf(fd, "\n"); - fprintf(fd, "\t0x%04x,", U((kmap->key_map[i])[j])); + fprintf(fd, "\t0x%04x,", U(lk_get_key(kmap, i, j))); } fprintf(fd, "\n};\n\n"); } @@ -402,7 +402,7 @@ lk_dump_keys(struct keymap *kmap, FILE *fd, char table_shape, char numeric) for (i = 1; i < NR_KEYS; i++) { int buf0, buf1, type; - buf0 = (kmap->key_map[j])[i]; + buf0 = lk_get_key(kmap, j, i); if (buf0 == -1) break; @@ -411,7 +411,7 @@ lk_dump_keys(struct keymap *kmap, FILE *fd, char table_shape, char numeric) if ((type == KT_LATIN || type == KT_LETTER) && KVAL(buf0) < 128) { buf1 = (kmap->defining[ja]) - ? kmap->key_map[ja][i] + ? lk_get_key(kmap, ja, i) : -1; if (buf1 != K(KT_META, KVAL(buf0))) @@ -430,7 +430,7 @@ no_shorthands: for (j = 0; j < keymapnr; j++) { buf[j] = (kmap->defining[j]) - ? (kmap->key_map[(kmap->defining[j])-1])[i] + ? lk_get_key(kmap, kmap->defining[j]-1, i) : K_HOLE; if (buf[j] != K_HOLE) diff --git a/src/libkeymap/keymap/kmap.h b/src/libkeymap/keymap/kmap.h index 1540373..aa2cd84 100644 --- a/src/libkeymap/keymap/kmap.h +++ b/src/libkeymap/keymap/kmap.h @@ -8,6 +8,7 @@ int lk_add_map(struct keymap *kmap, int i, int explicit); int lk_add_key(struct keymap *kmap, int k_index, int k_table, int keycode); int lk_remove_key(struct keymap *kmap, int k_index, int k_table); +int lk_get_key(struct keymap *kmap, int k_table, int k_index); int lk_add_func(struct keymap *kmap, struct kbsentry kbs); diff --git a/src/libkeymap/kmap.c b/src/libkeymap/kmap.c index 7096889..2d84293 100644 --- a/src/libkeymap/kmap.c +++ b/src/libkeymap/kmap.c @@ -31,6 +31,25 @@ lk_add_map(struct keymap *kmap, int i, int explicit) } int +lk_get_key(struct keymap *kmap, int k_table, int k_index) +{ + if (k_index < 0 || k_index >= NR_KEYS) { + ERR(kmap, _("lk_get_key called with bad index %d"), k_index); + return -1; + } + + if (k_table < 0 || k_table >= MAX_NR_KEYMAPS) { + ERR(kmap, _("lk_get_key called with bad table %d"), k_table); + return -1; + } + + if (!(kmap->keymap_was_set[k_table])) + return -1; + + return (kmap->key_map[k_table])[k_index]; +} + +int lk_remove_key(struct keymap *kmap, int k_index, int k_table) { /* roughly: addkey(k_index, k_table, K_HOLE); */ @@ -262,7 +281,7 @@ lk_add_constants(struct keymap *kmap) return -1; } - key = (kmap->key_map[r0])[i]; + key = lk_get_key(kmap, r0, i); if (do_constant_key(kmap, i, key) == -1) return -1; } diff --git a/src/libkeymap/loadkeys.c b/src/libkeymap/loadkeys.c index 4843759..b69263b 100644 --- a/src/libkeymap/loadkeys.c +++ b/src/libkeymap/loadkeys.c @@ -35,7 +35,7 @@ defkeys(struct keymap *kmap, int fd, int kbd_mode) ke.kb_index = j; ke.kb_table = i; - ke.kb_value = (kmap->key_map[i])[j]; + ke.kb_value = lk_get_key(kmap, i, j); fail = ioctl(fd, KDSKBENT, (unsigned long)&ke); @@ -50,11 +50,11 @@ defkeys(struct keymap *kmap, int fd, int kbd_mode) ct++; INFO(kmap, _("keycode %d, table %d = %d%s"), - j, i, (kmap->key_map[i])[j], fail ? _(" FAILED") : ""); + j, i, lk_get_key(kmap,i, j), fail ? _(" FAILED") : ""); if (fail) WARN(kmap, _("failed to bind key %d to value %d"), - j, (kmap->key_map[i])[j]); + j, lk_get_key(kmap, i, j)); } } else if (kmap->keymaps_line_seen && !kmap->defining[i]) { diff --git a/src/libkeymap/summary.c b/src/libkeymap/summary.c index 1eb4a8e..47f4236 100644 --- a/src/libkeymap/summary.c +++ b/src/libkeymap/summary.c @@ -61,7 +61,7 @@ lk_dump_summary(struct keymap *kmap, FILE *fd, int console) int i, allocct = 0; for (i = 0; i < MAX_NR_KEYMAPS; i++) { - if (kmap->key_map[i][0] == K_ALLOCATED) + if (lk_get_key(kmap, i, 0) == K_ALLOCATED) allocct++; } -- 2.7.4