Ejemplo n.º 1
0
static int powerdns_shutdown (void)
{
  llentry_t *e;

  if (list == NULL)
    return (0);

  for (e = llist_head (list); e != NULL; e = e->next)
  {
    list_item_t *item = (list_item_t *) e->value;
    e->value = NULL;

    sfree (item->instance);
    sfree (item->command);
    sfree (item);
  }

  llist_destroy (list);
  list = NULL;

  return (0);
} /* static int powerdns_shutdown */
Ejemplo n.º 2
0
int test_datastructure_link_list()
{
	llist_t *llist;
	allocator_t *allocator;

	struct test t1={1,2};
	struct test t2={2,2};
	struct test t3={3,2};
	struct test t4={4,2};
	int ret = 0;

	/*
	 *allocator = allocator_creator(ALLOCATOR_TYPE_CTR_MALLOC);
	 *allocator_ctr_init(allocator, 0, 0, 1024);
	 *dbg_str(DBG_CONTAINER_DETAIL,"list allocator addr:%p",allocator);
	 */

	allocator = allocator_creator(ALLOCATOR_TYPE_SYS_MALLOC,0);

	//ct = container_creator(CONTAINER_TYPE_LIST,allocator);
	llist = llist_create(allocator,0);
	llist_init(llist,sizeof(struct test));
	llist_push_front(llist,&t1);
	llist_push_front(llist,&t2);
	llist_push_front(llist,&t3);
	llist_push_front(llist,&t4);

	llist_push_back(llist,&t1);
	llist_push_back(llist,&t2);
	llist_push_back(llist,&t3);
	llist_push_back(llist,&t4);

	llist_for_each(llist,print_list_data);

	llist_destroy(llist);
	return ret;
}
Ejemplo n.º 3
0
static void destroy_all_callbacks (llist_t **list) /* {{{ */
{
	llentry_t *le;

	if (*list == NULL)
		return;

	le = llist_head (*list);
	while (le != NULL)
	{
		llentry_t *le_next;

		le_next = le->next;

		sfree (le->key);
		destroy_callback (le->value);
		le->value = NULL;

		le = le_next;
	}

	llist_destroy (*list);
	*list = NULL;
} /* }}} void destroy_all_callbacks */
Ejemplo n.º 4
0
void stack_destroy(STACK *ptr)
{
	llist_destroy(ptr);
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
	st_list *myList = NULL;
	st_list_item *item = NULL;
	en_llist_ret_code ret;

	myList = test();

	if (!myList) {
		fprintf(stderr, "Failed to operate with linke_list!\n");
		return -1;
	}

	// prints all elements from the list
	list_dump(myList);

	// prints the first item from the list
	item = llist_get_first(myList);
	if (!item) {
		fprintf(stderr, "Failed to retrieve an item from the list");
		llist_destroy(&myList);
		return -1;
	}
	list_dump_item(item);

	myStruct *mst = (myStruct *) item->data;
	free(mst->l);

	// prints the last item from the list
	item = llist_get_last(myList);
	if (!item) {
		fprintf(stderr, "Failed to retrieve an item from the list");
		llist_destroy(&myList);
		return -1;
	}
	list_dump_item(item);

	// get an item at the middle of the list
	item = llist_get_item(myList, 4);
	if (!item) {
		fprintf(stderr, "Failed to retrieve an item from the list");
		llist_destroy(&myList);
		return -1;
	}
	list_dump_item(item);

	// Remove test.
	printf("\nWill remove some items of the list!!\n");
	// First.
	ret = llist_rm_index(myList, 0);
	if (ret != LLIST_RET_SUCCESS) {
		fprintf(stderr, "Failed to remove first item.\n");
	}

	// Middle.
	ret = llist_rm_index(myList, 5);
	if (ret != LLIST_RET_SUCCESS) {
		fprintf(stderr, "Failed to remove middle item.\n");
	}

	// last.
	item = llist_get_last(myList);
	if (!item) {
		fprintf(stderr, "Failed to retrieve an item from the list");
		llist_destroy(&myList);
		return -1;
	}
	mst = (myStruct *) item->data;
	free(mst->l);

	ret = llist_rm_index(myList, item->index);
	if (ret != LLIST_RET_SUCCESS) {
		fprintf(stderr, "Failed to remove last item.\n");
	}

	list_dump(myList);

	// try to remove an invalid item.
	ret = llist_rm_index(myList, 9);
	if (ret == LLIST_RET_NOTFOUND) {
		fprintf(stderr, "[expected] Failed to remove last item. Item not found!\n");
	}
	else if (ret != LLIST_RET_SUCCESS) {
		fprintf(stderr, "Something went wrong while trying to remove last item.\n");
	}

	// free the list elements and erase the reference
	llist_destroy(&myList);

	return 0;
}
Ejemplo n.º 6
0
void stack_destroy(STACK *ptr){
	return llist_destroy(ptr);
}
Ejemplo n.º 7
0
static int cx_config_add_url(oconfig_item_t *ci) /* {{{ */
{
  if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) {
    WARNING("curl_xml plugin: The `URL' block "
            "needs exactly one string argument.");
    return -1;
  }

  cx_t *db = calloc(1, sizeof(*db));
  if (db == NULL) {
    ERROR("curl_xml plugin: calloc failed.");
    return -1;
  }

  db->instance = strdup("default");
  if (db->instance == NULL) {
    ERROR("curl_xml plugin: strdup failed.");
    sfree(db);
    return -1;
  }

  db->xpath_list = llist_create();
  if (db->xpath_list == NULL) {
    ERROR("curl_xml plugin: list creation failed.");
    sfree(db->instance);
    sfree(db);
    return -1;
  }

  db->timeout = -1;

  int status = cf_util_get_string(ci, &db->url);
  if (status != 0) {
    llist_destroy(db->xpath_list);
    sfree(db->instance);
    sfree(db);
    return status;
  }

  /* Fill the `cx_t' structure.. */
  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;

    if (strcasecmp("Instance", child->key) == 0)
      status = cf_util_get_string(child, &db->instance);
    else if (strcasecmp("Plugin", child->key) == 0)
      status = cf_util_get_string(child, &db->plugin_name);
    else if (strcasecmp("Host", child->key) == 0)
      status = cf_util_get_string(child, &db->host);
    else if (strcasecmp("User", child->key) == 0)
      status = cf_util_get_string(child, &db->user);
    else if (strcasecmp("Password", child->key) == 0)
      status = cf_util_get_string(child, &db->pass);
    else if (strcasecmp("Digest", child->key) == 0)
      status = cf_util_get_boolean(child, &db->digest);
    else if (strcasecmp("VerifyPeer", child->key) == 0)
      status = cf_util_get_boolean(child, &db->verify_peer);
    else if (strcasecmp("VerifyHost", child->key) == 0)
      status = cf_util_get_boolean(child, &db->verify_host);
    else if (strcasecmp("CACert", child->key) == 0)
      status = cf_util_get_string(child, &db->cacert);
    else if (strcasecmp("xpath", child->key) == 0)
      status = cx_config_add_xpath(db, child);
    else if (strcasecmp("Header", child->key) == 0)
      status = cx_config_append_string("Header", &db->headers, child);
    else if (strcasecmp("Post", child->key) == 0)
      status = cf_util_get_string(child, &db->post_body);
    else if (strcasecmp("Namespace", child->key) == 0)
      status = cx_config_add_namespace(db, child);
    else if (strcasecmp("Timeout", child->key) == 0)
      status = cf_util_get_int(child, &db->timeout);
    else if (strcasecmp("Statistics", child->key) == 0) {
      db->stats = curl_stats_from_config(child);
      if (db->stats == NULL)
        status = -1;
    } else {
      WARNING("curl_xml plugin: Option `%s' not allowed here.", child->key);
      status = -1;
    }

    if (status != 0)
      break;
  }

  if (status != 0) {
    cx_free(db);
    return status;
  }

  if (llist_size(db->xpath_list) == 0) {
    WARNING("curl_xml plugin: No `xpath' block within `URL' block `%s'.",
            db->url);
    cx_free(db);
    return -1;
  }

  if (cx_init_curl(db) != 0) {
    cx_free(db);
    return -1;
  }

  /* If all went well, register this database for reading */
  DEBUG("curl_xml plugin: Registering new read callback: %s", db->instance);

  char *cb_name = ssnprintf_alloc("curl_xml-%s-%s", db->instance, db->url);

  plugin_register_complex_read(/* group = */ "curl_xml", cb_name, cx_read,
                               /* interval = */ 0,
                               &(user_data_t){
                                   .data = db, .free_func = cx_free,
                               });
Ejemplo n.º 8
0
void relocations_destroy(struct relocations_t *sl)
{
    if (sl)
        llist_destroy(sl->first);
}
Ejemplo n.º 9
0
int main(void)
{
	struct linkedList* myList = llist_create(6);

	for(int i = 5; i > 0; i--)
	{
		llist_add(&myList,i);
	}

	struct linkedList* theirList = llist_create(5);

	for(int i = 1; i < 5; i++)
	{
		llist_add(&theirList,i);
	}

	printf("My list: ");
	ll_print(myList);
	printf("Their list: ");
	ll_print(theirList);

	double sum = ll_sum(myList);
	printf("My sum is: %lf!\n",sum);

	//llist_remove(&myList);

	sum = ll_sum(myList);
	printf("My sum is: %lf!\n",sum);

	// ll_append(myList, theirList);

	bool equality = false;
	equality = ll_equal_by(myList, theirList, cmp);

	printf("My list and their list is equal: %d\n",equality);

	struct linkedList* myList2 = llist_create(5);
	llist_add(&myList2,1);
	llist_add(&myList2,1);
	llist_add(&myList2,5);
	llist_add(&myList2,2);
	llist_add(&myList2,2);
	llist_add(&myList2,3);
	llist_add(&myList2,3);
	llist_add(&myList2,2);
	llist_add(&myList2,3);
	llist_add(&myList2,3);
	printf("My list2: ");
	ll_print(myList2);
	size_t lenOfList = ll_flatten(myList2,cmp);
	printf("Length of list2 after flatten: %zd\n",lenOfList);

	printf("My list2: ");
	ll_print(myList2);

	bool isSort = ll_is_sorted(myList,cmp);
	printf("My list is sort: %d\n",isSort);

	bool isCircular = ll_is_circular(myList);
	printf("My list is circular: %d\n",isCircular);
	// ll_append(myList, myList);
	// bool isCircular2 = ll_is_circular(myList);
	// printf("is circular2: %d\n",isCircular2);

	printf("My list before reverse: ");
	ll_print(myList);
	ll_reverse(&myList);
	printf("My list after reverse: ");
	ll_print(myList);


	printf("My list before insert: ");
	ll_print(myList);
	ll_insert_sorted(&myList,72);
	printf("My list after insert: ");
	ll_print(myList);

	llist_destroy(myList2);
	llist_destroy(myList);
	// llist_destroy(theirList);
	return(0);
}
Ejemplo n.º 10
0
int main(int argc, char *argv[])
{
    LLIST *handle = NULL, *find = NULL;
    int n;

    if (argc > 1)
        handle = llist_load("./db");
    else
    {
        handle = llist_create(sizeof(int));

        while (1)
        {
            printf("please input num : ");
            scanf("%d", &n);

            if (n == -1)
                break;
            /*llist_append(&n, handle);*/
            /*llist_prepend(&n, handle);*/
            /*llist_insert(&n, PREPEND, handle);*/
            llist_sort_insert(&n, cmp, handle);
        }

        llist_travel(ls, NULL, handle);
        printf("\n");

        n = 9999;
        llist_insert(&n, 3, handle);

        if (!llist_store("./db", handle))
            printf("存储成功!\n");
    }

    llist_travel(ls, NULL, handle);
    printf("\n");

    llist_sort(cmp, handle);

    printf("sort : ");
    llist_travel(ls, NULL, handle);
    printf("\n");

    while (1)
    {
        printf("please input key : ");
        scanf("%d", &n);
        if (n == -1)
            break;

        find = llist_findall(&n, cmp, handle);
        if (find != NULL)
        {
            llist_travel_find(ls, NULL, find);
            printf("\n");
        }
/*
 *        printf("delete = %d\n", llist_delete(&n, cmp, handle));
 *
 *        llist_travel(ls, NULL, handle);
 *        printf("\n");
 */
    }

    llist_destroy(&handle);

    return 0;
}
Ejemplo n.º 11
0
END_TEST

START_TEST ( llist_06_insert_nodes )
{
    int retval;
    llist listToTest = NULL;
    llist_node retptr;
    listToTest = llist_create ( NULL, trivial_equal, test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding nodes: " );
    print_llist ( listToTest );

    // Find the middle node (3)
    retval = llist_find_node ( listToTest, ( llist_node ) 3, &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // Add node before
    retval =  llist_insert_node ( listToTest,  ( llist_node ) 7, retptr, ADD_NODE_BEFORE );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding before 3 node: " );
    print_llist ( listToTest );


    // Add node after
    retval =  llist_insert_node ( listToTest,  ( llist_node ) 8, retptr, ADD_NODE_AFTER );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding after 3 node: " );
    print_llist ( listToTest );

    // insert node at the start of the list (before the first node)
    retval = llist_find_node ( listToTest, ( llist_node ) 5, &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval =  llist_insert_node ( listToTest,  ( llist_node ) 9, retptr, ADD_NODE_BEFORE );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding 9 before the first node: " );
    print_llist ( listToTest );


    // insert node at the start of the list (after the first node)
    retval = llist_find_node ( listToTest, ( llist_node ) 9, &retptr );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval =  llist_insert_node ( listToTest,  ( llist_node ) 10, retptr, ADD_NODE_AFTER );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding 10 after the first node: " );
    print_llist ( listToTest );

    // insert node at the end of the list (after the first node)
    retval = llist_find_node ( listToTest, ( llist_node ) 1, &retptr);
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval =  llist_insert_node ( listToTest,  ( llist_node ) 11, retptr, ADD_NODE_AFTER );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding 11 after the last node: " );
    print_llist ( listToTest );

    llist_destroy ( listToTest, false, NULL );
}
Ejemplo n.º 12
0
END_TEST

START_TEST ( llist_04_delete_nodes )
{
    int retval;
    //llist_node temp;
    llist listToTest = NULL;
    listToTest = llist_create ( NULL, trivial_equal,  test_mt ? MT_SUPPORT_FALSE : MT_SUPPORT_TRUE  );

    // Insert a 5 nodes 1..5
    retval = llist_add_node ( listToTest, ( llist_node ) 1, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 2, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 3, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 4, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    retval = llist_add_node ( listToTest, ( llist_node ) 5, ADD_NODE_FRONT );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after adding nodes: " );
    print_llist ( listToTest );

   // Delete tail
    retval = llist_delete_node ( listToTest, ( llist_node ) 1, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after deleting tail: " );
    print_llist ( listToTest );

    // Delete node in the middle
    retval = llist_delete_node ( listToTest, ( llist_node ) 3, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after deleting middle node: " );
    print_llist ( listToTest );

    // Delete head
    retval = llist_delete_node ( listToTest, ( llist_node ) 5, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    printf ( "List after deleting head node: " );
    print_llist ( listToTest );

    // Delete a node that doesn't exist
    retval = llist_delete_node ( listToTest, ( llist_node ) 6, false, NULL );
    ck_assert_int_eq ( retval, LLIST_NODE_NOT_FOUND );

    retval = llist_delete_node ( listToTest, ( llist_node ) 2, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // The list should not  be empty now
    ck_assert_int_eq(llist_is_empty ( listToTest ), FALSE );

    ck_assert_int_eq(llist_is_empty ( listToTest ), FALSE );

    // Delete last node
    retval = llist_delete_node ( listToTest, ( llist_node ) 4, false, NULL );
    ck_assert_int_eq ( retval, LLIST_SUCCESS );

    // The list should be empty now
    ck_assert_int_eq(llist_is_empty ( listToTest ), TRUE );

    llist_destroy ( listToTest, false, NULL );
}
Ejemplo n.º 13
0
static struct i_bitmap *
i_flood_fill_low(i_img *im,i_img_dim seedx,i_img_dim seedy,
                 i_img_dim *bxminp, i_img_dim *bxmaxp, i_img_dim *byminp, i_img_dim *bymaxp,
		 i_color const *seed, ff_cmpfunc cmpfunc) {
  i_img_dim ltx, rtx;
  i_img_dim tx = 0;

  i_img_dim bxmin = seedx;
  i_img_dim bxmax = seedx;
  i_img_dim bymin = seedy;
  i_img_dim bymax = seedy;

  struct llist *st;
  struct i_bitmap *btm;

  int channels;
  i_img_dim xsize,ysize;
  i_color cval;

  channels = im->channels;
  xsize    = im->xsize;
  ysize    = im->ysize;

  btm = btm_new(xsize, ysize);
  st  = llist_new(100, sizeof(struct stack_element*));

  /* Find the starting span and fill it */
  ltx = i_lspan(im, seedx, seedy, seed, cmpfunc);
  rtx = i_rspan(im, seedx, seedy, seed, cmpfunc);
  for(tx=ltx; tx<=rtx; tx++) SET(tx, seedy);
  bxmin = ltx;
  bxmax = rtx;

  ST_PUSH(ltx, rtx, ltx, rtx, seedy+1,  1);
  ST_PUSH(ltx, rtx, ltx, rtx, seedy-1, -1);

  while(st->count) {
    /* Stack variables */
    i_img_dim lx,rx;
    i_img_dim dadLx,dadRx;
    i_img_dim y;
    int direction;

    i_img_dim x;
    int wasIn=0;

    ST_POP(); /* sets lx, rx, dadLx, dadRx, y, direction */


    if (y<0 || y>ysize-1) continue;
    if (bymin > y) bymin=y; /* in the worst case an extra line */
    if (bymax < y) bymax=y; 


    x = lx+1;
    if ( lx >= 0 && (wasIn = INSIDE(lx, y, seed)) ) {
      SET(lx, y);
      lx--;
      while(lx >= 0 && INSIDE(lx, y, seed)) {
	SET(lx,y);
	lx--;
      }
    }

    if (bxmin > lx) bxmin = lx;
    while(x <= xsize-1) {
      /*  printf("x=%d\n",x); */
      if (wasIn) {
	
	if (INSIDE(x, y, seed)) {
	  /* case 1: was inside, am still inside */
	  SET(x,y);
	} else {
	  /* case 2: was inside, am no longer inside: just found the
	     right edge of a span */
	  ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);

	  if (bxmax < x) bxmax = x;
	  wasIn=0;
	}
      } else {
	if (x > rx) goto EXT;
	if (INSIDE(x, y, seed)) {
	  SET(x, y);
	  /* case 3: Wasn't inside, am now: just found the start of a new run */
	  wasIn = 1;
	    lx = x;
	} else {
	  /* case 4: Wasn't inside, still isn't */
	}
      }
      x++;
    }
  EXT: /* out of loop */
    if (wasIn) {
      /* hit an edge of the frame buffer while inside a run */
      ST_STACK(direction, dadLx, dadRx, lx, (x-1), y);
      if (bxmax < x) bxmax = x;
    }
  }

  llist_destroy(st);

  *bxminp = bxmin;
  *bxmaxp = bxmax;
  *byminp = bymin;
  *bymaxp = bymax;

  return btm;
}
Ejemplo n.º 14
0
int main(void)
{
    int n, ret;
    void *ret1;
    LLIST *handle = NULL;
    LLIST *find = NULL;
    
    handle = llist_create(sizeof(int), NULL, NULL, NULL);

    while (1)
    {
        printf("please input num : ");
        scanf("%d", &n);

        if (n == -1)
            break;

        llist_insert(&n, APPEND, handle);
    }
    
    llist_travel(printf_s, NULL, handle);
    printf("\n");

    printf("insert num : ");
    scanf("%d", &n);
    llist_insert(&n, 3, handle);
    llist_travel(printf_s, NULL, handle);
    printf("\n");

    printf("delete num : ");
    scanf("%d", &n);
    llist_delete(&n, cmp, handle);
    llist_travel(printf_s, NULL, handle);
    printf("\n");

	printf("find num : ");
	scanf("%d", &n);
	ret1 = llist_find(&n, cmp, handle);
    if(ret1 != NULL)
        printf("find = %d\n", *(int*)ret1);
    printf("\n");

    printf("findall num : ");
    scanf("%d", &n);
    find = llist_findall(&n, cmp, handle);
    llist_travel(printf_s, find, handle);
    printf("\n");

    llist_sort(cmp, handle);
    printf("sort:");
    llist_travel(printf_s, NULL, handle);
	printf("\n");

    ret = llist_store("./db", handle);
    if(ret == 0)
        printf("存储成功!\n");

    llist_destroy(&handle);

    return 0;
}