FindXkbFileInPath() opens the file so we're guaranteed that the file not only
exists, but that we can read it. Changing that would alter behavior so instead
let's just pass that file handle along and do the same for include files.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
read_rules_file(struct xkb_context *ctx,
struct matcher *matcher,
unsigned include_depth,
read_rules_file(struct xkb_context *ctx,
struct matcher *matcher,
unsigned include_depth,
const char *path);
static void
const char *path);
static void
unsigned include_depth,
struct sval inc)
{
unsigned include_depth,
struct sval inc)
{
struct scanner s; /* parses the !include value */
struct scanner s; /* parses the !include value */
scanner_init(&s, m->ctx, inc.start, inc.len,
parent_scanner->file_name, NULL);
scanner_init(&s, m->ctx, inc.start, inc.len,
parent_scanner->file_name, NULL);
- ret = read_rules_file(m->ctx, m, include_depth + 1, s.buf);
- if (!ret)
- log_err(m->ctx, "No components returned from included XKB rules \"%s\"\n", s.buf);
+ file = fopen(s.buf, "r");
+ if (file) {
+ bool ret = read_rules_file(m->ctx, m, include_depth + 1, file, s.buf);
+ if (!ret)
+ log_err(m->ctx, "No components returned from included XKB rules \"%s\"\n", s.buf);
+ fclose(file);
+ } else {
+ log_err(m->ctx, "Failed to open included XKB rules \"%s\"\n", s.buf);
+ }
read_rules_file(struct xkb_context *ctx,
struct matcher *matcher,
unsigned include_depth,
read_rules_file(struct xkb_context *ctx,
struct matcher *matcher,
unsigned include_depth,
const char *path)
{
bool ret = false;
const char *path)
{
bool ret = false;
char *string;
size_t size;
struct scanner scanner;
char *string;
size_t size;
struct scanner scanner;
- file = fopen(path, "r");
- if (!file)
- goto out;
-
ret = map_file(file, &string, &size);
if (!ret) {
log_err(ctx, "Couldn't read rules file \"%s\": %s\n",
ret = map_file(file, &string, &size);
if (!ret) {
log_err(ctx, "Couldn't read rules file \"%s\": %s\n",
unmap_file(string, size);
out:
unmap_file(string, size);
out:
- if (file)
- fclose(file);
- fclose(file); /* FIXME: fix FindFileInXkbPath to not open the file in
- the first place */
-
matcher = matcher_new(ctx, rmlvo);
matcher = matcher_new(ctx, rmlvo);
- ret = read_rules_file(ctx, matcher, 0, path);
+ ret = read_rules_file(ctx, matcher, 0, file, path);
if (!ret ||
darray_empty(matcher->kccgst[KCCGST_KEYCODES]) ||
darray_empty(matcher->kccgst[KCCGST_TYPES]) ||
if (!ret ||
darray_empty(matcher->kccgst[KCCGST_KEYCODES]) ||
darray_empty(matcher->kccgst[KCCGST_TYPES]) ||
mval->sval.len, mval->sval.start);
err_out:
mval->sval.len, mval->sval.start);
err_out:
+ if (file)
+ fclose(file);
matcher_free(matcher);
free(path);
return ret;
matcher_free(matcher);
free(path);
return ret;