Esempio n. 1
0
File: aostk.c Progetto: sgh/aos
static void aostk_free_traverse(struct list_head* l) {
    struct list_head* it;
    struct aostk_widget* w;
    list_for_each(it, l) {
        w = child_to_widget(it);
        aostk_free_traverse(&w->childlist);
// 		printf("Deleting child %s\n", w->name);
        list_erase(&w->childnode);  // Remove from parent-widgets list
        list_erase(&w->widgetnode); // Remove from global widget-list
        free(w);
    }
Node* list_erase(Node* n, Node* pos) {
  if (get_next(n) == NULL) {
    std::cerr << "ERROR" << std::endl;
    exit(1);
  }
  else if (n == pos) {
    Node* next_node = get_next(n);
    if (get_elem(n) && symbolp(get_elem(n))) {
      free((n->elem_m)->symbol_m);
    }
    free(n->elem_m);
    n->elem_m = get_elem(next_node);
    n->next_m = get_next(next_node);
    free(next_node);
    return n;
  }
  else if (get_next(n) == pos) {
    n->next_m = get_next(pos);
    if (get_elem(pos) && symbolp(get_elem(pos))) {
      free((pos->elem_m)->symbol_m);
    }
    free(pos->elem_m);
    free(pos);
    return n->next_m;
  }
  else {
    return list_erase(get_next(n), pos);
  }
}
Esempio n. 3
0
int main()
{
    List *list = list_create();

    if (!list)
        std::cout << "List creation error\n";

    list_insert(list, 1);
    list_insert(list, 2);
    list_insert(list, 3);

    if (list_item_data(list_first(list)) != 3)
        std::cout << "list_insert error\n";

    list_insert_after(list, list_first(list), 4);

    if (list_item_data(list_item_next(list_first(list))) != 4)
        std::cout << "list_insert_after error\n";

    list_erase(list, list_first(list));

    if (list_item_data(list_first(list)) != 4)
        std::cout << "list_erase error\n";

    std::cout << "List: ";
    for (ListItem *item = list_first(list) ; item ; item = list_item_next(item))
    {
        std::cout << list_item_data(item) << " ";
    }
    std::cout << "\n";
    
    list_delete(list);
}
Esempio n. 4
0
//功  能: 更改定时器间隔时间并重新开始计时
//描  叙: 更改定时器间隔时间并重新开始计时
//参  数: id: 定时器ID
//		  timeInterval: 间隔时间,以毫秒为单位
//返回值: 错误返回TIMER_ERROR,正确返回TIMER_OK
int ChangeTimerTime(USHORT id, long timeInterval)
{
	if (id >= MAX_TIMER_NUMBER || timeInterval <= 0)
	{
		LOG_WRITE_POS(LOG_WARNING, "Parameter error, id=%d, max id=%d, timeInterval=%ld\n", id, MAX_TIMER_NUMBER-1, timeInterval);
		return TIMER_ERROR;
	}
	sem_wait(&g_sem);
	if (g_timerArray[id].state == 0)
	{
		LOG_WRITE_POS(LOG_WARNING, "Parameter error, id=%d, state=%d\n", id, g_timerArray[id].state);
		sem_post(&g_sem);
		return TIMER_ERROR;
	}
	
	struct timeval tv={0, 0};
	gettimeofday (&tv , NULL);
	g_timerArray[id].interval.tv_sec = timeInterval / 1000;
	g_timerArray[id].interval.tv_usec = timeInterval % 1000 * 1000;
	g_timerArray[id].tv.tv_sec = (tv.tv_sec + g_timerArray[id].interval.tv_sec)
		+ (tv.tv_usec + g_timerArray[id].interval.tv_usec) / 1000000;
	g_timerArray[id].tv.tv_usec = (tv.tv_usec + g_timerArray[id].interval.tv_usec) % 1000000;
	list_erase(&g_timerArray[id].list);
	insertTimer(id);

	sem_post(&g_sem);
	return TIMER_OK;
}
Esempio n. 5
0
int	list_uniq(t_list* list, t_func_cmp cmp, t_func_clear clear)
{
  t_node*	cur;
  t_node*	tmp;
  size_t	size;

  if (!list || !list->__head__ || !cmp)
    return (0);
  cur = list->__head__;
  size = list->__size__;
  while (cur)
    {
      tmp = list->__head__;
      while (tmp)
	if (tmp != cur && cmp(tmp->data, cur->data))
	  {
	    list_erase(list, tmp->data, clear);
	    tmp = NULL;
	  }
	else
	  tmp = tmp->next;
      cur = cur->next;
    }
  return (size == list->__size__);
}
Esempio n. 6
0
/*! \brief Release the connection's resources */
static void hc_delete(HttpConnection* connection) {
    //HttpServer* server = connection->server;

    log(INFO, "Http connection closed socket=%p", connection->sock);

    /* call the close callback if there is any */
    if(connection->close_callback != NULL) {
        connection->close_callback(connection->close_data);
    }

    /* delete the socket */
    sock_delete(connection->sock);

    /* erase the connection from the list of connections */
	list_erase(connection->it);

    /* free header */
    if(connection->header != NULL) {
        http_delete(connection->header);
        connection->header = NULL;
    }

    /* free memory */
    HttpConnection_free(connection);
}
Esempio n. 7
0
File: list.c Progetto: ASMlover/libc
element_t 
list_pop_back(list_t L)
{
  list_node_t node = (list_node_t)list_end(L);
  if (NULL != node)
    node = node->prev;
  return list_erase(L, (list_iter_t)node);
}
Esempio n. 8
0
element_t 
list_pop_back(list_t l) 
{
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  return list_erase(l, l->head.next);
}
Esempio n. 9
0
element_t 
list_pop_front(list_t l)
{
  ASSERT_LIST(l);
  ASSERT_LIST_UNDERFLOW(l);

  return list_erase(l, (&l->head)->prev);
}
Esempio n. 10
0
File: llist.c Progetto: xorver/mikro
List *list_erased(List *l)
{
  if (l->data) {
    free(l->data);
    l->data = 0;
  }
  return list_erase(l);
}
Esempio n. 11
0
int hash_erase(HashTable *table,const ListElement *element,CompareElementFuncType equal,DestroyElementFuncType destroy)
{
    unsigned int hash=0;
    assert(table && element && equal && destroy);

    hash=hash_value((*table->elmtostr_fptr)(element),table->size);
    return list_erase(&table->hashbucket[hash].list,element,equal,destroy);
}
Esempio n. 12
0
File: server.c Progetto: kaye64/gem
/**
 * Cleans up a client for exit
 */
void server_client_cleanup(server_t* server, client_t* client)
{
	ev_io_stop(server->io_loop, &client->io_read);
	list_erase(&server->client_list, &client->node);
	object_free(&client->read_buffer);
	object_free(&client->write_buffer);
	server->drop_cb(client, server);
	close(client->fd);
}
Esempio n. 13
0
int32_t list_remove(struct list *l,void *v)
{
    assert(l);
    struct list_iter it = list_find(l,v);
    if(it.n == 0)
        return 0;
    list_erase(l,it);
    return 1;
}
Esempio n. 14
0
void dsdict_remove(dsdict* dict, const char* key) {
	dsdict_node* node = dsdict_iter(dict, key);

	if (node) {
		dfree(node->key);
		dfree(node->value);
		list_erase(dict, node);
		free(node);
	}
}
Esempio n. 15
0
int del_listRead(st_sock* sts, s_link *pslink)
{
	sem_wait(&sts->semListRead);
	if (!list_empty(&sts->stIDListMsgRead[pslink->id].list))
	{
		list_erase(&sts->stIDListMsgRead[pslink->id].list);
		//list_init(&sts->stIDListMsgRead[pslink->id].list);
	}
	sem_post(&sts->semListRead);
	return EX_UDP_OK;
}
Esempio n. 16
0
File: k9.c Progetto: hpersh/k9
static void
task_ev_wait_erase(struct k9_task * const task)
{
  struct k9_ev_wait_desc *w;
  unsigned                n;
  
  for (w = task->u->blocked->ev->wait, n = task->u->blocked->ev->nwait; n; --n, ++w) {
    list_erase(w->list_node);
  }
  
  tmout_erase(task);
}
Esempio n. 17
0
void 
list_clear(list_t l) 
{
  list_node_t iter, node;
  ASSERT_LIST(l);

  iter = l->head.next;
  while (iter != &l->head) {
    node = iter;
    iter = iter->next;
    list_erase(l, iter);
  }
  l->size = 0;
}
Esempio n. 18
0
/**
 * Opens a directory in cache fs form (ie. client cached index + data files)
 */
int cache_open_fs_dir(cache_t* cache, const char* directory)
{
	DIR *dir = opendir(directory);
	struct dirent *entry;
	int num_indices = 0;

	sorted_list_t* index_list = object_new(sorted_list);
	index_list->compare_func = strcmp_wrap;
	if (dir == NULL) {
		return 1;
	}

	char data_file[256];
	while ((entry = readdir(dir)) != NULL) {
		if (strstr(entry->d_name, "idx")) {
			index_list_node_t* node = (index_list_node_t*)malloc(sizeof(index_list_node_t));
			strcpy(node->index, entry->d_name);
			sorted_list_insert(index_list, &node->node);
			num_indices++;
		} else if (strstr(entry->d_name, "dat")) {
			sprintf(data_file, "%s/%s", directory, entry->d_name);
		}
	}

	if (data_file == NULL || num_indices == 0) {
		return 1;
	}

	char** index_files = (char**)malloc(sizeof(char*)*num_indices);
	int i = 0;
	while (!list_empty(&index_list->list)) {
		list_node_t* node = list_front(&index_list->list);
		index_list_node_t* index_node = container_of(node, index_list_node_t, node);
		index_files[i] = (char*)malloc(sizeof(char)*256);
		sprintf(index_files[i++], "%s/%s", directory, (char*)index_node->index);
		list_erase(&index_list->list, node);
		free(index_node);
	}
	object_free(index_list);
	closedir(dir);

	cache_open_fs(cache, num_indices, (const char**)index_files, data_file);

	for (int i = 0; i < num_indices; i++) {
		free(index_files[i]);
	}
	free(index_files);

	return 0;
}
Esempio n. 19
0
File: menu.c Progetto: glankk/gz
void menu_item_remove(struct menu_item *item)
{
  if (!item->destroy_proc || !item->destroy_proc(item)) {
    if (item->imenu) {
      menu_destroy(item->imenu);
      free(item->imenu);
    }
    if (item->text)
      free(item->text);
    if (item->data)
      free(item->data);
  }
  menu_deselect(item->owner, item);
  list_erase(&item->owner->items, item);
}
Esempio n. 20
0
int main() {
    char* first = malloc(sizeof(char));
    *first = 'b';

    char* second = malloc(sizeof(char));
    *second = 'o';

    char* third = malloc(sizeof(char));
    *third = 'n';

    char* fourth = malloc(sizeof(char));
    *fourth = 'v';

    char* fifth = malloc(sizeof(char));
    *fifth = 'h';

    char* sixth = malloc(sizeof(char));
    *sixth = 'a';

    char* seventh = malloc(sizeof(char));
    *seventh = 'm';

    char* eighth = malloc(sizeof(char));
    *eighth = 'X';

    list l1 = NULL;
    list_init(&l1, first);
    list_append(&l1, second);
    list_append(&l1, third);
    list_append(&l1, fourth);

    list l2 = list_new();
    list_append(&l2, fifth);
    list_append(&l2, sixth);
    list_append(&l2, seventh);
    list_append(&l2, eighth);

    list_extend(&l1, &l2);

    list_erase(&l1, list_find(l1, 'X'));
    list_remove(&l1, 'v');

    list_print(l1);

    return list_delete(l1);
}
Esempio n. 21
0
File: list.c Progetto: ASMlover/libc
void 
list_clear(list_t L, void (*destroy)(void*))
{
  list_node_t it, node;
  element_t   data;

  if (NULL == L)
    return;

  it = L->node.next;
  while (it != &L->node) {
    node = it;
    it   = it->next;
    data = list_erase(L, (list_iter_t)node);
    if (NULL != destroy)
      destroy(data);
  }
}
Esempio n. 22
0
//功  能: 关闭对应id的定时器
//描  叙: 关闭对应id的定时器任务
//参  数: id: 设置新定时器时返回的id值
//返回值: 无
void KillTimer(USHORT id)
{
	if (id >= MAX_TIMER_NUMBER)
	{
		LOG_WRITE_POS(LOG_NOTICE, "Parameter error, id=%d, max id=%d\n", id, MAX_TIMER_NUMBER-1);
		return;
	}
	sem_wait(&g_sem);
	if (g_timerArray[id].state == 0)
	{
		LOG_WRITE_POS(LOG_NOTICE, "Parameter error, id=%d, state=%d\n", id, g_timerArray[id].state);
		sem_post(&g_sem);
		return;
	}
	list_erase(&g_timerArray[id].list);
	g_timerArray[id].state = 0;
	list_push_back(&g_listTimerFree, &g_timerArray[id].list);
	printf_debug3("KillTimer  id=%d\n", id) ;
	sem_post(&g_sem);
	return;
}
Esempio n. 23
0
File: k9.c Progetto: hpersh/k9
int
k9_task_delete(struct k9_task *task)
{
  uint32   old;
  unsigned f = 0;

  task = task_or_self(task);

  old = k9_cpu_intr_dis();

  switch (task->state) {
  case K9_TASK_STATE_STOPPED:
  case K9_TASK_STATE_EXITED:
  case K9_TASK_STATE_FAULTED:
    break;

  default:
    return (-1);
  }

  list_erase(task->list_node);

  k9_cpu_intr_restore(old);
}
Esempio n. 24
0
static void List_dispose(List *self) {
    list_erase(self,self->first,NULL);
}
Esempio n. 25
0
File: llist.c Progetto: xorver/mikro
void list_pop_back(List *l)
{
  list_erase(list_back(l));
}
Esempio n. 26
0
File: llist.c Progetto: xorver/mikro
void list_pop_front(List *l)
{
  list_erase(list_front(l));
}
Esempio n. 27
0
File: list.c Progetto: ASMlover/libc
element_t 
list_pop_front(list_t L)
{
  return list_erase(L, list_begin(L));
}
Esempio n. 28
0
File: llist.c Progetto: xorver/mikro
void list_remove(List *l, void *data)
{
  List *l2;
  while ((l2 = list_find(l, data)))
    l = list_erase(l2); 
}
Esempio n. 29
0
int test_run (void)
   {
   SCL_list_t       list;
   SCL_iterator_t   iterator;

   void*   data;
   int     stat;
   int     i;

   printf ("Create list: ");
   fflush (stdout);
   list = list_new();
   printf ("(%p = list_new()) != NULL ....... ", list);
   fflush (stdout);
   printf ("%s\n", ((list!=NULL) ? "PASS" : "FAIL"));

   printf ("Push data in back list.\n");
   for (i=0 ; i<LIST1_SIZE ; i++)
      {
      stat = list_push_back (list, (void*)g_data1[i]);
      printf (
             "([%d,%s] = list_push_back (list, data[%d]) .... %s\n",
             stat, scl_statstr(stat), i, ((stat==SCL_OK) ? "PASS" : "FAIL")
             );
      }

   printf (
          "%2ld = list_count (list) .......................... %s\n",
          list_count(list), ((list_count(list)==LIST1_SIZE) ? "PASS" : "FAIL")
          );

   printf ("Foreach on list.\n");
   for (i=0 ; i<LIST1_SIZE ; i++) g_flag1[i] = 0;
   list_foreach (list, cbfn1, NULL);

   printf ("Insert data in list before 2 using iterator.\n");
   iterator = list_at (list, 2);
   printf ("%p = list_at (list, 2);\n", iterator);
   stat = list_insert_before (list, iterator, (void*)0x0101);
   printf (
          "[%d,%s] = list_insert_before (list, iterator=>%p, %08X);\n",
          stat, scl_statstr(stat), iterator, 0x0101
          );

   printf ("Insert data in list after 3 using iterator.\n");
   iterator = list_at (list, 3);
   printf ("%p = list_at (list, 3);\n", iterator);
   stat = list_insert_after (list, iterator, (void*)0xAAAAAAAA);
   printf (
          "[%d,%s] = list_insert_after (list, iterator=>%p, %08X);\n",
          stat, scl_statstr(stat), iterator, 0xAAAAAAAA
          );

   printf (
          "%2ld = list_count (list) .......................... %s\n",
          list_count(list), ((list_count(list)==LIST2_SIZE) ? "PASS" : "FAIL")
          );

   printf ("Foreach on list.\n");
   for (i=0 ; i<LIST2_SIZE ; i++) g_flag2[i] = 0;
   list_foreach (list, cbfn2, NULL);

   printf ("REVERSE the list.\n");
   list_reverse (list);

   printf (
          "%2ld = list_count (list) .......................... %s\n",
          list_count(list), ((list_count(list)==LIST3_SIZE) ? "PASS" : "FAIL")
          );

   printf ("Foreach on list.\n");
   for (i=0 ; i<LIST3_SIZE ; i++) g_flag3[i] = 0;
   list_foreach (list, cbfn3, NULL);

   printf ("Erase list.\n");
   list_erase (list);

   printf (
          "%2ld = list_count (list) .......................... %s\n",
          list_count(list), ((list_count(list)==0) ? "PASS" : "FAIL")
          );

   printf ("Delete list.\n");
   list_del (list);

   printf ("\n");

   return 0;
   }
Esempio n. 30
0
void stack_pop(Stack *stack)
{
	List *tmp = stack->list;
	list_erase(tmp, list_first(stack->list));
}