util.c (211496) | util.c (220421) |
---|---|
1/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ 2 3/*- 4 * Copyright (c) 1999 James Howard and Dag-Erling Co��dan Sm��rgrav 5 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */ 2 3/*- 4 * Copyright (c) 1999 James Howard and Dag-Erling Co��dan Sm��rgrav 5 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org> 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/usr.bin/grep/util.c 211496 2010-08-19 09:28:59Z des $"); | 31__FBSDID("$FreeBSD: head/usr.bin/grep/util.c 220421 2011-04-07 13:01:03Z gabor $"); |
32 33#include <sys/stat.h> 34#include <sys/types.h> 35 36#include <ctype.h> 37#include <err.h> 38#include <errno.h> 39#include <fnmatch.h> --- 10 unchanged lines hidden (view full) --- 50#include "grep.h" 51 52static int linesqueued; 53static int procline(struct str *l, int); 54 55bool 56file_matching(const char *fname) 57{ | 32 33#include <sys/stat.h> 34#include <sys/types.h> 35 36#include <ctype.h> 37#include <err.h> 38#include <errno.h> 39#include <fnmatch.h> --- 10 unchanged lines hidden (view full) --- 50#include "grep.h" 51 52static int linesqueued; 53static int procline(struct str *l, int); 54 55bool 56file_matching(const char *fname) 57{ |
58 char *fname_base; |
|
58 bool ret; 59 60 ret = finclude ? false : true; | 59 bool ret; 60 61 ret = finclude ? false : true; |
62 fname_base = basename(fname); |
|
61 62 for (unsigned int i = 0; i < fpatterns; ++i) { | 63 64 for (unsigned int i = 0; i < fpatterns; ++i) { |
63 if (fnmatch(fpattern[i].pat, 64 fname, 0) == 0 || fnmatch(fpattern[i].pat, 65 basename(fname), 0) == 0) { | 65 if (fnmatch(fpattern[i].pat, fname, 0) == 0 || 66 fnmatch(fpattern[i].pat, fname_base, 0) == 0) { |
66 if (fpattern[i].mode == EXCL_PAT) 67 return (false); 68 else 69 ret = true; 70 } 71 } 72 return (ret); 73} --- 198 unchanged lines hidden (view full) --- 272 273/* 274 * Processes a line comparing it with the specified patterns. Each pattern 275 * is looped to be compared along with the full string, saving each and every 276 * match, which is necessary to colorize the output and to count the 277 * matches. The matching lines are passed to printline() to display the 278 * appropriate output. 279 */ | 67 if (fpattern[i].mode == EXCL_PAT) 68 return (false); 69 else 70 ret = true; 71 } 72 } 73 return (ret); 74} --- 198 unchanged lines hidden (view full) --- 273 274/* 275 * Processes a line comparing it with the specified patterns. Each pattern 276 * is looped to be compared along with the full string, saving each and every 277 * match, which is necessary to colorize the output and to count the 278 * matches. The matching lines are passed to printline() to display the 279 * appropriate output. 280 */ |
280static inline int | 281static int |
281procline(struct str *l, int nottext) 282{ 283 regmatch_t matches[MAX_LINE_MATCHES]; 284 regmatch_t pmatch; 285 size_t st = 0; 286 unsigned int i; 287 int c = 0, m = 0, r = 0; 288 --- 24 unchanged lines hidden (view full) --- 313 if (r == REG_NOMATCH) 314 continue; 315 /* Check for full match */ 316 if (r == 0 && xflag) 317 if (pmatch.rm_so != 0 || 318 (size_t)pmatch.rm_eo != l->len) 319 r = REG_NOMATCH; 320 /* Check for whole word match */ | 282procline(struct str *l, int nottext) 283{ 284 regmatch_t matches[MAX_LINE_MATCHES]; 285 regmatch_t pmatch; 286 size_t st = 0; 287 unsigned int i; 288 int c = 0, m = 0, r = 0; 289 --- 24 unchanged lines hidden (view full) --- 314 if (r == REG_NOMATCH) 315 continue; 316 /* Check for full match */ 317 if (r == 0 && xflag) 318 if (pmatch.rm_so != 0 || 319 (size_t)pmatch.rm_eo != l->len) 320 r = REG_NOMATCH; 321 /* Check for whole word match */ |
321 if (r == 0 && wflag && pmatch.rm_so != 0) { | 322 if (r == 0 && fg_pattern[i].word && 323 pmatch.rm_so != 0) { |
322 wint_t wbegin, wend; 323 324 wbegin = wend = L' '; 325 if (pmatch.rm_so != 0 && 326 sscanf(&l->dat[pmatch.rm_so - 1], 327 "%lc", &wbegin) != 1) 328 r = REG_NOMATCH; 329 else if ((size_t)pmatch.rm_eo != l->len && --- 173 unchanged lines hidden --- | 324 wint_t wbegin, wend; 325 326 wbegin = wend = L' '; 327 if (pmatch.rm_so != 0 && 328 sscanf(&l->dat[pmatch.rm_so - 1], 329 "%lc", &wbegin) != 1) 330 r = REG_NOMATCH; 331 else if ((size_t)pmatch.rm_eo != l->len && --- 173 unchanged lines hidden --- |