Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 15 Feb 2006 19:05:32 +1100
From:      Peter Jeremy <peterjeremy@optushome.com.au>
To:        hackers@freebsd.org
Subject:   Re: Naive implementation of strverscmp(3)
Message-ID:  <20060215080532.GB684@turion.vk2pj.dyndns.org>
In-Reply-To: <20060214212503.GE1107@galgenberg.net>
References:  <20060214212503.GE1107@galgenberg.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--HcAYCG3uE/tztfnV
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

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=20
>a strverscmp(3) function I wrote. It is used by the graphics/gqview port=
=20
=2E..
>Is there a chance this might get included into libc? Or is it considered=
=20
>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/baseli=
b-strverscmp.html

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

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 =3D "0123456789";
>  int ret;
>  long n1, n2;
>  size_t p1, p2;
>
>  do {
>    p1 =3D strcspn(s1, digits);
>    p2 =3D strcspn(s2, digits);
>
+    if (p1 !=3D p2) break;
+ =20
>    /* Different prefix */
>    if ((ret =3D strncmp(s1, s2, p1)) !=3D 0)
>      return ret;
=2E..
>    /* Numbers are equal or not present, try with next ones. */
>    p1 =3D strspn(s1, digits);
>    p2 =3D strspn(s2, digits);

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

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

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

--=20
Peter Jeremy

--HcAYCG3uE/tztfnV
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (FreeBSD)

iD8DBQFD8uDK/opHv/APuIcRAhugAJ4ibgn65igh77GBpMI1IVeYci6p1wCeLEXp
+iAYRxDwLLK1thDEgoCHbco=
=bgEQ
-----END PGP SIGNATURE-----

--HcAYCG3uE/tztfnV--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20060215080532.GB684>