filevercmp: Move hidden files up in ordering.
authorKamil Dudka <kdudka@redhat.com>
Thu, 5 Mar 2009 21:56:29 +0000 (22:56 +0100)
committerBruno Haible <bruno@clisp.org>
Thu, 5 Mar 2009 21:56:29 +0000 (22:56 +0100)
ChangeLog
NEWS
lib/filevercmp.c
tests/test-filevercmp.c

index 903ff80bf41e1d75a0d459d5a0c833e64da5e084..795c34fdd42e6c6a5b89f30f92fb84548c39cc5b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-05  Kamil Dudka  <kdudka@redhat.com>
+
+       * lib/filevercmp.c: Move hidden files up in ordering.
+       * tests/test-filevercmp.c: Add tests for hidden files.
+
 2009-03-04  Bruno Haible  <bruno@clisp.org>
 
        * modules/visibility (Makefile.am): Augment AM_CFLAGS.
diff --git a/NEWS b/NEWS
index bf48451f5b213e31952888e39716bcd10601dcf2..17e241feae185aadb5f7839a8849142438755458 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2009-03-05  filevercmp      Move hidden files up in ordering.
+
 2009-01-22  c-strtod        This function no longer calls xalloc_die(). If
             c-strtold       you want to exit the program in case of out-of-
                             memory, the calling function needs to arrange
index 856f30ff0ccc6fa5349079fe083079d8f472eed9..7b40c98f7bff874f50b2b097749efe6447975d02 100644 (file)
@@ -124,8 +124,8 @@ verrevcmp (const char *s1, size_t s1_len, const char *s2, size_t s2_len)
 int
 filevercmp (const char *s1, const char *s2)
 {
-  const char *s1_pos = s1;
-  const char *s2_pos = s2;
+  const char *s1_pos;
+  const char *s2_pos;
   const char *s1_suffix, *s2_suffix;
   size_t s1_len, s2_len;
   int result;
@@ -135,7 +135,18 @@ filevercmp (const char *s1, const char *s2)
   if (simple_cmp == 0)
     return 0;
 
+  /* handle hidden files */
+  while (*s1 == '.' || *s2 == '.')
+    {
+      if (*s1 != *s2)
+       return *s1 - *s2;
+      s1++;
+      s2++;
+    }
+
   /* "cut" file suffixes */
+  s1_pos = s1;
+  s2_pos = s2;
   s1_suffix = match_suffix (&s1_pos);
   s2_suffix = match_suffix (&s2_pos);
   s1_len = (s1_suffix ? s1_suffix : s1_pos) - s1;
index 4efd108eb12f6bb595cb7e087b174103af9762ad..fe54dc2f15771f88476b877362cac55dd1e16107 100644 (file)
 /* set of well sorted examples */
 static const char *const examples[] =
 {
+  ".",
+  "..",
+  ".a~",
+  ".a",
+  ".b~",
+  ".b",
+  "a~",
+  "a",
+  "b~",
+  "b",
   "gcc-c++-10.fc9.tar.gz",
   "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2",
   "glibc-2-0.1.beta1.fc10.rpm",