Big rename functions and source files
[platform/upstream/kbd.git] / src / libkeymap / kernel.c
1 /* kernel.c
2  *
3  * This file is part of kbd project.
4  * Copyright (C) 2012-2013  Alexey Gladkov <gladkov.alexey@gmail.com>
5  *
6  * This file is covered by the GNU General Public License,
7  * which should be included with kbd as the file COPYING.
8  */
9 #include <string.h>
10 #include <errno.h>
11
12 #include <sys/ioctl.h>
13
14 #include "nls.h"
15 #include "keymap.h"
16
17 int
18 lk_kernel_keys(struct keymap *kmap, int fd)
19 {
20         int i, t;
21         struct kbentry ke;
22
23         for (t = 0; t < MAX_NR_KEYMAPS; t++) {
24                 for (i = 0; i < NR_KEYS; i++) {
25                         ke.kb_table = t;
26                         ke.kb_index = i;
27                         ke.kb_value = 0;
28
29                         if (ioctl(fd, KDGKBENT, (unsigned long) &ke)) {
30                                 log_error(kmap, _("KDGKBENT: %s: error at index %d in table %d"),
31                                         strerror(errno), i, t);
32                                 return -1;
33                         }
34
35                         if (lk_add_key(kmap, i, t, ke.kb_value) < 0)
36                                 return -1;
37                 }
38         }
39
40         if (lk_add_constants(kmap) < 0)
41                 return -1;
42
43         return 0;
44 }
45
46 int
47 lk_kernel_funcs(struct keymap *kmap, int fd)
48 {
49         int i;
50         struct kbsentry kbs;
51
52         for (i = 0; i < MAX_NR_FUNC; i++) {
53                 kbs.kb_func = i;
54
55                 if (ioctl(fd, KDGKBSENT, (unsigned long) &kbs)) {
56                         log_error(kmap, _("KDGKBSENT: %s: Unable to get function key string"),
57                                 strerror(errno));
58                         return -1;
59                 }
60
61                 if (!strlen((char *) kbs.kb_string))
62                         continue;
63
64                 if (lk_add_func(kmap, kbs) < 0)
65                         return -1;
66         }
67
68         return 0;
69 }
70
71 int
72 lk_kernel_diacrs(struct keymap *kmap, int fd)
73 {
74 #ifdef KDGKBDIACRUC
75         int request = KDGKBDIACRUC;
76         struct kbdiacrsuc kd;
77         struct kbdiacruc *ar = kd.kbdiacruc;
78 #else
79         int request = KDGKBDIACR;
80         struct kbdiacrs kd;
81         struct kbdiacr *ar = kd.kbdiacr;
82 #endif
83         unsigned int i;
84
85         if (ioctl(fd, request, (unsigned long) &kd)) {
86                 log_error(kmap, _("KDGKBDIACR(UC): %s: Unable to get accent table"),
87                         strerror(errno));
88                 return -1;
89         }
90
91         for (i = 0; i < kd.kb_cnt; i++) {
92                 if (lk_add_compose(kmap, (ar+i)->diacr, (ar+i)->base, (ar+i)->result) < 0)
93                         return -1;
94         }
95
96         return 0;
97 }
98
99 int
100 lk_kernel_keymap(struct keymap *kmap, int fd)
101 {
102         if (lk_kernel_keys(kmap, fd)   < 0 ||
103             lk_kernel_funcs(kmap, fd)  < 0 ||
104             lk_kernel_diacrs(kmap, fd) < 0)
105                 return -1;
106         return 0;
107 }