int grok_compilen(grok_t *grok, const char *pattern, int length) { grok_log(grok, LOG_COMPILE, "Compiling '%.*s'", length, pattern); /* clear the old tctree data */ tctreeclear(grok->captures_by_name); tctreeclear(grok->captures_by_subname); tctreeclear(grok->captures_by_capture_number); tctreeclear(grok->captures_by_id); grok->pattern = pattern; grok->pattern_len = length; grok->full_pattern = grok_pattern_expand(grok); if (grok->full_pattern == NULL) { grok_log(grok, LOG_COMPILE, "A failure occurred while compiling '%.*s'", length, pattern); grok->errstr = "failure occurred while expanding pattern "\ "(too pattern recursion?)"; return GROK_ERROR_COMPILE_FAILED; } grok->re = pcre_compile(grok->full_pattern, 0, &grok->pcre_errptr, &grok->pcre_erroffset, NULL); if (grok->re == NULL) { grok->errstr = (char *)grok->pcre_errptr; return GROK_ERROR_COMPILE_FAILED; } pcre_fullinfo(grok->re, NULL, PCRE_INFO_CAPTURECOUNT, &grok->pcre_num_captures); grok->pcre_num_captures++; /* include the 0th group */ grok->pcre_capture_vector = calloc(3 * grok->pcre_num_captures, sizeof(int)); /* Walk grok->captures_by_id. * For each, ask grok->re what stringnum it is */ grok_study_capture_map(grok); return GROK_OK; }
int grok_compilen(grok_t *grok, const char *pattern, int length) { grok_log(grok, LOG_COMPILE, "Compiling '%s'", pattern); grok->pattern = pattern; grok->full_pattern = grok_pattern_expand(grok); //, 0, strlen(pattern)); grok->re = pcre_compile(grok->full_pattern, 0, &grok->pcre_errptr, &grok->pcre_erroffset, NULL); if (grok->re == NULL) { grok->errstr = (char *)grok->pcre_errptr; return GROK_ERROR_COMPILE_FAILED; } pcre_fullinfo(grok->re, NULL, PCRE_INFO_CAPTURECOUNT, &grok->pcre_num_captures); grok->pcre_num_captures++; /* include the 0th group */ grok->pcre_capture_vector = calloc(3 * grok->pcre_num_captures, sizeof(int)); /* Walk grok->captures_by_id. * For each, ask grok->re what stringnum it is */ grok_study_capture_map(grok); return GROK_OK; }