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 ********************************************************/
35 HandleCollision(AliasInfo * old, AliasInfo * new)
37 if (strncmp(new->real, old->real, XkbKeyNameLength) == 0)
39 if (((new->def.fileID == old->def.fileID) && (warningLevel > 0)) ||
42 WARN("Alias of %s for %s declared more than once\n",
43 XkbcKeyNameText(new->alias), XkbcKeyNameText(new->real));
44 ACTION("First definition ignored\n");
50 if (new->def.merge == MergeAugment)
60 if (((old->def.fileID == new->def.fileID) && (warningLevel > 0)) ||
63 WARN("Multiple definitions for alias %s\n",
64 XkbcKeyNameText(old->alias));
65 ACTION("Using %s, ignoring %s\n",
66 XkbcKeyNameText(use), XkbcKeyNameText(ignore));
69 memcpy(old->real, use, XkbKeyNameLength);
71 old->def.fileID = new->def.fileID;
72 old->def.merge = new->def.merge;
76 InitAliasInfo(AliasInfo * info,
77 unsigned merge, unsigned file_id, char *alias, char *real)
79 memset(info, 0, sizeof(AliasInfo));
80 info->def.merge = merge;
81 info->def.fileID = file_id;
82 strncpy(info->alias, alias, XkbKeyNameLength);
83 strncpy(info->real, real, XkbKeyNameLength);
87 HandleAliasDef(KeyAliasDef * def,
88 unsigned merge, unsigned file_id, AliasInfo ** info_in)
92 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
94 if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0)
97 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
98 HandleCollision(info, &new);
102 info = uTypedCalloc(1, AliasInfo);
105 WSGO("Allocation failure in HandleAliasDef\n");
108 info->def.fileID = file_id;
109 info->def.merge = merge;
110 info->def.next = (CommonInfo *) * info_in;
111 memcpy(info->alias, def->alias, XkbKeyNameLength);
112 memcpy(info->real, def->real, XkbKeyNameLength);
113 *info_in = (AliasInfo *) AddCommonInfo(&(*info_in)->def, &info->def);
118 ClearAliases(AliasInfo ** info_in)
120 if ((info_in) && (*info_in))
121 ClearCommonInfo(&(*info_in)->def);
125 MergeAliases(AliasInfo ** into, AliasInfo ** merge, unsigned how_merge)
130 if ((*merge) == NULL)
138 memset(&def, 0, sizeof(KeyAliasDef));
139 for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next)
141 if (how_merge == MergeDefault)
142 def.merge = tmp->def.merge;
144 def.merge = how_merge;
145 memcpy(def.alias, tmp->alias, XkbKeyNameLength);
146 memcpy(def.real, tmp->real, XkbKeyNameLength);
147 if (!HandleAliasDef(&def, def.merge, tmp->def.fileID, into))
154 ApplyAliases(struct xkb_desc * xkb, AliasInfo ** info_in)
157 struct xkb_key_alias *old, *a;
162 if (*info_in == NULL)
164 nOld = (xkb->names ? xkb->names->num_key_aliases : 0);
165 old = (xkb->names ? xkb->names->key_aliases : NULL);
166 for (nNew = 0, info = *info_in; info != NULL;
167 info = (AliasInfo *) info->def.next)
172 lname = KeyNameToLong(info->real);
173 if (!FindNamedKey(xkb, lname, &kc, False, CreateKeyNames(xkb), 0))
175 if (warningLevel > 4)
177 WARN("Attempt to alias %s to non-existent key %s\n",
178 XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real));
181 info->alias[0] = '\0';
184 lname = KeyNameToLong(info->alias);
185 if (FindNamedKey(xkb, lname, &kc, False, False, 0))
187 if (warningLevel > 4)
189 WARN("Attempt to create alias with the name of a real key\n");
190 ACTION("Alias \"%s = %s\" ignored\n",
191 XkbcKeyNameText(info->alias),
192 XkbcKeyNameText(info->real));
194 info->alias[0] = '\0';
200 for (i = 0, a = old; i < nOld; i++, a++)
202 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
205 InitAliasInfo(&old_info, MergeAugment, 0, a->alias, a->real);
206 HandleCollision(&old_info, info);
207 memcpy(old_info.real, a->real, XkbKeyNameLength);
208 info->alias[0] = '\0';
217 ClearCommonInfo(&(*info_in)->def);
221 status = XkbcAllocNames(xkb, XkbKeyAliasesMask, nOld + nNew);
223 old = xkb->names->key_aliases;
224 if (status != Success)
226 WSGO("Allocation failure in ApplyAliases\n");
229 a = xkb->names ? &xkb->names->key_aliases[nOld] : NULL;
230 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
232 if (info->alias[0] != '\0')
234 strncpy(a->alias, info->alias, XkbKeyNameLength);
235 strncpy(a->real, info->real, XkbKeyNameLength);
240 if ((a - old) != (nOld + nNew))
242 WSGO("Expected %d aliases total but created %d\n", nOld + nNew,
246 ClearCommonInfo(&(*info_in)->def);