[Pkg-gnupg-commit] [gnupg2] 60/118: common: Add string operator gt, ge, le, lt to recsel.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Thu Sep 15 18:25:09 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch encoding-and-speling
in repository gnupg2.

commit 959cd8903fd012e63dbb156db56708dd3934b5df
Author: Werner Koch <wk at gnupg.org>
Date:   Mon Sep 5 09:49:06 2016 +0200

    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 at gnupg.org>
---
 common/recsel.c   | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 common/t-recsel.c | 33 ++++++++++++++++++++++++++++++++
 doc/gpg.texi      | 14 +++++++++++++-
 3 files changed, 101 insertions(+), 3 deletions(-)

diff --git a/common/recsel.c b/common/recsel.c
index 5dc685f..866861b 100644
--- a/common/recsel.c
+++ b/common/recsel.c
@@ -48,7 +48,11 @@ typedef enum
     SELECT_LE,
     SELECT_GE,
     SELECT_LT,
-    SELECT_GT
+    SELECT_GT,
+    SELECT_STRLE, /* String is less or equal.  */
+    SELECT_STRGE,
+    SELECT_STRLT,
+    SELECT_STRGT
   } select_op_t;
 
 
@@ -347,6 +351,26 @@ recsel_parse_expr (recsel_expr_t *selector, const char *expression)
       se->op = SELECT_ISTRUE;
       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
     {
       log_error ("invalid operator in expression\n");
@@ -467,7 +491,12 @@ recsel_dump (recsel_expr_t selector)
                  se->op == SELECT_LT?      "< ":
                  se->op == SELECT_LE?      "<=":
                  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);
     }
   log_debug ("--- End selectors ---\n");
@@ -541,6 +570,30 @@ recsel_select (recsel_expr_t selector,
             case SELECT_LE:
               result = (numvalue <= se->numvalue);
               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;
             }
         }
 
diff --git a/common/t-recsel.c b/common/t-recsel.c
index fe2a7b9..faddc97 100644
--- a/common/t-recsel.c
+++ b/common/t-recsel.c
@@ -171,6 +171,8 @@ test_2_getval (void *cookie, const char *name)
     return "    ";
   else if (!strcmp (name, "letters"))
     return "abcde";
+  else if (!strcmp (name, "str1"))
+    return "aaa";
   else
     return cookie;
 }
@@ -264,6 +266,37 @@ run_test_2 (void)
 
 
   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();
   ADDEXPR ("uid -n");
   if (!recsel_select (se, test_2_getval, NULL))
     fail (0, 0);
diff --git a/doc/gpg.texi b/doc/gpg.texi
index 68b21b6..901d1ee 100644
--- a/doc/gpg.texi
+++ b/doc/gpg.texi
@@ -3500,12 +3500,24 @@ The supported operators (@var{op}) are:
   @item  <
   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.
 
   @item  >=
   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
   True if value is not empty (no value allowed).
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git



More information about the Pkg-gnupg-commit mailing list