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 <X11/keysym.h>
34 #include "parseutils.h"
36 /***====================================================================***/
39 * Open the file given in the include statement and parse it's content.
40 * If the statement defines a specific map to use, this map is returned in
41 * file_rtrn. Otherwise, the default map is returned.
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(IncludeStmt * stmt,
53 XkbFile ** file_rtrn, unsigned *merge_rtrn)
56 XkbFile *rtrn, *mapToUse, *next;
57 char oldFile[1024] = {0};
58 int oldLine = lineNum;
60 file = XkbFindFileInPath(stmt->file, file_type, &stmt->path);
63 ERROR("Can't find file \"%s\" for %s include\n", stmt->file,
64 XkbDirectoryForInclude(file_type));
68 strcpy(oldFile, scanFile);
70 memset(oldFile, 0, sizeof(oldFile));
72 setScanState(stmt->file, 1);
74 INFO("About to parse include file %s\n", stmt->file);
76 if ((XKBParseFile(file, &rtrn) == 0) || (rtrn == NULL))
78 setScanState(oldFile, oldLine);
79 ERROR("Error interpreting include file \"%s\"\n", stmt->file);
86 if (stmt->map != NULL)
90 next = (XkbFile *)mapToUse->common.next;
91 mapToUse->common.next = NULL;
92 if (uStringEqual(mapToUse->name, stmt->map) &&
93 mapToUse->type == file_type)
100 FreeXKBFile(mapToUse);
106 ERROR("No %s named \"%s\" in the include file \"%s\"\n",
107 XkbcConfigText(file_type), stmt->map, stmt->file);
111 else if ((rtrn->common.next != NULL) && (warningLevel > 5))
113 WARN("No map in include statement, but \"%s\" contains several\n",
115 ACTION("Using first defined map, \"%s\"\n", rtrn->name);
117 setScanState(oldFile, oldLine);
118 if (mapToUse->type != file_type)
120 ERROR("Include file wrong type (expected %s, got %s)\n",
121 XkbcConfigText(file_type), XkbcConfigText(mapToUse->type));
122 ACTION("Include file \"%s\" ignored\n", stmt->file);
125 /* FIXME: we have to check recursive includes here (or somewhere) */
127 mapToUse->compiled = True;
128 *file_rtrn = mapToUse;
129 *merge_rtrn = stmt->merge;
133 /***====================================================================***/
136 ReportNotArray(const char *type, const char *field, const char *name)
138 ERROR("The %s %s field is not an array\n", type, field);
139 ACTION("Ignoring illegal assignment in %s\n", name);
144 ReportShouldBeArray(const char *type, const char *field, const char *name)
146 ERROR("Missing subscript for %s %s\n", type, field);
147 ACTION("Ignoring illegal assignment in %s\n", name);
152 ReportBadType(const char *type, const char *field,
153 const char *name, const char *wanted)
155 ERROR("The %s %s field must be a %s\n", type, field, wanted);
156 ACTION("Ignoring illegal assignment in %s\n", name);
161 ReportBadField(const char *type, const char *field, const char *name)
163 ERROR("Unknown %s field %s in %s\n", type, field, name);
164 ACTION("Ignoring assignment to unknown field in %s\n", name);
168 /***====================================================================***/
171 UseNewField(unsigned field,
172 CommonInfo * oldDefs, CommonInfo * newDefs, unsigned *pCollide)
177 if (oldDefs->defined & field)
179 if (newDefs->defined & field)
181 if (((oldDefs->fileID == newDefs->fileID)
182 && (warningLevel > 0)) || (warningLevel > 9))
186 if (newDefs->merge != MergeAugment)
190 else if (newDefs->defined & field)
196 ClearCommonInfo(CommonInfo * cmn)
200 CommonInfo *this, *next;
201 for (this = cmn; this != NULL; this = next)
211 AddCommonInfo(CommonInfo * old, CommonInfo * new)
216 while (old && old->next)
224 return (char *) first;
229 /***====================================================================***/
231 typedef struct _KeyNameDesc
240 * Find the key with the given name and return its keycode in kc_rtrn.
242 * @param name The 4-letter name of the key as a long.
243 * @param kc_rtrn Set to the keycode if the key was found, otherwise 0.
244 * @param use_aliases True if the key aliases should be searched too.
245 * @param create If True and the key is not found, it is added to the
246 * xkb->names at the first free keycode.
247 * @param start_from Keycode to start searching from.
249 * @return True if found, False otherwise.
252 FindNamedKey(struct xkb_desc * xkb,
254 xkb_keycode_t *kc_rtrn,
255 Bool use_aliases, Bool create, int start_from)
259 if (start_from < xkb->min_key_code)
261 start_from = xkb->min_key_code;
263 else if (start_from > xkb->max_key_code)
268 *kc_rtrn = 0; /* some callers rely on this */
269 if (xkb && xkb->names && xkb->names->keys)
271 for (n = start_from; n <= xkb->max_key_code; n++)
274 tmp = KeyNameToLong(xkb->names->keys[n].name);
283 unsigned long new_name;
284 if (FindKeyNameForAlias(xkb, name, &new_name))
285 return FindNamedKey(xkb, new_name, kc_rtrn, False, create, 0);
290 if ((!xkb->names) || (!xkb->names->keys))
292 if (XkbcAllocNames(xkb, XkbKeyNamesMask, 0) != Success)
294 if (warningLevel > 0)
296 WARN("Couldn't allocate key names in FindNamedKey\n");
297 ACTION("Key \"%s\" not automatically created\n",
303 /* Find first unused keycode and store our key here */
304 for (n = xkb->min_key_code; n <= xkb->max_key_code; n++)
306 if (xkb->names->keys[n].name[0] == '\0')
308 char buf[XkbKeyNameLength + 1];
309 LongToKeyName(name, buf);
310 memcpy(xkb->names->keys[n].name, buf, XkbKeyNameLength);
320 FindKeyNameForAlias(struct xkb_desc * xkb, unsigned long lname,
321 unsigned long *real_name)
324 char name[XkbKeyNameLength + 1];
326 if (xkb && xkb->names && xkb->names->key_aliases)
328 struct xkb_key_alias * a;
329 a = xkb->names->key_aliases;
330 LongToKeyName(lname, name);
331 name[XkbKeyNameLength] = '\0';
332 for (i = 0; i < xkb->names->num_key_aliases; i++, a++)
334 if (strncmp(name, a->alias, XkbKeyNameLength) == 0)
336 *real_name = KeyNameToLong(a->real);