3 * This file is part of kbd project.
4 * Copyright (C) 2012-2013 Alexey Gladkov <gladkov.alexey@gmail.com>
6 * This file is covered by the GNU General Public License,
7 * which should be included with kbd as the file COPYING.
13 #include <sys/ioctl.h>
20 int lk_kernel_keys(struct lk_ctx *ctx, int fd)
25 for (t = 0; t < MAX_NR_KEYMAPS; t++) {
26 for (i = 0; i < NR_KEYS; i++) {
31 if (ioctl(fd, KDGKBENT, (unsigned long)&ke)) {
32 ERR(ctx, _("KDGKBENT: %s: error at index %d in table %d"),
33 strerror(errno), i, t);
37 if (!i && ke.kb_value == K_NOSUCHMAP)
40 if (lk_add_key(ctx, t, i, ke.kb_value) < 0)
45 if (lk_add_constants(ctx) < 0)
51 int lk_kernel_funcs(struct lk_ctx *ctx, int fd)
56 for (i = 0; i < MAX_NR_FUNC; i++) {
59 if (ioctl(fd, KDGKBSENT, (unsigned long)&kbs)) {
60 ERR(ctx, _("KDGKBSENT: %s: Unable to get function key string"),
65 if (!strlen((char *)kbs.kb_string))
68 if (lk_add_func(ctx, &kbs) < 0)
75 int lk_kernel_diacrs(struct lk_ctx *ctx, int fd)
78 int request = KDGKBDIACRUC;
80 struct kbdiacruc *ar = kd.kbdiacruc;
82 int request = KDGKBDIACR;
84 struct kbdiacr *ar = kd.kbdiacr;
87 struct lk_kbdiacr dcr;
89 if (ioctl(fd, request, (unsigned long)&kd)) {
90 ERR(ctx, _("KDGKBDIACR(UC): %s: Unable to get accent table"),
95 for (i = 0; i < kd.kb_cnt; i++) {
96 dcr.diacr = (ar + i)->diacr;
97 dcr.base = (ar + i)->base;
98 dcr.result = (ar + i)->result;
100 if (lk_add_diacr(ctx, i, &dcr) < 0)
107 int lk_kernel_keymap(struct lk_ctx *ctx, int fd)
109 if (lk_kernel_keys(ctx, fd) < 0 ||
110 lk_kernel_funcs(ctx, fd) < 0 ||
111 lk_kernel_diacrs(ctx, fd) < 0)