diff options
author | Daniel Stone <daniel@fooishbar.org> | 2012-02-20 16:24:02 +0000 |
---|---|---|
committer | Daniel Stone <daniel@fooishbar.org> | 2012-02-20 16:24:02 +0000 |
commit | 91b8985297473eff51a4915fd47bf5d70299984f (patch) | |
tree | 3db4a85490cd3cb5156328cd19190e3815b1daf8 /src | |
parent | d32822e60f63bd69871458380116de248cba23c7 (diff) | |
download | libxkbcommon-91b8985297473eff51a4915fd47bf5d70299984f.tar.gz libxkbcommon-91b8985297473eff51a4915fd47bf5d70299984f.tar.bz2 libxkbcommon-91b8985297473eff51a4915fd47bf5d70299984f.zip |
Turn ExprResolveInteger into a simple wrapper
Move the bulk of ExprResolveInteger into an internal function called
ExprResolveIntegerLookup, and introduce ExprResolveInteger as a simple
wrapper which doesn't take priv/lookup arguments.
Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/xkbcomp/action.c | 18 | ||||
-rw-r--r-- | src/xkbcomp/expr.c | 65 | ||||
-rw-r--r-- | src/xkbcomp/expr.h | 4 | ||||
-rw-r--r-- | src/xkbcomp/geometry.c | 4 | ||||
-rw-r--r-- | src/xkbcomp/indicators.c | 2 | ||||
-rw-r--r-- | src/xkbcomp/symbols.c | 2 | ||||
-rw-r--r-- | src/xkbcomp/vmod.c | 2 |
7 files changed, 57 insertions, 40 deletions
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c index 8a1b422..0297907 100644 --- a/src/xkbcomp/action.c +++ b/src/xkbcomp/action.c @@ -588,7 +588,7 @@ HandleMovePtr(struct xkb_desc * xkb, absolute = False; else absolute = True; - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportMismatch(action->type, field, "integer"); if (field == F_X) { @@ -828,7 +828,7 @@ HandleSwitchScreen(struct xkb_desc * xkb, scrn = value; } - if (!ExprResolveInteger(scrn, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(scrn, &rtrn)) return ReportMismatch(action->type, field, "integer (0..255)"); if ((rtrn.ival < 0) || (rtrn.ival > 255)) { @@ -977,7 +977,7 @@ HandleActionMessage(struct xkb_desc * xkb, else { unsigned ndx; - if (!ExprResolveInteger(array_ndx, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(array_ndx, &rtrn)) { ERROR("Array subscript must be integer\n"); ACTION("Illegal subscript ignored\n"); @@ -990,7 +990,7 @@ HandleActionMessage(struct xkb_desc * xkb, ACTION("Attempt to use data[%d] ignored\n", ndx); return False; } - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportMismatch(action->type, field, "integer"); if ((rtrn.ival < 0) || (rtrn.ival > 255)) { @@ -1070,7 +1070,7 @@ HandleDeviceBtn(struct xkb_desc * xkb, { if (array_ndx != NULL) return ReportActionNotArray(action->type, field); - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportMismatch(action->type, field, "integer (range 1..255)"); if ((rtrn.ival < 0) || (rtrn.ival > 255)) @@ -1111,7 +1111,7 @@ HandleDeviceBtn(struct xkb_desc * xkb, { if (array_ndx != NULL) return ReportActionNotArray(action->type, field); - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportMismatch(action->type, field, "integer (range 1..255)"); if ((rtrn.ival < 0) || (rtrn.ival > 255)) @@ -1151,7 +1151,7 @@ HandlePrivate(struct xkb_desc * xkb, switch (field) { case F_Type: - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportMismatch(PrivateAction, field, "integer"); if ((rtrn.ival < 0) || (rtrn.ival > 255)) { @@ -1183,7 +1183,7 @@ HandlePrivate(struct xkb_desc * xkb, else { unsigned ndx; - if (!ExprResolveInteger(array_ndx, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(array_ndx, &rtrn)) { ERROR("Array subscript must be integer\n"); ACTION("Illegal subscript ignored\n"); @@ -1196,7 +1196,7 @@ HandlePrivate(struct xkb_desc * xkb, ACTION("Attempt to use data[%d] ignored\n", ndx); return False; } - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportMismatch(action->type, field, "integer"); if ((rtrn.ival < 0) || (rtrn.ival > 255)) { diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c index 39ce3a0..5b33ff8 100644 --- a/src/xkbcomp/expr.c +++ b/src/xkbcomp/expr.c @@ -529,10 +529,26 @@ ExprResolveKeyCode(ExprDef * expr, } return False; } -int -ExprResolveInteger(ExprDef * expr, - ExprResult * val_rtrn, - IdentLookupFunc lookup, char * lookupPriv) + +/** + * This function returns ... something. It's a bit of a guess, really. + * + * If a string is given in value context, its first character will be + * returned in uval. If an integer is given in value context, it will be + * returned in ival. If a float is given in value context, it will be + * returned as millimetres (rather than points) in ival. + * + * If an ident or field reference is given, the lookup function (if given) + * will be called. At the moment, only RadioLookup and SimpleLookup use + * this, and they both return the results in uval. And don't support field + * references. + * + * Cool. + */ +static int +ExprResolveIntegerLookup(ExprDef * expr, + ExprResult * val_rtrn, + IdentLookupFunc lookup, char * lookupPriv) { int ok = 0; ExprResult leftRtrn, rightRtrn; @@ -597,8 +613,8 @@ ExprResolveInteger(ExprDef * expr, case OpDivide: left = expr->value.binary.left; right = expr->value.binary.right; - if (ExprResolveInteger(left, &leftRtrn, lookup, lookupPriv) && - ExprResolveInteger(right, &rightRtrn, lookup, lookupPriv)) + if (ExprResolveIntegerLookup(left, &leftRtrn, lookup, lookupPriv) && + ExprResolveIntegerLookup(right, &rightRtrn, lookup, lookupPriv)) { switch (expr->op) { @@ -622,16 +638,12 @@ ExprResolveInteger(ExprDef * expr, WSGO("Assignment operator not implemented yet\n"); break; case OpNot: - left = expr->value.child; - if (ExprResolveInteger(left, &leftRtrn, lookup, lookupPriv)) - { - ERROR("The ! operator cannot be applied to an integer\n"); - } + ERROR("The ! operator cannot be applied to an integer\n"); return False; case OpInvert: case OpNegate: left = expr->value.child; - if (ExprResolveInteger(left, &leftRtrn, lookup, lookupPriv)) + if (ExprResolveIntegerLookup(left, &leftRtrn, lookup, lookupPriv)) { if (expr->op == OpNegate) val_rtrn->ival = -leftRtrn.ival; @@ -642,7 +654,7 @@ ExprResolveInteger(ExprDef * expr, return False; case OpUnaryPlus: left = expr->value.child; - return ExprResolveInteger(left, val_rtrn, lookup, lookupPriv); + return ExprResolveIntegerLookup(left, val_rtrn, lookup, lookupPriv); default: WSGO("Unknown operator %d in ResolveInteger\n", expr->op); break; @@ -651,10 +663,17 @@ ExprResolveInteger(ExprDef * expr, } int +ExprResolveInteger(ExprDef * expr, + ExprResult * val_rtrn) +{ + return ExprResolveIntegerLookup(expr, val_rtrn, NULL, NULL); +} + +int ExprResolveRadioGroup(ExprDef * expr, ExprResult * val_rtrn) { - return ExprResolveInteger(expr, val_rtrn, RadioLookup, NULL); + return ExprResolveIntegerLookup(expr, val_rtrn, RadioLookup, NULL); } int @@ -673,8 +692,8 @@ ExprResolveGroup(ExprDef * expr, { NULL, 0 } }; - return ExprResolveInteger(expr, val_rtrn, SimpleLookup, - (char *) group_names); + return ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, + (char *) group_names); } int @@ -693,8 +712,8 @@ ExprResolveLevel(ExprDef * expr, { NULL, 0 } }; - return ExprResolveInteger(expr, val_rtrn, SimpleLookup, - (char *) level_names); + return ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, + (char *) level_names); } int @@ -711,8 +730,8 @@ ExprResolveButton(ExprDef * expr, { NULL, 0 } }; - return ExprResolveInteger(expr, val_rtrn, SimpleLookup, - (char *) button_names); + return ExprResolveIntegerLookup(expr, val_rtrn, SimpleLookup, + (char *) button_names); } int @@ -978,7 +997,7 @@ ExprResolveMask(ExprDef * expr, break; case OpInvert: left = expr->value.child; - if (ExprResolveInteger(left, &leftRtrn, lookup, lookupPriv)) + if (ExprResolveIntegerLookup(left, &leftRtrn, lookup, lookupPriv)) { val_rtrn->ival = ~leftRtrn.ival; return True; @@ -988,7 +1007,7 @@ ExprResolveMask(ExprDef * expr, case OpNegate: case OpNot: left = expr->value.child; - if (ExprResolveInteger(left, &leftRtrn, lookup, lookupPriv)) + if (ExprResolveIntegerLookup(left, &leftRtrn, lookup, lookupPriv)) { ERROR("The %s operator cannot be used with a mask\n", (expr->op == OpNegate ? "-" : "!")); @@ -1018,7 +1037,7 @@ ExprResolveKeySym(ExprDef * expr, return True; } } - ok = ExprResolveInteger(expr, val_rtrn, NULL, NULL); + ok = ExprResolveInteger(expr, val_rtrn); if ((ok) && (val_rtrn->uval < 10)) val_rtrn->uval += '0'; return ok; diff --git a/src/xkbcomp/expr.h b/src/xkbcomp/expr.h index cdcfc0b..8a3471c 100644 --- a/src/xkbcomp/expr.h +++ b/src/xkbcomp/expr.h @@ -111,9 +111,7 @@ extern int ExprResolveKeyCode(ExprDef * /* expr */ , ); extern int ExprResolveInteger(ExprDef * /* expr */ , - ExprResult * /* val_rtrn */ , - IdentLookupFunc /* lookup */ , - char * /* lookupPriv */ + ExprResult * /* val_rtrn */ ); extern int ExprResolveRadioGroup(ExprDef * /* expr */ , diff --git a/src/xkbcomp/geometry.c b/src/xkbcomp/geometry.c index 52d9679..41e0ab0 100644 --- a/src/xkbcomp/geometry.c +++ b/src/xkbcomp/geometry.c @@ -1786,7 +1786,7 @@ SetDoodadField(DoodadInfo * di, info->errorCount++; return ReportNotArray("doodad", field, ddText(di)); } - if (!ExprResolveInteger(value, &tmp, NULL, NULL)) + if (!ExprResolveInteger(value, &tmp)) { info->errorCount++; return ReportBadType("doodad", field, ddText(di), "integer"); @@ -1888,7 +1888,7 @@ SetSectionField(SectionInfo * si, info->errorCount++; return ReportNotArray("keyboard section", field, scText(si)); } - if (!ExprResolveInteger(value, &tmp, NULL, NULL)) + if (!ExprResolveInteger(value, &tmp)) { info->errorCount++; ReportBadType("keyboard section", field, scText(si), "integer"); diff --git a/src/xkbcomp/indicators.c b/src/xkbcomp/indicators.c index d49a3bc..4cb7f0d 100644 --- a/src/xkbcomp/indicators.c +++ b/src/xkbcomp/indicators.c @@ -297,7 +297,7 @@ SetIndicatorMapField(LEDInfo * led, { if (arrayNdx != NULL) return ReportIndicatorNotArray(led, field); - if (!ExprResolveInteger(value, &rtrn, NULL, NULL)) + if (!ExprResolveInteger(value, &rtrn)) return ReportIndicatorBadType(led, field, "indicator index"); if ((rtrn.uval < 1) || (rtrn.uval > 32)) diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c index 0b225cc..d2dc4bc 100644 --- a/src/xkbcomp/symbols.c +++ b/src/xkbcomp/symbols.c @@ -1191,7 +1191,7 @@ SetSymbolsField(KeyInfo * key, tmp.uval = 0; } else { - ok = ExprResolveInteger(value, &tmp, NULL, 0); + ok = ExprResolveInteger(value, &tmp); } if (!ok) { diff --git a/src/xkbcomp/vmod.c b/src/xkbcomp/vmod.c index d7f92a5..29ef628 100644 --- a/src/xkbcomp/vmod.c +++ b/src/xkbcomp/vmod.c @@ -247,7 +247,7 @@ ResolveVirtualModifier(ExprDef * def, struct xkb_desc *xkb, } } } - if (ExprResolveInteger(def, val_rtrn, NULL, NULL)) + if (ExprResolveInteger(def, val_rtrn)) { if (val_rtrn->uval < XkbNumVirtualMods) return True; |