compat: use new log functions

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-07-21 01:35:46 +03:00
parent 270ff8ad83
commit 8e62b368a7
3 changed files with 140 additions and 108 deletions

View File

@ -246,61 +246,83 @@ FindMatchingInterp(CompatInfo * info, SymInterpInfo * new)
return NULL; return NULL;
} }
static bool
UseNewInterpField(unsigned field, SymInterpInfo *old, SymInterpInfo *new,
int verbosity, unsigned *collide)
{
if (!(old->defined & field))
return true;
if (new->defined & field) {
if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
*collide |= field;
if (new->merge != MERGE_AUGMENT)
return true;
}
return false;
}
static bool static bool
AddInterp(CompatInfo * info, SymInterpInfo * new) AddInterp(CompatInfo * info, SymInterpInfo * new)
{ {
unsigned collide; unsigned collide;
SymInterpInfo *old; SymInterpInfo *old;
struct list entry; struct list entry;
int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
collide = 0; collide = 0;
old = FindMatchingInterp(info, new); old = FindMatchingInterp(info, new);
if (old != NULL) { if (old != NULL) {
if (new->merge == MERGE_REPLACE) { if (new->merge == MERGE_REPLACE) {
entry = old->entry; entry = old->entry;
if ((old->file_id == new->file_id && warningLevel > 0) || if ((old->file_id == new->file_id && verbosity > 0) ||
warningLevel > 9) { verbosity > 9)
WARN("Multiple definitions for \"%s\"\n", siText(new, info)); log_warn(info->keymap->ctx,
ACTION("Earlier interpretation ignored\n"); "Multiple definitions for \"%s\"; "
} "Earlier interpretation ignored\n",
siText(new, info));
*old = *new; *old = *new;
old->entry = entry; old->entry = entry;
return true; return true;
} }
if (UseNewField(_SI_VirtualMod, old->defined, old->file_id, if (UseNewInterpField(_SI_VirtualMod, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->interp.virtual_mod = new->interp.virtual_mod; old->interp.virtual_mod = new->interp.virtual_mod;
old->defined |= _SI_VirtualMod; old->defined |= _SI_VirtualMod;
} }
if (UseNewField(_SI_Action, old->defined, old->file_id, new->defined, if (UseNewInterpField(_SI_Action, old, new, verbosity,
new->file_id, new->merge, &collide)) { &collide)) {
old->interp.act = new->interp.act; old->interp.act = new->interp.act;
old->defined |= _SI_Action; old->defined |= _SI_Action;
} }
if (UseNewField(_SI_AutoRepeat, old->defined, old->file_id, if (UseNewInterpField(_SI_AutoRepeat, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->interp.flags &= ~XkbSI_AutoRepeat; old->interp.flags &= ~XkbSI_AutoRepeat;
old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat); old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
old->defined |= _SI_AutoRepeat; old->defined |= _SI_AutoRepeat;
} }
if (UseNewField(_SI_LockingKey, old->defined, old->file_id, if (UseNewInterpField(_SI_LockingKey, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->interp.flags &= ~XkbSI_LockingKey; old->interp.flags &= ~XkbSI_LockingKey;
old->interp.flags |= (new->interp.flags & XkbSI_LockingKey); old->interp.flags |= (new->interp.flags & XkbSI_LockingKey);
old->defined |= _SI_LockingKey; old->defined |= _SI_LockingKey;
} }
if (UseNewField(_SI_LevelOneOnly, old->defined, old->file_id, if (UseNewInterpField(_SI_LevelOneOnly, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->interp.match &= ~XkbSI_LevelOneOnly; old->interp.match &= ~XkbSI_LevelOneOnly;
old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly); old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
old->defined |= _SI_LevelOneOnly; old->defined |= _SI_LevelOneOnly;
} }
if (collide) { if (collide) {
WARN("Multiple interpretations of \"%s\"\n", siText(new, info)); log_warn(info->keymap->ctx,
ACTION("Using %s definition for duplicate fields\n", "Multiple interpretations of \"%s\"; "
(new->merge != MERGE_AUGMENT ? "last" : "first")); "Using %s definition for duplicate fields\n",
siText(new, info),
(new->merge != MERGE_AUGMENT ? "last" : "first"));
} }
return true; return true;
@ -319,17 +341,17 @@ static bool
AddGroupCompat(CompatInfo *info, xkb_group_index_t group, GroupCompatInfo *new) AddGroupCompat(CompatInfo *info, xkb_group_index_t group, GroupCompatInfo *new)
{ {
GroupCompatInfo *gc; GroupCompatInfo *gc;
int verbosity = xkb_get_log_verbosity(info->keymap->ctx);
gc = &info->groupCompat[group]; gc = &info->groupCompat[group];
if (gc->real_mods == new->real_mods && gc->vmods == new->vmods) if (gc->real_mods == new->real_mods && gc->vmods == new->vmods)
return true; return true;
if ((gc->file_id == new->file_id && warningLevel > 0) || if ((gc->file_id == new->file_id && verbosity > 0) || verbosity > 9)
warningLevel > 9) { log_warn(info->keymap->ctx,
WARN("Compat map for group %u redefined\n", group + 1); "Compat map for group %u redefined; "
ACTION("Using %s definition\n", "Using %s definition\n",
(new->merge == MERGE_AUGMENT ? "old" : "new")); group + 1, (new->merge == MERGE_AUGMENT ? "old" : "new"));
}
if (new->defined && (new->merge != MERGE_AUGMENT || !gc->defined)) if (new->defined && (new->merge != MERGE_AUGMENT || !gc->defined))
*gc = *new; *gc = *new;
@ -367,8 +389,8 @@ ResolveStateAndPredicate(ExprDef * expr,
else if (strcasecmp(pred_txt, "exactly") == 0) else if (strcasecmp(pred_txt, "exactly") == 0)
*pred_rtrn = XkbSI_Exactly; *pred_rtrn = XkbSI_Exactly;
else { else {
ERROR("Illegal modifier predicate \"%s\"\n", pred_txt); log_err(info->keymap->ctx,
ACTION("Ignored\n"); "Illegal modifier predicate \"%s\"; Ignored\n", pred_txt);
return false; return false;
} }
expr = expr->value.action.args; expr = expr->value.action.args;
@ -392,12 +414,31 @@ ResolveStateAndPredicate(ExprDef * expr,
/***====================================================================***/ /***====================================================================***/
static bool
UseNewLEDField(unsigned field, LEDInfo *old, LEDInfo *new,
int verbosity, unsigned *collide)
{
if (!(old->defined & field))
return true;
if (new->defined & field) {
if ((old->file_id == new->file_id && verbosity > 0) || verbosity > 9)
*collide |= field;
if (new->merge != MERGE_AUGMENT)
return true;
}
return false;
}
static bool static bool
AddIndicatorMap(CompatInfo *info, LEDInfo *new) AddIndicatorMap(CompatInfo *info, LEDInfo *new)
{ {
LEDInfo *old; LEDInfo *old;
unsigned collide; unsigned collide;
struct xkb_context *ctx = info->keymap->ctx; struct xkb_context *ctx = info->keymap->ctx;
int verbosity = xkb_get_log_verbosity(ctx);
list_foreach(old, &info->leds, entry) { list_foreach(old, &info->leds, entry) {
if (old->name == new->name) { if (old->name == new->name) {
@ -413,65 +454,66 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
if (new->merge == MERGE_REPLACE) { if (new->merge == MERGE_REPLACE) {
struct list entry = old->entry; struct list entry = old->entry;
if (((old->file_id == new->file_id) if ((old->file_id == new->file_id && verbosity > 0) ||
&& (warningLevel > 0)) || (warningLevel > 9)) { verbosity > 9)
WARN("Map for indicator %s redefined\n", log_warn(info->keymap->ctx,
xkb_atom_text(ctx, old->name)); "Map for indicator %s redefined; "
ACTION("Earlier definition ignored\n"); "Earlier definition ignored\n",
} xkb_atom_text(ctx, old->name));
*old = *new; *old = *new;
old->entry = entry; old->entry = entry;
return true; return true;
} }
collide = 0; collide = 0;
if (UseNewField(_LED_Index, old->defined, old->file_id, if (UseNewLEDField(_LED_Index, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->indicator = new->indicator; old->indicator = new->indicator;
old->defined |= _LED_Index; old->defined |= _LED_Index;
} }
if (UseNewField(_LED_Mods, old->defined, old->file_id, if (UseNewLEDField(_LED_Mods, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->which_mods = new->which_mods; old->which_mods = new->which_mods;
old->real_mods = new->real_mods; old->real_mods = new->real_mods;
old->vmods = new->vmods; old->vmods = new->vmods;
old->defined |= _LED_Mods; old->defined |= _LED_Mods;
} }
if (UseNewField(_LED_Groups, old->defined, old->file_id, if (UseNewLEDField(_LED_Groups, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->which_groups = new->which_groups; old->which_groups = new->which_groups;
old->groups = new->groups; old->groups = new->groups;
old->defined |= _LED_Groups; old->defined |= _LED_Groups;
} }
if (UseNewField(_LED_Ctrls, old->defined, old->file_id, if (UseNewLEDField(_LED_Ctrls, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->ctrls = new->ctrls; old->ctrls = new->ctrls;
old->defined |= _LED_Ctrls; old->defined |= _LED_Ctrls;
} }
if (UseNewField(_LED_Explicit, old->defined, old->file_id, if (UseNewLEDField(_LED_Explicit, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->flags &= ~XkbIM_NoExplicit; old->flags &= ~XkbIM_NoExplicit;
old->flags |= (new->flags & XkbIM_NoExplicit); old->flags |= (new->flags & XkbIM_NoExplicit);
old->defined |= _LED_Explicit; old->defined |= _LED_Explicit;
} }
if (UseNewField(_LED_Automatic, old->defined, old->file_id, if (UseNewLEDField(_LED_Automatic, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->flags &= ~XkbIM_NoAutomatic; old->flags &= ~XkbIM_NoAutomatic;
old->flags |= (new->flags & XkbIM_NoAutomatic); old->flags |= (new->flags & XkbIM_NoAutomatic);
old->defined |= _LED_Automatic; old->defined |= _LED_Automatic;
} }
if (UseNewField(_LED_DrivesKbd, old->defined, old->file_id, if (UseNewLEDField(_LED_DrivesKbd, old, new, verbosity,
new->defined, new->file_id, new->merge, &collide)) { &collide)) {
old->flags &= ~XkbIM_LEDDrivesKB; old->flags &= ~XkbIM_LEDDrivesKB;
old->flags |= (new->flags & XkbIM_LEDDrivesKB); old->flags |= (new->flags & XkbIM_LEDDrivesKB);
old->defined |= _LED_DrivesKbd; old->defined |= _LED_DrivesKbd;
} }
if (collide) { if (collide) {
WARN("Map for indicator %s redefined\n", log_warn(info->keymap->ctx,
xkb_atom_text(ctx, old->name)); "Map for indicator %s redefined; "
ACTION("Using %s definition for duplicate fields\n", "Using %s definition for duplicate fields\n",
(new->merge == MERGE_AUGMENT ? "first" : "last")); xkb_atom_text(ctx, old->name),
(new->merge == MERGE_AUGMENT ? "first" : "last"));
} }
return true; return true;
@ -481,9 +523,10 @@ AddIndicatorMap(CompatInfo *info, LEDInfo *new)
/* new definition */ /* new definition */
old = malloc(sizeof(*old)); old = malloc(sizeof(*old));
if (!old) { if (!old) {
WSGO("Couldn't allocate indicator map\n"); log_wsgo(info->keymap->ctx,
ACTION("Map for indicator %s not compiled\n", "Couldn't allocate indicator map; "
xkb_atom_text(ctx, new->name)); "Map for indicator %s not compiled\n",
xkb_atom_text(ctx, new->name));
return false; return false;
} }
@ -804,9 +847,10 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
"indicator index"); "indicator index");
if (rtrn.uval < 1 || rtrn.uval > 32) { if (rtrn.uval < 1 || rtrn.uval > 32) {
ERROR("Illegal indicator index %d (range 1..%d)\n", log_err(info->keymap->ctx,
rtrn.uval, XkbNumIndicators); "Illegal indicator index %d (range 1..%d); "
ACTION("Index definition for %s indicator ignored\n", "Index definition for %s indicator ignored\n",
rtrn.uval, XkbNumIndicators,
xkb_atom_text(keymap->ctx, led->name)); xkb_atom_text(keymap->ctx, led->name));
return false; return false;
} }
@ -815,9 +859,10 @@ SetIndicatorMapField(CompatInfo *info, LEDInfo *led,
led->defined |= _LED_Index; led->defined |= _LED_Index;
} }
else { else {
ERROR("Unknown field %s in map for %s indicator\n", field, log_err(info->keymap->ctx,
xkb_atom_text(keymap->ctx, led->name)); "Unknown field %s in map for %s indicator; "
ACTION("Definition ignored\n"); "Definition ignored\n",
field, xkb_atom_text(keymap->ctx, led->name));
ok = false; ok = false;
} }
@ -874,8 +919,9 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
SymInterpInfo si; SymInterpInfo si;
if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) { if (!ResolveStateAndPredicate(def->match, &pred, &mods, info)) {
ERROR("Couldn't determine matching modifiers\n"); log_err(info->keymap->ctx,
ACTION("Symbol interpretation ignored\n"); "Couldn't determine matching modifiers; "
"Symbol interpretation ignored\n");
return false; return false;
} }
if (def->merge != MERGE_DEFAULT) if (def->merge != MERGE_DEFAULT)
@ -884,8 +930,10 @@ HandleInterpDef(CompatInfo *info, InterpDef *def, enum merge_mode merge)
si = info->dflt; si = info->dflt;
si.merge = merge; si.merge = merge;
if (!LookupKeysym(def->sym, &si.interp.sym)) { if (!LookupKeysym(def->sym, &si.interp.sym)) {
ERROR("Could not resolve keysym %s\n", def->sym); log_err(info->keymap->ctx,
ACTION("Symbol interpretation ignored\n"); "Could not resolve keysym %s; "
"Symbol interpretation ignored\n",
def->sym);
return false; return false;
} }
si.interp.match = pred & XkbSI_OpMask; si.interp.match = pred & XkbSI_OpMask;
@ -912,17 +960,19 @@ HandleGroupCompatDef(CompatInfo *info, GroupCompatDef *def,
if (def->merge != MERGE_DEFAULT) if (def->merge != MERGE_DEFAULT)
merge = def->merge; merge = def->merge;
if (def->group < 1 || def->group > XkbNumKbdGroups) { if (def->group < 1 || def->group > XkbNumKbdGroups) {
ERROR("Keyboard group must be in the range 1..%u\n", log_err(info->keymap->ctx,
XkbNumKbdGroups); "Keyboard group must be in the range 1..%u; "
ACTION("Compatibility map for illegal group %u ignored\n", def->group); "Compatibility map for illegal group %u ignored\n",
XkbNumKbdGroups, def->group);
return false; return false;
} }
tmp.file_id = info->file_id; tmp.file_id = info->file_id;
tmp.merge = merge; tmp.merge = merge;
if (!ExprResolveVModMask(def->def, &val, info->keymap)) { if (!ExprResolveVModMask(def->def, &val, info->keymap)) {
ERROR("Expected a modifier mask in group compatibility definition\n"); log_err(info->keymap->ctx,
ACTION("Ignoring illegal compatibility map for group %u\n", "Expected a modifier mask in group compatibility definition; "
def->group); "Ignoring illegal compatibility map for group %u\n",
def->group);
return false; return false;
} }
tmp.real_mods = val.uval & 0xff; tmp.real_mods = val.uval & 0xff;
@ -957,9 +1007,10 @@ HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
} }
if (elem.str != NULL) { if (elem.str != NULL) {
ERROR("Cannot set defaults for \"%s\" element in indicator map\n", log_err(info->keymap->ctx,
elem.str); "Cannot set defaults for \"%s\" element in indicator map; "
ACTION("Assignment to %s.%s ignored\n", elem.str, field.str); "Assignment to %s.%s ignored\n",
elem.str, elem.str, field.str);
ok = false; ok = false;
} }
else { else {
@ -1015,18 +1066,21 @@ HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
info->errorCount++; info->errorCount++;
break; break;
case StmtKeycodeDef: case StmtKeycodeDef:
ERROR("Interpretation files may not include other types\n"); log_err(info->keymap->ctx,
ACTION("Ignoring definition of key name\n"); "Interpretation files may not include other types; "
"Ignoring definition of key name\n");
info->errorCount++; info->errorCount++;
break; break;
default: default:
WSGO("Unexpected statement type %d in HandleCompatMapFile\n", log_wsgo(info->keymap->ctx,
stmt->stmtType); "Unexpected statement type %d in HandleCompatMapFile\n",
stmt->stmtType);
break; break;
} }
stmt = stmt->next; stmt = stmt->next;
if (info->errorCount > 10) { if (info->errorCount > 10) {
ACTION("Abandoning compatibility map \"%s\"\n", file->topName); log_err(info->keymap->ctx,
"Abandoning compatibility map \"%s\"\n", file->topName);
break; break;
} }
} }
@ -1080,9 +1134,10 @@ BindIndicators(CompatInfo *info, struct list *unbound_leds)
} }
if (led->indicator == _LED_NotBound) { if (led->indicator == _LED_NotBound) {
ERROR("No unnamed indicators found\n"); log_err(info->keymap->ctx,
ACTION("Virtual indicator map \"%s\" not bound\n", "No unnamed indicators found; "
xkb_atom_text(keymap->ctx, led->name)); "Virtual indicator map \"%s\" not bound\n",
xkb_atom_text(keymap->ctx, led->name));
continue; continue;
} }
} }
@ -1097,9 +1152,11 @@ BindIndicators(CompatInfo *info, struct list *unbound_leds)
if (strcmp(keymap->indicator_names[led->indicator - 1], if (strcmp(keymap->indicator_names[led->indicator - 1],
xkb_atom_text(keymap->ctx, led->name)) != 0) { xkb_atom_text(keymap->ctx, led->name)) != 0) {
const char *old = keymap->indicator_names[led->indicator - 1]; const char *old = keymap->indicator_names[led->indicator - 1];
ERROR("Multiple names bound to indicator %d\n", led->indicator); log_err(info->keymap->ctx,
ACTION("Using %s, ignoring %s\n", old, "Multiple names bound to indicator %d; "
xkb_atom_text(keymap->ctx, led->name)); "Using %s, ignoring %s\n",
led->indicator, old,
xkb_atom_text(keymap->ctx, led->name));
free(led); free(led);
continue; continue;
} }

View File

@ -106,26 +106,6 @@ ProcessIncludeFile(struct xkb_context *ctx,
return true; return true;
} }
bool
UseNewField(unsigned field, short old_defined, unsigned old_file_id,
short new_defined, unsigned new_file_id,
enum merge_mode new_merge, unsigned *collide)
{
if (!(old_defined & field))
return true;
if (new_defined & field) {
if ((old_file_id == new_file_id && warningLevel > 0) ||
warningLevel > 9)
*collide |= field;
if (new_merge != MERGE_AUGMENT)
return true;
}
return false;
}
/** /**
* Find the key with the given name. * Find the key with the given name.
* *

View File

@ -32,11 +32,6 @@
#include "text.h" #include "text.h"
#include "utils.h" #include "utils.h"
bool
UseNewField(unsigned field, short old_defined, unsigned old_file_id,
short new_defined, unsigned new_file_id,
enum merge_mode new_merge, unsigned *collide);
extern bool extern bool
ProcessIncludeFile(struct xkb_context *ctx, IncludeStmt *stmt, ProcessIncludeFile(struct xkb_context *ctx, IncludeStmt *stmt,
enum xkb_file_type file_type, XkbFile **file_rtrn, enum xkb_file_type file_type, XkbFile **file_rtrn,