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 #include <X11/extensions/XKBgeomcommon.h>
38 HandleCollision(AliasInfo * old, AliasInfo * new)
40 if (strncmp(new->real, old->real, XkbKeyNameLength) == 0)
42 if (((new->def.fileID == old->def.fileID) && (warningLevel > 0)) ||
45 WARN("Alias of %s for %s declared more than once\n",
46 XkbcKeyNameText(new->alias), XkbcKeyNameText(new->real));
47 ACTION("First definition ignored\n");
53 if (new->def.merge == MergeAugment)
63 if (((old->def.fileID == new->def.fileID) && (warningLevel > 0)) ||
66 WARN("Multiple definitions for alias %s\n",
67 XkbcKeyNameText(old->alias));
68 ACTION("Using %s, ignoring %s\n",
69 XkbcKeyNameText(use), XkbcKeyNameText(ignore));
72 memcpy(old->real, use, XkbKeyNameLength);
74 old->def.fileID = new->def.fileID;
75 old->def.merge = new->def.merge;
80 InitAliasInfo(AliasInfo * info,
81 unsigned merge, unsigned file_id, char *alias, char *real)
83 bzero(info, sizeof(AliasInfo));
84 info->def.merge = merge;
85 info->def.fileID = file_id;
86 strncpy(info->alias, alias, XkbKeyNameLength);
87 strncpy(info->real, real, XkbKeyNameLength);
92 HandleAliasDef(KeyAliasDef * def,
93 unsigned merge, unsigned file_id, AliasInfo ** info_in)
97 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
99 if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0)
102 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
103 HandleCollision(info, &new);
107 info = uTypedCalloc(1, AliasInfo);
110 WSGO("Allocation failure in HandleAliasDef\n");
113 info->def.fileID = file_id;
114 info->def.merge = merge;
115 info->def.next = (CommonInfo *) * info_in;
116 memcpy(info->alias, def->alias, XkbKeyNameLength);
117 memcpy(info->real, def->real, XkbKeyNameLength);
118 *info_in = (AliasInfo *) AddCommonInfo(&(*info_in)->def, &info->def);
123 ClearAliases(AliasInfo ** info_in)
125 if ((info_in) && (*info_in))
126 ClearCommonInfo(&(*info_in)->def);
131 MergeAliases(AliasInfo ** into, AliasInfo ** merge, unsigned how_merge)
136 if ((*merge) == NULL)
144 bzero((char *) &def, sizeof(KeyAliasDef));
145 for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next)
147 if (how_merge == MergeDefault)
148 def.merge = tmp->def.merge;
150 def.merge = how_merge;
151 memcpy(def.alias, tmp->alias, XkbKeyNameLength);
152 memcpy(def.real, tmp->real, XkbKeyNameLength);
153 if (!HandleAliasDef(&def, def.merge, tmp->def.fileID, into))
160 ApplyAliases(XkbcDescPtr xkb, Bool toGeom, AliasInfo ** info_in)
163 XkbKeyAliasPtr old, a;
168 if (*info_in == NULL)
172 nOld = (xkb->geom ? xkb->geom->num_key_aliases : 0);
173 old = (xkb->geom ? xkb->geom->key_aliases : NULL);
177 nOld = (xkb->names ? xkb->names->num_key_aliases : 0);
178 old = (xkb->names ? xkb->names->key_aliases : NULL);
180 for (nNew = 0, info = *info_in; info != NULL;
181 info = (AliasInfo *) info->def.next)
186 lname = KeyNameToLong(info->real);
187 if (!FindNamedKey(xkb, lname, &kc, False, CreateKeyNames(xkb), 0))
189 if (warningLevel > 4)
191 WARN("Attempt to alias %s to non-existent key %s\n",
192 XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real));
195 info->alias[0] = '\0';
198 lname = KeyNameToLong(info->alias);
199 if (FindNamedKey(xkb, lname, &kc, False, False, 0))
201 if (warningLevel > 4)
203 WARN("Attempt to create alias with the name of a real key\n");
204 ACTION("Alias \"%s = %s\" ignored\n",
205 XkbcKeyNameText(info->alias),
206 XkbcKeyNameText(info->real));
208 info->alias[0] = '\0';
214 for (i = 0, a = old; i < nOld; i++, a++)
216 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
219 InitAliasInfo(&old, MergeAugment, 0, a->alias, a->real);
220 HandleCollision(&old, info);
221 memcpy(old.real, a->real, XkbKeyNameLength);
222 info->alias[0] = '\0';
231 ClearCommonInfo(&(*info_in)->def);
240 XkbGeometrySizesRec sizes;
241 bzero((char *) &sizes, sizeof(XkbGeometrySizesRec));
242 sizes.which = XkbGeomKeyAliasesMask;
243 sizes.num_key_aliases = nOld + nNew;
244 status = XkbcAllocGeometry(xkb, &sizes);
248 status = XkbcAllocGeomKeyAliases(xkb->geom, nOld + nNew);
251 old = xkb->geom->key_aliases;
255 status = XkbcAllocNames(xkb, XkbKeyAliasesMask, 0, nOld + nNew);
257 old = xkb->names->key_aliases;
259 if (status != Success)
261 WSGO("Allocation failure in ApplyAliases\n");
265 a = &xkb->geom->key_aliases[nOld];
267 a = &xkb->names->key_aliases[nOld];
268 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
270 if (info->alias[0] != '\0')
272 strncpy(a->alias, info->alias, XkbKeyNameLength);
273 strncpy(a->real, info->real, XkbKeyNameLength);
278 if ((a - old) != (nOld + nNew))
280 WSGO("Expected %d aliases total but created %d\n", nOld + nNew,
285 xkb->geom->num_key_aliases += nNew;
286 ClearCommonInfo(&(*info_in)->def);