mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-12 22:11:29 +02:00
common: Add string operator gt,ge,le,lt to recsel.
* common/recsel.c (recsel_parse_expr): Add them. (recsel_dump): Print them. (recsel_select): Evaluate them. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
c8e0d37f41
commit
959cd8903f
@ -48,7 +48,11 @@ typedef enum
|
|||||||
SELECT_LE,
|
SELECT_LE,
|
||||||
SELECT_GE,
|
SELECT_GE,
|
||||||
SELECT_LT,
|
SELECT_LT,
|
||||||
SELECT_GT
|
SELECT_GT,
|
||||||
|
SELECT_STRLE, /* String is less or equal. */
|
||||||
|
SELECT_STRGE,
|
||||||
|
SELECT_STRLT,
|
||||||
|
SELECT_STRGT
|
||||||
} select_op_t;
|
} select_op_t;
|
||||||
|
|
||||||
|
|
||||||
@ -347,6 +351,26 @@ recsel_parse_expr (recsel_expr_t *selector, const char *expression)
|
|||||||
se->op = SELECT_ISTRUE;
|
se->op = SELECT_ISTRUE;
|
||||||
s += 2;
|
s += 2;
|
||||||
}
|
}
|
||||||
|
else if (!strncmp (s, "-le", 3))
|
||||||
|
{
|
||||||
|
se->op = SELECT_STRLE;
|
||||||
|
s += 3;
|
||||||
|
}
|
||||||
|
else if (!strncmp (s, "-ge", 3))
|
||||||
|
{
|
||||||
|
se->op = SELECT_STRGE;
|
||||||
|
s += 3;
|
||||||
|
}
|
||||||
|
else if (!strncmp (s, "-lt", 3))
|
||||||
|
{
|
||||||
|
se->op = SELECT_STRLT;
|
||||||
|
s += 3;
|
||||||
|
}
|
||||||
|
else if (!strncmp (s, "-gt", 3))
|
||||||
|
{
|
||||||
|
se->op = SELECT_STRGT;
|
||||||
|
s += 3;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_error ("invalid operator in expression\n");
|
log_error ("invalid operator in expression\n");
|
||||||
@ -467,7 +491,12 @@ recsel_dump (recsel_expr_t selector)
|
|||||||
se->op == SELECT_LT? "< ":
|
se->op == SELECT_LT? "< ":
|
||||||
se->op == SELECT_LE? "<=":
|
se->op == SELECT_LE? "<=":
|
||||||
se->op == SELECT_GT? "> ":
|
se->op == SELECT_GT? "> ":
|
||||||
se->op == SELECT_GE? ">=":"[oops]",
|
se->op == SELECT_GE? ">=":
|
||||||
|
se->op == SELECT_STRLT? "-lt":
|
||||||
|
se->op == SELECT_STRLE? "-le":
|
||||||
|
se->op == SELECT_STRGT? "-gt":
|
||||||
|
se->op == SELECT_STRGE? "-ge":
|
||||||
|
/**/ "[oops]",
|
||||||
se->value);
|
se->value);
|
||||||
}
|
}
|
||||||
log_debug ("--- End selectors ---\n");
|
log_debug ("--- End selectors ---\n");
|
||||||
@ -541,6 +570,30 @@ recsel_select (recsel_expr_t selector,
|
|||||||
case SELECT_LE:
|
case SELECT_LE:
|
||||||
result = (numvalue <= se->numvalue);
|
result = (numvalue <= se->numvalue);
|
||||||
break;
|
break;
|
||||||
|
case SELECT_STRGT:
|
||||||
|
if (se->xcase)
|
||||||
|
result = strcmp (value, se->value) > 0;
|
||||||
|
else
|
||||||
|
result = strcasecmp (value, se->value) > 0;
|
||||||
|
break;
|
||||||
|
case SELECT_STRGE:
|
||||||
|
if (se->xcase)
|
||||||
|
result = strcmp (value, se->value) >= 0;
|
||||||
|
else
|
||||||
|
result = strcasecmp (value, se->value) >= 0;
|
||||||
|
break;
|
||||||
|
case SELECT_STRLT:
|
||||||
|
if (se->xcase)
|
||||||
|
result = strcmp (value, se->value) < 0;
|
||||||
|
else
|
||||||
|
result = strcasecmp (value, se->value) < 0;
|
||||||
|
break;
|
||||||
|
case SELECT_STRLE:
|
||||||
|
if (se->xcase)
|
||||||
|
result = strcmp (value, se->value) <= 0;
|
||||||
|
else
|
||||||
|
result = strcasecmp (value, se->value) <= 0;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,6 +171,8 @@ test_2_getval (void *cookie, const char *name)
|
|||||||
return " ";
|
return " ";
|
||||||
else if (!strcmp (name, "letters"))
|
else if (!strcmp (name, "letters"))
|
||||||
return "abcde";
|
return "abcde";
|
||||||
|
else if (!strcmp (name, "str1"))
|
||||||
|
return "aaa";
|
||||||
else
|
else
|
||||||
return cookie;
|
return cookie;
|
||||||
}
|
}
|
||||||
@ -263,6 +265,37 @@ run_test_2 (void)
|
|||||||
fail (0, 0);
|
fail (0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("str1 -gt aa");
|
||||||
|
if (!recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("str1 -gt aaa");
|
||||||
|
if (recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("str1 -ge aaa");
|
||||||
|
if (!recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("str1 -lt aab");
|
||||||
|
if (!recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("str1 -le aaa");
|
||||||
|
if (!recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("-c str1 -lt AAB");
|
||||||
|
if (recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
FREEEXPR();
|
||||||
|
ADDEXPR ("str1 -lt AAB");
|
||||||
|
if (!recsel_select (se, test_2_getval, NULL))
|
||||||
|
fail (0, 0);
|
||||||
|
|
||||||
|
|
||||||
FREEEXPR();
|
FREEEXPR();
|
||||||
ADDEXPR ("uid -n");
|
ADDEXPR ("uid -n");
|
||||||
if (!recsel_select (se, test_2_getval, NULL))
|
if (!recsel_select (se, test_2_getval, NULL))
|
||||||
|
14
doc/gpg.texi
14
doc/gpg.texi
@ -3500,12 +3500,24 @@ The supported operators (@var{op}) are:
|
|||||||
@item <
|
@item <
|
||||||
The numerical value of the field must be LT than the value.
|
The numerical value of the field must be LT than the value.
|
||||||
|
|
||||||
@item >=
|
@item >
|
||||||
The numerical value of the field must be GT than the value.
|
The numerical value of the field must be GT than the value.
|
||||||
|
|
||||||
@item >=
|
@item >=
|
||||||
The numerical value of the field must be GE than the value.
|
The numerical value of the field must be GE than the value.
|
||||||
|
|
||||||
|
@item -le
|
||||||
|
The string value of the field must be less or equal than the value.
|
||||||
|
|
||||||
|
@item -lt
|
||||||
|
The string value of the field must be less than the value.
|
||||||
|
|
||||||
|
@item -gt
|
||||||
|
The string value of the field must be greater than the value.
|
||||||
|
|
||||||
|
@item -ge
|
||||||
|
The string value of the field must be greater or equal than the value.
|
||||||
|
|
||||||
@item -n
|
@item -n
|
||||||
True if value is not empty (no value allowed).
|
True if value is not empty (no value allowed).
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user