-
Notifications
You must be signed in to change notification settings - Fork 39
/
diacr.c
106 lines (83 loc) · 2.19 KB
/
diacr.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/* diacr.c
*
* This file is part of kbd project.
* Copyright (C) 2014 Alexey Gladkov <gladkov.alexey@gmail.com>
*
* This file is covered by the GNU General Public License,
* which should be included with kbd as the file COPYING.
*/
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include "keymap.h"
#include "libcommon.h"
#include "contextP.h"
#include "ksyms.h"
int lk_diacr_exists(struct lk_ctx *ctx, int index)
{
return (lk_array_get_ptr(ctx->accent_table, index) != NULL);
}
int lk_get_diacr(struct lk_ctx *ctx, int index, struct lk_kbdiacr *dcr)
{
struct lk_kbdiacr *ptr;
ptr = lk_array_get_ptr(ctx->accent_table, index);
if (!ptr) {
ERR(ctx, _("Index %d in the accent table does not exist"), index);
return -1;
}
dcr->diacr = ptr->diacr;
dcr->base = ptr->base;
dcr->result = ptr->result;
return 0;
}
int lk_append_diacr(struct lk_ctx *ctx, struct lk_kbdiacr *dcr)
{
struct lk_kbdiacr *ptr;
ptr = malloc(sizeof(struct lk_kbdiacr));
if (!ptr) {
ERR(ctx, _("out of memory"));
return -1;
}
ptr->diacr = dcr->diacr;
ptr->base = dcr->base;
ptr->result = dcr->result;
lk_array_append(ctx->accent_table, &ptr);
return 0;
}
int lk_add_diacr(struct lk_ctx *ctx, int index, struct lk_kbdiacr *dcr)
{
struct lk_kbdiacr *ptr;
ptr = malloc(sizeof(struct lk_kbdiacr));
if (!ptr) {
ERR(ctx, _("out of memory"));
return -1;
}
ptr->diacr = dcr->diacr;
ptr->base = dcr->base;
ptr->result = dcr->result;
lk_array_set(ctx->accent_table, index, &ptr);
return 0;
}
int lk_del_diacr(struct lk_ctx *ctx, int index)
{
int rc;
rc = lk_array_unset(ctx->accent_table, index);
if (rc) {
ERR(ctx, _("Unable to remove item from the diacritical table"));
return -1;
}
return 0;
}
int lk_append_compose(struct lk_ctx *ctx, struct lk_kbdiacr *dcr)
{
struct lk_kbdiacr dcr0;
int direction = TO_8BIT;
#ifdef KDSKBDIACRUC
if (ctx->flags & LK_FLAG_PREFER_UNICODE)
direction = TO_UNICODE;
#endif
dcr0.diacr = (unsigned int) convert_code(ctx, (int) dcr->diacr, direction);
dcr0.base = (unsigned int) convert_code(ctx, (int) dcr->base, direction);
dcr0.result = (unsigned int) convert_code(ctx, (int) dcr->result, direction);
return lk_append_diacr(ctx, &dcr0);
}