From owner-p4-projects@FreeBSD.ORG Sun Sep 20 11:02:54 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 346D11065670; Sun, 20 Sep 2009 11:02:54 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id ED3AE106566B for ; Sun, 20 Sep 2009 11:02:53 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id C25268FC15 for ; Sun, 20 Sep 2009 11:02:53 +0000 (UTC) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n8KB2rfL039659 for ; Sun, 20 Sep 2009 11:02:53 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n8KB2rIF039657 for perforce@freebsd.org; Sun, 20 Sep 2009 11:02:53 GMT (envelope-from gabor@freebsd.org) Date: Sun, 20 Sep 2009 11:02:53 GMT Message-Id: <200909201102.n8KB2rIF039657@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 168701 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 Sep 2009 11:02:54 -0000 http://perforce.freebsd.org/chv.cgi?CH=168701 Change 168701 by gabor@gabor_server on 2009/09/20 11:02:44 - Try to make -f more GNU compatible Affected files ... .. //depot/projects/soc2008/gabor_textproc/newsort/coll.c#5 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/newsort/coll.c#5 (text+ko) ==== @@ -34,6 +34,8 @@ #include "sort.h" +#define MAX(a, b) (((#a) > (#b)) ? (#a) : (#b)) + static wchar_t **months; static inline int _wcscoll(const wchar_t *, const wchar_t *); @@ -168,6 +170,9 @@ return (_wcscoll(s1, s2)); } +/* + * Inline wrapper for wcscoll() and wcscasecoll(). + */ static inline int _wcscoll(const wchar_t *s1, const wchar_t *s2) { @@ -175,27 +180,52 @@ } /* + * Collating single wide characters in a non case-sensitive way. + */ +static int +wccasecoll(const wint_t c1, const wint_t c2) { + + if (iswpunct(c1) && !iswpunct(c2)) + return (-1); + else if (!iswpunct(c1) && iswpunct(c2)) + return (1); + + if (iswupper(c1) && !iswupper(c2)) + return (1); + else if (!iswupper(c1) && iswupper(c2)) + return (-1); + else { + wchar_t *s1, *s2; + + s1 = sort_malloc(2 * sizeof(wint_t)); + s2 = sort_malloc(2 * sizeof(wint_t)); + + s1[0] = towlower(c1); + s1[1] = L'\0'; + + s2[0] = towlower(c2); + s2[1] = L'\0'; + + return (wcscoll(s1, s2)); + } +} + +/* * A case insensitive version of wcscoll(). */ static int wcscasecoll(const wchar_t *s1, const wchar_t *s2) { - int len1, len2, i; - wchar_t *ss1, *ss2; + int len1, len2, len; len1 = wcslen(s1); len2 = wcslen(s2); + len = MAX(len1, len2); - ss1 = sort_malloc(sizeof(wint_t) * (len1 + 1)); - ss2 = sort_malloc(sizeof(wint_t) * (len2 + 1)); + for (int i = 0; i < len; i++) + if (wccasecoll(s1[i], s2[i]) != 0) + return (wccasecoll(s1[i], s2[i])); - for (i = 0; i < len1; i++) - ss1[i]= towlower(s1[i]); - ss1[i + 1] = L'\0'; - for (i = 0; i < len2; i++) - ss2[i]= towlower(s2[i]); - ss2[i + 1] = L'\0'; - - return (wcscoll(ss1, ss2)); + return (len1 > len2 ? -1 : (len2 > len1 ? 1 : 0)); } #define NUMCHECK_COMMON(a, b) \