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 ********************************************************/
30 #include "xkbcomp-priv.h"
33 * Extract the first token from an include statement.
34 * @param str_inout Input statement, modified in-place. Can be passed in
35 * repeatedly. If str_inout is NULL, the parsing has completed.
36 * @param file_rtrn Set to the include file to be used.
37 * @param map_rtrn Set to whatever comes after ), if any.
38 * @param nextop_rtrn Set to the next operation in the complete statement.
39 * @param extra_data Set to the string between ( and ), if any.
41 * @return true if parsing was succcessful, false for an illegal string.
43 * Example: "evdev+aliases(qwerty)"
44 * str_inout = aliases(qwerty)
50 * 2nd run with "aliases(qwerty)"
59 XkbParseIncludeMap(char **str_inout, char **file_rtrn, char **map_rtrn,
60 char *nextop_rtrn, char **extra_data)
62 char *tmp, *str, *next;
65 if ((*str == '+') || (*str == '|'))
67 *file_rtrn = *map_rtrn = NULL;
73 *file_rtrn = *map_rtrn = NULL;
74 *nextop_rtrn = str[1];
79 /* search for tokens inside the string */
80 next = strpbrk(str, "|+");
83 /* set nextop_rtrn to \0, next to next character */
92 /* search for :, store result in extra_data */
93 tmp = strchr(str, ':');
97 *extra_data = uDupString(tmp);
103 tmp = strchr(str, '(');
106 *file_rtrn = uDupString(str);
109 else if (str[0] == '(')
117 *file_rtrn = uDupString(str);
119 tmp = strchr(str, ')');
120 if ((tmp == NULL) || (tmp[1] != '\0'))
127 *map_rtrn = uDupString(str);
130 if (*nextop_rtrn == '\0')
132 else if ((*nextop_rtrn == '|') || (*nextop_rtrn == '+'))
139 /***====================================================================***/
142 * Return the xkb directory based on the type.
145 XkbDirectoryForInclude(unsigned type)
149 case XkmSemanticsFile:
155 case XkmKeyNamesIndex:
159 case XkmSymbolsIndex:
161 case XkmCompatMapIndex:
163 case XkmGeometryIndex:
172 /***====================================================================***/
175 * Search for the given file name in the include directories.
177 * @param ctx the XKB ctx containing the include paths
178 * @param type one of XkbTypesIndex, XkbCompatMapIndex, ..., or
179 * XkbSemanticsFile, XkmKeymapFile, ...
180 * @param pathReturn is set to the full path of the file if found.
182 * @return an FD to the file or NULL. If NULL is returned, the value of
183 * pathRtrn is undefined.
186 XkbFindFileInPath(struct xkb_ctx *ctx,
187 const char *name, unsigned type, char **pathRtrn)
195 typeDir = XkbDirectoryForInclude(type);
196 for (i = 0; i < xkb_ctx_num_include_paths(ctx); i++)
198 ret = snprintf(buf, sizeof(buf), "%s/%s/%s",
199 xkb_ctx_include_path_get(ctx, i), typeDir, name);
200 if (ret >= (ssize_t)sizeof(buf))
202 ERROR("File name (%s/%s/%s) too long\n",
203 xkb_ctx_include_path_get(ctx, i), typeDir, name);
207 file = fopen(buf, "r");
209 ERROR("Couldn't open file (%s/%s/%s): %s\n",
210 xkb_ctx_include_path_get(ctx, i), typeDir, name,
218 if ((file != NULL) && (pathRtrn != NULL))
219 *pathRtrn = strdup(buf);