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
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++;
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;
default:
log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleCompatMapFile\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 compatibility map \"%s\"\n", file->topName);

View File

@ -748,51 +748,41 @@ static void
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++;
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++;
ok = HandleIndicatorNameDef(info, (IndicatorNameDef *) stmt,
merge);
break;
default:
log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleKeycodesFile\n",
stmt->type);
log_err(info->keymap->ctx,
"Keycode files may define key and indicator names only; "
"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);

View File

@ -879,56 +879,38 @@ HandleKeyTypeDef(KeyTypesInfo *info, KeyTypeDef *def, enum merge_mode merge)
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++;
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++;
ok = HandleVModDef((VModDef *) stmt, info->keymap, merge,
&info->vmods);
break;
default:
log_wsgo(info->keymap->ctx,
"Unexpected statement type %d in HandleKeyTypesFile\n",
stmt->type);
log_err(info->keymap->ctx,
"Key type files may not include other declarations; "
"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);

View File

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

View File

@ -49,6 +49,9 @@ UpdateModifiersFromCompat(struct xkb_keymap *keymap);
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)
{

View File

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