rules: reformat ApplyRule

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-05-18 10:33:38 +03:00
parent 06205717c3
commit c02c9ab2f2
1 changed files with 18 additions and 11 deletions

View File

@ -682,8 +682,9 @@ free_multi_defs(struct multi_defs *defs)
free(UNCONSTIFY(defs->variant[1])); free(UNCONSTIFY(defs->variant[1]));
} }
/* See apply_rule below. */
static void static void
Apply(char *src, char **dst) apply(const char *src, char **dst)
{ {
int ret; int ret;
char *tmp; char *tmp;
@ -699,21 +700,27 @@ Apply(char *src, char **dst)
free(tmp); free(tmp);
} }
else if (*dst == NULL) { else if (*dst == NULL) {
*dst = uDupString(src); *dst = strdup(src);
} }
} }
/*
* Add the info from the matching rule to the resulting
* xkb_component_names. If we already had a match for something
* (e.g. keycodes), and the rule is not an appending one (e.g.
* +whatever), than we don't override but drop the new one.
*/
static void static void
XkbRF_ApplyRule(struct rule *rule, struct xkb_component_names *names) apply_rule(struct rule *rule, struct xkb_component_names *kccgst)
{ {
/* clear the flag because it's applied */ /* Clear the flag because it's applied. */
rule->flags &= ~RULE_FLAG_PENDING_MATCH; rule->flags &= ~RULE_FLAG_PENDING_MATCH;
Apply(rule->keycodes, &names->keycodes); apply(rule->keycodes, &kccgst->keycodes);
Apply(rule->symbols, &names->symbols); apply(rule->symbols, &kccgst->symbols);
Apply(rule->types, &names->types); apply(rule->types, &kccgst->types);
Apply(rule->compat, &names->compat); apply(rule->compat, &kccgst->compat);
Apply(rule->keymap, &names->keymap); apply(rule->keymap, &kccgst->keymap);
} }
static bool static bool
@ -830,7 +837,7 @@ XkbRF_CheckApplyRule(struct rule *rule, struct multi_defs *mdefs,
return rule->number; return rule->number;
} }
/* exact match, apply it now */ /* exact match, apply it now */
XkbRF_ApplyRule(rule,names); apply_rule(rule, names);
return rule->number; return rule->number;
} }
@ -855,7 +862,7 @@ XkbRF_ApplyPartialMatches(struct rules *rules,
for (rule = rules->rules, i = 0; i < rules->num_rules; i++, rule++) { for (rule = rules->rules, i = 0; i < rules->num_rules; i++, rule++) {
if ((rule->flags & RULE_FLAG_PENDING_MATCH)==0) if ((rule->flags & RULE_FLAG_PENDING_MATCH)==0)
continue; continue;
XkbRF_ApplyRule(rule,names); apply_rule(rule, names);
} }
} }