rules: reformat LoadRules and XkbRF_Free Signed-off-by: Ran Benita <ran234@gmail.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index e6a5233..da36e68 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -1087,7 +1087,7 @@ add_group(struct rules *rules)
}
static struct rules *
-XkbcRF_LoadRules(FILE *file)
+load_rules(FILE *file)
{
struct input_line line;
struct mapping mapping;
@@ -1107,36 +1107,39 @@ XkbcRF_LoadRules(FILE *file)
if (match_line(&line, &mapping, &trule, &tgroup)) {
if (tgroup.number) {
group = add_group(rules);
- if (group != NULL) {
- *group= tgroup;
- memset(&tgroup, 0, sizeof(tgroup));
- }
- } else {
+ if (group) {
+ *group = tgroup;
+ memset(&tgroup, 0, sizeof(tgroup));
+ }
+ } else {
rule = add_rule(rules);
- if (rule != NULL) {
- *rule= trule;
- memset(&trule, 0, sizeof(trule));
- }
- }
- }
- line.offset = 0;
+ if (rule) {
+ *rule = trule;
+ memset(&trule, 0, sizeof(trule));
+ }
+ }
+ }
+
+ line.offset = 0;
}
+
input_line_deinit(&line);
return rules;
}
static void
-static void
-XkbcRF_Free(struct rules *rules)
+free_rules(struct rules *rules)
{
int i;
struct rule *rule;
struct group *group;
if (!rules)
- return;
+ return;
+
+ for (i = 0; i < rules->num_rules; i++) {
+ rule = &rules->rules[i];
- for (i=0, rule = rules->rules; i < rules->num_rules && rules; i++, rule++) {
free(rule->model);
free(rule->layout);
free(rule->variant);
@@ -1149,7 +1152,9 @@ XkbcRF_Free(struct rules *rules)
}
free(rules->rules);
- for (i=0, group = rules->groups; i < rules->num_groups && group; i++, group++) {
+ for (i = 0; i < rules->num_groups; i++) {
+ group = &rules->groups[i];
+
free(group->name);
free(group->words);
}
@@ -1185,7 +1190,7 @@ xkb_components_from_rules(struct xkb_context *ctx,
return NULL;
}
- loaded = XkbcRF_LoadRules(rulesFile);
+ loaded = load_rules(rulesFile);
if (!loaded) {
ERROR("failed to load XKB rules \"%s\"\n", rulesPath);
goto unwind_file;
@@ -1209,7 +1214,7 @@ xkb_components_from_rules(struct xkb_context *ctx,
}
unwind_file:
- XkbcRF_Free(loaded);
+ free_rules(loaded);
if (rulesFile)
fclose(rulesFile);
free(rulesPath);