예제 #1
0
파일: grep.c 프로젝트: Inkdit/git
static int match_line(struct grep_opt *opt, char *bol, char *eol,
		      enum grep_context ctx, int collect_hits)
{
	struct grep_pat *p;
	if (opt->extended)
		return match_expr(opt, bol, eol, ctx, collect_hits);

	/* we do not call with collect_hits without being extended */
	for (p = opt->pattern_list; p; p = p->next) {
		if (match_one_pattern(opt, p, bol, eol, ctx))
			return 1;
	}
	return 0;
}
예제 #2
0
파일: grep.c 프로젝트: sanj/git
static int match_next_pattern(struct grep_pat *p, char *bol, char *eol,
			      enum grep_context ctx,
			      regmatch_t *pmatch, int eflags)
{
	regmatch_t match;

	if (!match_one_pattern(p, bol, eol, ctx, &match, eflags))
		return 0;
	if (match.rm_so < 0 || match.rm_eo < 0)
		return 0;
	if (pmatch->rm_so >= 0 && pmatch->rm_eo >= 0) {
		if (match.rm_so > pmatch->rm_so)
			return 1;
		if (match.rm_so == pmatch->rm_so && match.rm_eo < pmatch->rm_eo)
			return 1;
	}
	pmatch->rm_so = match.rm_so;
	pmatch->rm_eo = match.rm_eo;
	return 1;
}
예제 #3
0
파일: grep.c 프로젝트: Inkdit/git
static int match_expr_eval(struct grep_opt *o,
			   struct grep_expr *x,
			   char *bol, char *eol,
			   enum grep_context ctx,
			   int collect_hits)
{
	int h = 0;

	switch (x->node) {
	case GREP_NODE_ATOM:
		h = match_one_pattern(o, x->u.atom, bol, eol, ctx);
		break;
	case GREP_NODE_NOT:
		h = !match_expr_eval(o, x->u.unary, bol, eol, ctx, 0);
		break;
	case GREP_NODE_AND:
		if (!collect_hits)
			return (match_expr_eval(o, x->u.binary.left,
						bol, eol, ctx, 0) &&
				match_expr_eval(o, x->u.binary.right,
						bol, eol, ctx, 0));
		h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
		h &= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 0);
		break;
	case GREP_NODE_OR:
		if (!collect_hits)
			return (match_expr_eval(o, x->u.binary.left,
						bol, eol, ctx, 0) ||
				match_expr_eval(o, x->u.binary.right,
						bol, eol, ctx, 0));
		h = match_expr_eval(o, x->u.binary.left, bol, eol, ctx, 0);
		x->u.binary.left->hit |= h;
		h |= match_expr_eval(o, x->u.binary.right, bol, eol, ctx, 1);
		break;
	default:
		die("Unexpected node type (internal error) %d\n", x->node);
	}
	if (collect_hits)
		x->hit |= h;
	return h;
}
예제 #4
0
파일: grep.c 프로젝트: 2quala/git
static int match_expr_eval(struct grep_expr *x, char *bol, char *eol,
			   enum grep_context ctx, int collect_hits)
{
	int h = 0;
	regmatch_t match;

	if (!x)
		die("Not a valid grep expression");
	switch (x->node) {
	case GREP_NODE_TRUE:
		h = 1;
		break;
	case GREP_NODE_ATOM:
		h = match_one_pattern(x->u.atom, bol, eol, ctx, &match, 0);
		break;
	case GREP_NODE_NOT:
		h = !match_expr_eval(x->u.unary, bol, eol, ctx, 0);
		break;
	case GREP_NODE_AND:
		if (!match_expr_eval(x->u.binary.left, bol, eol, ctx, 0))
			return 0;
		h = match_expr_eval(x->u.binary.right, bol, eol, ctx, 0);
		break;
	case GREP_NODE_OR:
		if (!collect_hits)
			return (match_expr_eval(x->u.binary.left,
						bol, eol, ctx, 0) ||
				match_expr_eval(x->u.binary.right,
						bol, eol, ctx, 0));
		h = match_expr_eval(x->u.binary.left, bol, eol, ctx, 0);
		x->u.binary.left->hit |= h;
		h |= match_expr_eval(x->u.binary.right, bol, eol, ctx, 1);
		break;
	default:
		die("Unexpected node type (internal error) %d", x->node);
	}
	if (collect_hits)
		x->hit |= h;
	return h;
}
예제 #5
0
static void match_up(char *data,int data_length,int hash_index){
    int i;
    for(i=0; i<pcount; i++){
      match_one_pattern(&(patterns[i]),data,data_length,hash_index);
    }
}