From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 15 08:05:35 2006 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9262D16A420 for ; Wed, 15 Feb 2006 08:05:35 +0000 (GMT) (envelope-from peterjeremy@optushome.com.au) Received: from mail10.syd.optusnet.com.au (mail10.syd.optusnet.com.au [211.29.132.191]) by mx1.FreeBSD.org (Postfix) with ESMTP id DB72343D45 for ; Wed, 15 Feb 2006 08:05:34 +0000 (GMT) (envelope-from peterjeremy@optushome.com.au) Received: from turion.vk2pj.dyndns.org (c220-239-19-236.belrs4.nsw.optusnet.com.au [220.239.19.236]) by mail10.syd.optusnet.com.au (8.12.11/8.12.11) with ESMTP id k1F85XPM016433 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Wed, 15 Feb 2006 19:05:33 +1100 Received: from turion.vk2pj.dyndns.org (localhost.vk2pj.dyndns.org [127.0.0.1]) by turion.vk2pj.dyndns.org (8.13.4/8.13.4) with ESMTP id k1F85WcO001150 for ; Wed, 15 Feb 2006 19:05:32 +1100 (EST) (envelope-from peter@turion.vk2pj.dyndns.org) Received: (from peter@localhost) by turion.vk2pj.dyndns.org (8.13.4/8.13.4/Submit) id k1F85WWG001149 for hackers@freebsd.org; Wed, 15 Feb 2006 19:05:32 +1100 (EST) (envelope-from peter) Date: Wed, 15 Feb 2006 19:05:32 +1100 From: Peter Jeremy To: hackers@freebsd.org Message-ID: <20060215080532.GB684@turion.vk2pj.dyndns.org> References: <20060214212503.GE1107@galgenberg.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="HcAYCG3uE/tztfnV" Content-Disposition: inline In-Reply-To: <20060214212503.GE1107@galgenberg.net> X-PGP-Key: http://members.optusnet.com.au/peterjeremy/pubkey.asc User-Agent: Mutt/1.5.11 Cc: Subject: Re: Naive implementation of strverscmp(3) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Feb 2006 08:05:35 -0000 --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--