Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 93443 | Differences between
and this patch

Collapse All | Expand All

(-)grep-2.5.1/src/search.c.fgrep (-36 / +26 lines)
Lines 360-372 Link Here
360
	      /* Find a possible match using the KWset matcher. */
360
	      /* Find a possible match using the KWset matcher. */
361
	      size_t offset = kwsexec (kwset, beg, buflim - beg, &kwsm);
361
	      size_t offset = kwsexec (kwset, beg, buflim - beg, &kwsm);
362
	      if (offset == (size_t) -1)
362
	      if (offset == (size_t) -1)
363
		{
363
	        goto failure;
364
#ifdef MBS_SUPPORT
365
		  if (MB_CUR_MAX > 1)
366
		    free(mb_properties);
367
#endif
368
		  return (size_t)-1;
369
		}
370
	      beg += offset;
364
	      beg += offset;
371
	      /* Narrow down to the line containing the candidate, and
365
	      /* Narrow down to the line containing the candidate, and
372
		 run it through DFA. */
366
		 run it through DFA. */
Lines 379-385 Link Here
379
	      while (beg > buf && beg[-1] != eol)
373
	      while (beg > buf && beg[-1] != eol)
380
		--beg;
374
		--beg;
381
	      if (kwsm.index < kwset_exact_matches)
375
	      if (kwsm.index < kwset_exact_matches)
382
		goto success;
376
		goto success_in_beg_and_end;
383
	      if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
377
	      if (dfaexec (&dfa, beg, end - beg, &backref) == (size_t) -1)
384
		continue;
378
		continue;
385
	    }
379
	    }
Lines 398-404 Link Here
398
	    }
392
	    }
399
	  /* Successful, no backreferences encountered! */
393
	  /* Successful, no backreferences encountered! */
400
	  if (!backref)
394
	  if (!backref)
401
	    goto success;
395
	    goto success_in_beg_and_end;
402
	}
396
	}
403
      else
397
      else
404
	end = beg + size;
398
	end = beg + size;
Lines 413-426 Link Here
413
				       end - beg - 1, &(patterns[i].regs))))
407
				       end - beg - 1, &(patterns[i].regs))))
414
	    {
408
	    {
415
	      len = patterns[i].regs.end[0] - start;
409
	      len = patterns[i].regs.end[0] - start;
416
	      if (exact)
410
	      if (exact && !match_words)
417
		{
411
	        goto success_in_start_and_len;
418
		  *match_size = len;
419
		  return start;
420
		}
421
	      if ((!match_lines && !match_words)
412
	      if ((!match_lines && !match_words)
422
		  || (match_lines && len == end - beg - 1))
413
		  || (match_lines && len == end - beg - 1))
423
		goto success;
414
		goto success_in_beg_and_end;
424
	      /* If -w, check if the match aligns with word boundaries.
415
	      /* If -w, check if the match aligns with word boundaries.
425
		 We do this iteratively because:
416
		 We do this iteratively because:
426
		 (a) the line may contain more than one occurence of the
417
		 (a) the line may contain more than one occurence of the
Lines 434-440 Link Here
434
		    if ((start == 0 || !WCHAR ((unsigned char) beg[start - 1]))
425
		    if ((start == 0 || !WCHAR ((unsigned char) beg[start - 1]))
435
			&& (len == end - beg - 1
426
			&& (len == end - beg - 1
436
			    || !WCHAR ((unsigned char) beg[start + len])))
427
			    || !WCHAR ((unsigned char) beg[start + len])))
437
		      goto success;
428
		      goto success_in_beg_and_end;
438
		    if (len > 0)
429
		    if (len > 0)
439
		      {
430
		      {
440
			/* Try a shorter length anchored at the same place. */
431
			/* Try a shorter length anchored at the same place. */
Lines 461-479 Link Here
461
	    }
452
	    }
462
	} /* for Regex patterns.  */
453
	} /* for Regex patterns.  */
463
    } /* for (beg = end ..) */
454
    } /* for (beg = end ..) */
455
456
 failure:
464
#ifdef MBS_SUPPORT
457
#ifdef MBS_SUPPORT
465
  if (MB_CUR_MAX > 1 && mb_properties)
458
  if (MB_CUR_MAX > 1 && mb_properties)
466
    free (mb_properties);
459
    free (mb_properties);
467
#endif /* MBS_SUPPORT */
460
#endif /* MBS_SUPPORT */
468
  return (size_t) -1;
461
  return (size_t) -1;
469
462
470
 success:
463
 success_in_beg_and_end:
464
  len = end - beg;
465
  start = beg - buf;
466
  /* FALLTHROUGH */
467
468
 success_in_start_and_len:
471
#ifdef MBS_SUPPORT
469
#ifdef MBS_SUPPORT
472
  if (MB_CUR_MAX > 1 && mb_properties)
470
  if (MB_CUR_MAX > 1 && mb_properties)
473
    free (mb_properties);
471
    free (mb_properties);
474
#endif /* MBS_SUPPORT */
472
#endif /* MBS_SUPPORT */
475
  *match_size = end - beg;
473
  *match_size = len;
476
  return beg - buf;
474
  return start;
477
}
475
}
478
476
479
static void
477
static void
Lines 516-543 Link Here
516
    {
514
    {
517
      size_t offset = kwsexec (kwset, beg, buf + size - beg, &kwsmatch);
515
      size_t offset = kwsexec (kwset, beg, buf + size - beg, &kwsmatch);
518
      if (offset == (size_t) -1)
516
      if (offset == (size_t) -1)
519
	{
517
	goto failure;
520
#ifdef MBS_SUPPORT
521
	  if (MB_CUR_MAX > 1)
522
	    free(mb_properties);
523
#endif /* MBS_SUPPORT */
524
	  return offset;
525
	}
526
#ifdef MBS_SUPPORT
518
#ifdef MBS_SUPPORT
527
      if (MB_CUR_MAX > 1 && mb_properties[offset+beg-buf] == 0)
519
      if (MB_CUR_MAX > 1 && mb_properties[offset+beg-buf] == 0)
528
	continue; /* It is a part of multibyte character.  */
520
	continue; /* It is a part of multibyte character.  */
529
#endif /* MBS_SUPPORT */
521
#endif /* MBS_SUPPORT */
530
      beg += offset;
522
      beg += offset;
531
      len = kwsmatch.size[0];
523
      len = kwsmatch.size[0];
532
      if (exact)
524
      if (exact && !match_words)
533
	{
525
	goto success_in_beg_and_len;
534
	  *match_size = len;
535
#ifdef MBS_SUPPORT
536
	  if (MB_CUR_MAX > 1)
537
	    free (mb_properties);
538
#endif /* MBS_SUPPORT */
539
	  return beg - buf;
540
	}
541
      if (match_lines)
526
      if (match_lines)
542
	{
527
	{
543
	  if (beg > buf && beg[-1] != eol)
528
	  if (beg > buf && beg[-1] != eol)
Lines 551-556 Link Here
551
	goto success;
536
	goto success;
552
    }
537
    }
553
538
539
 failure:
554
#ifdef MBS_SUPPORT
540
#ifdef MBS_SUPPORT
555
  if (MB_CUR_MAX > 1)
541
  if (MB_CUR_MAX > 1)
556
    free (mb_properties);
542
    free (mb_properties);
Lines 583-589 Link Here
583
  end++;
569
  end++;
584
  while (buf < beg && beg[-1] != eol)
570
  while (buf < beg && beg[-1] != eol)
585
    --beg;
571
    --beg;
586
  *match_size = end - beg;
572
  len = end - beg;
573
  /* FALLTHROUGH */
574
575
 success_in_beg_and_len:
576
  *match_size = len;
587
#ifdef MBS_SUPPORT
577
#ifdef MBS_SUPPORT
588
  if (MB_CUR_MAX > 1)
578
  if (MB_CUR_MAX > 1)
589
    free (mb_properties);
579
    free (mb_properties);

Return to bug 93443