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>
17 #include "libcommon.h"
20 int lk_kernel_keys(struct lk_ctx *ctx, int fd)
25 for (t = 0; t < MAX_NR_KEYMAPS; t++) {
27 ERR(ctx, _("table %d must be less than %d"), t, UCHAR_MAX);
30 for (i = 0; i < NR_KEYS; i++) {
32 ERR(ctx, _("index %d must be less than %d"), t, UCHAR_MAX);
35 ke.kb_table = (unsigned char) t;
36 ke.kb_index = (unsigned char) i;
39 if (ioctl(fd, KDGKBENT, (unsigned long)&ke)) {
40 ERR(ctx, _("KDGKBENT: %s: error at index %d in table %d"),
41 strerror(errno), i, t);
45 if (!i && ke.kb_value == K_NOSUCHMAP)
48 if (lk_add_key(ctx, t, i, ke.kb_value) < 0)
53 if (lk_add_constants(ctx) < 0)
59 int lk_kernel_funcs(struct lk_ctx *ctx, int fd)
64 for (i = 0; i < MAX_NR_FUNC; i++) {
66 ERR(ctx, _("function index %d must be less than %d"), i, UCHAR_MAX);
69 kbs.kb_func = (unsigned char) i;
71 if (ioctl(fd, KDGKBSENT, (unsigned long)&kbs)) {
72 ERR(ctx, _("KDGKBSENT: %s: Unable to get function key string"),
77 if (!strlen((char *)kbs.kb_string))
80 if (lk_add_func(ctx, &kbs) < 0)
87 int lk_kernel_diacrs(struct lk_ctx *ctx, int fd)
90 unsigned long request = KDGKBDIACRUC;
92 struct kbdiacruc *ar = kd.kbdiacruc;
94 unsigned long request = KDGKBDIACR;
96 struct kbdiacr *ar = kd.kbdiacr;
99 struct lk_kbdiacr dcr;
101 if (ioctl(fd, request, (unsigned long)&kd)) {
102 ERR(ctx, _("KDGKBDIACR(UC): %s: Unable to get accent table"),
107 for (i = 0; (unsigned int) i < kd.kb_cnt; i++) {
108 dcr.diacr = (ar + i)->diacr;
109 dcr.base = (ar + i)->base;
110 dcr.result = (ar + i)->result;
112 if (lk_add_diacr(ctx, i, &dcr) < 0)
119 int lk_kernel_keymap(struct lk_ctx *ctx, int fd)
121 if (lk_kernel_keys(ctx, fd) < 0 ||
122 lk_kernel_funcs(ctx, fd) < 0 ||
123 lk_kernel_diacrs(ctx, fd) < 0)