bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: filevercmp: please post final filevercmp


From: Jim Meyering
Subject: Re: filevercmp: please post final filevercmp
Date: Fri, 03 Oct 2008 11:55:40 +0200

Kamil Dudka <address@hidden> wrote:
> On Friday 03 October 2008 08:18:32 you wrote:
>> I suppose you've seen Bruno's reply.
>> So would you please make the copyright change he proposed,
>> add the paragraph suggested by Ian, and post a final version?
> Final version of patch is attached.
>
> Summary:
> - add copyrights (from Bruno's reply)
> - add verrevcmp function description (as Ian suggested)
> - use c_isdigit from c_ctype.h

Thank you.
Please review these small changes that I expect to fold into your change set:
  - use c_isdigit, c_isalpha, c_isalnum directly; no need for casts
  - reword match_suffix comment
  - reword module description
  - s/0/NULL/ in test-filevercmp.c

>From 44266b31e530ce198638700d401d9c589aa332a3 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Fri, 3 Oct 2008 11:51:55 +0200
Subject: [PATCH] tweaks

---
 lib/filevercmp.c        |   32 +++++++++++++-------------------
 modules/filevercmp      |    2 +-
 tests/test-filevercmp.c |    3 +--
 3 files changed, 15 insertions(+), 22 deletions(-)

diff --git a/lib/filevercmp.c b/lib/filevercmp.c
index a73c618..36ae95d 100644
--- a/lib/filevercmp.c
+++ b/lib/filevercmp.c
@@ -26,16 +26,10 @@
 #include <c-ctype.h>
 #include <limits.h>

-#define ISDIGIT(c) c_isdigit ((unsigned char) (c))
-#define ISALPHA(c) c_isalpha ((unsigned char) (c))
-#define ISALNUM(c) c_isalnum ((unsigned char) (c))
-
-/*
-   match file suffix defined as RE (\.[A-Za-z][A-Za-z0-9]*)*$
-
-   Scan string pointed by *str and return pointer to suffix begin or NULL if
-   not found. Pointer *str points to ending zero of scanned string after
-   return. */
+/* Match a file suffix defined by this regular expression:
+   /(\.[A-Za-z][A-Za-z0-9]*)*$/
+   Scan the string *STR and return a pointer to the matching suffix, or
+   NULL if not found.  Upon return, *STR points to terminating NUL.  */
 static const char *
 match_suffix (const char **str)
 {
@@ -46,7 +40,7 @@ match_suffix (const char **str)
       if (read_alpha)
         {
           read_alpha = false;
-          if (!ISALPHA (**str))
+          if (!c_isalpha (**str))
             match = NULL;
         }
       else if ('.'  == **str)
@@ -55,7 +49,7 @@ match_suffix (const char **str)
           if (!match)
             match = *str;
         }
-      else if (!ISALNUM (**str))
+      else if (!c_isalnum (**str))
         match = NULL;
       (*str)++;
     }
@@ -66,9 +60,9 @@ match_suffix (const char **str)
 static inline int
 order (unsigned char c)
 {
-  if (ISDIGIT (c))
+  if (c_isdigit (c))
     return 0;
-  else if (ISALPHA (c))
+  else if (c_isalpha (c))
     return c;
   else if (c == '~')
     return -1;
@@ -94,8 +88,8 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, 
size_t s2_len)
   while (s1_pos < s1_len || s2_pos < s2_len)
     {
       int first_diff = 0;
-      while ((s1_pos < s1_len && !ISDIGIT (s1[s1_pos])) || (s2_pos < s2_len
-           && !ISDIGIT (s2[s2_pos])))
+      while ((s1_pos < s1_len && !c_isdigit (s1[s1_pos])) || (s2_pos < s2_len
+           && !c_isdigit (s2[s2_pos])))
        {
          int s1_c = (s1_pos == s1_len) ? 0 : order (s1[s1_pos]);
          int s2_c = (s2_pos == s2_len) ? 0 : order (s2[s2_pos]);
@@ -108,16 +102,16 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, 
size_t s2_len)
        s1_pos++;
       while (s2[s2_pos] == '0')
        s2_pos++;
-      while (ISDIGIT (s1[s1_pos]) && ISDIGIT (s2[s2_pos]))
+      while (c_isdigit (s1[s1_pos]) && c_isdigit (s2[s2_pos]))
        {
          if (!first_diff)
            first_diff = s1[s1_pos] - s2[s2_pos];
          s1_pos++;
          s2_pos++;
        }
-      if (ISDIGIT (s1[s1_pos]))
+      if (c_isdigit (s1[s1_pos]))
        return 1;
-      if (ISDIGIT (s2[s2_pos]))
+      if (c_isdigit (s2[s2_pos]))
        return -1;
       if (first_diff)
        return first_diff;
diff --git a/modules/filevercmp b/modules/filevercmp
index db71442..12b0520 100644
--- a/modules/filevercmp
+++ b/modules/filevercmp
@@ -1,5 +1,5 @@
 Description:
-function comparing version strings (and file names with version)
+compare version strings and version-containing file names

 Files:
 lib/filevercmp.h
diff --git a/tests/test-filevercmp.c b/tests/test-filevercmp.c
index af5ca4a..4efd108 100644
--- a/tests/test-filevercmp.c
+++ b/tests/test-filevercmp.c
@@ -56,7 +56,7 @@ static const char *const examples[] =
   "nss_ldap-1.0-0.1a.tar.gz",
   "nss_ldap-10beta1.fc8.tar.gz",
   "nss_ldap-10.11.8.6.20040204cvs.fc10.ebuild",
-  0
+  NULL
 };

 int
@@ -93,4 +93,3 @@ main (int argc, char **argv)

   return 0;
 }
-
--
1.6.0.2.307.gc427




reply via email to

[Prev in Thread] Current Thread [Next in Thread]