Make top level Handle*File functions nicer

Signed-off-by: Ran Benita <ran234@gmail.com>
master
Ran Benita 2012-08-01 18:46:01 +03:00
parent 82ee45b374
commit 3bea189bd5
7 changed files with 100 additions and 119 deletions

View File

@ -1045,54 +1045,46 @@ HandleIndicatorMapDef(CompatInfo *info, IndicatorMapDef *def,
static void static void
HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge) HandleCompatMapFile(CompatInfo *info, XkbFile *file, enum merge_mode merge)
{ {
bool ok;
ParseCommon *stmt; ParseCommon *stmt;
if (merge == MERGE_DEFAULT) merge = (merge == MERGE_DEFAULT ? MERGE_AUGMENT : merge);
merge = MERGE_AUGMENT;
free(info->name); free(info->name);
info->name = strdup_safe(file->name); info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt) for (stmt = file->defs; stmt; stmt = stmt->next) {
{
switch (stmt->type) { switch (stmt->type) {
case STMT_INCLUDE: case STMT_INCLUDE:
if (!HandleIncludeCompatMap(info, (IncludeStmt *) stmt)) ok = HandleIncludeCompatMap(info, (IncludeStmt *) stmt);
info->errorCount++;
break; break;
case STMT_INTERP: case STMT_INTERP:
if (!HandleInterpDef(info, (InterpDef *) stmt, merge)) ok = HandleInterpDef(info, (InterpDef *) stmt, merge);
info->errorCount++;
break; break;
case STMT_GROUP_COMPAT: case STMT_GROUP_COMPAT:
if (!HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge)) ok = HandleGroupCompatDef(info, (GroupCompatDef *) stmt, merge);
info->errorCount++;
break; break;
case STMT_INDICATOR_MAP: case STMT_INDICATOR_MAP:
if (!HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge)) ok = HandleIndicatorMapDef(info, (IndicatorMapDef *) stmt, merge);
info->errorCount++;
break; break;
case STMT_VAR: case STMT_VAR:
if (!HandleInterpVar(info, (VarDef *) stmt)) ok = HandleInterpVar(info, (VarDef *) stmt);
info->errorCount++;
break; break;
case STMT_VMOD: case STMT_VMOD:
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods)) &info->vmods);
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++;
break; break;
default: default:
log_wsgo(info->keymap->ctx, log_err(info->keymap->ctx,
"Unexpected statement type %d in HandleCompatMapFile\n", "Interpretation files may not include other types; "
stmt->type); "Ignoring %s\n", StmtTypeToString(stmt->type));
ok = false;
break; break;
} }
stmt = stmt->next;
if (!ok)
info->errorCount++;
if (info->errorCount > 10) { if (info->errorCount > 10) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Abandoning compatibility map \"%s\"\n", file->topName); "Abandoning compatibility map \"%s\"\n", file->topName);

View File

@ -748,51 +748,41 @@ static void
HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge) HandleKeycodesFile(KeyNamesInfo *info, XkbFile *file, enum merge_mode merge)
{ {
ParseCommon *stmt; ParseCommon *stmt;
bool ok;
free(info->name); free(info->name);
info->name = strdup_safe(file->name); info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt) for (stmt = file->defs; stmt; stmt = stmt->next) {
{
switch (stmt->type) { switch (stmt->type) {
case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */ case STMT_INCLUDE: /* e.g. include "evdev+aliases(qwerty)" */
if (!HandleIncludeKeycodes(info, (IncludeStmt *) stmt)) ok = HandleIncludeKeycodes(info, (IncludeStmt *) stmt);
info->errorCount++;
break; break;
case STMT_KEYCODE: /* e.g. <ESC> = 9; */ case STMT_KEYCODE: /* e.g. <ESC> = 9; */
if (!HandleKeycodeDef(info, (KeycodeDef *) stmt, merge)) ok = HandleKeycodeDef(info, (KeycodeDef *) stmt, merge);
info->errorCount++;
break; break;
case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */ case STMT_ALIAS: /* e.g. alias <MENU> = <COMP>; */
if (!HandleAliasDef(info, (KeyAliasDef *) stmt, merge, ok = HandleAliasDef(info, (KeyAliasDef *) stmt, merge,
info->file_id)) info->file_id);
info->errorCount++;
break; break;
case STMT_VAR: /* e.g. minimum, maximum */ case STMT_VAR: /* e.g. minimum, maximum */
if (!HandleKeyNameVar(info, (VarDef *) stmt)) ok = HandleKeyNameVar(info, (VarDef *) stmt);
info->errorCount++;
break; break;
case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */ case STMT_INDICATOR_NAME: /* e.g. indicator 1 = "Caps Lock"; */
if (!HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt, ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
merge)) merge);
info->errorCount++;
break;
case STMT_INTERP:
case STMT_VMOD:
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; break;
default: default:
log_wsgo(info->keymap->ctx, log_err(info->keymap->ctx,
"Unexpected statement type %d in HandleKeycodesFile\n", "Keycode files may define key and indicator names only; "
stmt->type); "Ignoring %s\n", StmtTypeToString(stmt->type));
ok = false;
break; break;
} }
stmt = stmt->next;
if (!ok)
info->errorCount++;
if (info->errorCount > 10) { if (info->errorCount > 10) {
log_err(info->keymap->ctx, "Abandoning keycodes file \"%s\"\n", log_err(info->keymap->ctx, "Abandoning keycodes file \"%s\"\n",
file->topName); file->topName);

View File

@ -879,56 +879,38 @@ HandleKeyTypeDef(KeyTypesInfo *info, KeyTypeDef *def, enum merge_mode merge)
static void static void
HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge) HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
{ {
bool ok;
ParseCommon *stmt; ParseCommon *stmt;
free(info->name); free(info->name);
info->name = strdup_safe(file->name); info->name = strdup_safe(file->name);
stmt = file->defs;
while (stmt) for (stmt = file->defs; stmt; stmt = stmt->next) {
{
switch (stmt->type) { switch (stmt->type) {
case STMT_INCLUDE: case STMT_INCLUDE:
if (!HandleIncludeKeyTypes(info, (IncludeStmt *) stmt)) ok = HandleIncludeKeyTypes(info, (IncludeStmt *) stmt);
info->errorCount++;
break; break;
case STMT_TYPE: /* e.g. type "ONE_LEVEL" */ case STMT_TYPE: /* e.g. type "ONE_LEVEL" */
if (!HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge)) ok = HandleKeyTypeDef(info, (KeyTypeDef *) stmt, merge);
info->errorCount++;
break; break;
case STMT_VAR: case STMT_VAR:
if (!HandleKeyTypeVar(info, (VarDef *) stmt)) ok = HandleKeyTypeVar(info, (VarDef *) stmt);
info->errorCount++;
break; break;
case STMT_VMOD: /* virtual_modifiers NumLock, ... */ case STMT_VMOD: /* virtual_modifiers NumLock, ... */
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods)) &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++;
break;
case STMT_INTERP:
log_err(info->keymap->ctx,
"Key type files may not include other declarations; "
"Ignoring definition of symbol interpretation\n");
info->errorCount++;
break; break;
default: default:
log_wsgo(info->keymap->ctx, log_err(info->keymap->ctx,
"Unexpected statement type %d in HandleKeyTypesFile\n", "Key type files may not include other declarations; "
stmt->type); "Ignoring %s\n", StmtTypeToString(stmt->type));
ok = false;
break; break;
} }
stmt = stmt->next;
if (!ok)
info->errorCount++;
if (info->errorCount > 10) { if (info->errorCount > 10) {
log_err(info->keymap->ctx, log_err(info->keymap->ctx,
"Abandoning keytypes file \"%s\"\n", file->topName); "Abandoning keytypes file \"%s\"\n", file->topName);

View File

@ -671,3 +671,28 @@ FreeXKBFile(XkbFile *file)
file = next; 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];
}

View File

@ -1409,54 +1409,42 @@ HandleModMapDef(SymbolsInfo *info, ModMapDef *def)
static void static void
HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge) HandleSymbolsFile(SymbolsInfo *info, XkbFile *file, enum merge_mode merge)
{ {
bool ok;
ParseCommon *stmt; ParseCommon *stmt;
free(info->name); free(info->name);
info->name = strdup_safe(file->name); info->name = strdup_safe(file->name);
stmt = file->defs; stmt = file->defs;
while (stmt) for (stmt = file->defs; stmt; stmt = stmt->next) {
{
switch (stmt->type) { switch (stmt->type) {
case STMT_INCLUDE: case STMT_INCLUDE:
if (!HandleIncludeSymbols(info, (IncludeStmt *) stmt)) ok = HandleIncludeSymbols(info, (IncludeStmt *) stmt);
info->errorCount++;
break; break;
case STMT_SYMBOLS: case STMT_SYMBOLS:
if (!HandleSymbolsDef(info, (SymbolsDef *) stmt)) ok = HandleSymbolsDef(info, (SymbolsDef *) stmt);
info->errorCount++;
break; break;
case STMT_VAR: case STMT_VAR:
if (!HandleSymbolsVar(info, (VarDef *) stmt)) ok = HandleSymbolsVar(info, (VarDef *) stmt);
info->errorCount++;
break; break;
case STMT_VMOD: case STMT_VMOD:
if (!HandleVModDef((VModDef *) stmt, info->keymap, merge, ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods)) &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++;
break; break;
case STMT_MODMAP: case STMT_MODMAP:
if (!HandleModMapDef(info, (ModMapDef *) stmt)) ok = HandleModMapDef(info, (ModMapDef *) stmt);
info->errorCount++;
break; break;
default: default:
log_wsgo(info->keymap->ctx, log_err(info->keymap->ctx,
"Unexpected statement type %d in HandleSymbolsFile\n", "Interpretation files may not include other types; "
stmt->type); "Ignoring %s\n", StmtTypeToString(stmt->type));
ok = false;
break; break;
} }
stmt = stmt->next;
if (!ok)
info->errorCount++;
if (info->errorCount > 10) { if (info->errorCount > 10) {
log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n", log_err(info->keymap->ctx, "Abandoning symbols file \"%s\"\n",
file->topName); file->topName);

View File

@ -49,6 +49,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap);
xkb_mod_mask_t xkb_mod_mask_t
VModsToReal(struct xkb_keymap *keymap, xkb_mod_mask_t vmodmask); VModsToReal(struct xkb_keymap *keymap, xkb_mod_mask_t vmodmask);
const char *
StmtTypeToString(enum stmt_type type);
static inline unsigned long static inline unsigned long
KeyNameToLong(const char *name) KeyNameToLong(const char *name)
{ {

View File

@ -44,6 +44,7 @@ enum stmt_type {
STMT_GROUP_COMPAT, STMT_GROUP_COMPAT,
STMT_INDICATOR_MAP, STMT_INDICATOR_MAP,
STMT_INDICATOR_NAME, STMT_INDICATOR_NAME,
_STMT_NUM_VALUES
}; };
enum expr_value_type { enum expr_value_type {