void test__hash_multiset_insert_varg__libcstl_builtin_not_equal(void** state)
{
    hash_multiset_t* pt_hash_multiset = _create_hash_multiset("list_t<int>");
    hash_multiset_iterator_t it_iter;
    list_t* plist = create_list(int);
    int i = 0;

    hash_multiset_init_ex(pt_hash_multiset, 0, _test__hash_private__libcstl_builtin_hash, NULL);
    list_init(plist);

    for(i = 0; i < 10; i++)
    {
        list_clear(plist);
        list_push_back(plist, i * 2);
        _hash_multiset_insert(pt_hash_multiset, plist);
    }

    list_clear(plist);
    list_push_back(plist, 5);
    it_iter = _hash_multiset_insert(pt_hash_multiset, plist);
    assert_true(*(int*)list_front((list_t*)_hash_multiset_iterator_get_pointer(it_iter)) == 5);
    assert_true(hash_multiset_size(pt_hash_multiset) == 11);

    hash_multiset_destroy(pt_hash_multiset);
    list_destroy(plist);
}
void test__hash_multiset_count__hash_multiset_count_varg__libcstl_builtin_n(void** state)
{
    hash_multiset_t* pt_hash_multiset = _create_hash_multiset("list_t<int>");
    list_t* plist = create_list(int);
    int i = 0;

    hash_multiset_init_ex(pt_hash_multiset, 0, _test__hash_private__libcstl_builtin_hash, NULL);
    list_init(plist);

    for(i = 0; i < 10; i++)
    {
        list_clear(plist);
        list_push_back(plist, i);
        hash_multiset_insert(pt_hash_multiset, plist);
        hash_multiset_insert(pt_hash_multiset, plist);
        hash_multiset_insert(pt_hash_multiset, plist);
    }

    list_clear(plist);
    list_push_back(plist, 6);
    assert_true(_hash_multiset_count(pt_hash_multiset, plist) == 3);

    hash_multiset_destroy(pt_hash_multiset);
    list_destroy(plist);
}
void test__hash_multiset_equal_range__hash_multiset_equal_range_varg__libcstl_builtin_equal(void** state)
{
    hash_multiset_t* pt_hash_multiset = _create_hash_multiset("list_t<int>");
    range_t r_range;
    list_t* plist = create_list(int);
    int i = 0;

    hash_multiset_init_ex(pt_hash_multiset, 0, _test__hash_private__libcstl_builtin_hash, NULL);
    list_init(plist);

    for(i = 0; i < 10; i++)
    {
        list_clear(plist);
        list_push_back(plist, i);
        hash_multiset_insert(pt_hash_multiset, plist);
    }

    list_clear(plist);
    list_push_back(plist, 6);
    r_range = _hash_multiset_equal_range(pt_hash_multiset, plist);
    assert_true(*(int*)list_front((list_t*)iterator_get_pointer(r_range.it_begin)) == 6);
    assert_true(*(int*)list_front((list_t*)iterator_get_pointer(r_range.it_end)) == 7);

    hash_multiset_destroy(pt_hash_multiset);
    list_destroy(plist);
}
void test__hash_multiset_equal_range__hash_multiset_equal_range_varg__libcstl_builtin_greater(void** state)
{
    hash_multiset_t* pt_hash_multiset = _create_hash_multiset("list_t<int>");
    range_t r_range;
    list_t* plist = create_list(int);
    int i = 0;

    hash_multiset_init_ex(pt_hash_multiset, 0, _test__hash_private__libcstl_builtin_hash, NULL);
    list_init(plist);

    for(i = 0; i < 10; i++)
    {
        list_clear(plist);
        list_push_back(plist, i * 2);
        hash_multiset_insert(pt_hash_multiset, plist);
    }

    list_clear(plist);
    list_push_back(plist, 5);
    r_range = _hash_multiset_equal_range(pt_hash_multiset, plist);
    assert_true(iterator_equal(r_range.it_begin, hash_multiset_end(pt_hash_multiset)));
    assert_true(iterator_equal(r_range.it_end, hash_multiset_end(pt_hash_multiset)));

    hash_multiset_destroy(pt_hash_multiset);
    list_destroy(plist);
}
void test__hash_multiset_find__hash_multiset_find_varg__libcstl_builtin_not_find(void** state)
{
    hash_multiset_t* pt_hash_multiset = _create_hash_multiset("list_t<int>");
    hash_multiset_iterator_t it_iter;
    list_t* plist = create_list(int);
    int i = 0;

    hash_multiset_init_ex(pt_hash_multiset, 0, _test__hash_private__libcstl_builtin_hash, NULL);
    list_init(plist);

    for(i = 0; i < 10; i++)
    {
        list_clear(plist);
        list_push_back(plist, i);
        hash_multiset_insert(pt_hash_multiset, plist);
    }

    list_clear(plist);
    list_push_back(plist, 96);
    it_iter = _hash_multiset_find(pt_hash_multiset, plist);
    assert_true(iterator_equal(it_iter, hash_multiset_end(pt_hash_multiset)));

    hash_multiset_destroy(pt_hash_multiset);
    list_destroy(plist);
}
示例#6
0
_export bool module_finit() {
	unregister_packet_handler(D2GS_RECEIVED, 0x9c, d2gs_item_action);
	
	unregister_packet_handler(D2GS_RECEIVED, 0x15, d2gs_char_location_update);
	unregister_packet_handler(D2GS_RECEIVED, 0x95, d2gs_char_location_update);
	unregister_packet_handler(D2GS_SENT, 0x0c, d2gs_char_location_update);

	unregister_packet_handler(D2GS_RECEIVED, 0x19, d2gs_gold_update);
	unregister_packet_handler(D2GS_RECEIVED, 0x1d, d2gs_gold_update);
	unregister_packet_handler(D2GS_RECEIVED, 0x1e, d2gs_gold_update);
	unregister_packet_handler(D2GS_RECEIVED, 0x1f, d2gs_gold_update);
	//unregister_packet_handler(D2GS_RECEIVED, 0x20, d2gs_gold_update);

	//unregister_packet_handler(INTERNAL, 0x9c, internal_trigger_pickit);
	
	list_clear(&items);
	list_clear(&valuable);
	list_clear(&nolog);

	pthread_mutex_destroy(&items_m);

	ui_add_statistics_plugin("pickit", "attempts to pick items: %i\n", n_attempts);
	ui_add_statistics_plugin("pickit", "picked items: %i (%i%%)\n", n_picked, PERCENT(n_attempts, n_picked));

	return TRUE;
}
示例#7
0
文件: list3.c 项目: etoestja/inf
void destroy()
{
    list_clear(a);
    list_clear(b);
    free(a);
    free(b);
    a = b = NULL;
}
示例#8
0
void map_destroy(map *m, void (*destroy_callback)(void*))
{
    if(!m)
        return;

    list_clear(&m->keys, &free);
    list_clear(&m->values, destroy_callback);
    free(m);
}
示例#9
0
void multirom_ui_tab_misc_destroy(void *data)
{
    tab_data_misc *t = (tab_data_misc*)data;

    list_clear(&t->ui_elements, &fb_remove_item);
    list_clear(&t->buttons, &button_destroy);

    free(t);
}
示例#10
0
void afd_free(struct afd *afd)
{
	list_clear(&afd->st);
	list_clear(&afd->stf);
	list_clear(&afd->alfa);
	list_clear_func(&afd->trans, afd_free_tran);
	
	free(afd);
}
示例#11
0
文件: cplusplus.c 项目: spchamp/ilu
/* makes up an interface_header_translation_list based on what's in
   InterfaceHeaderTranslationFile. Each entry in the list consists of
   the two null terminated names in one buffer e.g. fromname\0toname\0  
   - added by Dan Larner
*/ 
static list make_header_translation_list(char* pc_translation_file_name) {

  char  trans_delims[4] = {' ', '\t', '\n', '\0'};
  list  list_translations;
  FILE* pfile_translations;
  char* pc_translation_line;
  char* pc_from_name;
  char* pc_to_name;
  char* pc_list_entry;

  /* open up the file */
  if ((pfile_translations = fopen(pc_translation_file_name, "r")) == NULL)
  	return NULL;

  /* make a new empty list */
  list_translations = (list) new_list();
  list_clear (list_translations, FALSE);

  /* get some space to read lines into */
  pc_translation_line = (char*) iluparser_Malloc(256);

  /* read in a line at a time, creating the pairs - anything bad and we bomb */
  while (fgets(pc_translation_line, 256, pfile_translations) != NULL) {

	 /* ignore comment lines and simple spacing */
	 if ((pc_translation_line[0] == '#') || (pc_translation_line[0] == '\n'))
	 	continue;

  	 /* get the names */
	 pc_from_name = strtok(pc_translation_line, trans_delims);
	 pc_to_name = strtok(NULL, trans_delims);

	 if ((pc_from_name == NULL) || (pc_to_name == NULL)) { 
	 	/* some problem reading the names cleanup and return failure */
		list_clear (list_translations, TRUE);
		iluparser_Free(list_translations);
		iluparser_Free(pc_translation_line);
		fclose(pfile_translations);
		return NULL;
	 }

   /* make an entry to hold the two names, and add it to the list 
      note that an entry is two null terminated strings next to each other */
   pc_list_entry = iluparser_Malloc(strlen(pc_from_name) + strlen(pc_to_name) + 2);
   strcpy (pc_list_entry, pc_from_name);
   strcpy (pc_list_entry + strlen(pc_from_name) + 1, pc_to_name);
   list_insert(list_translations, pc_list_entry);
   
  } /* end while */

  /* cleanup */
  iluparser_Free(pc_translation_line);
  fclose(pfile_translations);

  return list_translations;
}
示例#12
0
int		libanio_fdesc_close(t_fdesc *fdesc)
{
  list_clear(&fdesc->readbuf);
  list_clear(&fdesc->writebuf);
  fdesc->closed = 1;
  if (fdesc->fd == -1)
    return (-1);
  close(fdesc->fd);
  return (0);
}
示例#13
0
文件: visitor.c 项目: entwanne/BNF
void bnf_free_visitor(bnf_visitor_t* visitor)
{
  if (visitor)
    {
      list_clear(&visitor->rules);
      list_clear(&visitor->states);
      list_clear(&visitor->next_states);
    }
  free(visitor);
}
示例#14
0
文件: prstat.c 项目: andreiw/polaris
static void
Exit()
{
	curses_off();
	list_clear(&lwps);
	list_clear(&users);
	list_clear(&tasks);
	list_clear(&projects);
	list_clear(&zones);
	fd_exit();
}
/*
====================================================================
Clear all client data.
====================================================================
*/
void client_data_clear( void )
{
    list_clear( client_users );
    client_user = 0;
    list_clear( client_channels );
    list_clear( client_levelsets );
    client_levelset = 0;
    gui_list_update( list_users, 0 );
    gui_list_update( list_channels, 0 );
    gui_list_update( list_levels, 0 );
}
示例#16
0
void	client_shutdown(t_client *client)
{
  printf_log("Client %s:%d disconnected", client->ip, client->port);
  close(client->socket);
  free(client->ip);
  if (client->receiver)
    client->receiver->destroy(client->receiver);
  list_clear(&client->inbound, true);
  list_clear(&client->outbound, true);
  list_remove(&g_server.network.pool.nodes, client, true);
}
示例#17
0
文件: rdimpl.c 项目: andreiw/polaris
void
monitor_stop()
{
	/* store the list state */
	if (ltdb_file != NULL)
		(void) list_store(ltdb_file);
	list_clear(&lwps);
	list_clear(&processes);
	list_clear(&users);
	list_clear(&projects);
	fd_exit();
}
示例#18
0
int		session_destroy(void)
{
  t_session	*session;

  logger_message("[SESSION] Stop session service");
  session = session_get_session();
  list_foreach(&(session->in), &delete_instruction_in);
  list_clear(&(session->in));
  list_foreach(&(session->out), &delete_instruction_out);
  list_clear(&(session->out));
  return (0);
}
示例#19
0
文件: db.c 项目: AdUser/xa-tags
/** return values:
 * 0 - all ok
 * 1 - more data expected
 * 2 - error
 */
int
db_tags_find(const char *str, query_limits_t *lim, list_t *results)
{
#ifdef UNIQ_TAGS_LIST
  sqlite3_stmt *stmt = NULL;
  char buf[PATH_MAX]; /* not exactly 'path', but size should be reasonable */
  char *p = NULL;
  size_t len = 0;
  int ret = 0;

  ASSERT(str != NULL && lim != NULL && results != NULL, MSG_M_NULLPTR);

  len = strlen(SQL_T_FIND);
  if (sqlite3_prepare_v2(db_conn, SQL_T_FIND, len, &stmt, NULL) != SQLITE_OK)
    {
      msg(msg_warn, COMMON_ERR_FMTN, MSG_D_FAILPREPARE, sqlite3_errmsg(db_conn));
      return 2;
    }

  if (results != NULL)
    list_clear(results);

  strncpy(buf, str, PATH_MAX);
  for (p = buf; *p != '\0'; p++)
    if (*p == '*') *p = '%';

  sqlite3_bind_text(stmt, 1, buf, len, SQLITE_TRANSIENT);
  sqlite3_bind_int(stmt, 2, lim->limit);
  sqlite3_bind_int64(stmt, 3, lim->offset);

  while ((ret = sqlite3_step(stmt)) == SQLITE_ROW)
    {
      len = snprintf(buf, PATH_MAX, "%s", (char *) sqlite3_column_text(stmt, 0));
      list_item_add(results, buf, len);
      lim->offset++;
    }

  if (ret != SQLITE_DONE)
    {
      msg(msg_warn, COMMON_ERR_FMTN, MSG_D_FAILEXEC, sqlite3_errmsg(db_conn));
      sqlite3_finalize(stmt);
      list_clear(results);
      return 2;
    }

  sqlite3_finalize(stmt);

  return (results->items == MAX_QUERY_LIMIT) ? 1 : 0;
#else
  return 0;
#endif
}
示例#20
0
_export bool module_finit() {
	unregister_packet_handler(MCP_RECEIVED, 0x07, mcp_charlogon_handler);
	unregister_packet_handler(MCP_RECEIVED, 0x03, mcp_creategame_handler);
	unregister_packet_handler(MCP_RECEIVED, 0x04, mcp_joingame_handler);
	unregister_packet_handler(INTERNAL, D2GS_ENGINE_MESSAGE, on_d2gs_shutdown);

	unregister_packet_handler(INTERNAL, MCP_ENGINE_MESSAGE, on_mcp_cleanup);

	unregister_packet_handler(MCP_RECEIVED, 0x05, mcp_gamelist_handler);

	struct iterator it = list_iterator(&setting_cleaners);
	setting_cleanup_t *sc;
	while ((sc = iterator_next(&it))) {
		sc->cleanup(sc->set);
	}

	list_clear(&setting_cleaners);

	if (keyset) {
		free(keyset);
		keyset = NULL;
		n_keyset = 0;
		i_keyset = 0;
		rotated = FALSE;
	}

	pthread_cond_destroy(&game_created_cond_v);
	pthread_cond_destroy(&game_joined_cond_v);
	pthread_cond_destroy(&mcp_char_logon_cond_v);
	pthread_cond_destroy(&d2gs_engine_shutdown_cond_v);

	pthread_mutex_destroy(&game_created_mutex);
	pthread_mutex_destroy(&game_joined_mutex);
	pthread_mutex_destroy(&mcp_char_logon_mutex);
	pthread_mutex_destroy(&d2gs_engine_shutdown_mutex);

	pthread_mutex_destroy(&mcp_cleanup_m);
	pthread_cond_destroy(&mcp_cleanup_cv);

	pthread_mutex_destroy(&pub_m);
	pthread_cond_destroy(&pub_cv);

	list_clear(&public_games);

	ui_add_statistics_plugin("mcp game", "games created: %i\n", n_created);
	if (module_setting("JoinPublicGames")->b_var) ui_add_statistics_plugin("mcp game", "public games joined: %i\n", n_joined);
	ui_add_statistics_plugin("mcp game", "failed to join: %i (%i%%)\n", ftj, PERCENT(n_created, ftj));

	return TRUE;
}
示例#21
0
int main()
{
  int ret = 0;
  list_t terms;
  search_t search;

  SIGCATCH_INIT

  memset(&terms, 0x0, sizeof(list_t));
  memset(&search, 0x0, sizeof(search_t));

  /* simple match */
  list_item_add(&terms, "alice", 0);
  list_item_add(&terms, "mary", 0);

  ret = search_parse_terms(&search, &terms);
  assert(ret == 0);

  assert(search_match_substr(&search, "test1 test2 test3") == 0);
  assert(search_match_substr(&search, " alice mary ") == 1);
  assert(search_match_substr(&search, " alice rose ") == 0);
  assert(search_match_substr(&search, " alice mary bob") == 1);
  assert(search_match_substr(&search, " alice rosemary ") == 1);
  assert(search_match_substr(&search, " alice rosemary bob ") == 1);

  list_clear(&terms);
  search_free(&search);

  /* more complex examples */
  list_item_add(&terms, "alice", 0);
  assert(search_parse_terms(&search, &terms) == 0);
  assert(search_match_substr(&search, " alice ") == 1);
  assert(search_match_substr(&search, "malice") == 1);
  assert(search_match_substr(&search, " mary ") == 0);
  list_clear(&terms);
  search_free(&search);

  list_item_add(&terms, "~mary", 0);
  assert(search_parse_terms(&search, &terms) == 0);
  assert(search_match_substr(&search, " alice ") == 1);
  assert(search_match_substr(&search, " mary ") == 0);
  assert(search_match_substr(&search, "mary") == 0);
  assert(search_match_substr(&search, "rosemary") == 0);
  assert(search_match_substr(&search, " rosemary ") == 0);
  list_clear(&terms);
  search_free(&search);

  return 0;
}
示例#22
0
int button_keyaction_call(void *data, int act)
{
    button *b = data;
    switch(act)
    {
        case KEYACT_UP:
        case KEYACT_DOWN:
        case KEYACT_CLEAR:
        {
            if(act != KEYACT_CLEAR && b->keyact_frame == NULL)
            {
                fb_add_rect_notfilled(b->level_off + LEVEL_RECT, b->x, b->y, b->w, b->h, C_KEYACT_FRAME, KEYACT_FRAME_W, &b->keyact_frame);
                fb_request_draw();
                return 0;
            }
            else
            {
                list_clear(&b->keyact_frame, &fb_remove_item);
                fb_request_draw();
                return (act == KEYACT_CLEAR) ? 0 : 1;
            }
        }
        case KEYACT_CONFIRM:
        {
            if(b->clicked && !(b->flags & BTN_DISABLED))
                (*b->clicked)(b->action);
            return 0;
        }
        default:
            return 0;
    }
}
示例#23
0
文件: hdata_set.c 项目: hailongz/c
/**
 return item count
 */
hlist_t hdata_set_sort(hdata_set_t data_set, list_compare_t comparator ,hany param,InvokeTickDeclare){
	data_set_t *ds = (data_set_t *)data_set;
	if(ds && comparator){
		hdata_t items = ext_data(ds->data);
		hdata_t item;
		hint32 i,c;
		c = hdata_array_size(ext_data_class(ds->data), items);
		if(c >0){
			if(ds->items==NULL){
				ds->items = list_alloc( c, 20);
			}
			else{
				list_clear(ds->items);
			}
			for(i=0;i<c;i++){
				item = hdata_array(ext_data_class(ds->data),items,i);
				if(comparator){
					list_add_and_order(ds->items, item, comparator, param);
				}
				else{
					list_add(ds->items,item);
				}
			}
		}
		
		return ds->items;
	}
	return NULL;
}
示例#24
0
文件: skills.c 项目: liwcezar/atrinik
/**
 * Reload the skills list, due to a change of the skill type, for example.
 */
static void skill_list_reload(void)
{
    size_t i;
    uint32_t offset, rows, selected;

    if (!list_skills) {
        return;
    }

    offset = list_skills->row_offset;
    selected = list_skills->row_selected;
    rows = list_skills->rows;
    list_clear(list_skills);

    for (i = 0; i < skill_list_num; i++) {
        list_add(list_skills, list_skills->rows - (i % list_skills->cols == 0 ? 0 : 1), i % list_skills->cols, NULL);
    }

    if (list_skills->rows == rows) {
        list_skills->row_offset = offset;
        list_skills->row_selected = selected;
    }

    cur_widget[SKILLS_ID]->redraw = 1;
}
示例#25
0
/* ------------------------------------------------------------------------- */
void
list_destroy(struct list_t* list)
{
    assert(list);
    list_clear(list);
    FREE(list);
}
示例#26
0
文件: list.c 项目: atrinik/atrinik
/**
 * Remove the specified list from the linked list of visible lists and
 * deinitialize it.
 * @param list
 * List to remove.
 */
void list_remove(list_struct *list)
{
    uint32_t col;

    if (!list) {
        return;
    }

    if (list->data) {
        efree(list->data);
    }

    list_clear(list);

    efree(list->col_widths);
    efree(list->col_spacings);
    efree(list->col_centered);

    /* Free column names. */
    for (col = 0; col < list->cols; col++) {
        if (list->col_names[col]) {
            efree(list->col_names[col]);
        }
    }

    if (list->font != NULL) {
        font_free(list->font);
    }

    efree(list->col_names);
    efree(list);
}
示例#27
0
int main()
{
  int ret = 0;
  list_t terms;
  search_t search;

  SIGCATCH_INIT

  memset(&terms, 0x0, sizeof(list_t));
  memset(&search, 0x0, sizeof(search_t));

  /* simple match */
  list_item_add(&terms, "alice", 0);
  list_item_add(&terms, "+mary", 0);
  list_item_add(&terms, "-bob", 0);

  ret = search_parse_terms(&search, &terms);
  assert(ret == 0);

  /* motto: nobody loves bob */
  assert(search_match_exact(&search, "test1 test2 test3") == 0);
  assert(search_match_exact(&search, " alice mary ") == 1);
  assert(search_match_exact(&search, " alice rose ") == 0);
  assert(search_match_exact(&search, " alice mary bob ") == 0);
  assert(search_match_exact(&search, " alice rosemary ") == 0);
  assert(search_match_exact(&search, " alice rosemary bob ") == 0);
  assert(search_match_exact(&search, " alice mary robert ") == 1);
  assert(search_match_exact(&search, " malice rosemary robert ") == 0);

  list_clear(&terms);
  search_free(&search);

  return 0;
}
示例#28
0
文件: list.c 项目: JanDeVisser/obelix
void list_free(list_t *list) {
  if (list && (list != EmptyList)) {
    free(list -> str);
    list_clear(list);
    free(list);
  }
}
示例#29
0
void pong_calc_movement(void)
{
    list_clear(&movement_steps, &free);

    ball_step *step = NULL;
    float x = ball->x;
    float y = ball->y;

    if(y < PADDLE_Y+PADDLE_H)
        y = PADDLE_Y+PADDLE_H;
    else if(y > fb_height-PADDLE_Y-PADDLE_H-BALL_W)
        y = fb_height-PADDLE_Y-PADDLE_H-BALL_W;

    if(x < 0)
        x = 0;
    else if(x > fb_width-BALL_W)
        x = fb_width-BALL_W;

    while(!step || step->collision == COL_NONE)
    {
        x += ball_speed_x;
        y += ball_speed_y;

        step = malloc(sizeof(ball_step));
        step->x = x;
        step->y = y;
        step->collision = pong_get_collision(x, y);
        list_add(&movement_steps, step);
    }
}
示例#30
0
void user_login(struct plugin_handle* plugin, struct plugin_user* user)
{
	struct chat_history_data* data = (struct chat_history_data*) plugin->ptr;
	struct cbuffer* buf = NULL;
	struct linked_list* found = (struct linked_list*) list_create();
	
	sql_execute(data, get_messages_callback, found, "SELECT from_nick,message, datetime(time, 'localtime') as time FROM chat_history ORDER BY time DESC LIMIT 0,%d;", (int) data->history_connect);

	if (data->history_connect > 0 && list_size(found) > 0)
	{
		buf = cbuf_create(MAX_HISTORY_SIZE);
		cbuf_append(buf, "Chat history:\n\n");
		struct chat_history_line* history_line;
		history_line = (struct chat_history_line*) list_get_last(found);
		while (history_line)
		{
			cbuf_append_format(buf, "[%s] <%s> %s\n", history_line->time, history_line->from, history_line->message);
			list_remove(found, history_line);
			hub_free(history_line);
			history_line = (struct chat_history_line*) list_get_last(found);
		}
		plugin->hub.send_message(plugin, user, cbuf_get(buf));
		cbuf_destroy(buf);
	}
	list_clear(found, &hub_free);
	list_destroy(found);
}