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 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{ |
58 char *fname_base; |
59 bool ret; 60 61 ret = finclude ? false : true; |
62 fname_base = basename(fname); |
63 64 for (unsigned int i = 0; i < fpatterns; ++i) { |
65 if (fnmatch(fpattern[i].pat, fname, 0) == 0 || 66 fnmatch(fpattern[i].pat, fname_base, 0) == 0) { |
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 */ |
281static int |
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 */ |
322 if (r == 0 && fg_pattern[i].word && 323 pmatch.rm_so != 0) { |
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 --- |