X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fxkbcomp%2Fsymbols.c;h=e438139daa33ab8aceca0098361d1719790056de;hb=ef81d04eef4b1a60ff42bd9ccbe2918b0a5420ec;hp=cda93b086eeb84f6b5dc1f9cadd36db442f763ec;hpb=c03834a1c61b7e22dbd7d9c8fbe9273032f1dbfb;p=platform%2Fupstream%2Flibxkbcommon.git diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index cda93b0..e438139 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -51,6 +51,8 @@ * Ran Benita */ +#include "config.h" + #include "xkbcomp-priv.h" #include "text.h" #include "expr.h" @@ -59,6 +61,10 @@ #include "include.h" #include "keysym.h" + +// TODO: convert log_err to log_err_with_code +// TODO: convert log_vrb to log_vrb_with_code + enum key_repeat { KEY_REPEAT_UNDEFINED = 0, KEY_REPEAT_YES = 1, @@ -160,6 +166,8 @@ ClearKeyInfo(KeyInfo *keyi) typedef struct { enum merge_mode merge; bool haveSymbol; + // NOTE: Can also be XKB_MOD_NONE, meaning + // “don’t add a modifier to the modmap”. xkb_mod_index_t modifier; union { xkb_atom_t keyName; @@ -218,19 +226,6 @@ KeyInfoText(SymbolsInfo *info, KeyInfo *keyi) } static bool -LevelsSameSyms(const struct xkb_level *a, const struct xkb_level *b) -{ - if (a->num_syms != b->num_syms) - return false; - if (a->num_syms <= 1) - return a->u.sym == b->u.sym; - else - return memcmp(a->u.syms, b->u.syms, - sizeof(*a->u.syms) * a->num_syms) == 0; - -} - -static bool MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, bool report, xkb_layout_index_t group, xkb_atom_t key_name) { @@ -240,6 +235,7 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, /* First find the type of the merged group. */ if (into->type != from->type) { if (from->type == XKB_ATOM_NONE) { + /* it's empty for consistency with other comparisons */ } else if (into->type == XKB_ATOM_NONE) { into->type = from->type; @@ -248,13 +244,15 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, xkb_atom_t use = (clobber ? from->type : into->type); xkb_atom_t ignore = (clobber ? into->type : from->type); - if (report) - log_warn(info->ctx, + if (report) { + log_warn_with_code(info->ctx, + XKB_WARNING_CONFLICTING_KEY_TYPE, "Multiple definitions for group %d type of key %s; " "Using %s, ignoring %s\n", group + 1, KeyNameText(info->ctx, key_name), xkb_atom_text(info->ctx, use), xkb_atom_text(info->ctx, ignore)); + } into->type = use; } @@ -282,6 +280,7 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, struct xkb_level *fromLevel = &darray_item(from->levels, i); if (fromLevel->action.type == ACTION_TYPE_NONE) { + /* it's empty for consistency with other comparisons */ } else if (intoLevel->action.type == ACTION_TYPE_NONE) { intoLevel->action = fromLevel->action; @@ -291,18 +290,21 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, use = (clobber ? &fromLevel->action : &intoLevel->action); ignore = (clobber ? &intoLevel->action : &fromLevel->action); - if (report) - log_warn(info->ctx, + if (report) { + log_warn_with_code(info->ctx, + XKB_WARNING_CONFLICTING_KEY_ACTION, "Multiple actions for level %d/group %u on key %s; " "Using %s, ignoring %s\n", i + 1, group + 1, KeyNameText(info->ctx, key_name), ActionTypeText(use->type), ActionTypeText(ignore->type)); + } intoLevel->action = *use; } if (fromLevel->num_syms == 0) { + /* it's empty for consistency with other comparisons */ } else if (intoLevel->num_syms == 0) { intoLevel->num_syms = fromLevel->num_syms; @@ -312,14 +314,16 @@ MergeGroups(SymbolsInfo *info, GroupInfo *into, GroupInfo *from, bool clobber, intoLevel->u.sym = fromLevel->u.sym; fromLevel->num_syms = 0; } - else if (!LevelsSameSyms(fromLevel, intoLevel)) { - if (report) - log_warn(info->ctx, + else if (!XkbLevelsSameSyms(fromLevel, intoLevel)) { + if (report) { + log_warn_with_code(info->ctx, + XKB_WARNING_CONFLICTING_KEY_SYMBOL, "Multiple symbols for level %d/group %u on key %s; " "Using %s, ignoring %s\n", i + 1, group + 1, KeyNameText(info->ctx, key_name), (clobber ? "from" : "to"), (clobber ? "to" : "from")); + } if (clobber) { ClearLevelInfo(intoLevel); @@ -412,12 +416,14 @@ MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from, bool same_file) into->defined |= KEY_FIELD_GROUPINFO; } - if (collide) - log_warn(info->ctx, + if (collide) { + log_warn_with_code(info->ctx, + XKB_WARNING_CONFLICTING_KEY_FIELDS, "Symbol map for key %s redefined; " "Using %s definition for conflicting fields\n", KeyNameText(info->ctx, into->name), (clobber ? "first" : "last")); + } ClearKeyInfo(from); InitKeyInfo(info->ctx, from); @@ -470,21 +476,23 @@ AddModMapEntry(SymbolsInfo *info, ModMapEntry *new) use = (clobber ? new->modifier : old->modifier); ignore = (clobber ? old->modifier : new->modifier); - if (new->haveSymbol) - log_err(info->ctx, - "Symbol \"%s\" added to modifier map for multiple modifiers; " - "Using %s, ignoring %s\n", - KeysymText(info->ctx, new->u.keySym), - ModIndexText(info->ctx, &info->mods, use), - ModIndexText(info->ctx, &info->mods, ignore)); - else - log_err(info->ctx, - "Key \"%s\" added to modifier map for multiple modifiers; " - "Using %s, ignoring %s\n", - KeyNameText(info->ctx, new->u.keyName), - ModIndexText(info->ctx, &info->mods, use), - ModIndexText(info->ctx, &info->mods, ignore)); - + if (new->haveSymbol) { + log_warn_with_code(info->ctx, + XKB_WARNING_CONFLICTING_MODMAP, + "Symbol \"%s\" added to modifier map for multiple modifiers; " + "Using %s, ignoring %s\n", + KeysymText(info->ctx, new->u.keySym), + ModIndexText(info->ctx, &info->mods, use), + ModIndexText(info->ctx, &info->mods, ignore)); + } else { + log_warn_with_code(info->ctx, + XKB_WARNING_CONFLICTING_MODMAP, + "Key \"%s\" added to modifier map for multiple modifiers; " + "Using %s, ignoring %s\n", + KeyNameText(info->ctx, new->u.keyName), + ModIndexText(info->ctx, &info->mods, use), + ModIndexText(info->ctx, &info->mods, ignore)); + } old->modifier = use; return true; } @@ -645,7 +653,7 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx, } if (!ExprResolveGroup(info->ctx, arrayNdx, ndx_rtrn)) { - log_err(info->ctx, + log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, "Illegal group index for %s of key %s\n" "Definition with non-integer array index ignored\n", name, KeyInfoText(info, keyi)); @@ -763,7 +771,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx, } nActs = 0; - for (act = value->unary.child; act; act = (ExprDef *) act->common.next) + for (act = value->actions.actions; act; act = (ExprDef *) act->common.next) nActs++; if (darray_size(groupi->levels) < nActs) @@ -771,7 +779,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx, groupi->defined |= GROUP_FIELD_ACTS; - act = value->unary.child; + act = value->actions.actions; for (unsigned i = 0; i < nActs; i++) { union xkb_action *toAct = &darray_item(groupi->levels, i).action; @@ -818,7 +826,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, keyi->defined |= KEY_FIELD_DEFAULT_TYPE; } else if (!ExprResolveGroup(info->ctx, arrayNdx, &ndx)) { - log_err(info->ctx, + log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, "Illegal group index for type of key %s; " "Definition with non-integer array index ignored\n", KeyInfoText(info, keyi)); @@ -930,7 +938,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field, xkb_layout_index_t grp; if (!ExprResolveGroup(info->ctx, value, &grp)) { - log_err(info->ctx, + log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, "Illegal group index for redirect of key %s; " "Definition with non-integer group ignored\n", KeyInfoText(info, keyi)); @@ -966,7 +974,7 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value) } if (!ExprResolveGroup(info->ctx, arrayNdx, &group)) { - log_err(info->ctx, + log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX, "Illegal index in group name definition; " "Definition with non-integer array index ignored\n"); return false; @@ -986,7 +994,8 @@ SetGroupName(SymbolsInfo *info, ExprDef *arrayNdx, ExprDef *value) group_to_use = info->explicit_group; } else { - log_warn(info->ctx, + log_warn_with_code(info->ctx, + XKB_WARNING_NON_BASE_GROUP_NAME, "An explicit group was specified for the '%s' map, " "but it provides a name for a group other than Group1 (%d); " "Ignoring group name '%s'\n", @@ -1104,12 +1113,14 @@ SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi) } } - if (warn) - log_warn(info->ctx, + if (warn) { + log_warn_with_code(info->ctx, + XKB_WARNING_MULTIPLE_GROUPS_AT_ONCE, "For the map %s an explicit group specified, " "but key %s has more than one group defined; " "All groups except first one will be ignored\n", info->name, KeyInfoText(info, keyi)); + } darray_resize0(keyi->groups, info->explicit_group + 1); if (info->explicit_group > 0) { @@ -1160,14 +1171,21 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def) xkb_mod_index_t ndx; bool ok; struct xkb_context *ctx = info->ctx; - - ndx = XkbModNameToIndex(&info->mods, def->modifier, MOD_REAL); - if (ndx == XKB_MOD_INVALID) { - log_err(info->ctx, - "Illegal modifier map definition; " - "Ignoring map for non-modifier \"%s\"\n", - xkb_atom_text(ctx, def->modifier)); - return false; + const char *modifier_name = xkb_atom_text(ctx, def->modifier); + + if (istreq(modifier_name, "none")) { + // Handle special "None" entry + ndx = XKB_MOD_NONE; + } else { + // Handle normal entry + ndx = XkbModNameToIndex(&info->mods, def->modifier, MOD_REAL); + if (ndx == XKB_MOD_INVALID) { + log_err(info->ctx, + "Illegal modifier map definition; " + "Ignoring map for non-modifier \"%s\"\n", + xkb_atom_text(ctx, def->modifier)); + return false; + } } ok = true; @@ -1370,7 +1388,8 @@ FindTypeForGroup(struct xkb_keymap *keymap, KeyInfo *keyi, } if (type_name == XKB_ATOM_NONE) { - log_warn(keymap->ctx, + log_warn_with_code(keymap->ctx, + XKB_WARNING_CANNOT_INFER_KEY_TYPE, "Couldn't find an automatic type for key '%s' group %d with %lu levels; " "Using the default type\n", KeyNameText(keymap->ctx, keyi->name), group + 1, @@ -1383,7 +1402,8 @@ FindTypeForGroup(struct xkb_keymap *keymap, KeyInfo *keyi, break; if (i >= keymap->num_types) { - log_warn(keymap->ctx, + log_warn_with_code(keymap->ctx, + XKB_WARNING_UNDEFINED_KEY_TYPE, "The type \"%s\" for key '%s' group %d was not previously defined; " "Using the default type\n", xkb_atom_text(keymap->ctx, type_name), @@ -1416,7 +1436,8 @@ CopySymbolsDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, */ key = XkbKeyByName(keymap, keyi->name, false); if (!key) { - log_vrb(info->ctx, 5, + log_vrb_with_code(info->ctx, 5, + XKB_WARNING_UNDEFINED_KEYCODE, "Key %s not found in keycodes; Symbols ignored\n", KeyInfoText(info, keyi)); return false; @@ -1459,7 +1480,8 @@ CopySymbolsDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, if (type->num_levels < darray_size(groupi->levels)) { struct xkb_level *leveli; - log_vrb(info->ctx, 1, + log_vrb_with_code(info->ctx, 1, + XKB_WARNING_EXTRA_SYMBOLS_IGNORED, "Type \"%s\" has %d levels, but %s has %d levels; " "Ignoring extra symbols\n", xkb_atom_text(keymap->ctx, type->name), type->num_levels, @@ -1511,7 +1533,8 @@ CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, if (!entry->haveSymbol) { key = XkbKeyByName(keymap, entry->u.keyName, true); if (!key) { - log_vrb(info->ctx, 5, + log_vrb_with_code(info->ctx, 5, + XKB_WARNING_UNDEFINED_KEYCODE, "Key %s not found in keycodes; " "Modifier map entry for %s not updated\n", KeyNameText(info->ctx, entry->u.keyName), @@ -1522,7 +1545,8 @@ CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, else { key = FindKeyForSymbol(keymap, entry->u.keySym); if (!key) { - log_vrb(info->ctx, 5, + log_vrb_with_code(info->ctx, 5, + XKB_WARNING_UNRESOLVED_KEYMAP_SYMBOL, "Key \"%s\" not found in symbol map; " "Modifier map entry for %s not updated\n", KeysymText(info->ctx, entry->u.keySym), @@ -1531,7 +1555,12 @@ CopyModMapDefToKeymap(struct xkb_keymap *keymap, SymbolsInfo *info, } } - key->modmap |= (1u << entry->modifier); + // Handle modMap None + if (entry->modifier != XKB_MOD_NONE) { + // Convert modifier index to modifier mask + key->modmap |= (1u << entry->modifier); + } + return true; }