1 /************************************************************
2 Copyright (c) 1994 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 ********************************************************/
27 #include "xkbcomp-priv.h"
28 #include "parseutils.h"
31 /***====================================================================***/
34 * Open the file given in the include statement and parse it's content.
35 * If the statement defines a specific map to use, this map is returned in
36 * file_rtrn. Otherwise, the default map is returned.
38 * @param ctx The ctx containing include paths
39 * @param stmt The include statement, specifying the file name to look for.
40 * @param file_type Type of file (XkmKeyNamesIdx, etc.)
41 * @param file_rtrn Returns the key map to be used.
42 * @param merge_rtrn Always returns stmt->merge.
44 * @return true on success or false otherwise.
47 ProcessIncludeFile(struct xkb_context *ctx,
50 XkbFile ** file_rtrn, unsigned *merge_rtrn)
53 XkbFile *rtrn, *mapToUse, *next;
55 file = XkbFindFileInPath(ctx, stmt->file, file_type, &stmt->path);
58 ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
59 XkbDirectoryForInclude(file_type));
64 if (!XKBParseFile(ctx, file, stmt->file, &rtrn))
66 ERROR("Error interpreting include file \"%s\"\n", stmt->file);
73 if (stmt->map != NULL)
77 next = (XkbFile *)mapToUse->common.next;
78 mapToUse->common.next = NULL;
79 if (strcmp(mapToUse->name, stmt->map) == 0 &&
80 mapToUse->type == file_type)
87 FreeXKBFile(mapToUse);
93 ERROR("No %s named \"%s\" in the include file \"%s\"\n",
94 XkbcConfigText(file_type), stmt->map, stmt->file);
98 else if ((rtrn->common.next != NULL) && (warningLevel > 5))
100 WARN("No map in include statement, but \"%s\" contains several\n",
102 ACTION("Using first defined map, \"%s\"\n", rtrn->name);
104 if (mapToUse->type != file_type)
106 ERROR("Include file wrong type (expected %s, got %s)\n",
107 XkbcConfigText(file_type), XkbcConfigText(mapToUse->type));
108 ACTION("Include file \"%s\" ignored\n", stmt->file);
111 /* FIXME: we have to check recursive includes here (or somewhere) */
113 *file_rtrn = mapToUse;
114 *merge_rtrn = stmt->merge;
118 /***====================================================================***/
121 ReportNotArray(const char *type, const char *field, const char *name)
123 ERROR("The %s %s field is not an array\n", type, field);
124 ACTION("Ignoring illegal assignment in %s\n", name);
129 ReportShouldBeArray(const char *type, const char *field, const char *name)
131 ERROR("Missing subscript for %s %s\n", type, field);
132 ACTION("Ignoring illegal assignment in %s\n", name);
137 ReportBadType(const char *type, const char *field,
138 const char *name, const char *wanted)
140 ERROR("The %s %s field must be a %s\n", type, field, wanted);
141 ACTION("Ignoring illegal assignment in %s\n", name);
146 ReportBadField(const char *type, const char *field, const char *name)
148 ERROR("Unknown %s field %s in %s\n", type, field, name);
149 ACTION("Ignoring assignment to unknown field in %s\n", name);
153 /***====================================================================***/
156 UseNewField(unsigned field,
157 CommonInfo * oldDefs, CommonInfo * newDefs, unsigned *pCollide)
162 if (oldDefs->defined & field)
164 if (newDefs->defined & field)
166 if (((oldDefs->fileID == newDefs->fileID)
167 && (warningLevel > 0)) || (warningLevel > 9))
171 if (newDefs->merge != MergeAugment)
175 else if (newDefs->defined & field)
181 ClearCommonInfo(CommonInfo * cmn)
185 CommonInfo *this, *next;
186 for (this = cmn; this != NULL; this = next)
196 AddCommonInfo(CommonInfo * old, CommonInfo * new)
201 while (old && old->next)
209 return (char *) first;
214 /***====================================================================***/
217 * Find the key with the given name and return its keycode in kc_rtrn.
219 * @param keymap The keymap to search in.
220 * @param name The 4-letter name of the key as a long.
221 * @param kc_rtrn Set to the keycode if the key was found, otherwise 0.
222 * @param use_aliases true if the key aliases should be searched too.
223 * @param create If true and the key is not found, it is added to the
224 * keymap->names at the first free keycode.
225 * @param start_from Keycode to start searching from.
227 * @return true if found, false otherwise.
230 FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
231 xkb_keycode_t *kc_rtrn, bool use_aliases, bool create,
232 xkb_keycode_t start_from)
236 if (start_from < keymap->min_key_code)
238 start_from = keymap->min_key_code;
240 else if (start_from > keymap->max_key_code)
245 *kc_rtrn = 0; /* some callers rely on this */
246 if (keymap && keymap->names && keymap->names->keys)
248 for (n = start_from; n <= keymap->max_key_code; n++)
251 tmp = KeyNameToLong(keymap->names->keys[n].name);
260 unsigned long new_name;
261 if (FindKeyNameForAlias(keymap, name, &new_name))
262 return FindNamedKey(keymap, new_name, kc_rtrn, false,
268 if ((!keymap->names) || (!keymap->names->keys))
270 if (XkbcAllocNames(keymap, XkbKeyNamesMask, 0) != Success)
272 if (warningLevel > 0)
274 WARN("Couldn't allocate key names in FindNamedKey\n");
275 ACTION("Key \"%s\" not automatically created\n",
281 /* Find first unused keycode and store our key here */
282 for (n = keymap->min_key_code; n <= keymap->max_key_code; n++)
284 if (keymap->names->keys[n].name[0] == '\0')
286 char buf[XkbKeyNameLength + 1];
287 LongToKeyName(name, buf);
288 memcpy(keymap->names->keys[n].name, buf, XkbKeyNameLength);
298 FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
299 unsigned long *real_name)
302 char name[XkbKeyNameLength + 1];
304 if (keymap && keymap->names && keymap->names->key_aliases)
306 struct xkb_key_alias * a;
307 a = keymap->names->key_aliases;
308 LongToKeyName(lname, name);
309 name[XkbKeyNameLength] = '\0';
310 for (i = 0; i < keymap->names->num_key_aliases; i++, a++)
312 if (strncmp(name, a->alias, XkbKeyNameLength) == 0)
314 *real_name = KeyNameToLong(a->real);