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 ********************************************************/
33 #include "parseutils.h"
35 /***====================================================================***/
38 * Open the file given in the include statement and parse it's content.
39 * If the statement defines a specific map to use, this map is returned in
40 * file_rtrn. Otherwise, the default map is returned.
42 * @param context The context containing include paths
43 * @param stmt The include statement, specifying the file name to look for.
44 * @param file_type Type of file (XkmKeyNamesIdx, etc.)
45 * @param file_rtrn Returns the key map to be used.
46 * @param merge_rtrn Always returns stmt->merge.
48 * @return true on success or false otherwise.
51 ProcessIncludeFile(struct xkb_context *context,
54 XkbFile ** file_rtrn, unsigned *merge_rtrn)
57 XkbFile *rtrn, *mapToUse, *next;
59 file = XkbFindFileInPath(context, stmt->file, file_type, &stmt->path);
62 ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
63 XkbDirectoryForInclude(file_type));
67 if ((XKBParseFile(file, stmt->file, &rtrn) == 0) || (rtrn == NULL))
69 ERROR("Error interpreting include file \"%s\"\n", stmt->file);
76 if (stmt->map != NULL)
80 next = (XkbFile *)mapToUse->common.next;
81 mapToUse->common.next = NULL;
82 if (strcmp(mapToUse->name, stmt->map) == 0 &&
83 mapToUse->type == file_type)
90 FreeXKBFile(mapToUse);
96 ERROR("No %s named \"%s\" in the include file \"%s\"\n",
97 XkbcConfigText(file_type), stmt->map, stmt->file);
101 else if ((rtrn->common.next != NULL) && (warningLevel > 5))
103 WARN("No map in include statement, but \"%s\" contains several\n",
105 ACTION("Using first defined map, \"%s\"\n", rtrn->name);
107 if (mapToUse->type != file_type)
109 ERROR("Include file wrong type (expected %s, got %s)\n",
110 XkbcConfigText(file_type), XkbcConfigText(mapToUse->type));
111 ACTION("Include file \"%s\" ignored\n", stmt->file);
114 /* FIXME: we have to check recursive includes here (or somewhere) */
116 *file_rtrn = mapToUse;
117 *merge_rtrn = stmt->merge;
121 /***====================================================================***/
124 ReportNotArray(const char *type, const char *field, const char *name)
126 ERROR("The %s %s field is not an array\n", type, field);
127 ACTION("Ignoring illegal assignment in %s\n", name);
132 ReportShouldBeArray(const char *type, const char *field, const char *name)
134 ERROR("Missing subscript for %s %s\n", type, field);
135 ACTION("Ignoring illegal assignment in %s\n", name);
140 ReportBadType(const char *type, const char *field,
141 const char *name, const char *wanted)
143 ERROR("The %s %s field must be a %s\n", type, field, wanted);
144 ACTION("Ignoring illegal assignment in %s\n", name);
149 ReportBadField(const char *type, const char *field, const char *name)
151 ERROR("Unknown %s field %s in %s\n", type, field, name);
152 ACTION("Ignoring assignment to unknown field in %s\n", name);
156 /***====================================================================***/
159 UseNewField(unsigned field,
160 CommonInfo * oldDefs, CommonInfo * newDefs, unsigned *pCollide)
165 if (oldDefs->defined & field)
167 if (newDefs->defined & field)
169 if (((oldDefs->fileID == newDefs->fileID)
170 && (warningLevel > 0)) || (warningLevel > 9))
174 if (newDefs->merge != MergeAugment)
178 else if (newDefs->defined & field)
184 ClearCommonInfo(CommonInfo * cmn)
188 CommonInfo *this, *next;
189 for (this = cmn; this != NULL; this = next)
199 AddCommonInfo(CommonInfo * old, CommonInfo * new)
204 while (old && old->next)
212 return (char *) first;
217 /***====================================================================***/
220 * Find the key with the given name and return its keycode in kc_rtrn.
222 * @param name The 4-letter name of the key as a long.
223 * @param kc_rtrn Set to the keycode if the key was found, otherwise 0.
224 * @param use_aliases true if the key aliases should be searched too.
225 * @param create If true and the key is not found, it is added to the
226 * xkb->names at the first free keycode.
227 * @param start_from Keycode to start searching from.
229 * @return true if found, false otherwise.
232 FindNamedKey(struct xkb_keymap * xkb,
234 xkb_keycode_t *kc_rtrn,
235 bool use_aliases, bool create, xkb_keycode_t start_from)
239 if (start_from < xkb->min_key_code)
241 start_from = xkb->min_key_code;
243 else if (start_from > xkb->max_key_code)
248 *kc_rtrn = 0; /* some callers rely on this */
249 if (xkb && xkb->names && xkb->names->keys)
251 for (n = start_from; n <= xkb->max_key_code; n++)
254 tmp = KeyNameToLong(xkb->names->keys[n].name);
263 unsigned long new_name;
264 if (FindKeyNameForAlias(xkb, name, &new_name))
265 return FindNamedKey(xkb, new_name, kc_rtrn, false, create, 0);
270 if ((!xkb->names) || (!xkb->names->keys))
272 if (XkbcAllocNames(xkb, XkbKeyNamesMask, 0) != Success)
274 if (warningLevel > 0)
276 WARN("Couldn't allocate key names in FindNamedKey\n");
277 ACTION("Key \"%s\" not automatically created\n",
283 /* Find first unused keycode and store our key here */
284 for (n = xkb->min_key_code; n <= xkb->max_key_code; n++)
286 if (xkb->names->keys[n].name[0] == '\0')
288 char buf[XkbKeyNameLength + 1];
289 LongToKeyName(name, buf);
290 memcpy(xkb->names->keys[n].name, buf, XkbKeyNameLength);
300 FindKeyNameForAlias(struct xkb_keymap * xkb, unsigned long lname,
301 unsigned long *real_name)
304 char name[XkbKeyNameLength + 1];
306 if (xkb && xkb->names && xkb->names->key_aliases)
308 struct xkb_key_alias * a;
309 a = xkb->names->key_aliases;
310 LongToKeyName(lname, name);
311 name[XkbKeyNameLength] = '\0';
312 for (i = 0; i < xkb->names->num_key_aliases; i++, a++)
314 if (strncmp(name, a->alias, XkbKeyNameLength) == 0)
316 *real_name = KeyNameToLong(a->real);