diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2019-09-03 10:56:01 +1000 |
---|---|---|
committer | Ran Benita <ran234@gmail.com> | 2019-12-24 09:50:03 +0200 |
commit | f57c13ea4f1e53507540dab5ddb73617ec4d635d (patch) | |
tree | a1b130558196b386fed94406461050ecaae8d8ce /src/xkbcomp | |
parent | 13b30f4f0dccc08dfea426d73570b913596ed602 (diff) | |
download | xorg-lib-libxkbcommon-f57c13ea4f1e53507540dab5ddb73617ec4d635d.tar.gz |
rules: factor out the function to parse a rules file
No functional changes, this just makes the part to parse a single rules file
re-usable.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Diffstat (limited to 'src/xkbcomp')
-rw-r--r-- | src/xkbcomp/rules.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c index 2a364c8..47c2ff9 100644 --- a/src/xkbcomp/rules.c +++ b/src/xkbcomp/rules.c @@ -999,6 +999,37 @@ error: return false; } +static bool +read_rules_file(struct xkb_context *ctx, + struct matcher *matcher, + const char *path, + struct xkb_component_names *out) +{ + bool ret = false; + FILE *file; + char *string; + size_t size; + + 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", + path, strerror(errno)); + goto out; + } + + ret = matcher_match(matcher, string, size, path, out); + + unmap_file(string, size); +out: + if (file) + fclose(file); + return ret; +} + bool xkb_components_from_rules(struct xkb_context *ctx, const struct xkb_rule_names *rmlvo, @@ -1007,31 +1038,23 @@ xkb_components_from_rules(struct xkb_context *ctx, bool ret = false; FILE *file; char *path; - char *string; - size_t size; struct matcher *matcher; file = FindFileInXkbPath(ctx, rmlvo->rules, FILE_TYPE_RULES, &path); if (!file) goto err_out; - ret = map_file(file, &string, &size); - if (!ret) { - log_err(ctx, "Couldn't read rules file \"%s\": %s\n", - path, strerror(errno)); - goto err_file; - } + fclose(file); /* FIXME: fix FindFileInXkbPath to not open the file in + the first place */ matcher = matcher_new(ctx, rmlvo); - ret = matcher_match(matcher, string, size, path, out); + + ret = read_rules_file(ctx, matcher, path, out); if (!ret) log_err(ctx, "No components returned from XKB rules \"%s\"\n", path); - matcher_free(matcher); - unmap_file(string, size); -err_file: + matcher_free(matcher); free(path); - fclose(file); err_out: return ret; } |