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 ********************************************************/
36 HandleCollision(AliasInfo * old, AliasInfo * new)
38 if (strncmp(new->real, old->real, XkbKeyNameLength) == 0)
40 if (((new->def.fileID == old->def.fileID) && (warningLevel > 0)) ||
43 WARN("Alias of %s for %s declared more than once\n",
44 XkbcKeyNameText(new->alias), XkbcKeyNameText(new->real));
45 ACTION("First definition ignored\n");
51 if (new->def.merge == MergeAugment)
61 if (((old->def.fileID == new->def.fileID) && (warningLevel > 0)) ||
64 WARN("Multiple definitions for alias %s\n",
65 XkbcKeyNameText(old->alias));
66 ACTION("Using %s, ignoring %s\n",
67 XkbcKeyNameText(use), XkbcKeyNameText(ignore));
70 memcpy(old->real, use, XkbKeyNameLength);
72 old->def.fileID = new->def.fileID;
73 old->def.merge = new->def.merge;
77 InitAliasInfo(AliasInfo * info,
78 unsigned merge, unsigned file_id, char *alias, char *real)
80 memset(info, 0, sizeof(AliasInfo));
81 info->def.merge = merge;
82 info->def.fileID = file_id;
83 strncpy(info->alias, alias, XkbKeyNameLength);
84 strncpy(info->real, real, XkbKeyNameLength);
88 HandleAliasDef(KeyAliasDef * def,
89 unsigned merge, unsigned file_id, AliasInfo ** info_in)
93 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
95 if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0)
98 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
99 HandleCollision(info, &new);
103 info = uTypedCalloc(1, AliasInfo);
106 WSGO("Allocation failure in HandleAliasDef\n");
109 info->def.fileID = file_id;
110 info->def.merge = merge;
111 info->def.next = (CommonInfo *) * info_in;
112 memcpy(info->alias, def->alias, XkbKeyNameLength);
113 memcpy(info->real, def->real, XkbKeyNameLength);
114 *info_in = (AliasInfo *) AddCommonInfo(&(*info_in)->def, &info->def);
119 ClearAliases(AliasInfo ** info_in)
121 if ((info_in) && (*info_in))
122 ClearCommonInfo(&(*info_in)->def);
126 MergeAliases(AliasInfo ** into, AliasInfo ** merge, unsigned how_merge)
131 if ((*merge) == NULL)
139 memset(&def, 0, sizeof(KeyAliasDef));
140 for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next)
142 if (how_merge == MergeDefault)
143 def.merge = tmp->def.merge;
145 def.merge = how_merge;
146 memcpy(def.alias, tmp->alias, XkbKeyNameLength);
147 memcpy(def.real, tmp->real, XkbKeyNameLength);
148 if (!HandleAliasDef(&def, def.merge, tmp->def.fileID, into))
155 ApplyAliases(struct xkb_desc * xkb, Bool toGeom, AliasInfo ** info_in)
158 struct xkb_key_alias *old, *a;
163 if (*info_in == NULL)
167 nOld = (xkb->geom ? xkb->geom->num_key_aliases : 0);
168 old = (xkb->geom ? xkb->geom->key_aliases : NULL);
172 nOld = (xkb->names ? xkb->names->num_key_aliases : 0);
173 old = (xkb->names ? xkb->names->key_aliases : NULL);
175 for (nNew = 0, info = *info_in; info != NULL;
176 info = (AliasInfo *) info->def.next)
181 lname = KeyNameToLong(info->real);
182 if (!FindNamedKey(xkb, lname, &kc, False, CreateKeyNames(xkb), 0))
184 if (warningLevel > 4)
186 WARN("Attempt to alias %s to non-existent key %s\n",
187 XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real));
190 info->alias[0] = '\0';
193 lname = KeyNameToLong(info->alias);
194 if (FindNamedKey(xkb, lname, &kc, False, False, 0))
196 if (warningLevel > 4)
198 WARN("Attempt to create alias with the name of a real key\n");
199 ACTION("Alias \"%s = %s\" ignored\n",
200 XkbcKeyNameText(info->alias),
201 XkbcKeyNameText(info->real));
203 info->alias[0] = '\0';
209 for (i = 0, a = old; i < nOld; i++, a++)
211 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
214 InitAliasInfo(&old_info, MergeAugment, 0, a->alias, a->real);
215 HandleCollision(&old_info, info);
216 memcpy(old_info.real, a->real, XkbKeyNameLength);
217 info->alias[0] = '\0';
226 ClearCommonInfo(&(*info_in)->def);
234 struct xkb_geometry_sizes sizes;
235 memset(&sizes, 0, sizeof(struct xkb_geometry_sizes));
236 sizes.which = XkbGeomKeyAliasesMask;
237 sizes.num_key_aliases = nOld + nNew;
238 status = XkbcAllocGeometry(xkb, &sizes);
242 status = XkbcAllocGeomKeyAliases(xkb->geom, nOld + nNew);
245 old = xkb->geom->key_aliases;
249 status = XkbcAllocNames(xkb, XkbKeyAliasesMask, 0, nOld + nNew);
251 old = xkb->names->key_aliases;
253 if (status != Success)
255 WSGO("Allocation failure in ApplyAliases\n");
259 a = &xkb->geom->key_aliases[nOld];
261 a = xkb->names ? &xkb->names->key_aliases[nOld] : NULL;
262 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
264 if (info->alias[0] != '\0')
266 strncpy(a->alias, info->alias, XkbKeyNameLength);
267 strncpy(a->real, info->real, XkbKeyNameLength);
272 if ((a - old) != (nOld + nNew))
274 WSGO("Expected %d aliases total but created %d\n", nOld + nNew,
279 xkb->geom->num_key_aliases += nNew;
280 ClearCommonInfo(&(*info_in)->def);