Пример #1
0
void lsystem_destroy (LSYSTEM * l) {
  while (!dynarr_isEmpty (l->p)) {
    production_destroy (*(PRODUCTION **)dynarr_pop (l->p));
  }
  dynarr_destroy (l->p);
  xph_free (l);
}
Пример #2
0
void production_destroy (PRODUCTION * p) {
  while (!dynarr_isEmpty (p->exp)) {
    xph_free (*(char **)dynarr_pop (p->exp));
  }
  dynarr_destroy (p->exp);
  xph_free (p);
}
Пример #3
0
int main(void) {
    DynArr dynarr;
    int i;

    dynarr_create(&dynarr);

    printf("Enter numbers! Stop input by entering not a number.\n");
    for (;;) {
        int num;
        printf("Enter number: ");
        if (scanf("%d", &num) == 1) {
            if (dynarr_append(&dynarr, num) == 0) {
                printf("\n\nError!\n");
                return 1;
            }
        } else {
            break;
        }
    }

    printf("You have entered:");
    for (i = 0; i < dynarr_length(&dynarr); ++i) {
        printf(" %d", dynarr_get(&dynarr, i));
    }
    printf("\n");

    dynarr_destroy(&dynarr);

    return 0;
}
Пример #4
0
static void pp_define_object_macro(struct lexer *lexer, const char *name) {
	struct dynarr *darr = store_token_until_newline(lexer);

	// simple check for: #define x x case.
	// a real example is in: /usr/include/bits/confname.h
	//
	// the ultimate way to sovle the (indirectly) referring itself obj/func macro is 
	// constructing the macro expanding tree
	if (dynarr_size(darr) == 1) {
		union token *tok = dynarr_get(darr, 0);
		if (tok->tok_tag == TOK_IDENTIFIER && strcmp(tok->id.s, name) == 0) {
			token_destroy(*tok);
			free(tok);
			dynarr_destroy(darr);
			red("ignore identity obj macro %s", name);
			return;
		}
	}
	struct macro *macro = obj_macro_init(darr);
	define_macro(lexer, name, macro);

#if DUMP_MACRO
	// fprintf(stderr, "%s define the macro %s\n", lexer->cstream->path, name);
	macro_dump(lexer, name, macro);
#endif
}
Пример #5
0
void nodedb_c_curve_destroy(NodeCurve *node, NdbCCurve *curve)
{
	if(node == NULL || curve == NULL)
		return;
	list_destroy(curve->curve);
	dynarr_destroy(curve->keys);
	curve->name[0] = '\0';
	curve->id = -1;
}
Пример #6
0
static int sync_text_buffer(const NodeText *n, const NdbTBuffer *buffer,
			    const NodeText *target, const NdbTBuffer *tbuffer)
{
	int		sync = 1, d;
	DynArr		*edit;
	DiffEdit	*ed;
	const char	*text, *ttext;
	size_t		len, tlen;

	text  = textbuf_text(buffer->text);
	len   = textbuf_length(buffer->text);
	ttext = textbuf_text(tbuffer->text);
	tlen  = textbuf_length(tbuffer->text);
	if(len == tlen && strcmp(text, ttext) == 0)	/* Avoid allocating memory and running diff if equal. */
		return sync;

	edit  = dynarr_new(sizeof (*ed), 8);

/*	printf("  text: '%s' (%u)\n", text, len);
	printf("target: '%s' (%u)\n", ttext, tlen);
*/	d = diff_compare_simple(ttext, tlen, text, len, edit);
/*	printf("Edit distance: %d\n", d);*/
	if(d > 0)
	{
		unsigned int	i, pos = 0;

		for(i = 0; (ed = dynarr_index(edit, i)) != NULL; i++)
		{
			if(ed->op == DIFF_MATCH)
			{
				pos = ed->off + ed->len;
			}
			else if(ed->op == DIFF_DELETE)
			{
				verse_send_t_text_set(target->node.id, tbuffer->id, ed->off, ed->len, NULL);
				pos = ed->off;
			}
			else if(ed->op == DIFF_INSERT)	/* Split inserts into something Verse can handle. */
			{
				char	temp[1024];
				size_t	off, chunk;

				for(off = ed->off, len = ed->len; len > 0; off += chunk, len -= chunk)
				{
					chunk = len > sizeof temp - 1 ? sizeof temp - 1 : len;
					stu_strncpy(temp, chunk + 1, text + off);
					temp[chunk] = '\0';
					verse_send_t_text_set(target->node.id, tbuffer->id, pos, 0, temp);
					pos += chunk - 1;
				}
			}
		}
		sync = 0;
	}
	dynarr_destroy(edit);
	return sync;
}
Пример #7
0
void nodedb_c_destruct(NodeCurve *n)
{
	unsigned int	i, num;

	num = dynarr_size(n->curves);
	for(i = 0; i < num; i++)
	{
		NdbCCurve	*c;

		if((c = dynarr_index(n->curves, i)) != NULL && c->name[0] != '\0')
		{
			printf("destroying curve %u\n", i);
			dynarr_destroy(c->keys);
			list_destroy(c->curve);
		}
	}
	dynarr_destroy(n->curves);
	n->curves = NULL;
}
Пример #8
0
static void chaser_destroy (EntComponent comp, EntSpeech speech)
{
    Chaser
    chaser = component_getData (comp);
    dynarr_wipe (chaser->targets, xph_free);
    dynarr_destroy (chaser->targets);
    xph_free (chaser);

    component_clearData (comp);
}
Пример #9
0
static void register_potential_typedefs(struct parser *parser, struct declaration_specifiers *decl_specifiers, struct init_declarator_list *init_declarator_list) {
	bool is_typedef = has_typedef(decl_specifiers);
	if (init_declarator_list != NULL) {
		struct dynarr *idlist = extract_id_list_from_init_declarator_list(init_declarator_list);
		DYNARR_FOREACH_PLAIN_BEGIN(idlist, char *, each);
			lexer_register_typedef(parser->lexer, each, is_typedef);
		DYNARR_FOREACH_END();

		dynarr_destroy(idlist);
	}
}
Пример #10
0
void optlayout_destroy (EntComponent comp, EntSpeech speech)
{
	struct optlayout
		* opt = component_getData (comp);
	// FIXME: entities that destroy other entities in their destruction code can probably lead to a double-free bug if they're only destroyed when everything is destroyed (or alternately they could cause the entity list to get into a bad state if they destroy entities while other code is iterating through it) - xph 2012 02 05
	dynarr_map (opt->options, (void (*)(void *))entity_destroy);
	dynarr_destroy (opt->options);
	entity_destroy (opt->cancel);
	entity_destroy (opt->confirm);
	xph_free (opt);

	component_clearData (comp);
}
Пример #11
0
void textureFloodFill (TEXTURE t, signed int startX, signed int startY)
{
	unsigned char
		replaceColor[4] = {0, 0, 0, 0};
	struct txpx {
		signed int
			x,y;
	} * current,
	  * next;
	VECTOR3
		loc;
	Dynarr
		affectedPixels;

	if (TextureColor[3] == 0x00)
	{
		ERROR ("Can't flood fill with a transparent color.");
		return;
	}

	loc = vectorCreate (startX, startY, 0);
	
	if (textureOOB (t, loc))
	{
		INFO ("Can't centre flood at %d, %d; it's out of bounds of image (%dx%d)", startX, startY, t->width, t->height);
		return;
	}
	affectedPixels = dynarr_create (64, sizeof (struct txpx *));
	memcpy (replaceColor, textureColorAt (t, loc), t->mode);

	current = xph_alloc (sizeof (struct txpx));
	current->x = startX;
	current->y = startY;
	dynarr_queue (affectedPixels, current);

	while (!dynarr_isEmpty (affectedPixels))
	{
		current = *(struct txpx **)dynarr_dequeue (affectedPixels);
		//printf ("got: %d, %d\n", current->x, current->y);
		loc = vectorCreate (current->x, current->y, 0);
		if (textureOOB (t, loc))
		{
		}
		else if (memcmp (replaceColor, textureColorAt (t, loc), t->mode) == 0)
		{
			textureDrawPixel (t, loc);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x + 1;
			next->y = current->y;
			dynarr_queue (affectedPixels, next);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x;
			next->y = current->y + 1;
			dynarr_queue (affectedPixels, next);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x - 1;
			next->y = current->y;
			dynarr_queue (affectedPixels, next);

			next = xph_alloc (sizeof (struct txpx));
			next->x = current->x;
			next->y = current->y - 1;
			dynarr_queue (affectedPixels, next);
		}
		xph_free (current);
	}

	INFO ("FINAL SIZE: %d ENTRIES", dynarr_capacity (affectedPixels));
	dynarr_destroy (affectedPixels);
}