Exemplo n.º 1
0
static void
list_memfree(void* value)
{

	if (!value){
		cl_log(LOG_ERR,
		       "value is NULL");
		return ;
	}
	
	list_cleanup(value);	
	
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: remij/c
int main(void) {

  list_t *list = NULL;
  
  printf("----- Print add elements  -----\n");
  list_add_node_front(&list, "J");
  list_add_node_front(&list, "I");
  list_add_node_front(&list, "H");
  list_add_node_front(&list, "G");
  list_add_node_front(&list, "F");
  list_add_node_front(&list, "E");
  list_add_node_front(&list, "D");
  list_add_node_front(&list, "C");
  list_add_node_front(&list, "B");
  list_add_node_front(&list, "A");

  printf("----- Print list -----\n");
  list_print(list, print_callback);

  printf("----- Access elements -----\n");
  printf("The element number %u of the list is %s\n", 0, (char *)list_get_node_by_id(list, 0));
  printf("The element number %u of the list is %s\n", 1, (char *)list_get_node_by_id(list, 1));
  printf("The element number %u of the list is %s\n", 5, (char *)list_get_node_by_id(list, 5));
  printf("The element number %u of the list is %s\n", 9, (char *)list_get_node_by_id(list, 9));
  // The last id is 9 so 10 is out of range
  printf("The element number %u of the list is %s\n", 10,(char *)list_get_node_by_id(list, 10));

  printf("----- Delete last element -----\n");
  list_del_node_by_id(&list, 9);
  printf("----- Print list -----\n");
  list_print(list, print_callback);

  printf("----- Delete first element -----\n");
  list_del_node_by_id(&list, 0);
  printf("----- Print list -----\n");
  list_print(list, print_callback);

  uint32_t size = list_get_size(list);
  printf("----- Size of the list: %u -----\n", size);
  printf("----- Delete all element -----\n");
  uint32_t i;
  for (i = 0; i < size ; i++) {
    list_del_node_by_id(&list, 0);
  }
  printf("----- Print list -----\n");
  list_print(list, print_callback);

  list_add_node_back(&list, "A");
  list_add_node_back(&list, "B");
  list_add_node_back(&list, "C");
  list_add_node_back(&list, "D");

  printf("----- Print list -----\n");
  list_print(list, print_callback);

  printf("----- Reverse the list -----\n");
  list_reverse_order(&list);

  printf("----- Print list -----\n");
  list_print(list, print_callback);

  printf("----- Clean list -----\n");
  list_cleanup(&list);

  i = 0;
  while (1) {
    list_add_node_back(&list, "A");
    printf("add_elem %u\n", i);
    ++i;
  }
  return (0);
}
Exemplo n.º 3
0
//Free a list of jump blocks properly
void jump_block_list_cleanup (jump_block* to_cleanup, char scrub_insn)
{
	list_cleanup (to_cleanup, cleanup_jump_block, scrub_insn);
}
Exemplo n.º 4
0
/* 
   this is reverse process of pack_string_list
*/
GList* 
string_list_unpack(const char* packed_str_list, size_t length)
{
	GList*		list = NULL;
	const char*	psl = packed_str_list;
	const char *	maxp= packed_str_list + length;
	int		len = 0;
	
	
	while(TRUE){
		char* buf;

		if (*psl == '\0' || psl >=  maxp){
			break;
		}
		
		if (sscanf( psl, "%d:", &len) <= 0 ){
			break;
		}
		
		if (len <=0){
			cl_log(LOG_ERR, "unpack_string_list:"
			       "reading len of string error");
			if (list){
				list_cleanup(list);
			}
			return NULL;
		}
		
		while (*psl != ':' && *psl != '\0' ){
			psl++;
		}
		
		if (*psl == '\0'){
			break;
		}
		
		psl++;
		
		buf = cl_malloc(len + 1);
		if (buf == NULL){
			cl_log(LOG_ERR, "unpack_string_list:"
			       "unable to allocate buf");
			if(list){
				list_cleanup(list);
			}
			return NULL;			
			
		}
		memcpy(buf, psl, len);
		buf[len] = '\0';
		list = g_list_append(list, buf);
		psl +=len;
		
		if (*psl != ','){
			cl_log(LOG_ERR, "unpack_string_list:"
			       "wrong format, s=%s",packed_str_list);	
		}
		psl++;
	}
	
	return list;

}