Beispiel #1
0
/**
 * Updates a particle array (eg blood). will move the particles according to
 * the particles velocity, and if a particle hits a solid block, will stop
 * the particle.
 */
static void update_particles()
{
    Particle *p;
    Node *current_node = list_first_node(particles);
    while(current_node){
        p = node_value(current_node);
        if(p->update(p)){
            Node *next = node_next(current_node);
            list_remove(particles, current_node);
            current_node = next;
        } else {
            current_node = node_next(current_node);
        }
    }
}
Beispiel #2
0
ret_t
chula_avl_generic_while (chula_avl_generic_t             *avl,
                         chula_avl_generic_while_func_t   func,
                         void                            *param,
                         chula_avl_generic_node_t       **key,
                         void                           **value)
{
	ret_t                     ret;
	chula_avl_generic_node_t *node = avl->root;

	if (avl->root == NULL) {
		return ret_ok;
	}

	node = node_first (avl);
	while (node) {
		if (key)
			*key = node;
		if (value)
			*value = node->value;

		ret = func (node, node->value, param);
		if (ret != ret_ok) return ret;

		node = node_next (node);
	}

	return ret_ok;
}
Beispiel #3
0
/**
 * Find a child of an internal node starting with a character
 * @param v the internal node
 * @param c the char to look for
 * @return the child node
 */
static node *find_child( node *v, char c )
{
    v = node_children(v);
    while ( v != NULL && str[node_start(v)] != c )
       v = node_next(v);
    return v;
}
Beispiel #4
0
ret_t
chula_avl_mrproper (chula_avl_generic_t *avl,
                    chula_func_free_t    free_func)
{
	chula_avl_generic_node_t *node;
	chula_avl_generic_node_t *next;

	if (unlikely (avl == NULL))
		return ret_ok;

	node = node_first (avl);

	while (node) {
		next = node_next (node);

		/* Node content */
		if (free_func) {
			free_func (node->value);
		}

		/* Node itself */
		node_free (node, avl);

		node = next;
	}

	return ret_ok;
}
Beispiel #5
0
/**
 * Updates a particle array (eg blood). will move the particles according to
 * the particles velocity, and if a particle hits a solid block, will stop
 * the particle.
 */
static void update_particles()
{
    Particle *p;
    Node *current_node = list_first_node(particles);
    if (SDL_MUSTLOCK(map_buffer)) SDL_LockSurface(map_buffer);
    while(current_node){
        p = node_value(current_node);
        if(p->update(p)){
            Node *next = node_next(current_node);
            list_remove(particles, current_node);
            current_node = next;
        } else {
            current_node = node_next(current_node);
        }
    }
    if (SDL_MUSTLOCK(map_buffer)) SDL_UnlockSurface(map_buffer);
}
Beispiel #6
0
/******************************************************************
 inserts the headers of the mail into the given nlist object
*******************************************************************/
static void insert_headers(Object *header_list, struct mail *mail)
{
	struct header *header = (struct header*)list_first(&mail->header_list);
	while (header)
	{
		DoMethod(header_list,MUIM_NList_InsertSingle, header, MUIV_NList_Insert_Bottom);
		header = (struct header*)node_next(&header->node);
	}
}
Beispiel #7
0
static int node_iterate_next(lua_State *L) {
	if (lua_isnil(L, 2)) { // The first iteration
		// Copy the state
		lua_pushvalue(L, 1);
	} else {
		lua_remove(L, 1); // Drop the state and call next on the value
		node_next(L);
	}
	return 1;
}
Beispiel #8
0
void* iter_bintree_next(void** handle)
{
	// (n is the handle, and, incidentally, a node)
	if (!*handle)
		return 0;
	
	bintree_node* n = (bintree_node*)*handle;	
	void* data = n->data;
	*handle = node_next(n);
	return data;
}
Beispiel #9
0
int
hb_itor_next(hb_itor *itor)
{
	ASSERT(itor != NULL);

	if (itor->node == NULL)
		hb_itor_first(itor);
	else
		itor->node = node_next(itor->node);
	RETVALID(itor);
}
Beispiel #10
0
static void draw_particles()
{
    Particle *p;
    Node *current_node = list_first_node(particles);
    int OFFSETX, OFFSETY;

    while(current_node){
        p = (Particle*) node_value(current_node);
        p->draw(p);
        current_node = node_next(current_node);
    }
}
Beispiel #11
0
bool rbtree_iterator_next(RBTreeIterator *iter, void **key, void **value)
{
    if (iterator_peek(iter, key, value))
    {
        iter->curr = node_next(iter->tree, iter->curr);
        return true;
    }
    else
    {
        return false;
    }
}
Beispiel #12
0
/**
 * Refreshes the rules of the current filter.
 */
static void filter_refresh_rules(void)
{
	struct filter *filter;

	/* Get the current selected filter */
	DoMethod(filter_list, MUIM_NList_GetEntry, MUIV_NList_GetEntry_Active, (ULONG)&filter);

	DoMethod(filter_rule_group, MUIM_Group_InitChange);

	/* Dispose all the objects in the group, they are setted completly new */
	DisposeAllChilds(filter_rule_group);

	if (filter)
	{
		struct filter_rule *fr;
		fr = (struct filter_rule*)list_first(&filter->rules_list);

		/* Add every filter rule as a pair objects - the filter rule object and the
		   remove button */
		while (fr)
		{
			Object *group, *rem;
			Object *rule = FilterRuleObject,
						 MUIA_Dropable, TRUE,
						 MUIA_UserData,fr,   /* Is used to identify the object as a FilterRuleObject */
						 MUIA_FilterRule_Data, fr,
						 End;

			group = HGroup,
				Child, RectangleObject,MUIA_HorizWeight,0,MUIA_Rectangle_VBar, TRUE,End,
				Child, rem = MakeButton(_("Remove")),
				End;

			set(rem,MUIA_Weight,0);
			if (rule && group)
			{
				DoMethod(filter_rule_group, OM_ADDMEMBER, (ULONG)rule);
				DoMethod(filter_rule_group, OM_ADDMEMBER, (ULONG)group);

				/* According to autodocs MUIM_Application_PushMethod has an limit of 7
				   args, but 8 seems to work also. */
				DoMethod(rem, MUIM_Notify, MUIA_Pressed, FALSE, (ULONG)App, 8, MUIM_Application_PushMethod, (ULONG)App, 5, MUIM_CallHook, (ULONG)&hook_standard, (ULONG)filter_remove_rule_gui, (ULONG)rule, (ULONG)group);
			}
			fr = (struct filter_rule*)node_next(&fr->node);
		}
	}

	/* Add two space objects (in case no rule objects have been created */
	DoMethod(filter_rule_group, OM_ADDMEMBER, (ULONG)HVSpace);
	DoMethod(filter_rule_group, OM_ADDMEMBER, (ULONG)HVSpace);
	DoMethod(filter_rule_group, MUIM_Group_ExitChange);
}
Beispiel #13
0
void
cc_trie_match(struct cc_trie* tp, const char* prefix, trie_visit func, void* ud) {
    char c;
    struct cc_node* cur = pos2node(tp, tp->root);
    for(; (prefix && (c=*prefix++)); ) {
        struct cc_node* next = node_next(tp, cur, c);
        if(!next) return;
        cur = next;
    }

    // dump
    _dump_node(tp, cur, func, ud);
}
Beispiel #14
0
STATIC VOID MultiString_Event(void **msg)
{
/*	struct IClass *cl = (struct IClass*)msg[0];*/
	Object *obj = (Object*)msg[1];
	struct object_node *obj_node = (struct object_node*)msg[2];
	Object *window = (Object*)xget(obj,MUIA_WindowObject);
	int event = (int)msg[3];

	if (event == MUIV_SingleString_Event_CursorUp && node_prev(&obj_node->node))
	{
		set(window, MUIA_Window_ActiveObject, ((struct object_node*)node_prev(&obj_node->node))->obj);
		return;
	}

	if (event == MUIV_SingleString_Event_CursorDown && node_next(&obj_node->node))
	{
		set(window, MUIA_Window_ActiveObject, ((struct object_node*)node_next(&obj_node->node))->obj);
		return;
	}

	if (event == MUIV_SingleString_Event_ContentsToPrevLine && node_prev(&obj_node->node))
	{
		struct object_node *prev_node = (struct object_node*)node_prev(&obj_node->node);
		char *contents = (char*)xget(obj_node->obj, MUIA_UTF8String_Contents);
		int new_cursor_pos = strlen((char*)xget(prev_node->obj, MUIA_String_Contents)); /* is Okay */

		DoMethod(prev_node->obj, MUIM_UTF8String_Insert, (ULONG)contents, MUIV_BetterString_Insert_EndOfString);
		set(prev_node-> obj,MUIA_String_BufferPos, new_cursor_pos);
		set(window, MUIA_Window_ActiveObject, prev_node->obj);

		node_remove(&obj_node->node);
		DoMethod(obj, MUIM_Group_InitChange);
		DoMethod(obj, OM_REMMEMBER, (ULONG)obj_node->obj);
		MUI_DisposeObject(obj_node->obj);
		free(obj_node);
		DoMethod(obj, MUIM_Group_ExitChange);
		return;
	}
}
Beispiel #15
0
/**
 * Set the length of each leaf to e recursively
 * @param v the node in question
 */
static void set_e( node *v )
{
    if ( node_is_leaf(v) )
    {
        node_set_len( v, e-node_start(v)+1 );
    }
    node *u = node_children( v );
    while ( u != NULL )
    {
        set_e( u );
        u = node_next( u );
    }
}
Beispiel #16
0
void
hb_tree_walk(hb_tree *tree, dict_vis_func visit)
{
	hb_node *node;

	ASSERT(tree != NULL);

	if (tree->root == NULL)
		return;
	for (node = node_min(tree->root); node; node = node_next(node))
		if (visit(node->key, node->dat) == 0)
			break;
}
Beispiel #17
0
int main() {
  int a = 5;
  int b = 10;

  Node* node_a = node_create(&a);
  Node* node_b = node_create(&b);
  
  assert(&a == node_value(node_a));
  assert(&b == node_value(node_b));

  assert(NULL == node_next(node_a));
  assert(NULL == node_next(node_b));

  node_set_next(node_a, node_b);

  assert(node_b == node_next(node_a));
  assert(NULL == node_next(node_b));

  node_destroy(node_a);
  node_destroy(node_b);

  return 0;
}
Beispiel #18
0
int node_num_children(node* sibling) {
	int result = 0;

	while(sibling != NULL) {
		if (node_is_leaf(sibling)) {
			result++;
		} else {
			result += node_num_children(node_children(sibling));
		}

		sibling = node_next(sibling);
	}

	return result;
}
Beispiel #19
0
static ret_t
node_check (chula_avl_generic_node_t *node)
{
	int32_t                   left_height;
	int32_t                   right_height;
	int32_t                   balance;
	chula_avl_generic_node_t *tmp;

	if (node == NULL)
		return ret_ok;

	if (node->left_child) {
		tmp = node_prev (node);
		if (tmp->right != node) {
            chula_log_error ("AVL Tree inconsistency: Right child");
			return ret_error;
		}
	}

	if (node->right_child) {
		tmp = node_next (node);
		if (tmp->left != node) {
            chula_log_error ("AVL Tree inconsistency: Left child");
			return ret_error;
		}
	}

	left_height  = 0;
	right_height = 0;

	if (node->left_child)
		left_height  = node_height (node->left);
	if (node->right_child)
		right_height = node_height (node->right);

	balance = right_height - left_height;
	if (balance != node->balance) {
        chula_log_error ("AVL Tree inconsistency: Balance");
		return ret_error;
	}

	if (node->left_child)
		node_check (node->left);
	if (node->right_child)
		node_check (node->right);

	return ret_ok;
}
Beispiel #20
0
static ret_t
node_check (http2d_avl_generic_node_t *node)
{
	cint_t                       left_height;
	cint_t                       right_height;
	cint_t                       balance;
	http2d_avl_generic_node_t *tmp;

	if (node == NULL)
		return ret_ok;

	if (node->left_child) {
		tmp = node_prev (node);
		if (tmp->right != node) {
			LOG_ERROR_S (HTTP2D_ERROR_AVL_PREVIOUS);
			return ret_error;
		}
	}

	if (node->right_child) {
		tmp = node_next (node);
		if (tmp->left != node) {
			LOG_ERROR_S (HTTP2D_ERROR_AVL_NEXT);
			return ret_error;
		}
	}

	left_height  = 0;
	right_height = 0;

	if (node->left_child)
		left_height  = node_height (node->left);
	if (node->right_child)
		right_height = node_height (node->right);

	balance = right_height - left_height;
	if (balance != node->balance) {
		LOG_ERROR_S (HTTP2D_ERROR_AVL_BALANCE);
		return ret_error;
	}

	if (node->left_child)
		node_check (node->left);
	if (node->right_child)
		node_check (node->right);

	return ret_ok;
}
Beispiel #21
0
STATIC Object *MultiString_AddStringField(struct IClass *cl,Object *obj, struct MUIP_MultiString_AddStringField *msg, struct object_node *prev_node)
{
	struct MultiString_Data *data = (struct MultiString_Data*)INST_DATA(cl,obj);
	struct object_node *obj_node;

	if ((obj_node = (struct object_node*)malloc(sizeof(struct object_node))))
	{
		obj_node->obj = SingleStringObject,
			MUIA_CycleChain, 1,
			MUIA_UTF8String_Contents, msg->contents,
			MUIA_UTF8String_Charset, user.config.default_codeset,
			End;

		if (obj_node->obj)
		{
			Object **sort_array = (Object**)malloc(sizeof(Object*)*(list_length(&data->object_list)+3));
			list_insert(&data->object_list, &obj_node->node, &prev_node->node);
			DoMethod(obj, MUIM_Group_InitChange);
			DoMethod(obj, OM_ADDMEMBER, (ULONG)obj_node->obj);

			if (sort_array)
			{
				int i = 1;
				struct object_node *cursor = (struct object_node *)list_first(&data->object_list);

				sort_array[0] = (Object*)MUIM_Group_Sort;

				while (cursor)
				{
					sort_array[i] = cursor->obj;
					cursor = (struct object_node*)node_next(&cursor->node);
					i++;
				}
				sort_array[i] = NULL;
				DoMethodA(obj, (Msg)sort_array);

				free(sort_array);
			}

			DoMethod(obj,MUIM_Group_ExitChange);
			DoMethod(obj_node->obj, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime, (ULONG)obj, 6, MUIM_CallHook, (ULONG)&hook_standard, (ULONG)MultiString_Acknowledge, (ULONG)cl, (ULONG)obj, (ULONG)obj_node);
			DoMethod(obj_node->obj, MUIM_Notify, MUIA_SingleString_Event, MUIV_EveryTime, (ULONG)App, 10, MUIM_Application_PushMethod, (ULONG)App, 7, MUIM_CallHook, (ULONG)&hook_standard, (ULONG)MultiString_Event, (ULONG)cl, (ULONG)obj, (ULONG)obj_node, MUIV_TriggerValue);
			return obj_node->obj;
		}
	}
	return NULL;
}
Beispiel #22
0
void pcm_out_sdl_shutdown(void)
{

	// set state to stop
	pcm_out_sdl_state_set(0);	
	
	// close all remaining channels
	if (chan_list)
	{
		list_free(chan_list);
		chan_list=0;
	}
	
	// shutdown audio subsystem
	//SDL_CloseAudio();
	
	//SDL_QuitSubSystem(SDL_INIT_AUDIO);
	
#if WRITE_TO_DISK
	if (list_data)
	{
		DATA *cur;
		int amount;
		
		cur = list_element_head(list_data);
#ifndef RAD_LINUX
		file_handle = open("sound.raw", O_BINARY|O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
#else
		file_handle = open("sound.raw", O_RDWR|O_CREAT, S_IREAD|S_IWRITE);
#endif
		printf("handle = %d\n", file_handle);
		while (cur)
		{
			printf("writing %d bytes...\n", cur->len);
			amount = write(file_handle, cur->data, cur->len);
			if ((amount != cur->len) || (amount <= -1))
			{
				printf("error! %d\n", amount);
				print_err_code();
			}
			cur = node_next(cur);
		}
		close(file_handle);
	}
#endif
}
Beispiel #23
0
int
hb_itor_nextn(hb_itor *itor, unsigned count)
{
	ASSERT(itor != NULL);

	if (count) {
		if (itor->node == NULL) {
			hb_itor_first(itor);
			count--;
		}

		while (count-- && itor->node)
			itor->node = node_next(itor->node);
	}

	RETVALID(itor);
}
Beispiel #24
0
void pcm_out_sdl_close(int handle)
{
	SDL_CHAN *ch;
	(void) handle;
	
	if (chan_list)
	{
		// find the one with a handle
		ch = list_element_head(chan_list);
		while ((ch) && (ch->handle != handle))
			ch=node_next(ch);
		
		// kill it
		if (ch)
		{
			handle_free(ch->handle);
			list_remove(chan_list, ch);
		}
	}
}
Beispiel #25
0
STATIC ULONG MultiString_Get(struct IClass *cl,Object *obj, struct opGet *msg)
{
	struct MultiString_Data *data = (struct MultiString_Data*)INST_DATA(cl,obj);
	if (msg->opg_AttrID == MUIA_MultiString_ContentsArray)
	{
		free(data->contents_array);
		if ((data->contents_array = (char**)malloc(sizeof(char*)*(list_length(&data->object_list)+1))))
		{
			struct object_node *obj_node;
			int i = 0;
			obj_node = (struct object_node*)list_first(&data->object_list);
			while (obj_node)
			{
				data->contents_array[i++] = (char*)xget(obj_node->obj,MUIA_UTF8String_Contents);
				obj_node = (struct object_node*)node_next(&obj_node->node);
			}
			data->contents_array[i] = NULL;
			*msg->opg_Storage = (ULONG)data->contents_array;
		}
	}
	return DoSuperMethodA(cl,obj,(Msg)msg);
}
Beispiel #26
0
long calc_similars(const char* line) {
	root = build_tree( line );
	int total = 0, multiple = 0, pplus = 0;
	if ( root != NULL )
	{
		node *u = node_children(root);
		const char *p = line;
		node *next_u = NULL;

		while(*p) {
			next_u = NULL;
			while(u != NULL) {
				int nstart = node_start(u);

				if (line[nstart] == *p) {
					int end = node_end(u,e);
					pplus = end - nstart + (line[end] == 0 ? 0 : 1);
					next_u = node_children(u);
				} else if (node_is_leaf(u)){
					multiple++;
				} else {
					multiple += node_num_children(node_children(u));
				}
				u = node_next(u);
			}

			total += (p - line) * multiple;
			p += pplus;
			u = next_u;
			multiple = 0;
		}

		total += (p - line);

		node_dispose( root );
	}
	return total;
}
Beispiel #27
0
int treeNodeCalcPos(Ihandle* h, int *x, int *y, int *text_x)
{
  int err;
  TtreePtr tree=(TtreePtr)tree_data(h);
  Node node = (Node)tree_root(tree);
  float posy = IupGetFloat(h, IUP_POSY);     
  float dy = IupGetFloat(h, IUP_DY);
  float posx = IupGetFloat(h, IUP_POSX);
  float dx = IupGetFloat(h, IUP_DX);

  CdActivate(tree,err);

  *y = (int)((1.0 + posy/dy)*(YmaxCanvas(tree)-TREE_TOP_MARGIN));

  while(node != tree_selected(tree))
  {
    if( node_visible(node) == YES ) *y -= NODE_Y;

    node = node_next(node);
    if (node == NULL)
      return 0;
  }

  *y -= NODE_Y;
  *x = (int)(TREE_LEFT_MARGIN - (XmaxCanvas(tree)-NODE_X)*posx/dx) + NODE_X * node_depth(node);

  /* if node has a text associated to it... */
  *text_x = 0;
  if(node_name(node))
  {
    /* Calculates its dimensions */
    iupdrvStringSize(tree->self, node_name(node), text_x, NULL);
  }

  return 1;
}
Beispiel #28
0
bool rbtree_remove(RBTree *tree, const void *key)
{
    assert(!tree->nil->red);

    RBNode *z = node_get(tree, key);
    if (z == tree->nil)
    {
        return false;
    }

    RBNode *y = ((z->left == tree->nil) || (z->right == tree->nil)) ? z : node_next(tree, z);
    RBNode *x = (y->left == tree->nil) ? y->right : y->left;

    x->parent = y->parent;
    if (tree->root == x->parent)
    {
        tree->root->left = x;
    }
    else
    {
        if (y == y->parent->left)
        {
            y->parent->left = x;
        }
        else
        {
            y->parent->right = x;
        }
    }

    if (z != y)
    {
        assert(y != tree->nil);
        assert(!tree->nil->red);

        if (!y->red)
        {
            remove_fix(tree, x);
        }

        y->left = z->left;
        y->right = z->right;
        y->parent = z->parent;
        y->red = z->red;
        z->left->parent = y;
        z->right->parent = y;

        if (z == z->parent->left)
        {
            z->parent->left = y;
        }
        else
        {
            z->parent->right = y;
        }
        node_destroy(tree, z);
    }
    else
    {
        if (!y->red)
        {
            remove_fix(tree, x);
        }
        node_destroy(tree, y);
    }

    assert(!tree->nil->red);

    tree->size--;
    return true;
}
Beispiel #29
0
int main(int argc, char** argv)
{
	printf("testing bintree\n");
	
	node na,nb,nc,nd;
	init_node(&na,"Anchor");
	init_node(&nb,"Bunk");
	init_node(&nc,"Corgi");
	init_node(&nd,"Dapper");
	
	node_add_child(&nb,&nd,comp_string);
	node_add_child(&nb,&nc,comp_string);
	node_add_child(&nb,&na,comp_string);
	
	printf("heythere\n");
	printf("%x: %x, %x\n",nb.data,nb.left,nb.right);
	printf("%s: %s, %s\n",nb.data,((bintree_node*)nb.left)->data,((bintree_node*)nb.right)->data);
	printf("%s: %s, %s\n",nd.data,((bintree_node*)nd.left)->data,(nd.right ? ((bintree_node*)nd.right)->data : 0));
	
	bintree_node* ns[] = {&na,&nb,&nc,&nd};
	int i;
	for (i=0; i<4; ++i)
	{
#define ndata(a,b) ((bintree_node*)a->b)->data
		printf("<%s: (%s) %s, %s, %i>\n",
			(ns[i]->data ? ns[i]->data : 0),
			(ns[i]->parent ? ndata(ns[i],parent) : 0),
			(ns[i]->left ? ndata(ns[i],left) : 0),
			(ns[i]->right ? ndata(ns[i],right) : 0),
			ns[i]->weight);
	}
	
	bintree_node* n = &na;
	printf("testing node_next\n");
	do {
		printf("- %s\n",n->data);
	} while ((n = node_next(n)));
	
	n = &nd;
	printf("testing node_prev\n");
	do {
		printf("- %s\n",n->data);
	} while ((n = node_prev(n)));
	
#undef ndata
	
#ifdef mtrace_active
	mtrace();	
#endif

	bintree* b = new_bintree(comp_string);	
	del_bintree(b,DEL_STRUCT);
	
	b = new_bintree(comp_string);
	bintree_add(b,"Brawn");
	bintree_add(b,"Dour");
	bintree_add(b,"Court");
	bintree_add(b,"Acclamate");
	
	char* s;
	void* h = iter_bintree(b);
	while (s = iter_bintree_next(&h))
		printf("%s\n",s);
	
	h = iter_bintree(b);
	while (s = iter_bintree_next(&h))
		printf("%s\n",bintree_contains(b,s));
	
	del_bintree(b,DEL_STRUCT);
	
#ifdef mtrace_active
	muntrace();
#endif
	
	return 0;
}
Beispiel #30
0
void ast_print(node * ast) {
   print_action(ast);
   node_next(ast, &ast_print); 
}