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 ********************************************************/
32 #include <X11/extensions/XKBgeomcommon.h>
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;
77 InitAliasInfo(AliasInfo * info,
78 unsigned merge, unsigned file_id, char *alias, char *real)
80 bzero(info, 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);
89 HandleAliasDef(KeyAliasDef * def,
90 unsigned merge, unsigned file_id, AliasInfo ** info_in)
94 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
96 if (strncmp(info->alias, def->alias, XkbKeyNameLength) == 0)
99 InitAliasInfo(&new, merge, file_id, def->alias, def->real);
100 HandleCollision(info, &new);
104 info = uTypedCalloc(1, AliasInfo);
107 WSGO("Allocation failure in HandleAliasDef\n");
110 info->def.fileID = file_id;
111 info->def.merge = merge;
112 info->def.next = (CommonInfo *) * info_in;
113 memcpy(info->alias, def->alias, XkbKeyNameLength);
114 memcpy(info->real, def->real, XkbKeyNameLength);
115 *info_in = (AliasInfo *) AddCommonInfo(&(*info_in)->def, &info->def);
120 ClearAliases(AliasInfo ** info_in)
122 if ((info_in) && (*info_in))
123 ClearCommonInfo(&(*info_in)->def);
128 MergeAliases(AliasInfo ** into, AliasInfo ** merge, unsigned how_merge)
133 if ((*merge) == NULL)
141 bzero((char *) &def, sizeof(KeyAliasDef));
142 for (tmp = *merge; tmp != NULL; tmp = (AliasInfo *) tmp->def.next)
144 if (how_merge == MergeDefault)
145 def.merge = tmp->def.merge;
147 def.merge = how_merge;
148 memcpy(def.alias, tmp->alias, XkbKeyNameLength);
149 memcpy(def.real, tmp->real, XkbKeyNameLength);
150 if (!HandleAliasDef(&def, def.merge, tmp->def.fileID, into))
157 ApplyAliases(XkbcDescPtr xkb, Bool toGeom, AliasInfo ** info_in)
160 XkbKeyAliasPtr old, a;
165 if (*info_in == NULL)
169 nOld = (xkb->geom ? xkb->geom->num_key_aliases : 0);
170 old = (xkb->geom ? xkb->geom->key_aliases : NULL);
174 nOld = (xkb->names ? xkb->names->num_key_aliases : 0);
175 old = (xkb->names ? xkb->names->key_aliases : NULL);
177 for (nNew = 0, info = *info_in; info != NULL;
178 info = (AliasInfo *) info->def.next)
183 lname = KeyNameToLong(info->real);
184 if (!FindNamedKey(xkb, lname, &kc, False, CreateKeyNames(xkb), 0))
186 if (warningLevel > 4)
188 WARN("Attempt to alias %s to non-existent key %s\n",
189 XkbcKeyNameText(info->alias), XkbcKeyNameText(info->real));
192 info->alias[0] = '\0';
195 lname = KeyNameToLong(info->alias);
196 if (FindNamedKey(xkb, lname, &kc, False, False, 0))
198 if (warningLevel > 4)
200 WARN("Attempt to create alias with the name of a real key\n");
201 ACTION("Alias \"%s = %s\" ignored\n",
202 XkbcKeyNameText(info->alias),
203 XkbcKeyNameText(info->real));
205 info->alias[0] = '\0';
211 for (i = 0, a = old; i < nOld; i++, a++)
213 if (strncmp(a->alias, info->alias, XkbKeyNameLength) == 0)
216 InitAliasInfo(&old, MergeAugment, 0, a->alias, a->real);
217 HandleCollision(&old, info);
218 memcpy(old.real, a->real, XkbKeyNameLength);
219 info->alias[0] = '\0';
228 ClearCommonInfo(&(*info_in)->def);
237 XkbGeometrySizesRec sizes;
238 bzero((char *) &sizes, sizeof(XkbGeometrySizesRec));
239 sizes.which = XkbGeomKeyAliasesMask;
240 sizes.num_key_aliases = nOld + nNew;
241 status = XkbcAllocGeometry(xkb, &sizes);
245 status = XkbcAllocGeomKeyAliases(xkb->geom, nOld + nNew);
248 old = xkb->geom->key_aliases;
252 status = XkbcAllocNames(xkb, XkbKeyAliasesMask, 0, nOld + nNew);
254 old = xkb->names->key_aliases;
256 if (status != Success)
258 WSGO("Allocation failure in ApplyAliases\n");
262 a = &xkb->geom->key_aliases[nOld];
264 a = &xkb->names->key_aliases[nOld];
265 for (info = *info_in; info != NULL; info = (AliasInfo *) info->def.next)
267 if (info->alias[0] != '\0')
269 strncpy(a->alias, info->alias, XkbKeyNameLength);
270 strncpy(a->real, info->real, XkbKeyNameLength);
275 if ((a - old) != (nOld + nNew))
277 WSGO("Expected %d aliases total but created %d\n", nOld + nNew,
282 xkb->geom->num_key_aliases += nNew;
283 ClearCommonInfo(&(*info_in)->def);