compat: use list instead of CommonInfo in SymInterpInfo 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 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 7f74c8a..a0e1220 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -30,7 +30,11 @@
#include "vmod.h"
typedef struct _SymInterpInfo {
- CommonInfo defs;
+ unsigned short defined;
+ unsigned file_id;
+ enum merge_mode merge;
+ struct list entry;
+
struct xkb_sym_interpret interp;
} SymInterpInfo;
@@ -76,7 +80,7 @@ typedef struct _CompatInfo {
unsigned file_id;
int errorCount;
int nInterps;
- SymInterpInfo *interps;
+ struct list interps;
SymInterpInfo dflt;
LEDInfo ledDflt;
GroupCompatInfo groupCompat[XkbNumKbdGroups];
@@ -154,11 +158,11 @@ InitCompatInfo(CompatInfo *info, struct xkb_keymap *keymap, unsigned file_id)
info->file_id = file_id;
info->errorCount = 0;
info->nInterps = 0;
- info->interps = NULL;
+ list_init(&info->interps);
info->act = NULL;
- info->dflt.defs.file_id = file_id;
- info->dflt.defs.defined = 0;
- info->dflt.defs.merge = MERGE_OVERRIDE;
+ info->dflt.file_id = file_id;
+ info->dflt.defined = 0;
+ info->dflt.merge = MERGE_OVERRIDE;
info->dflt.interp.flags = 0;
info->dflt.interp.virtual_mod = XkbNoModifier;
info->dflt.interp.act.type = XkbSA_NoAction;
@@ -178,12 +182,13 @@ static void
ClearCompatInfo(CompatInfo *info, struct xkb_keymap *keymap)
{
unsigned int i;
- ActionInfo *next;
+ ActionInfo *next_act;
+ SymInterpInfo *si, *next_si;
free(info->name);
info->name = NULL;
- info->dflt.defs.defined = 0;
- info->dflt.defs.merge = MERGE_AUGMENT;
+ info->dflt.defined = 0;
+ info->dflt.merge = MERGE_AUGMENT;
info->dflt.interp.flags = 0;
info->dflt.interp.virtual_mod = XkbNoModifier;
info->dflt.interp.act.type = XkbSA_NoAction;
@@ -191,14 +196,15 @@ ClearCompatInfo(CompatInfo *info, struct xkb_keymap *keymap)
info->dflt.interp.act.any.data[i] = 0;
ClearIndicatorMapInfo(keymap->ctx, &info->ledDflt);
info->nInterps = 0;
- info->interps = ClearCommonInfo(&info->interps->defs);
+ list_foreach_safe(si, next_si, &info->interps, entry)
+ free(si);
memset(&info->groupCompat[0], 0,
XkbNumKbdGroups * sizeof(GroupCompatInfo));
info->leds = ClearCommonInfo(&info->leds->defs);
while (info->act) {
- next = info->act->next;
+ next_act = info->act->next;
free(info->act);
- info->act = next;
+ info->act = next_act;
}
ClearVModInfo(&info->vmods, keymap);
}
@@ -208,12 +214,13 @@ NextInterp(CompatInfo * info)
{
SymInterpInfo *si;
- si = uTypedAlloc(SymInterpInfo);
- if (si) {
- memset(si, 0, sizeof(SymInterpInfo));
- info->interps = AddCommonInfo(&info->interps->defs, &si->defs);
- info->nInterps++;
- }
+ si = calloc(1, sizeof(*si));
+ if (!si)
+ return NULL;
+
+ list_append(&si->entry, &info->interps);
+ info->nInterps++;
+
return si;
}
@@ -222,14 +229,12 @@ FindMatchingInterp(CompatInfo * info, SymInterpInfo * new)
{
SymInterpInfo *old;
- for (old = info->interps; old != NULL;
- old = (SymInterpInfo *) old->defs.next) {
- if ((old->interp.sym == new->interp.sym) &&
- (old->interp.mods == new->interp.mods) &&
- (old->interp.match == new->interp.match)) {
+ list_foreach(old, &info->interps, entry)
+ if (old->interp.sym == new->interp.sym &&
+ old->interp.mods == new->interp.mods &&
+ old->interp.match == new->interp.match)
return old;
- }
- }
+
return NULL;
}
@@ -238,57 +243,67 @@ AddInterp(CompatInfo * info, SymInterpInfo * new)
{
unsigned collide;
SymInterpInfo *old;
+ struct list entry;
collide = 0;
old = FindMatchingInterp(info, new);
if (old != NULL) {
- if (new->defs.merge == MERGE_REPLACE) {
- SymInterpInfo *next = (SymInterpInfo *) old->defs.next;
- if (((old->defs.file_id == new->defs.file_id)
- && (warningLevel > 0)) || (warningLevel > 9)) {
+ if (new->merge == MERGE_REPLACE) {
+ entry = old->entry;
+ if ((old->file_id == new->file_id && warningLevel > 0) ||
+ warningLevel > 9) {
WARN("Multiple definitions for \"%s\"\n", siText(new, info));
ACTION("Earlier interpretation ignored\n");
}
*old = *new;
- old->defs.next = &next->defs;
+ old->entry = entry;
return true;
}
- if (UseNewField(_SI_VirtualMod, &old->defs, &new->defs, &collide)) {
+
+ if (use_new_field(_SI_VirtualMod, old->defined, old->file_id,
+ new->defined, new->file_id, new->merge, &collide)) {
old->interp.virtual_mod = new->interp.virtual_mod;
- old->defs.defined |= _SI_VirtualMod;
+ old->defined |= _SI_VirtualMod;
}
- if (UseNewField(_SI_Action, &old->defs, &new->defs, &collide)) {
+ if (use_new_field(_SI_Action, old->defined, old->file_id, new->defined,
+ new->file_id, new->merge, &collide)) {
old->interp.act = new->interp.act;
- old->defs.defined |= _SI_Action;
+ old->defined |= _SI_Action;
}
- if (UseNewField(_SI_AutoRepeat, &old->defs, &new->defs, &collide)) {
+ if (use_new_field(_SI_AutoRepeat, old->defined, old->file_id,
+ new->defined, new->file_id, new->merge, &collide)) {
old->interp.flags &= ~XkbSI_AutoRepeat;
old->interp.flags |= (new->interp.flags & XkbSI_AutoRepeat);
- old->defs.defined |= _SI_AutoRepeat;
+ old->defined |= _SI_AutoRepeat;
}
- if (UseNewField(_SI_LockingKey, &old->defs, &new->defs, &collide)) {
+ if (use_new_field(_SI_LockingKey, old->defined, old->file_id,
+ new->defined, new->file_id, new->merge, &collide)) {
old->interp.flags &= ~XkbSI_LockingKey;
old->interp.flags |= (new->interp.flags & XkbSI_LockingKey);
- old->defs.defined |= _SI_LockingKey;
+ old->defined |= _SI_LockingKey;
}
- if (UseNewField(_SI_LevelOneOnly, &old->defs, &new->defs,
- &collide)) {
+ if (use_new_field(_SI_LevelOneOnly, old->defined, old->file_id,
+ new->defined, new->file_id, new->merge, &collide)) {
old->interp.match &= ~XkbSI_LevelOneOnly;
old->interp.match |= (new->interp.match & XkbSI_LevelOneOnly);
- old->defs.defined |= _SI_LevelOneOnly;
+ old->defined |= _SI_LevelOneOnly;
}
+
if (collide) {
WARN("Multiple interpretations of \"%s\"\n", siText(new, info));
ACTION("Using %s definition for duplicate fields\n",
- (new->defs.merge != MERGE_AUGMENT ? "last" : "first"));
+ (new->merge != MERGE_AUGMENT ? "last" : "first"));
}
+
return true;
}
+
old = new;
if ((new = NextInterp(info)) == NULL)
return false;
+ entry = new->entry;
*new = *old;
- new->defs.next = NULL;
+ new->entry = entry;
return true;
}
@@ -487,14 +502,16 @@ MergeIncludedCompatMaps(CompatInfo * into, CompatInfo * from,
into->name = from->name;
from->name = NULL;
}
- for (si = from->interps; si; si = (SymInterpInfo *) si->defs.next) {
+
+ list_foreach(si, &from->interps, entry) {
if (merge != MERGE_DEFAULT)
- si->defs.merge = merge;
+ si->merge = merge;
if (!AddInterp(into, si))
into->errorCount++;
}
- for (i = 0, gcm = &from->groupCompat[0]; i < XkbNumKbdGroups; i++,
- gcm++) {
+
+ for (i = 0, gcm = &from->groupCompat[0]; i < XkbNumKbdGroups;
+ i++, gcm++) {
if (merge != MERGE_DEFAULT)
gcm->merge = merge;
if (!AddGroupCompat(into, i, gcm))
@@ -536,7 +553,7 @@ HandleIncludeCompatMap(IncludeStmt *stmt, struct xkb_keymap *keymap,
&newMerge)) {
InitCompatInfo(&included, keymap, rtrn->id);
included.dflt = info->dflt;
- included.dflt.defs.merge = newMerge;
+ included.dflt.merge = newMerge;
included.ledDflt.defs.merge = newMerge;
included.act = info->act;
HandleCompatMapFile(rtrn, keymap, MERGE_OVERRIDE, &included);
@@ -569,8 +586,8 @@ HandleIncludeCompatMap(IncludeStmt *stmt, struct xkb_keymap *keymap,
InitCompatInfo(&next_incl, keymap, rtrn->id);
next_incl.file_id = rtrn->id;
next_incl.dflt = info->dflt;
- next_incl.dflt.defs.file_id = rtrn->id;
- next_incl.dflt.defs.merge = op;
+ next_incl.dflt.file_id = rtrn->id;
+ next_incl.dflt.merge = op;
next_incl.ledDflt.defs.file_id = rtrn->id;
next_incl.ledDflt.defs.merge = op;
next_incl.act = info->act;
@@ -616,7 +633,7 @@ SetInterpField(SymInterpInfo *si, struct xkb_keymap *keymap, char *field,
return ReportSINotArray(si, field, info);
ok = HandleActionDef(value, keymap, &si->interp.act.any, info->act);
if (ok)
- si->defs.defined |= _SI_Action;
+ si->defined |= _SI_Action;
}
else if ((strcasecmp(field, "virtualmodifier") == 0) ||
(strcasecmp(field, "virtualmod") == 0)) {
@@ -625,7 +642,7 @@ SetInterpField(SymInterpInfo *si, struct xkb_keymap *keymap, char *field,
ok = ResolveVirtualModifier(value, keymap, &tmp, &info->vmods);
if (ok) {
si->interp.virtual_mod = tmp.uval;
- si->defs.defined |= _SI_VirtualMod;
+ si->defined |= _SI_VirtualMod;
}
else
return ReportSIBadType(si, field, "virtual modifier", info);
@@ -639,7 +656,7 @@ SetInterpField(SymInterpInfo *si, struct xkb_keymap *keymap, char *field,
si->interp.flags |= XkbSI_AutoRepeat;
else
si->interp.flags &= ~XkbSI_AutoRepeat;
- si->defs.defined |= _SI_AutoRepeat;
+ si->defined |= _SI_AutoRepeat;
}
else
return ReportSIBadType(si, field, "boolean", info);
@@ -653,7 +670,7 @@ SetInterpField(SymInterpInfo *si, struct xkb_keymap *keymap, char *field,
si->interp.flags |= XkbSI_LockingKey;
else
si->interp.flags &= ~XkbSI_LockingKey;
- si->defs.defined |= _SI_LockingKey;
+ si->defined |= _SI_LockingKey;
}
else
return ReportSIBadType(si, field, "boolean", info);
@@ -668,7 +685,7 @@ SetInterpField(SymInterpInfo *si, struct xkb_keymap *keymap, char *field,
si->interp.match |= XkbSI_LevelOneOnly;
else
si->interp.match &= ~XkbSI_LevelOneOnly;
- si->defs.defined |= _SI_LevelOneOnly;
+ si->defined |= _SI_LevelOneOnly;
}
else
return ReportSIBadType(si, field, "level specification", info);
@@ -897,7 +914,7 @@ HandleInterpDef(InterpDef *def, struct xkb_keymap *keymap,
merge = def->merge;
si = info->dflt;
- si.defs.merge = merge;
+ si.merge = merge;
if (!LookupKeysym(def->sym, &si.interp.sym)) {
ERROR("Could not resolve keysym %s\n", def->sym);
ACTION("Symbol interpretation ignored\n");
@@ -1065,11 +1082,12 @@ CopyInterps(CompatInfo *info, struct xkb_keymap *keymap,
{
SymInterpInfo *si;
- for (si = info->interps; si; si = (SymInterpInfo *) si->defs.next) {
+ list_foreach(si, &info->interps, entry) {
if (((si->interp.match & XkbSI_OpMask) != pred) ||
- (needSymbol && (si->interp.sym == XKB_KEY_NoSymbol)) ||
- ((!needSymbol) && (si->interp.sym != XKB_KEY_NoSymbol)))
+ (needSymbol && si->interp.sym == XKB_KEY_NoSymbol) ||
+ (!needSymbol && si->interp.sym != XKB_KEY_NoSymbol))
continue;
+
darray_append(keymap->sym_interpret, si->interp);
}
}
@@ -1215,7 +1233,7 @@ CompileCompatMap(XkbFile *file, struct xkb_keymap *keymap,
GroupCompatInfo *gcm;
InitCompatInfo(&info, keymap, file->id);
- info.dflt.defs.merge = merge;
+ info.dflt.merge = merge;
info.ledDflt.defs.merge = merge;
HandleCompatMapFile(file, keymap, merge, &info);
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 55c77e6..8cecd19 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -128,6 +128,26 @@ UseNewField(unsigned field,
return useNew;
}
+bool
+use_new_field(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;
+}
+
+
void *
ClearCommonInfo(CommonInfo * cmn)
{
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 67e6a57..ea03e9c 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -483,25 +483,6 @@ out:
}
static bool
-use_new_field(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;
-}
-
-static bool
MergeKeys(SymbolsInfo *info, struct xkb_keymap *keymap,
KeyInfo *into, KeyInfo *from)
{
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 3b03709..7e5d47d 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -43,6 +43,11 @@ extern bool
UseNewField(unsigned field, CommonInfo *oldDefs, CommonInfo *newDefs,
unsigned *pCollide);
+bool
+use_new_field(unsigned field, short old_defined, unsigned old_file_id,
+ short new_defined, unsigned new_file_id,
+ enum merge_mode new_merge, unsigned *collide);
+
extern void *
ClearCommonInfo(CommonInfo *cmn);