Example #1
0
void main(int argc, char* argv[])
{
	list * l;
	list_iter it;
	intptr_t i;
	char* sv[] = { "fff", "zzz", "rrr", "bbb", "ggg", "hhh", "lll", "ttt" };
	
	//list test
	l = list_new();
	for (i=0; i<10; ++i) {
		(i%2 ? list_append(l, (void*)i): list_prepend(l, (void*)i));
	}
	list_insert_at(l, (void*)20,9);
	list_append(l, (void*)22);
	list_delete_item(l, (void*)22);
	list_delete_at(l, 10);
	list_dump(l, "%d\n");
	list_free(l);
	
	//string list test
	l = list_new_full(free);
	for(i=0; i<8; ++i) list_append(l, strdup(sv[i]));
	list_prepend(l, strdup("nine"));
	list_delete_item_comp(l, strdup("seven"), (list_comparator)strcmp);
	list_delete_item_comp(l, "eee", (list_comparator)strcmp);
	list_dump(l, "%s\n");
	list_free(l);
	
	l = list_new();
	for(i=0; i<8; ++i) list_insert_sorted_comp(l, sv[i], (list_comparator)strcmp);
	list_dump(l, "%s\n");
	list_free(l);
}
Example #2
0
int main()
{
	node_t*a=malloc(sizeof(node_t)),*b=malloc(sizeof(node_t)),*c=0;
	list_from_integer_b(a,1342,1);
	list_from_integer_b(b,248,1);
	list_dump(a);
	list_dump(b);
	c=add_two_list_b(a,b);
	list_dump(c);
	return 0;
}
Example #3
0
int main(/*int argc, char **argv*/) {
    int v0 = 0, v1 = 1, v2 = 1, v3 = 2, v4 = 3, v5 = 5, v6 = 8, v7 = 13;
    ImmutableListNode *list = list_create(8, 
                                      0, &v0,
                                      0, &v1,
                                      0, &v2,
                                      0, &v3,
                                      0, &v4,
                                      0, &v5,
                                      0, &v6,
                                      0, &v7);
    ImmutableListNode *old;
    old = list;
    ImmutableListNode *orig = list_head(list);
    list_free(old);

    // test prepend
    printf("Testing Prepend:\n");
    printf("length before: %d\n", list->length);
    int pref = 42;
    old = list;
    list = list_prepend(list, 0, &pref);
    printf("prev->head: %p, free old: %p\n", old, list_free(old));
    printf("length after: %d\n", list->length);

    // test append
    printf("Testing Append (2x):\n");
    printf("length before: %d\n", list->length);
    int aff = 21;
    old = list;
    list = list_append(list, 0, &aff);
    printf("length after 1x: %d\n", list->length);
    old = list;
    list = list_append(list, 0, &aff);
    printf("length after 2x: %d\n", list->length);

    // test concat
    printf("Testing Concatenation:\n");
    printf("length a: %d, length b: %d\n", orig->length, list->length);
    ImmutableListNode *cattd = list_concat(orig, list);

    printf("orig: \n");
    list_dump(stdout, orig);
    printf("list: \n");
    list_dump(stdout, list);
    printf("cattd: \n");
    list_dump(stdout, cattd);

    printf("free cattd: %p\n", list_free(cattd));
    printf("free list: %p\n", list_free(list));
    printf("free orig: %p\n", list_free(orig));

    return 0;
}
Example #4
0
void dict_dump(dict_t dict, FILE * fd) {
    assert(dict != NULL);
    list_t current = list_empty();
    current = bst_to_list(dict->data, current);
    list_dump(current, fd);
    current = list_destroy(current);
}
Example #5
0
void list_dump(t_list list, t_value_displayer val_disp)
{
  if (list != NULL)
    {
      val_disp(list->value);
      list_dump(list->next, val_disp);
    }
}
Example #6
0
int main()
{	
	node_t*list=list_append(0,3);
	list_append(list,1);
	list_append(list,4);
	list_append(list,1);
	list_append(list,5);
	list_append(list,9);
	list_append(list,2);
	list_append(list,6);
	list_append(list,5);
	list_dump(list);

	sort_two_group(list,3);

	list_dump(list);	
	return 0;
}
Example #7
0
void sort_two_group(node_t*root,int arg)
{
	node_t*S=0,*s=0;
	node_t*B=0,*b=0;
	node_t*iter=0;
	iter=root;
	while(iter)
	{
		if(arg<iter->value)
		{
			printf("B:%d\n",iter->value);
			B=list_append(B,iter->value);
			list_dump(B);
		}
		else
		{
			printf("S:%d\n",iter->value);
			S=list_append(S,iter->value);
			list_dump(S);
		}
		iter=iter->next;
	}
	list_dump(S);
	list_dump(B);
	s=S;
	b=B;
	while(root)
	{
		if(s)
		{
			root->value=s->value;
			s=s->next;
		}
		else
		if(b)
		{
			root->value=b->value;
			b=b->next;
		}
		root=root->next;
	}		
}
Example #8
0
/* Dump the given 'dict' in the given file descriptor 'fd'.*/
void dict_dump(dict_t dict, FILE * fd) {

    /*Precondition verification*/
    assert(fd != NULL);
    assert(dict != NULL);

    list_t list = bst_to_list(dict->data, list_empty());
    list_dump(list, fd);
    list_destroy(list);

}
Example #9
0
void
test_list_move_first_to_middle(
		)
{
	list_type *list;
	list_type *ptr;
	
	TEST_INIT("list_move_first_to (middle)", "tsitneg");
/*	TEST_INIT("list_move_first_to (middle)", "estitng"); */
	list = create_testing();

	ptr = list_find(list, (void *) 'n');
	list = list_move_first_to(list, ptr);
printf("%s", list_dump(list));
	ptr = list_find(list, (void *) 'g');
	list = list_move_first_to(list, ptr);
printf("%s", list_dump(list));
	ptr = list_find(list, (void *) 'i');
	list = list_move_first_to(list, ptr);
printf("%s", list_dump(list));
	TEST_FINISH(list);
}
Example #10
0
int main(int argc, char **argv)
{
  int x = 1;
  int y = 2;
  int z = 3;
  
  list_node_t *list = list_create(&x);
  list_dump(list, &output);

  list = list_insert_end(list, &y);
  list_dump(list, &output);
  
  list = list_insert_beginning(list, &z);
  list_dump(list, &output);

  list = list_insert_beginning(list, &z);
  list_dump(list, &output);

  list = list_insert_after(list, &y);
  list_dump(list, &output);

  return 0;
}
Example #11
0
int main(){
	setup();

	for(int i=0; i<10; i++){
		graph_add_vertex(gp, v[i]);
	}

	graph_add_edge(gp, v[0], v[1]);
	graph_add_edge(gp, v[0], v[2]);
	graph_add_edge(gp, v[0], v[3]);
	graph_add_edge(gp, v[0], v[4]);

	graph_add_edge(gp, v[1], v[5]);
	graph_add_edge(gp, v[1], v[8]);
	graph_add_edge(gp, v[1], v[2]);

	graph_add_edge(gp, v[2], v[5]);
	graph_add_edge(gp, v[2], v[7]);

	graph_add_edge(gp, v[3], v[1]);
	graph_add_edge(gp, v[3], v[6]);
	graph_add_edge(gp, v[3], v[7]);

	graph_add_edge(gp, v[4], v[5]);

	graph_add_edge(gp, v[5], v[6]);

	graph_add_edge(gp, v[6], v[7]);

	graph_add_edge(gp, v[7], v[8]);

	graph_add_edge(gp, v[8], v[9]);

	graph_add_edge(gp, v[9], v[0]);

	graph_dump(gp, print);

	List lst;
	list_init(&lst, NULL, NULL);
	bfs(gp, v[0], &lst);
	list_dump(&lst, print_list);

	enddown();
	return 0;
}
Example #12
0
int main()
{
    list* List = list_ctor();
    list_dump(List);
    el_add(List, List -> head, 5);
    list_dump(List);
    el_add(List, List -> head, 5);
    list_dump(List);
    el_add(List, List -> head, 5);
    list_dump(List);
    el_add(List, List -> head, 5);
    list_dump(List);
    el_add(List, List -> head, 5);
    list_dump(List);
}
Example #13
0
void dbg_alts(hash_table_t * ht, char a[][BUFSIZ]) {
  uint32_t i;
  for (i = 0; i < ht->size; i++) {
    list_dump(ht->row[i]);
    printf("\n");
    list_iter(ht->row[i], &print_kv);
  }

  size_t maxlen = 0;
  for (i = 0; i < ht->size; i++) {
    size_t len = list_length(ht->row[i]);
    maxlen = len > maxlen ? len : maxlen;
    printf("%d -> %lu\n", i, len);
  }

  printf("maxlen = %lu\n", maxlen);

  for (i = 0; i < NUMA; i++) {
    printf("%d -> %s\n", i, a[i]);
  }
}
Example #14
0
void *io_handler(void *param) {
char option[OPTLEN];
while(scanf("%s", option)==1) {
if(!strcmp(option, "exit")) {
/* clean up */
printf("Terminating server...\n");
pthread_mutex_destroy(&clientlist_mutex);
close(sockfd);
exit(0);
}
else if(!strcmp(option, "list")) {
pthread_mutex_lock(&clientlist_mutex);
list_dump(&client_list);
pthread_mutex_unlock(&clientlist_mutex);
}
else {
fprintf(stderr, ANSI_COLOR_RED "Unknown command: %s...\n" ANSI_COLOR_RESET, option);
}
}
return NULL;
}
Example #15
0
/**
 * test
 */
static void list_test(void)
{
	int i = 0;
	struct list *l = list_create();
	for (i = 0; i < 20; i++) {
		list_append(l, i);
	}

	list_dump(l);

	l = list_rollback(l);

	list_dump(l);

	list_delete(l, 1);
	list_dump(l);
	list_delete(l, 0);
	list_dump(l);
	list_delete(l, 19);
        list_dump(l);

	printf("\n");

	struct list *l1 = list_create();
	for (i = 0; i < 11; i++) {
		list_append(l1, i);
	}

	list_dump(l1);

        l1 = list_rollforward(l1);

        list_dump(l1);

	printf("\n");
	
}
Example #16
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;
}
Example #17
0
void dict_dump(dict_t dict, FILE * fd) {
	assert(dict != NULL);
	
	list_dump(dict->data,fd);
}
Example #18
0
int main(int argc, char **argv)
{
	unsigned i;
	conf_t *conf;
	dict_t *repositories;
	dict_t *ports_dict;
	dict_t *not_founds;
	list_t *ports_list;
	list_t *packages;
	list_t *list;
	list_t *drivers;
	struct arguments arguments;

	arguments.action = 0;
	arguments.no_favourite_repositories = 0;
	arguments.no_locked_versions = 0;
	arguments.no_aliases = 0;
	arguments.no_colors = 0;
	arguments.no_deps = 1;
	arguments.all = 0;
	arguments.fetch_only = 0;
	arguments.no_repositories_hierarchy = 0;
	arguments.tree = 0;
	arguments.verbose = 0;
	arguments.rebuild_cache = 0;
	arguments.args = list_new();

	if (argc < 2) {
		char *fake_arg[2];
		fake_arg[0] = "ilenia";
		fake_arg[1] = "--help";
		argp_parse(&argp, 2, fake_arg, 0, 0, &arguments);
	}

	argp_parse(&argp, argc, argv, 0, 0, &arguments);

	conf = conf_init();

	if (arguments.no_repositories_hierarchy) {
		list_free(conf->repositories_hierarchy, free);
		conf->repositories_hierarchy = list_new();
	}

	if (arguments.no_favourite_repositories) {
		dict_free(conf->favourite_repositories, NULL);
		conf->favourite_repositories = dict_new();
	}

	if (arguments.no_locked_versions) {
		dict_free(conf->locked_versions, free);
		conf->locked_versions = dict_new();
	}

	if (arguments.no_aliases) {
		aliases_free(conf->aliases);
		conf->aliases = dict_new();
	}

	drivers = drivers_list_init();
	repositories = repositories_dict_init(drivers,
					      conf->repositories_hierarchy);
	if (!conf->enable_colors || arguments.no_colors)
		cprintf = uncoloredprintf;
	else
		cprintf = coloredprintf;

	if (arguments.rebuild_cache)
		cache_build(repositories);
	packages = packages_list_init();
	if ((ports_list = ports_list_init(repositories)) == NULL) {
		list_free(arguments.args, NULL);
		dict_free(repositories, repository_free);
		list_free(packages, port_free);
		list_free(drivers, free);
		dict_free(conf->favourite_repositories, free);
		conf->favourite_repositories = dict_new();
		conf_free(conf);
		return 1;
	}

	conf_reparse(conf, ports_list);
	ports_dict = ports_dict_init(ports_list, packages, conf);
	not_founds = dict_new();

	if (!arguments.verbose)
		arguments.verbose = conf->verbose;

	switch (arguments.action) {
	case ACT_LIST:
		if (!arguments.args->length) {
			list_dump(ports_list, port_dump);
			break;
		}
		for (i = 0; i < arguments.args->length; i++) {
			if (dict_get(repositories, list_get(arguments.args, i))
			    == NULL) {
				warning("repository %s not found!",
					list_get(arguments.args, i));
				continue;
			}
			list = list_query(ports_list,
					  port_query_by_repository,
					  list_get(arguments.args, i));
			list_dump(list, port_dump);
			list_free(list, NULL);
		}
		break;
	case ACT_SEARCH:
		if (!arguments.args->length) {
			warning("action --search (-s) requires at least an "
				"argument!");
			break;
		}
		for (i = 0; i < arguments.args->length; i++) {
			list = list_query(ports_list, port_query_by_name,
					  list_get(arguments.args, i));
			if (arguments.verbose)
				list_dump(list, port_info_dump);
			else
				list_dump(list, port_dump);
			if (list->length == 0)
				printf("%s not found!\n",
				       (char *)list_get(arguments.args, i));
			list_free(list, NULL);
		}
		break;
	case ACT_SEARCHDESC:
		if (!arguments.args->length) {
			warning("action --search-desc requires at least an "
				"argument!");
			break;
		}
		for (i = 0; i < arguments.args->length; i++) {
			char *key = xstrdup(list_get(arguments.args, i));
			if (isalpha(*key) && isalpha(*(key + strlen(key) - 1))) {
				strprepend(&key, "*");
				strappend(&key, "*");
			}
			list = list_query(ports_list, port_query_by_description,
					  key);
			if (arguments.verbose)
				list_dump(list, port_info_dump);
			else
				list_dump(list, port_dump);
			list_free(list, NULL);
			free(key);
		}
		break;
	case ACT_DIFF:
		port_show_diffs(ports_dict, packages);
		break;
	case ACT_UPDATED:
		port_show_outdated(ports_dict, packages);
		break;
	case ACT_DEPENDENCIES:
		if (!arguments.args->length) {
			warning("action --dependencies (-D) requires at "
				"least an argument!");
			break;
		}
		//for (i = 0; i < arguments.args->length; i++)
		dependencies_dump(arguments.args,
				  ports_dict, conf->aliases,
				  not_founds,
				  arguments.tree, arguments.verbose);
		break;
	case ACT_DEPENDENTS:
		if (!arguments.args->length) {
			warning("action --dependents (-T) requires at "
				"least an argument!");
			break;
		}
		for (i = 0; i < arguments.args->length; i++)
			dependents_dump(list_get(arguments.args, i),
					ports_dict, conf->aliases,
					arguments.tree, arguments.verbose,
					arguments.all);
		break;
	case ACT_INFO:
		if (!arguments.args->length) {
			warning("action --info requires at "
				"least an argument!");
			break;
		}
		for (i = 0; i < arguments.args->length; i++)
			info_dump(list_get(arguments.args, i), ports_dict);
		break;
	case ACT_README:
		if (!arguments.args->length) {
			warning("action --show-readme requires at "
				"least an argument!");
			break;
		}
		for (i = 0; i < arguments.args->length; i++)
			readme_dump(list_get(arguments.args, i), ports_dict);
		break;
	case ACT_REPOSITORY_LIST:
		repositories_dict_dump(repositories);
		break;
	case ACT_UPDATE:
		if (arguments.args->length)
			repositories_dict_update(repositories, arguments.args);
		else
			repositories_dict_update_all(repositories);
		break;
	case ACT_REMOVE:
		if (!arguments.args->length) {
			warning("action --remove (-R) requires at "
				"least an argument!");
			break;
		}
		remove_packages(arguments.args, packages, ports_dict, conf,
				arguments.all);
		break;
	case ACT_UPDATE_PKG:
		if (!arguments.args->length) {
			update_system(ports_dict,
				      conf->aliases, arguments.fetch_only,
				      conf->ask_for_update,
				      conf->not_found_policy);
			break;
		}
		update_package(arguments.args, ports_dict, conf,
			       arguments.fetch_only);
		break;
	default:
		if (!arguments.rebuild_cache)
			warning("What can I do for you?");
	}

	list_free(arguments.args, NULL);
	dict_free(repositories, repository_free);
	list_free(ports_list, port_free);
	list_free(packages, port_free);
	dict_free(ports_dict, NULL);
	list_free(drivers, free);
	conf_free(conf);
	dict_free(not_founds, port_free);

	return 0;
}
Example #19
0
File: M_list.c Project: proffK/iLab
int list_valide(list* lst) {

#ifndef LIST_DEBUG

    return 1;

#endif

    const int OK = 1;
    const int INVAL = 0;
    int i = 0;

    if (lst == NULL) {

        errno = ENOMEM;
        return INVAL;

    }

    if (lst -> size == 0) {

        if (lst -> tail == NULL && lst -> head == NULL)
            return OK;

        else {

            errno = EINVAL;
            list_dump(lst);
            return INVAL;

        }
    }

    if (lst -> size > 0) {

        list_elem* current_elem = lst -> tail;

        if (lst -> head == NULL || lst -> tail == NULL) {

            errno = EINVAL;
            list_dump(lst);
            return INVAL;

        }

        for (i = 0; i < lst -> size - 1; ++i) {

            if (current_elem -> next == NULL) {

                errno = EINVAL;
                list_dump(lst);
                return INVAL;

            }

            if (current_elem -> next -> prev != current_elem) {

                errno = EINVAL;
                list_dump(lst);
                return INVAL;

            }

            current_elem = current_elem -> next;

        }

        if (current_elem != lst -> head) {

            errno = EINVAL;
            list_dump(lst);
            return INVAL;

        }

        while(i--) {

            if (current_elem -> prev == NULL) {

                errno = EINVAL;
                list_dump(lst);
                return INVAL;

            }

            if (current_elem -> prev -> next != current_elem) {

                errno = EINVAL;
                list_dump(lst);
                return INVAL;

            }

            current_elem = current_elem -> prev;

        }

        if (current_elem != lst -> tail) {

            errno = EINVAL;
            list_dump(lst);
            return INVAL;

        }

        return OK;
    }

    return INVAL;
}