Exemple #1
0
int main (int argc, char** argv) {

  list_t l0 = list_create();
  for (int i=1; i<argc; i++)
    list_append (l0, argv [i]);
  
  list_t l1 = list_create();
  list_map1 (intValue, l1, l0);
  
  list_t l2 = list_create();
  list_map2 (nullIfNegative, l2, l0, l1);
  
  list_t l3 = list_create();
  list_filter (isNotNegative, l3, l1);
  
  list_t l4 = list_create();
  list_filter (isNotNull, l4, l2);

  list_t l5 = list_create();
  list_map2 (truncate, l5, l4, l3);
  
  list_foreach (printString, l5);
  list_foreach (free, l5);
  
  intptr_t v = -1;
  list_foldl (max, (void**) &v, l3);
  printf ("%ld\n", v);
  
  list_destroy (l0);
  list_destroy (l1);
  list_destroy (l2);
  list_destroy (l3);
  list_destroy (l4);
  list_destroy (l5);
}
Exemple #2
0
int main ( int argc, char *argv[] )
{
   List* list = list_create ( sizeof ( int ),EqualInt );
   int t;
   ListNode* n;
   int i;
   for ( i=0; i<10; ++i )
      list_push_back ( list,createInt ( &t,rand() ) );
   /*list_foreach(list,printInt);*/
   ListIter iter = list_get_iter ( list );
   while ( list_iter_hasNext ( iter ) )
   {
      printInt ( list_iter_next ( iter ) );
   }
   printf ( "\n" );
   list_pop_back ( list );
   list_foreach ( list,incInt );
   list_foreach ( list,printInt );
   printf ( "\n" );
   n = list_find_first_node ( list,createInt ( &t,846930887 ) );
   list_erase_node ( list,n );
   list_foreach ( list,printInt );
   list_delete ( list );
   return 0;
}
Exemple #3
0
void print_symbol_table(void* rootscope) {
    scope* castedscope = (scope*) rootscope;
    printf("Printing scope at %p (parent = %p):\n", castedscope, castedscope->parent);
    list_foreach(castedscope->symbol_list, print_symbol);
    printf("\n");
    list_foreach(castedscope->children, print_symbol_table);
}
void xmpp_iq_player_status(int status)
{
    send_stream_format(session.wfs,
                       "<iq to='k01.warface' type='get'>"
                       "<query xmlns='urn:cryonline:k01'>"
                       "<player_status prev_status='%u' new_status='%u'"
                       "               to='%s'/>"
                       "</query>"
                       "</iq>",
                       session.status, status, "");

    session.status = status;

    list_foreach(session.friends,
                 (f_list_callback) xmpp_iq_peer_status_update_friend,
                 NULL);

    list_foreach(session.clanmates,
                 (f_list_callback) xmpp_iq_peer_clan_member_update_clanmate,
                 NULL);
#ifdef DBUS_API
    dbus_api_emit_status_update(session.nickname,
                                session.status,
                                session.experience,
                                session.clan_points);
#endif
}
void xmpp_iq_player_status(int status)
{
    xmpp_send_iq_get(
        JID_K01,
        NULL, NULL,
        "<query xmlns='urn:cryonline:k01'>"
        "<player_status prev_status='%u' new_status='%u' to='%s'/>"
        "</query>",
        session.online.status,
        status,
        session.gameroom.jid != NULL ? session.online.channel : "");

    session.online.status = status;
    session.online.last_status_update = time(NULL);

    /* Broadcast to every buddy */

    list_foreach(session.profile.friends,
                 (f_list_callback) xmpp_iq_peer_status_update_friend,
                 NULL);

    list_foreach(session.profile.clanmates,
                 (f_list_callback) xmpp_iq_peer_clan_member_update_clanmate,
                 NULL);
#ifdef DBUS_API
    dbus_api_emit_status_update(session.profile.nickname,
                                session.online.status,
                                session.profile.experience,
                                session.profile.clan.points);
#endif
}
static int prepare_math_qry(struct subpaths *subpaths)
{
	struct list_sort_arg sort_arg;
	uint32_t new_path_id = 0;

	/* strip gener paths because they are not used for searching */
	list_foreach(&subpaths->li, &dele_if_gener, NULL);

	/* HACK: overwrite path_id of subpaths to the number of paths belong
	 * to this bond variable, i.e. bound variable size. */
	list_foreach(&subpaths->li, &overwrite_pathID_to_bondvar_sz, NULL);

	/* sort subpaths by <bound variable size, symbol> tuple */
	sort_arg.cmp = &compare_qry_path;
	sort_arg.extra = NULL;
	list_sort(&subpaths->li, &sort_arg);

	/* assign new path_id for each subpaths, in its list node order. */
	list_foreach(&subpaths->li, &assign_path_id_in_order, &new_path_id);

	/* prepare score structure for query subpaths */
	prepare_score_struct(subpaths);

	return 0;
}
struct gpio *gpio_open(int pin, const char *usage, int type, ...)
{
	if(!usage)
		return NULL; // no usage specified

	int valid = 0;
	int i;
	for(i=0; i<PINS_COUNT; i++)
	{
		if(pins[i] == pin)
		{
			valid = 1;
			break;
		}
	}
	if(!valid)
		return NULL; // invalid pin number

	struct pin_lookup_data data_pin;
	data_pin.pin = pin;
	data_pin.result = NULL;
	list_foreach(&gpios, pin_lookup, &data_pin);
	if(data_pin.result)
		return NULL; // already in use

	struct type_lookup_data data;
	data.type = type;
	data.result = NULL;
	list_foreach(&types, type_lookup, &data);
	if(!data.result)
		return NULL; // type not found

	struct gpio *gpio;
	malloc_nofail(gpio);
	gpio->pin = pin;
	strdup_nofail(gpio->usage, usage);
	gpio->type = data.result;
	gpio->gpio = gpio_from_pin[gpio->pin];

	va_list args;
	va_start(args, type);
	int ret = gpio->type->open(gpio, args);
	va_end(args);

	if(!ret)
	{
		free(gpio->usage);
		free(gpio);
		return NULL; // type open failed
	}

	list_add(&gpios, gpio);
	++(gpio->type->refcount);

	return gpio;
}
Exemple #8
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);
}
Exemple #9
0
void testNTH()
{
    list_t *l = list_new();
    for (int i = 0; i < 100; ++i)
        {
            int *x = malloc(sizeof(int));
            *x = i;
            list_add(l, x);
        }

    int *x;

    for (int i = 0; i < 100; ++i)
        {
            CU_ASSERT(list_nth(l, i, (void **)&x));
            CU_ASSERT_EQUAL(*x, i);
        }

    CU_ASSERT_FALSE(list_nth(l, -1, (void **)&x));
    CU_ASSERT_EQUAL(x, NULL);
    CU_ASSERT_FALSE(list_nth(l, 100, (void **)&x));
    CU_ASSERT_EQUAL(x, NULL);

    list_foreach(l, free);
    list_free(l);
}
Exemple #10
0
int main(int argc, char *argv[])
{
   List *list = NULL;
   int i;
   int *data;

   for (i = 10; i<20; i++)
   {
      data = (int*) malloc(sizeof (int));
      *data = i;
      list = list_append(list, data );
   }	

   for (i = 0; i<10; i++)
   {
      data = (int*) malloc(sizeof (int));
      *data = i;
      list = list_insert(list, data, i);
   }	

   list_foreach(list, func, NULL);

   list_free(list);

   return 0;
}
int mb__system_properties_init()
{
    if (initialized) {
        list_foreach(contexts, [](context_node* l) { l->reset_access(); });
        return 0;
    }
    if (is_dir(property_filename)) {
        if (!initialize_properties()) {
            return -1;
        }
        if (!map_system_property_area(false, nullptr)) {
            free_and_unmap_contexts();
            return -1;
        }
    } else {
        mb__system_property_area__ = map_prop_area(property_filename, true);
        if (!mb__system_property_area__) {
            return -1;
        }
        list_add(&contexts, "legacy_system_prop_area", mb__system_property_area__);
        list_add_after_len(&prefixes, "*", contexts);
    }
    initialized = true;
    return 0;
}
/*
** DBus method call: "CrownChallenge"
*/
gboolean on_handle_crown_challenge ( Warfacebot *object,
									 GDBusMethodInvocation *invocation )
{
	if ( invalidated )
	{
		struct list *ml = session.wf.missions;

		GVariantBuilder *marr_builder;

		if ( marr != NULL )
			g_variant_unref ( marr );

		marr_builder = g_variant_builder_new ( G_VARIANT_TYPE ( "a(sssii)" ) );

		list_foreach ( ml, (f_list_callback) mlist_to_array, marr_builder );

		marr = g_variant_new ( "a(sssii)", marr_builder );

		g_variant_ref ( marr );

		g_variant_builder_unref ( marr_builder );

		invalidated = FALSE;
	}

	warfacebot_complete_crown_challenge ( object, invocation, marr );

	return TRUE;
}
Exemple #13
0
void oqueue_flush(OQueue *q, FILE *fh)
{
    q->data = list_reverse(q->data);
    list_foreach(q->data, CBFUNC(fputs), fh);
    list_destroy(q->data, DESTROYFUNC(free));
    q->data = NULL;
}
Exemple #14
0
static int count(list_t *list)
{
    int cnt = 0;

    fail_unless(QEO_OK == list_foreach(list, count_cb, (uintptr_t)&cnt));
    return cnt;
}
static void prepare_score_struct(struct subpaths *subpaths)
{
	/* initialize 'mark and score' query dimension */
	mnc_reset_qry();

	/* push queries to MNC stack for future scoring */
	list_foreach(&subpaths->li, &push_query_path, NULL);
}
Exemple #16
0
/* Iterate over the list of agents */
static void
load_host_agents (void *list, void *user_data, GO_UNUSED int count)
{
  GSLList *lst = list;
  GAgents *agents = user_data;

  agents->items = new_gagent_item (count);
  list_foreach (lst, fill_host_agents, agents);
}
Exemple #17
0
static void
load_host_agents_gmenu (void *list, void *user_data, int count)
{
  GSLList *lst = list;
  GMenu *menu = user_data;

  menu->items = (GItem *) xcalloc (count, sizeof (GItem));
  list_foreach (lst, fill_host_agents_gmenu, menu);
}
Exemple #18
0
void config_free(config_t* cfg)
{
	if (cfg->config == NULL)
		return;

	list_foreach((node_l**)&cfg->config, configitem_free);
	list_destroy((node_l**)&cfg->config);
	cfg->config = NULL;
}
Exemple #19
0
void print_ready(){
    lock();
    printk("ready:\n");
    ListHead *p1;
    list_foreach(p1,&ready)
        printk("id : %d ,tf : %x\n",((PCB *)(list_entry(p1,PCB,list)))->pid,
                                    ((PCB *)(list_entry(p1,PCB,list)))->tf);
    printk("-------------\n");
    unlock();
}
void cfw_send_event(struct cfw_message * msg)
{
#ifdef SVC_MANAGER_DEBUG
    pr_debug(LOG_MODULE_CFW, "%s : msg:%d", __func__, CFW_MESSAGE_ID(msg));
#endif
    list_head_t * list = get_event_list(CFW_MESSAGE_ID(msg));
    if (list != NULL ) {
        list_foreach(list, send_event_callback, msg);
    }
}
Exemple #21
0
void test_list_foreach(void)
{
    List *l = list_prepend(NULL, INT_TO_POINTER(1));
    l = list_prepend(l, INT_TO_POINTER(2));
    l = list_prepend(l, INT_TO_POINTER(3));

    int sum = 0;
    list_foreach(l, foreach_cb, &sum);
    cut_assert_equal_int(6, sum);
}
Exemple #22
0
void ps_collect(struct t_peer_storage * ps, const ps_consumer consumer, const void * token) {
    struct t_ps_list_token list_token = {ps, consumer, ps_time_cycle(ps), token};
    struct t_list * list = ps->item_list;
    /* set current list to new one, for writing new items */
    ps->item_list = list_create();
    /* consume and migrate items */
    list_foreach(list, ps_accept, (void *)&list_token);
    /* destroy old list */
    list_destroy(list);
}
Exemple #23
0
static void pin_debounce_timer_handler(void *priv_data)
{
	struct managed_comparator_info *priv =
		(struct managed_comparator_info *)priv_data;

	priv->pin_deb_counter = 0;

	/* Call user callbacks */
	list_foreach(&priv->cb_head, call_user_callback,
		     (void *)priv->pin_status);
}
Exemple #24
0
static void leaf_group(struct tex_tr *l)
{
	struct tex_tr *f /* father */
	     = MEMBER_2_STRUCT(l->tnd.father, struct tex_tr, tnd);

	/* 
	 * for leaf, n_fan means the number of brothers 
	 * with same symbol_id. 
	 */
	list_foreach(&f->tnd.sons, &update_same_brothers, l);
}
Exemple #25
0
void *thread_close(struct thread *t)
{
    xprintf("Closed %s\n", t->name);

    session.active = 0;

    list_foreach(thread_list,
                 (f_list_callback) thread_kill,
                 NULL);

    pthread_exit(NULL);
}
Exemple #26
0
void testLISTHAS()
{
    list_t *l = list_new();
    list_add(l, strdup("hello"));
    list_add(l, strdup("world"));

    CU_ASSERT_FALSE(list_has(l, streq, "HELLO"));
    CU_ASSERT(list_has(l, streq, "hello"));

    list_foreach(l, free);
    list_free(l);
}
Exemple #27
0
void client_manager_destroy()
{
  if (!g_client_manager)
    return;
  logger_message("[CLIENT] Manager destroy");
  list_foreach(&g_client_manager->clients, (feach) &client_destroy);
  list_clear(&g_client_manager->clients);
  list_free(&g_client_manager->commands);
  network_destroy();
  free(g_client_manager);
  g_client_manager = NULL;
}
Exemple #28
0
void testLENGTH()
{
    list_t *l = list_new();
    for (int i = 0; i < 100; ++i)
        {
            CU_ASSERT_EQUAL(list_len(l), i);
            list_add(l, malloc(sizeof(int)));
        }

    list_foreach(l, free);
    list_free(l);
}
Exemple #29
0
void status_set(enum status status)
{
    enum status old_status = session.online.status;
    time_t now = time(NULL);

    /* Check if status is different */
    if ((old_status ^ STATUS_AFK)
         != (status ^ STATUS_AFK))
    {
        session.online.last_status_change = now;
    }

    xmpp_iq_player_status(status);

    session.online.status = status;
    session.online.last_status_update = now;

    /* Update cached infos */
    status_update_location();

    /* Broadcast to every buddy */

    list_foreach(session.profile.friends,
                 (f_list_callback) xmpp_iq_peer_status_update_friend,
                 NULL);

    list_foreach(session.profile.clanmates,
                 (f_list_callback) xmpp_iq_peer_clan_member_update_clanmate,
                 NULL);

#ifdef DBUS_API
    /* Broadcast to DBus */
    dbus_api_emit_status_update(session.profile.nickname,
                                session.online.status,
                                session.profile.experience,
                                session.profile.clan.points);
#endif
}
Exemple #30
0
/* Soc Specific initialization */
static inline void usb_generic_callback(struct device *dev)
{
	struct usb_pm_info *priv = (struct usb_pm_info*)dev->priv;
	// Toggle USB status
	priv->is_plugged = !priv->is_plugged;
#ifdef CONFIG_USB
#ifdef CONFIG_QUARK_SE_SWITCH_INTERNAL_OSCILLATOR
	set_oscillator(priv->is_plugged ? OSC_EXTERNAL:OSC_INTERNAL);
#endif
	enable_vusb_regulator(priv, priv->is_plugged);
#endif
	/* Call user callbacks */
	list_foreach(&priv->cb_head, call_user_callback, (void*)priv->is_plugged);
}