From owner-p4-projects@FreeBSD.ORG Tue Jul 8 12:15:54 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8D2791065671; Tue, 8 Jul 2008 12:15: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 510E8106566C for ; Tue, 8 Jul 2008 12:15:54 +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 3EA338FC1F for ; Tue, 8 Jul 2008 12:15:54 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m68CFsXG035430 for ; Tue, 8 Jul 2008 12:15:54 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.2/8.14.1/Submit) id m68CFsPR035428 for perforce@freebsd.org; Tue, 8 Jul 2008 12:15:54 GMT (envelope-from gabor@freebsd.org) Date: Tue, 8 Jul 2008 12:15:54 GMT Message-Id: <200807081215.m68CFsPR035428@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 144876 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: Tue, 08 Jul 2008 12:15:54 -0000 http://perforce.freebsd.org/chv.cgi?CH=144876 Change 144876 by gabor@gabor_server on 2008/07/08 12:15:14 - Make -w respect wide characters Affected files ... .. //depot/projects/soc2008/gabor_textproc/grep/util.c#51 edit Differences ... ==== //depot/projects/soc2008/gabor_textproc/grep/util.c#51 (text+ko) ==== @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include "grep.h" @@ -218,7 +220,7 @@ return (c); } -#define isword(x) (isalnum((unsigned char)(x)) || (x) == '_') +#define iswword(x) (iswalnum((x)) || (x) == L'_') static int procline(struct str *l, int nottext) @@ -242,10 +244,37 @@ if (r == 0 && xflag) if (pmatch.rm_so != 0 || pmatch.rm_eo != l->len) r = REG_NOMATCH; - if (r == 0 && wflag) - if ((pmatch.rm_so != 0 && isword((unsigned char)l->dat[pmatch.rm_so - 1])) - || (pmatch.rm_eo != l->len && isword((unsigned char)l->dat[pmatch.rm_eo]))) + if (r == 0 && wflag) { + char *begin, *end; + wchar_t *wbegin, *wend; + size_t size; + + begin = grep_malloc(sizeof(char) * (pmatch.rm_so + 1)); + end = grep_malloc(sizeof(char) * (strlen(l->dat) - pmatch.rm_eo)); + strlcpy(begin, l->dat, pmatch.rm_so); + strlcpy(end, &(l->dat[pmatch.rm_eo]), (strlen(l->dat) - pmatch.rm_eo)); + + size = mbstowcs(NULL, begin, 0); + wbegin = grep_malloc(sizeof(wint_t) * size); + if (mbstowcs(wbegin, begin, size) == -1) { + r = REG_NOMATCH; + continue; + } + free(begin); + size = mbstowcs(NULL, end, 0); + wend = grep_malloc(sizeof(wint_t) * size); + if (mbstowcs(wend, end, size) == -1) { + r = REG_NOMATCH; + continue; + } + free(end); + + if ((pmatch.rm_so != 0 && iswword(wbegin[wcslen(wbegin -1)])) + || (pmatch.rm_eo != l->len && iswword(wend[0]))) r = REG_NOMATCH; + free(wbegin); + free(wend); + } if (r == t) { if (m == 0) c++;