diff --git a/src/maprules.c b/src/maprules.c index 6060a03..c852082 100644 --- a/src/maprules.c +++ b/src/maprules.c @@ -76,10 +76,12 @@ #define PR_DEBUG(s) fprintf(stderr,s) #define PR_DEBUG1(s,a) fprintf(stderr,s,a) #define PR_DEBUG2(s,a,b) fprintf(stderr,s,a,b) +#define PR_DEBUG3(s,a,b,c) fprintf(stderr,s,a,b,c) #else #define PR_DEBUG(s) #define PR_DEBUG1(s,a) #define PR_DEBUG2(s,a,b) +#define PR_DEBUG3(s,a,b,c) #endif /***====================================================================***/ @@ -608,14 +610,17 @@ FreeMultiDefs(XkbRF_MultiDefsPtr defs) } static void -Apply(char *src, char **dst) +Apply(char *desc, char *src, char **dst) { if (src) { if (*src == '+' || *src == '!') { + PR_DEBUG3("Adding %s: was [%s], appending [%s]\n", desc, *dst, src); *dst= _Concat(*dst, src); } else { - if (*dst == NULL) + if (*dst == NULL) { *dst= _XkbDupString(src); + PR_DEBUG2("Setting %s to [%s]\n", desc, src); + } } } } @@ -624,14 +629,18 @@ static void XkbRF_ApplyRule( XkbRF_RulePtr rule, XkbComponentNamesPtr names) { - rule->flags&= ~XkbRF_PendingMatch; /* clear the flag because it's applied */ - - Apply(rule->keycodes, &names->keycodes); - Apply(rule->symbols, &names->symbols); - Apply(rule->types, &names->types); - Apply(rule->compat, &names->compat); - Apply(rule->geometry, &names->geometry); - Apply(rule->keymap, &names->keymap); + if (rule->flags & XkbRF_PendingMatch) { + PR_DEBUG("Applying the deferred rule: "); + rule->flags&= ~XkbRF_PendingMatch; /* clear the flag because it's applied */ + } else + PR_DEBUG("Applying the immediate rule: "); + + Apply("keycodes", rule->keycodes, &names->keycodes); + Apply("symbols", rule->symbols, &names->symbols); + Apply("types", rule->types, &names->types); + Apply("compat", rule->compat, &names->compat); + Apply("geometry", rule->geometry, &names->geometry); + Apply("keymap", rule->keymap, &names->keymap); } static Bool @@ -666,67 +675,117 @@ XkbRF_CheckApplyRule( XkbRF_RulePtr rule, { Bool pending = False; + PR_DEBUG1("The rule from group %d.", rule->number); + if (rule->model != NULL) { + PR_DEBUG2(" Model: \"%s\" in the rule, requested \"%s\": ", + rule->model, + mdefs->model); if(mdefs->model == NULL) return 0; if (strcmp(rule->model, "*") == 0) { + PR_DEBUG("wildcard."); pending = True; } else { if (rule->model[0] == '$') { - if (!CheckGroup(rules, rule->model, mdefs->model)) + PR_DEBUG1("checking against the list \"%s\": ", rule->model); + if (!CheckGroup(rules, rule->model, mdefs->model)) { + PR_DEBUG("ignore.\n"); return 0; + } + PR_DEBUG("match."); } else { - if (strcmp(rule->model, mdefs->model) != 0) + if (strcmp(rule->model, mdefs->model) != 0) { + PR_DEBUG("ignore.\n"); return 0; + } + PR_DEBUG("match."); } } } if (rule->option != NULL) { - if (mdefs->options == NULL) + PR_DEBUG2(" Option(s): \"%s\" in the rule, requested \"%s\": ", + rule->option, + mdefs->options); + if (mdefs->options == NULL) { + PR_DEBUG("no input.\n"); return 0; - if ((!MatchOneOf(rule->option,mdefs->options))) + } + if ((!MatchOneOf(rule->option,mdefs->options))) { + PR_DEBUG("ignore.\n"); return 0; + } } if (rule->layout != NULL) { + PR_DEBUG3(" Layout[%d]: \"%s\" in the rule, requested \"%s\": ", + rule->layout_num, + rule->layout, + mdefs->layout[rule->layout_num]); if(mdefs->layout[rule->layout_num] == NULL || - *mdefs->layout[rule->layout_num] == '\0') + *mdefs->layout[rule->layout_num] == '\0') { + PR_DEBUG("no input.\n"); return 0; + } if (strcmp(rule->layout, "*") == 0) { + PR_DEBUG("wildcard."); pending = True; } else { if (rule->layout[0] == '$') { + PR_DEBUG1("checking against the list \"%s\": ", rule->layout); if (!CheckGroup(rules, rule->layout, - mdefs->layout[rule->layout_num])) + mdefs->layout[rule->layout_num])) { + PR_DEBUG("ignore.\n"); return 0; + } + PR_DEBUG("match."); } else { - if (strcmp(rule->layout, mdefs->layout[rule->layout_num]) != 0) - return 0; + if (strcmp(rule->layout, mdefs->layout[rule->layout_num]) != 0) { + PR_DEBUG("ignore.\n"); + return 0; + } + PR_DEBUG("match."); } } } if (rule->variant != NULL) { + PR_DEBUG3(" Variant[%d]: \"%s\" in the rule, requested \"%s\": ", + rule->variant_num, + rule->variant, + mdefs->variant[rule->variant_num]); if (mdefs->variant[rule->variant_num] == NULL || - *mdefs->variant[rule->variant_num] == '\0') + *mdefs->variant[rule->variant_num] == '\0') { + PR_DEBUG("no input.\n"); return 0; + } if (strcmp(rule->variant, "*") == 0) { + PR_DEBUG("wildcard."); pending = True; } else { if (rule->variant[0] == '$') { + PR_DEBUG1("checking against the list \"%s\": ", rule->variant); if (!CheckGroup(rules, rule->variant, - mdefs->variant[rule->variant_num])) + mdefs->variant[rule->variant_num])) { + PR_DEBUG("ignore.\n"); return 0; + } + PR_DEBUG("match."); } else { if (strcmp(rule->variant, - mdefs->variant[rule->variant_num]) != 0) + mdefs->variant[rule->variant_num]) != 0) { + PR_DEBUG("ignore.\n"); return 0; + } + PR_DEBUG("match."); } } } if (pending) { rule->flags|= XkbRF_PendingMatch; + PR_DEBUG(" The rule is to apply later.\n"); return rule->number; } + PR_DEBUG(" The rule is to apply immediately.\n"); /* exact match, apply it now */ XkbRF_ApplyRule(rule,names); return rule->number;