On Tue, 2006-Feb-14 22:25:03 +0100, Ulrich Spoerlein wrote:
>this is probably not the right list, but I'd like to collect reviews of 
>a strverscmp(3) function I wrote. It is used by the graphics/gqview port 
...
>Is there a chance this might get included into libc? Or is it considered 
>bloat?

I don't think it belongs in libc.  Maybe libutil.

>The GNU version can be found here
>http://refspecs.freestandards.org/LSB_2.0.1/LSB-generic/LSB-generic/baselib-strverscmp.html

>Quite frankly, I don't understand their integral/fraction distinction, 

I don't think their description makes sense - it's not clear what the
point is or where it would be used.  If '.' was also a magic character
then (IMHO) it would make more sense.

>int
>strverscmp(const char *s1, const char *s2)
>{
>  static const char *digits = "0123456789";
>  int ret;
>  long n1, n2;
>  size_t p1, p2;
>
>  do {
>    p1 = strcspn(s1, digits);
>    p2 = strcspn(s2, digits);
>
+    if (p1 != p2) break;
+  
>    /* Different prefix */
>    if ((ret = strncmp(s1, s2, p1)) != 0)
>      return ret;
...
>    /* Numbers are equal or not present, try with next ones. */
>    p1 = strspn(s1, digits);
>    p2 = strspn(s2, digits);

You can avoid these strspn() calls [which are not cheap] by saving the
endptr values from the strtol() calls above.

>    s1 += p1;
>    s2 += p2;
-  } while (p1 == p2 && p1 != 0 && p1 != 0);
+  } while (p1 == p2 && p1 != 0);

For the first point, consider
   strverscmp("jan25", "janx25");

-- 
Peter Jeremy

Attachment: pgpNufHyYuuur.pgp
Description: PGP signature

Reply via email to