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;
78 InitAliasInfo(AliasInfo * info,
79 unsigned merge, unsigned file_id, char *alias, char *real)
81 bzero(info, sizeof(AliasInfo));
82 info->def.merge = merge;
83 info->def.fileID = file_id;
84 strncpy(info->alias, alias, XkbKeyNameLength);
85 strncpy(info->real, real, XkbKeyNameLength);
90 HandleAliasDef(KeyAliasDef * def,
91 unsigned merge, unsigned file_id, AliasInfo ** info_in)
95 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
97 if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0)
100 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
101 HandleCollision(info, &new);
105 info = uTypedCalloc(1, AliasInfo);
108 WSGO("Allocation failure in HandleAliasDef\n");
111 info->def.fileID = file_id;
112 info->def.merge = merge;
113 info->def.next = (CommonInfo *) * info_in;
114 memcpy(info->alias, def->alias, XkbKeyNameLength);
115 memcpy(info->real, def->real, XkbKeyNameLength);
116 *info_in = (AliasInfo *) AddCommonInfo(&(*info_in)->def, &info->def);
121 ClearAliases(AliasInfo ** info_in)
123 if ((info_in) && (*info_in))
124 ClearCommonInfo(&(*info_in)->def);
129 MergeAliases(AliasInfo ** into, AliasInfo ** merge, unsigned how_merge)
134 if ((*merge) == NULL)
142 bzero((char *) &def, sizeof(KeyAliasDef));
143 for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next)
145 if (how_merge == MergeDefault)
146 def.merge = tmp->def.merge;
148 def.merge = how_merge;
149 memcpy(def.alias, tmp->alias, XkbKeyNameLength);
150 memcpy(def.real, tmp->real, XkbKeyNameLength);
151 if (!HandleAliasDef(&def, def.merge, tmp->def.fileID, into))
158 ApplyAliases(XkbcDescPtr xkb, Bool toGeom, AliasInfo ** info_in)
161 XkbKeyAliasPtr old, a;
166 if (*info_in == NULL)
170 nOld = (xkb->geom ? xkb->geom->num_key_aliases : 0);
171 old = (xkb->geom ? xkb->geom->key_aliases : NULL);
175 nOld = (xkb->names ? xkb->names->num_key_aliases : 0);
176 old = (xkb->names ? xkb->names->key_aliases : NULL);
178 for (nNew = 0, info = *info_in; info != NULL;
179 info = (AliasInfo *) info->def.next)
184 lname = KeyNameToLong(info->real);
185 if (!FindNamedKey(xkb, lname, &kc, False, CreateKeyNames(xkb), 0))
187 if (warningLevel > 4)
189 WARN("Attempt to alias %s to non-existent key %s\n",
190 XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real));
193 info->alias[0] = '\0';
196 lname = KeyNameToLong(info->alias);
197 if (FindNamedKey(xkb, lname, &kc, False, False, 0))
199 if (warningLevel > 4)
201 WARN("Attempt to create alias with the name of a real key\n");
202 ACTION("Alias \"%s = %s\" ignored\n",
203 XkbcKeyNameText(info->alias),
204 XkbcKeyNameText(info->real));
206 info->alias[0] = '\0';
212 for (i = 0, a = old; i < nOld; i++, a++)
214 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
217 InitAliasInfo(&old, MergeAugment, 0, a->alias, a->real);
218 HandleCollision(&old, info);
219 memcpy(old.real, a->real, XkbKeyNameLength);
220 info->alias[0] = '\0';
229 ClearCommonInfo(&(*info_in)->def);
238 XkbcGeometrySizesRec sizes;
239 bzero((char *) &sizes, sizeof(XkbcGeometrySizesRec));
240 sizes.which = XkbGeomKeyAliasesMask;
241 sizes.num_key_aliases = nOld + nNew;
242 status = XkbcAllocGeometry(xkb, &sizes);
246 status = XkbcAllocGeomKeyAliases(xkb->geom, nOld + nNew);
249 old = xkb->geom->key_aliases;
253 status = XkbcAllocNames(xkb, XkbKeyAliasesMask, 0, nOld + nNew);
255 old = xkb->names->key_aliases;
257 if (status != Success)
259 WSGO("Allocation failure in ApplyAliases\n");
263 a = &xkb->geom->key_aliases[nOld];
265 a = &xkb->names->key_aliases[nOld];
266 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
268 if (info->alias[0] != '\0')
270 strncpy(a->alias, info->alias, XkbKeyNameLength);
271 strncpy(a->real, info->real, XkbKeyNameLength);
276 if ((a - old) != (nOld + nNew))
278 WSGO("Expected %d aliases total but created %d\n", nOld + nNew,
283 xkb->geom->num_key_aliases += nNew;
284 ClearCommonInfo(&(*info_in)->def);