- int ok = 0;
- ExprResult leftRtrn, rightRtrn;
- ExprDef *left;
- ExprDef *right;
- char *bogus = NULL;
-
- switch (expr->op)
- {
- case ExprValue:
- if (expr->type != TypeString)
- {
- ERROR1("Found constant of type %s, expected a string\n",
- exprTypeText(expr->type));
- return False;
- }
- val_rtrn->str = XkbAtomGetString(NULL, expr->value.str);
- if (val_rtrn->str == NULL)
- {
- static char *empty = "";
- val_rtrn->str = empty;
- }
- return True;
- case ExprIdent:
- if (lookup)
- {
- ok = (*lookup) (lookupPriv,
- None, expr->value.str, TypeString, val_rtrn);
- }
- if (!ok)
- ERROR1("Identifier \"%s\" of type string not found\n",
- XkbAtomText(NULL, expr->value.str, XkbMessage));
- return ok;
- case ExprFieldRef:
- if (lookup)
- {
- ok = (*lookup) (lookupPriv,
- expr->value.field.element,
- expr->value.field.field, TypeString, val_rtrn);
- }
- if (!ok)
- ERROR2("Default \"%s.%s\" of type string not found\n",
- XkbAtomText(NULL, expr->value.field.element, XkbMessage),
- XkbAtomText(NULL, expr->value.field.field, XkbMessage));
- return ok;
- case OpAdd:
- left = expr->value.binary.left;
- right = expr->value.binary.right;
- if (ExprResolveString(left, &leftRtrn, lookup, lookupPriv) &&
- ExprResolveString(right, &rightRtrn, lookup, lookupPriv))
- {
- int len;
- char *new;
- len = strlen(leftRtrn.str) + strlen(rightRtrn.str) + 1;
- new = (char *) uAlloc(len);
- if (new)
- {
- sprintf(new, "%s%s", leftRtrn.str, rightRtrn.str);
- val_rtrn->str = new;
- return True;
- }
- }
- return False;
- case OpSubtract:
- if (bogus == NULL)
- bogus = "Subtraction";
- case OpMultiply:
- if (bogus == NULL)
- bogus = "Multiplication";
- case OpDivide:
- if (bogus == NULL)
- bogus = "Division";
- case OpAssign:
- if (bogus == NULL)
- bogus = "Assignment";
- case OpNegate:
- if (bogus == NULL)
- bogus = "Negation";
- case OpInvert:
- if (bogus == NULL)
- bogus = "Bitwise complement";
- ERROR1("%s of string values not permitted\n", bogus);
- return False;
- case OpNot:
- left = expr->value.child;
- if (ExprResolveString(left, &leftRtrn, lookup, lookupPriv))
- {
- ERROR("The ! operator cannot be applied to a string\n");
- }
- return False;
- case OpUnaryPlus:
- left = expr->value.child;
- if (ExprResolveString(left, &leftRtrn, lookup, lookupPriv))
- {
- ERROR("The + operator cannot be applied to a string\n");
- }
- return False;
- default:
- WSGO1("Unknown operator %d in ResolveString\n", expr->op);
- break;
+ return ExprResolveIntegerLookup(ctx, expr, val_rtrn, NULL, NULL);
+}
+
+bool
+ExprResolveGroup(struct xkb_context *ctx, const ExprDef *expr,
+ xkb_layout_index_t *group_rtrn)
+{
+ bool ok;
+ int result;
+
+ ok = ExprResolveIntegerLookup(ctx, expr, &result, SimpleLookup,
+ groupNames);
+ if (!ok)
+ return false;
+
+ if (result <= 0 || result > XKB_MAX_GROUPS) {
+ log_err_with_code(ctx, XKB_ERROR_UNSUPPORTED_GROUP_INDEX,
+ "Group index %u is out of range (1..%d)\n",
+ result, XKB_MAX_GROUPS);
+ return false;