1 /************************************************************
2 * Copyright (c) 1995 by Silicon Graphics Computer Systems, Inc.
4 * Permission to use, copy, modify, and distribute this
5 * software and its documentation for any purpose and without
6 * fee is hereby granted, provided that the above copyright
7 * notice appear in all copies and that both that copyright
8 * notice and this permission notice appear in supporting
9 * documentation, and that the name of Silicon Graphics not be
10 * used in advertising or publicity pertaining to distribution
11 * of the software without specific prior written permission.
12 * Silicon Graphics makes no representation about the suitability
13 * of this software for any purpose. It is provided "as is"
14 * without any express or implied warranty.
16 * SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19 * GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
23 * THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ********************************************************/
31 HandleCollision(AliasInfo * old, AliasInfo * new)
33 if (strncmp(new->real, old->real, XkbKeyNameLength) == 0) {
34 if (((new->def.file_id == old->def.file_id) && (warningLevel > 0)) ||
36 WARN("Alias of %s for %s declared more than once\n",
37 XkbcKeyNameText(new->alias), XkbcKeyNameText(new->real));
38 ACTION("First definition ignored\n");
43 if (new->def.merge == MERGE_AUGMENT) {
51 if (((old->def.file_id == new->def.file_id) && (warningLevel > 0)) ||
53 WARN("Multiple definitions for alias %s\n",
54 XkbcKeyNameText(old->alias));
55 ACTION("Using %s, ignoring %s\n",
56 XkbcKeyNameText(use), XkbcKeyNameText(ignore));
59 memcpy(old->real, use, XkbKeyNameLength);
61 old->def.file_id = new->def.file_id;
62 old->def.merge = new->def.merge;
66 InitAliasInfo(AliasInfo * info,
67 enum merge_mode merge, unsigned file_id, char *alias,
70 memset(info, 0, sizeof(AliasInfo));
71 info->def.merge = merge;
72 info->def.file_id = file_id;
73 strncpy(info->alias, alias, XkbKeyNameLength);
74 strncpy(info->real, real, XkbKeyNameLength);
78 HandleAliasDef(KeyAliasDef * def,
79 enum merge_mode merge, unsigned file_id, AliasInfo ** info_in)
83 for (info = *info_in; info != NULL; info =
84 (AliasInfo *) info->def.next) {
85 if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0) {
87 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
88 HandleCollision(info, &new);
92 info = uTypedCalloc(1, AliasInfo);
94 WSGO("Allocation failure in HandleAliasDef\n");
97 info->def.file_id = file_id;
98 info->def.merge = merge;
99 info->def.next = (CommonInfo *) *info_in;
100 memcpy(info->alias, def->alias, XkbKeyNameLength);
101 memcpy(info->real, def->real, XkbKeyNameLength);
102 *info_in = AddCommonInfo(&(*info_in)->def, &info->def);
107 ClearAliases(AliasInfo ** info_in)
109 if ((info_in) && (*info_in))
110 ClearCommonInfo(&(*info_in)->def);
114 MergeAliases(AliasInfo ** into, AliasInfo ** merge,
115 enum merge_mode how_merge)
120 if ((*merge) == NULL)
122 if ((*into) == NULL) {
127 memset(&def, 0, sizeof(KeyAliasDef));
128 for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next) {
129 if (how_merge == MERGE_DEFAULT)
130 def.merge = tmp->def.merge;
132 def.merge = how_merge;
133 memcpy(def.alias, tmp->alias, XkbKeyNameLength);
134 memcpy(def.real, tmp->real, XkbKeyNameLength);
135 if (!HandleAliasDef(&def, def.merge, tmp->def.file_id, into))
142 ApplyAliases(struct xkb_keymap *keymap, AliasInfo ** info_in)
146 struct xkb_key_alias *old, *a;
150 nOld = darray_size(keymap->key_aliases);
151 old = &darray_item(keymap->key_aliases, 0);
153 for (nNew = 0, info = *info_in; info;
154 info = (AliasInfo *)info->def.next) {
157 lname = KeyNameToLong(info->real);
158 key = FindNamedKey(keymap, lname, false, CreateKeyNames(keymap), 0);
160 if (warningLevel > 4) {
161 WARN("Attempt to alias %s to non-existent key %s\n",
162 XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real));
165 info->alias[0] = '\0';
169 lname = KeyNameToLong(info->alias);
170 key = FindNamedKey(keymap, lname, false, false, 0);
172 if (warningLevel > 4) {
173 WARN("Attempt to create alias with the name of a real key\n");
174 ACTION("Alias \"%s = %s\" ignored\n",
175 XkbcKeyNameText(info->alias),
176 XkbcKeyNameText(info->real));
178 info->alias[0] = '\0';
187 for (i = 0, a = old; i < nOld; i++, a++) {
190 if (strncmp(a->alias, info->alias, XkbKeyNameLength) != 0)
193 InitAliasInfo(&old_info, MERGE_AUGMENT, 0, a->alias, a->real);
194 HandleCollision(&old_info, info);
195 memcpy(old_info.real, a->real, XkbKeyNameLength);
196 info->alias[0] = '\0';
205 darray_resize0(keymap->key_aliases, nOld + nNew);
207 a = &darray_item(keymap->key_aliases, nOld);
208 for (info = *info_in; info; info = (AliasInfo *)info->def.next) {
209 if (info->alias[0] != '\0') {
210 strncpy(a->alias, info->alias, XkbKeyNameLength);
211 strncpy(a->real, info->real, XkbKeyNameLength);
217 ClearCommonInfo(&(*info_in)->def);