Beispiel #1
0
void grok_init(grok_t *grok) {
  //int ret;
  /* set global pcre_callout for libpcre */
  pcre_callout = grok_pcre_callout;

  grok->re = NULL;
  grok->pattern = NULL;
  grok->full_pattern = NULL;
  grok->pcre_capture_vector = NULL;
  grok->pcre_num_captures = 0;
  grok->max_capture_num = 0;
  grok->pcre_errptr = NULL;
  grok->pcre_erroffset = 0;
  grok->logmask = 0;
  grok->logdepth = 0;

#ifndef GROK_TEST_NO_PATTERNS
  grok->patterns = tctreenew();
#endif /* GROK_TEST_NO_PATTERNS */

#ifndef GROK_TEST_NO_CAPTURE
  grok->captures_by_id = tctreenew();
  grok->captures_by_name = tctreenew();
  grok->captures_by_subname = tctreenew();
  grok->captures_by_capture_number = tctreenew();
#endif /* GROK_TEST_NO_CAPTURE */

  if (g_grok_global_initialized == 0) {
    /* do first initalization */
    g_grok_global_initialized = 1;

    /* VALGRIND NOTE: Valgrind complains here, but this is a global variable.
     * Ignore valgrind here. */
    g_pattern_re = pcre_compile(PATTERN_REGEX, 0,
                                &grok->pcre_errptr,
                                &grok->pcre_erroffset,
                                NULL);
    if (g_pattern_re == NULL) {
      fprintf(stderr, "Internal compiler error: %s\n", grok->pcre_errptr);
      fprintf(stderr, "Regexp: %s\n", PATTERN_REGEX);
      fprintf(stderr, "Position: %d\n", grok->pcre_erroffset);
    }

    pcre_fullinfo(g_pattern_re, NULL, PCRE_INFO_CAPTURECOUNT,
                  &g_pattern_num_captures);
    g_pattern_num_captures++; /* include the 0th group */
    g_cap_name = pcre_get_stringnumber(g_pattern_re, "name");
    g_cap_pattern = pcre_get_stringnumber(g_pattern_re, "pattern");
    g_cap_subname = pcre_get_stringnumber(g_pattern_re, "subname");
    g_cap_predicate = pcre_get_stringnumber(g_pattern_re, "predicate");
  }
}
Beispiel #2
0
void main () {

  uint32_t key = 123;
  const char *val = "abcdefkrnglrg";

  // Make a new tree
  TCTREE *tree = tctreenew();

  // Put an integer key
  tctreeput(tree, &key, sizeof(key), val, strlen(val));
  
  // Put a different key
  key = 122;
  tctreeput(tree, &key, sizeof(key), val, strlen(val));
  
  // Put the same key twice
  tctreeput(tree, &key, sizeof(key), val, strlen(val));

  // Put the same key but keep the old value
  tctreeputkeep(tree, &key, sizeof(key), val, strlen(val));

  // Get back a value
  int size;
  void *newVal = tctreeget(tree, &key, sizeof(key), &size);
  printf("Got value %s\n", newVal);

  // Create an iterator
  tctreeiterinit(tree);

  // Walk the tree
  tctreeiternext(tree, &size);
  tctreeiternext(tree, &size);
  tctreeiternext(tree, &size);

  // Clear the tree
  tctreeclear(tree);

  // Put one value back in the tree to make sure it's freed on delete 
  tctreeput(tree, &key, sizeof(key), val, strlen(val));

  // Delete the tree
  tctreedel(tree);

  // Make a list
  TCLIST *list = tclistnew();

  // Push a few times
  tclistpush(list, &key, sizeof(key));
  key += 1;
  tclistpush(list, &key, sizeof(key));
  key += 1;
  tclistpush(list, &key, sizeof(key));
 
  // Overwrite an existing element
  tclistover(list, 1, &key, sizeof(key));

  // Get a value
  tclistval(list, 2, &size);

  // Remove some values
  newVal = tclistremove(list, 2, &size);
  free(newVal);
  newVal = tclistremove(list, 0, &size);
  free(newVal);

  // Free the whole list
  tclistdel(list);
}