static void
HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
{
+ bool ok;
ParseCommon *stmt;
- if (merge == MERGE_DEFAULT)
- merge = MERGE_AUGMENT;
+ merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
+
free(info->name);
info->name = strdup_safe(file->name);
- stmt = file->defs;
- while (stmt)
- {
+
+ for (stmt = file->defs; stmt; stmt = stmt->next) {
switch (stmt->type) {
case STMT_INCLUDE:
- if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt))
- info->errorCount++;
+ ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
break;
case STMT_INTERP:
- if (!HandleInterpDef(info, (InterpDef *) stmt, merge))
- info->errorCount++;
+ ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
break;
case STMT_GROUP_COMPAT:
- if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge))
- info->errorCount++;
+ ok = HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge);
break;
case STMT_INDICATOR_MAP:
- if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge))
- info->errorCount++;
+ ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
break;
case STMT_VAR:
- if (!HandleInterpVar(info, (VarDef *) stmt))
- info->errorCount++;
+ ok = HandleInterpVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
- &info->vmods))
- info->errorCount++;
+ ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
+ &info->vmods);
break;
- case STMT_KEYCODE:
+ default:
log_err(info->keymap->ctx,
"Interpretation files may not include other types; "
- "Ignoring definition of key name\n");
- info->errorCount++;
- break;
- default:
- log_wsgo(info->keymap->ctx,
- "Unexpected statement type %d in HandleCompatMapFile\n",
- stmt->type);
+ "Ignoring %s\n", StmtTypeToString(stmt->type));
+ ok = false;
break;
}
- stmt = stmt->next;
+
+ if (!ok)
+ info->errorCount++;
+
if (info->errorCount > 10) {
log_err(info->keymap->ctx,
"Abandoning compatibility map \"%s\"\n", file->topName);
HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
{
ParseCommon *stmt;
+ bool ok;
free(info->name);
info->name = strdup_safe(file->name);
- stmt = file->defs;
- while (stmt)
- {
+
+ for (stmt = file->defs; stmt; stmt = stmt->next) {
switch (stmt->type) {
case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */
- if (!HandleIncludeKeycodes(info, (IncludeStmt *) stmt))
- info->errorCount++;
+ ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt);
break;
case STMT_KEYCODE: /* e.g. <ESC> = 9; */
- if (!HandleKeycodeDef(info, (KeycodeDef *) stmt, merge))
- info->errorCount++;
+ ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
break;
case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
- if (!HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
- info->file_id))
- info->errorCount++;
+ ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
+ info->file_id);
break;
case STMT_VAR: /* e.g. minimum, maximum */
- if (!HandleKeyNameVar(info, (VarDef *) stmt))
- info->errorCount++;
+ ok = HandleKeyNameVar(info, (VarDef *) stmt);
break;
case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */
- if (!HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
- merge))
- info->errorCount++;
+ ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
+ merge);
break;
- case STMT_INTERP:
- case STMT_VMOD:
+ default:
log_err(info->keymap->ctx,
"Keycode files may define key and indicator names only; "
- "Ignoring definition of %s\n",
- (stmt->type == STMT_INTERP ?
- "a symbol interpretation" : "virtual modifiers"));
- info->errorCount++;
- break;
- default:
- log_wsgo(info->keymap->ctx,
- "Unexpected statement type %d in HandleKeycodesFile\n",
- stmt->type);
+ "Ignoring %s\n", StmtTypeToString(stmt->type));
+ ok = false;
break;
}
- stmt = stmt->next;
+
+ if (!ok)
+ info->errorCount++;
+
if (info->errorCount > 10) {
log_err(info->keymap->ctx, "Abandoning keycodes file \"%s\"\n",
file->topName);
static void
HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
{
+ bool ok;
ParseCommon *stmt;
free(info->name);
info->name = strdup_safe(file->name);
- stmt = file->defs;
- while (stmt)
- {
+
+ for (stmt = file->defs; stmt; stmt = stmt->next) {
switch (stmt->type) {
case STMT_INCLUDE:
- if (!HandleIncludeKeyTypes(info, (IncludeStmt *) stmt))
- info->errorCount++;
+ ok = HandleIncludeKeyTypes(info, (IncludeStmt *) stmt);
break;
case STMT_TYPE: /* e.g. type "ONE_LEVEL" */
- if (!HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge))
- info->errorCount++;
+ ok = HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge);
break;
case STMT_VAR:
- if (!HandleKeyTypeVar(info, (VarDef *) stmt))
- info->errorCount++;
+ ok = HandleKeyTypeVar(info, (VarDef *) stmt);
break;
case STMT_VMOD: /* virtual_modifiers NumLock, ... */
- if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
- &info->vmods))
- info->errorCount++;
- break;
- case STMT_ALIAS:
- log_err(info->keymap->ctx,
- "Key type files may not include other declarations; "
- "Ignoring definition of key alias\n");
- info->errorCount++;
- break;
- case STMT_KEYCODE:
- log_err(info->keymap->ctx,
- "Key type files may not include other declarations; "
- "Ignoring definition of key name\n");
- info->errorCount++;
+ ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
+ &info->vmods);
break;
- case STMT_INTERP:
+ default:
log_err(info->keymap->ctx,
"Key type files may not include other declarations; "
- "Ignoring definition of symbol interpretation\n");
- info->errorCount++;
- break;
- default:
- log_wsgo(info->keymap->ctx,
- "Unexpected statement type %d in HandleKeyTypesFile\n",
- stmt->type);
+ "Ignoring %s\n", StmtTypeToString(stmt->type));
+ ok = false;
break;
}
- stmt = stmt->next;
+
+ if (!ok)
+ info->errorCount++;
+
if (info->errorCount > 10) {
log_err(info->keymap->ctx,
"Abandoning keytypes file \"%s\"\n", file->topName);
file = next;
}
}
+
+const char *stmt_type_strings[_STMT_NUM_VALUES] = {
+ [STMT_UNKNOWN] = "unknown statement",
+ [STMT_INCLUDE] = "include statement",
+ [STMT_KEYCODE] = "key name definition",
+ [STMT_ALIAS] = "key alias definition",
+ [STMT_EXPR] = "expression",
+ [STMT_VAR] = "variable definition",
+ [STMT_TYPE] = "key type definition",
+ [STMT_INTERP] = "symbol interpretation definition",
+ [STMT_VMOD] = "virtual modifiers definition",
+ [STMT_SYMBOLS] = "key symbols definition",
+ [STMT_MODMAP] = "modifier map declaration",
+ [STMT_GROUP_COMPAT] = "group declaration",
+ [STMT_INDICATOR_MAP] = "indicator map declaration",
+ [STMT_INDICATOR_NAME] = "indicator name declaration",
+};
+
+const char *
+StmtTypeToString(enum stmt_type type)
+{
+ if (type >= _STMT_NUM_VALUES)
+ type = STMT_UNKNOWN;
+ return stmt_type_strings[type];
+}
static void
HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
{
+ bool ok;
ParseCommon *stmt;
free(info->name);
info->name = strdup_safe(file->name);
+
stmt = file->defs;
- while (stmt)
- {
+ for (stmt = file->defs; stmt; stmt = stmt->next) {
switch (stmt->type) {
case STMT_INCLUDE:
- if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt))
- info->errorCount++;
+ ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
break;
case STMT_SYMBOLS:
- if (!HandleSymbolsDef(info, (SymbolsDef *) stmt))
- info->errorCount++;
+ ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
break;
case STMT_VAR:
- if (!HandleSymbolsVar(info, (VarDef *) stmt))
- info->errorCount++;
+ ok = HandleSymbolsVar(info, (VarDef *) stmt);
break;
case STMT_VMOD:
- if (!HandleVModDef((VModDef *) stmt, info->keymap, merge,
- &info->vmods))
- info->errorCount++;
- break;
- case STMT_INTERP:
- log_err(info->keymap->ctx,
- "Interpretation files may not include other types; "
- "Ignoring definition of symbol interpretation\n");
- info->errorCount++;
- break;
- case STMT_KEYCODE:
- log_err(info->keymap->ctx,
- "Interpretation files may not include other types; "
- "Ignoring definition of key name\n");
- info->errorCount++;
+ ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
+ &info->vmods);
break;
case STMT_MODMAP:
- if (!HandleModMapDef(info, (ModMapDef *) stmt))
- info->errorCount++;
+ ok = HandleModMapDef(info, (ModMapDef *) stmt);
break;
default:
- log_wsgo(info->keymap->ctx,
- "Unexpected statement type %d in HandleSymbolsFile\n",
- stmt->type);
+ log_err(info->keymap->ctx,
+ "Interpretation files may not include other types; "
+ "Ignoring %s\n", StmtTypeToString(stmt->type));
+ ok = false;
break;
}
- stmt = stmt->next;
+
+ if (!ok)
+ info->errorCount++;
+
if (info->errorCount > 10) {
log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
file->topName);
xkb_mod_mask_t
VModsToReal(struct xkb_keymap *keymap, xkb_mod_mask_t vmodmask);
+const char *
+StmtTypeToString(enum stmt_type type);
+
static inline unsigned long
KeyNameToLong(const char *name)
{
STMT_GROUP_COMPAT,
STMT_INDICATOR_MAP,
STMT_INDICATOR_NAME,
+ _STMT_NUM_VALUES
};
enum expr_value_type {