From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/2710 Path: news.gmane.org!not-for-mail From: Isaac Dunham Newsgroups: gmane.linux.lib.musl.general Subject: strverscmp Date: Fri, 1 Feb 2013 20:04:52 -0800 Message-ID: <20130201200452.26687bed.idunham@lavabit.com> References: <20130201071053.GA14593@brightrain.aerifal.cx> <20130201182340.c60061b6.idunham@lavabit.com> <20130202023833.GW20323@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Multipart=_Fri__1_Feb_2013_20_04_52_-0800_wJtAMHfdPDwjg=0b" X-Trace: ger.gmane.org 1359777906 29648 80.91.229.3 (2 Feb 2013 04:05:06 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 2 Feb 2013 04:05:06 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-2711-gllmg-musl=m.gmane.org@lists.openwall.com Sat Feb 02 05:05:26 2013 Return-path: Envelope-to: gllmg-musl@plane.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1U1UM0-000395-JJ for gllmg-musl@plane.gmane.org; Sat, 02 Feb 2013 05:05:24 +0100 Original-Received: (qmail 1521 invoked by uid 550); 2 Feb 2013 04:05:06 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 1513 invoked from network); 2 Feb 2013 04:05:05 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=lavabit; d=lavabit.com; b=wLs0vA253iKqsMliKQS8m8F0YRiHeBC2mQSHwSkZZS0CCVehmrqb2+jfRknkD2JFNwOJ+BpmYWXb/Oz2A9EvedP1brxAR278wgqNKXmqmM7+oGWKT+FCKefRPQb9DAFrb/qVwpWF0E/yKp4nMWKcVWmKP/YBnSax1IsUwVUQ8pk=; h=Date:From:To:Subject:Message-Id:In-Reply-To:References:X-Mailer:Mime-Version:Content-Type; In-Reply-To: <20130202023833.GW20323@brightrain.aerifal.cx> X-Mailer: Sylpheed 3.0.2 (GTK+ 2.20.1; i486-pc-linux-gnu) Xref: news.gmane.org gmane.linux.lib.musl.general:2710 Archived-At: This is a multi-part message in MIME format. --Multipart=_Fri__1_Feb_2013_20_04_52_-0800_wJtAMHfdPDwjg=0b Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 1 Feb 2013 21:38:33 -0500 Rich Felker wrote: > > Fix strverscmp (patch same as the last time I sent it) > > I'm not sure whether we got it into a fully-working state or not; the > conversation kinda died out last time. I'll review it again too. I > remember it didn't look quite like the algorithm I described/proposed, > but that doesn't mean it's wrong. It looked like it could at least use > some streamlining though. The last review was just before I got it working. Here's the final version. Probably somewhere it could be optimized, though... As long as it doesn't end up looking like the GNU one. -- Isaac Dunham --Multipart=_Fri__1_Feb_2013_20_04_52_-0800_wJtAMHfdPDwjg=0b Content-Type: text/x-diff; name="strverscmp.diff" Content-Disposition: attachment; filename="strverscmp.diff" Content-Transfer-Encoding: 7bit diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c index 7054967..8f3f11f 100644 --- a/src/string/strverscmp.c +++ b/src/string/strverscmp.c @@ -1,7 +1,41 @@ +#define _GNU_SOURCE +#include #include int strverscmp(const char *l, const char *r) { - /* FIXME */ - return strcmp(l, r); + int haszero=1; + while (*l && *r && l[0]==r[0]){ + if (l[0]=='0'){ + if (haszero==1) { + haszero=0; + } + } else if (isdigit(l[0])) { + if (haszero==1) { + haszero=2; + } + } else { + haszero=1; + } + l++; r++; + } + if (haszero==1 && (l[0]=='0' || r[0]=='0')) { + haszero=0; + } + if ((isdigit(l[0]) && isdigit(r[0]) ) && haszero) { + int lenl=0, lenr=0, firstl=l[0], firstr=r[0]; + while (isdigit(l++[0]) ) { + lenl++; + } + while (isdigit(r++[0]) ) { + lenr++; + } + if (lenl==lenr) { + return (firstl - firstr); + } else { + return (lenl - lenr); + } + } else { + return (l[0] - r[0]); + } } --Multipart=_Fri__1_Feb_2013_20_04_52_-0800_wJtAMHfdPDwjg=0b--