From owner-freebsd-hackers@FreeBSD.ORG Wed Feb 15 16:05:26 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 7C5EE16A420 for ; Wed, 15 Feb 2006 16:05:26 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id C4E8C43D49 for ; Wed, 15 Feb 2006 16:05:25 +0000 (GMT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.3) id k1FG5OGw044343; Wed, 15 Feb 2006 10:05:24 -0600 (CST) (envelope-from dan) Date: Wed, 15 Feb 2006 10:05:24 -0600 From: Dan Nelson To: Peter Jeremy , hackers@freebsd.org Message-ID: <20060215160524.GA70956@dan.emsphone.com> References: <20060214212503.GE1107@galgenberg.net> <20060215080532.GB684@turion.vk2pj.dyndns.org> <20060215150237.GA1123@galgenberg.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20060215150237.GA1123@galgenberg.net> X-OS: FreeBSD 5.4-STABLE X-message-flag: Outlook Error 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 16:05:26 -0000 In the last episode (Feb 15), Ulrich Spoerlein said: > Peter Jeremy wrote: > >>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. > > This would require patching the gqview configure script, but I can live > with that. > > >For the first point, consider > > strverscmp("jan25", "janx25"); > > This fell victim to a rearranging of the while loop. Thanks for > pointing that out! > > Attached is an updated version, which now also takes leading zeros > into account. It still differs from the GNU version, because > strverscmp("foo.009", "foo.0") > 0 In my book, '009' is just greater > than zero, no matter what. If someone could explain to me, why the > GNU folks do it the other way round, I could try implementing that > too. This looks a lot like strnatcmp, which is "natural sort" or "do what I mean" sort :) http://sourcefrog.net/projects/natsort/ Your function is simpler than the C implementation on that site, but falls over when a run of numbers exceeds 2^31 (raise it to 2^64 if you use strtoull, but that's as high as you can yet). -- Dan Nelson dnelson@allantgroup.com