util.c (554491ffbdcfe51993d5b436a9bbca7aba388dd3) util.c (3f39ffc893961a8e73eea2bb70fed8ed11e0edd2)
1/* $NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $ */
2/* $FreeBSD$ */
3/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */
4
5/*-
6 * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
7 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org>
8 * All rights reserved.

--- 35 unchanged lines hidden (view full) ---

44#include <stdbool.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <unistd.h>
49#include <wchar.h>
50#include <wctype.h>
51
1/* $NetBSD: util.c,v 1.9 2011/02/27 17:33:37 joerg Exp $ */
2/* $FreeBSD$ */
3/* $OpenBSD: util.c,v 1.39 2010/07/02 22:18:03 tedu Exp $ */
4
5/*-
6 * Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
7 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org>
8 * All rights reserved.

--- 35 unchanged lines hidden (view full) ---

44#include <stdbool.h>
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <unistd.h>
49#include <wchar.h>
50#include <wctype.h>
51
52#ifndef WITHOUT_FASTMATCH
52#include "fastmatch.h"
53#include "fastmatch.h"
54#endif
53#include "grep.h"
54
55static int linesqueued;
56static int procline(struct str *l, int);
57
58static int lasta;
59static bool ctxover;
60

--- 251 unchanged lines hidden (view full) ---

312 lastmatches = 0;
313 startm = m;
314 if (st > 0)
315 leflags |= REG_NOTBOL;
316 /* Loop to compare with all the patterns */
317 for (i = 0; i < patterns; i++) {
318 pmatch.rm_so = st;
319 pmatch.rm_eo = l->len;
55#include "grep.h"
56
57static int linesqueued;
58static int procline(struct str *l, int);
59
60static int lasta;
61static bool ctxover;
62

--- 251 unchanged lines hidden (view full) ---

314 lastmatches = 0;
315 startm = m;
316 if (st > 0)
317 leflags |= REG_NOTBOL;
318 /* Loop to compare with all the patterns */
319 for (i = 0; i < patterns; i++) {
320 pmatch.rm_so = st;
321 pmatch.rm_eo = l->len;
322#ifndef WITHOUT_FASTMATCH
320 if (fg_pattern[i].pattern)
321 r = fastexec(&fg_pattern[i],
322 l->dat, 1, &pmatch, leflags);
323 else
323 if (fg_pattern[i].pattern)
324 r = fastexec(&fg_pattern[i],
325 l->dat, 1, &pmatch, leflags);
326 else
327#endif
324 r = regexec(&r_pattern[i], l->dat, 1,
325 &pmatch, leflags);
326 r = (r == 0) ? 0 : REG_NOMATCH;
327 if (r == REG_NOMATCH)
328 continue;
329 /* Check for full match */
330 if (r == 0 && xflag)
331 if (pmatch.rm_so != 0 ||
332 (size_t)pmatch.rm_eo != l->len)
333 r = REG_NOMATCH;
334 /* Check for whole word match */
328 r = regexec(&r_pattern[i], l->dat, 1,
329 &pmatch, leflags);
330 r = (r == 0) ? 0 : REG_NOMATCH;
331 if (r == REG_NOMATCH)
332 continue;
333 /* Check for full match */
334 if (r == 0 && xflag)
335 if (pmatch.rm_so != 0 ||
336 (size_t)pmatch.rm_eo != l->len)
337 r = REG_NOMATCH;
338 /* Check for whole word match */
339#ifndef WITHOUT_FASTMATCH
335 if (r == 0 && (wflag || fg_pattern[i].word)) {
340 if (r == 0 && (wflag || fg_pattern[i].word)) {
341#else
342 if (r == 0 && wflag) {
343#endif
336 wchar_t wbegin, wend;
337
338 wbegin = wend = L' ';
339 if (pmatch.rm_so != 0 &&
340 sscanf(&l->dat[pmatch.rm_so - 1],
341 "%lc", &wbegin) != 1)
342 r = REG_NOMATCH;
343 else if ((size_t)pmatch.rm_eo !=

--- 216 unchanged lines hidden ---
344 wchar_t wbegin, wend;
345
346 wbegin = wend = L' ';
347 if (pmatch.rm_so != 0 &&
348 sscanf(&l->dat[pmatch.rm_so - 1],
349 "%lc", &wbegin) != 1)
350 r = REG_NOMATCH;
351 else if ((size_t)pmatch.rm_eo !=

--- 216 unchanged lines hidden ---