Пример #1
0
void slip_release(pSlip gd)
{
	DLElement *e;

	e = dlist_tail(gd->lstObjects);

	while (e != NULL)
	{
		pSlipObject obj;

		obj = dlist_data(e);
		e = dlist_prev(e);

		s_ReleaseObject(gd, obj);
	}

	FreeDList(gd->lstObjects);

	FreeDList(gd->lstSymbols);
	FreeDList(gd->lstStrings);
	FreeDList(gd->lstGlobalEnvironment);

	FreeDList(gd->parse_data.lstTokens);

	free(gd);
}
Пример #2
0
static LakeVal *_lambda(LakeCtx *ctx, Env *env, LakeList *expr)
{
    /* (lambda (a b c) ...) */
  if (LIST_N(expr) >= 3 && lake_is_type(TYPE_LIST, LIST_VAL(expr, 1))) {
    list_shift(expr); /* drop the "lambda" symbol */
    LakeList *params = LIST(list_shift(expr));
    LakeList *body = expr;
    return VAL(fn_make(params, NULL, body, env));
  }
  else if (LIST_N(expr) >= 3 && lake_is_type(TYPE_DLIST, LIST_VAL(expr, 1))) {
    list_shift(expr); /* drop the "lambda" symbol */
    LakeDottedList *def = DLIST(list_shift(expr));
    LakeList *params = dlist_head(def);
    LakeSym *varargs = SYM(dlist_tail(def));
    LakeList *body = expr;
    return VAL(fn_make(params, varargs, body, env));
  }
  else if (LIST_N(expr) >= 3 && lake_is_type(TYPE_SYM, LIST_VAL(expr, 1))) {
    list_shift(expr); /* drop the "lambda" symbol */
    LakeSym *varargs = SYM(list_shift(expr));
    LakeList *body = expr;
    return VAL(fn_make(list_make(), varargs, body, env));
  }
  else {
    invalid_special_form(expr, "lambda requires at least 2 parameters");
    return NULL;
  }
}
Пример #3
0
void dlist_destroy(dlist_t *list)
{
    void *data;
    while (dlist_size(list) > 0)
    {
        if (dlist_remove(list, dlist_tail(list), (void **)&data) == 0 && list->destroy != NULL)
            list->destroy(data);
    }
    memset(list, 0, sizeof(dlist_t));
}
Пример #4
0
//删除所有节点,利用init函数的destroy函数来清理内存
void dlist_destroy(DList* list)
{
	void *data;
	while((dlist_size(list))>0){
		if(dlist_remove(list,dlist_tail(list),(void **)&data)==0
				&& list->destroy != NULL){
			list->destroy(data);
		}
	}
}
Пример #5
0
void dlist_destroy(DList *list)
{
    void *data;
    while (dlist_size(list) > 0){
        if (dlist_remove(list, dlist_tail(list), (void**)&data) == 0 && list->destroy != NULL){
            //saukiam vartotojo nustatyta funkcija destroy dinaminei atminciai atlaisvinti
            list->destroy(data);
        }
    }
}
Пример #6
0
// destroy a list by removing all the elements
void dlist_destroy (DList *list)
{
    void *data;

    while (dlist_size(list) > 0) {
        if ((dlist_remove(list, dlist_tail(list), (void **)&data)) == 0 && list-destroy != NULL) {
            list->destroy (data);
        }
    }

    memset (list, 0, sizeof(DList));
    return;
}
Пример #7
0
/* dlist_destroy */
void dlist_destroy(Dlist *list) {
    void *data;
    /* Remove each element. */
    while(dlist_size(list) > 0) {
        if(dlist_remove(list, dlist_tail(list), (void **)&data) == 0 && list->destroy != NULL) {
            /* call a user-defined function to free dynamically allocated data. */
            list->destroy(data);
        }
    }

    /* no operations are allowed now, but clear the structure as a precaution. */
    memset(list, 0, sizeof(DList));
    return;
}
Пример #8
0
void dlist_destroy(DList *list)
{
    /* Destroy the double list */
    void    *data;
    while(dlist_size(list) != 0) {
        if (dlist_remove(list, dlist_tail(list), (void **)&data) == 0 && 
            list->destroy != NULL) {
            list->destroy(data);
        }
    }

    memset(list, 0, sizeof(DList));
    return;
}
Пример #9
0
int visit(struct bitree_node *node)
{
	struct dlist *list;

	if (!visit_list) {
		visit_list = (struct dlist *) malloc(sizeof(struct dlist));
		dlist_init(visit_list, NULL);
	}
	list = visit_list;

	if (!node || !node->data)
		return -1;

	dlist_ins_next(list, dlist_tail(list), (const void *) node->data);

	return 0;
}
Пример #10
0
void dlist_destroy(DList *list)
{
        /* Will point to data payload to be removed for each element */
        void *data;

        /* Remove each element (and its payload) */
        while (dlist_size(list) > 0) {

		if (dlist_remove(list, dlist_tail(list), (void **)&data) != 0) {
			fprintf(stderr, "Problem removing element from dlist\n");
			return;
		}

		if (list->destroy != NULL)
			list->destroy(data);
        }

        /* Zero list out */
        memset(list, 0, sizeof(DList));

	return;
}
Пример #11
0
static LakeVal *_define(LakeCtx *ctx, Env *env, LakeList *expr)
{
  /* TODO: make these more robust, check all expected params */

  /* (define x 42) */
  if (LIST_N(expr) == 3 && lake_is_type(TYPE_SYM, LIST_VAL(expr, 1))) {
    list_shift(expr); /* drop the "define" symbol */
    LakeSym *var = SYM(list_shift(expr));
    LakeVal *form = list_shift(expr);
    env_define(env, var, eval(ctx, env, form));
  }

  /* (define (inc x) (+ 1 x)) */
  else if (LIST_N(expr) >= 3 && lake_is_type(TYPE_LIST, LIST_VAL(expr, 1))) {
    list_shift(expr); /* drop the "define" symbol */
    LakeList *params = LIST(list_shift(expr));
    LakeSym *var = SYM(list_shift(params));
    LakeList *body = expr;
    env_define(env, var, VAL(fn_make(params, NULL, body, env)));
  }

  /* (define (print format . args) (...)) */
  else if (LIST_N(expr) >= 3 && lake_is_type(TYPE_DLIST, LIST_VAL(expr, 1))) {
    list_shift(expr); /* drop the "define" symbol */
    LakeDottedList *def = DLIST(list_shift(expr));
    LakeList *params = dlist_head(def);
    LakeSym *varargs = SYM(dlist_tail(def));
    LakeSym *var = SYM(list_shift(params));
    LakeList *body = expr;
    env_define(env, var, VAL(fn_make(params, varargs, body, env)));
  }

  else {
    invalid_special_form(expr, "define requires at least 2 parameters");
  }

  return NULL;
}
Пример #12
0
SERVER *server_add(char *host, u_short port, char ipv6)
{	
	SERVER *server;

	if (port == 0 || host == NULL)
		return NULL;

	server = malloc(sizeof(SERVER));
	bzero(server, sizeof(SERVER));

	strncpy(server->host, host, MAX_HOSTNAME_LEN - 1);
	server->host[MAX_HOSTNAME_LEN - 1] = '\0';
	server->port = port;
	
#ifdef IPV6
	server->ipv6 = ipv6;
#endif
	
	dlist_ins_next(&e_global->servers, dlist_tail(&e_global->servers), server);
	log(LOG_INIT_DEBUG, "Server %s (Port: %i) has been added.",
			server->host, server->port);

	return server;
}
Пример #13
0
int main(int argc, char **argv) {

DList              list;
DListElmt          *element;

int                *data,
                   i;

/*****************************************************************************
*                                                                            *
*  Initialize the doubly-linked list.                                        *
*                                                                            *
*****************************************************************************/

dlist_init(&list, free);

/*****************************************************************************
*                                                                            *
*  Perform some doubly-linked list operations.                               *
*                                                                            *
*****************************************************************************/

element = dlist_head(&list);

for (i = 10; i > 0; i--) {

   if ((data = (int *)malloc(sizeof(int))) == NULL)
      return 1;

   *data = i;

   if (dlist_ins_prev(&list, dlist_head(&list), data) != 0)
      return 1;

}

print_list(&list);

element = dlist_head(&list);

for (i = 0; i < 8; i++)
   element = dlist_next(element);

data = dlist_data(element);
fprintf(stdout, "Removing an element after the one containing %03d\n", *data);

if (dlist_remove(&list, element, (void **)&data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Inserting 011 at the tail of the list\n");

*data = 11;
if (dlist_ins_next(&list, dlist_tail(&list), data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Removing an element at the tail of the list\n");

element = dlist_tail(&list);
if (dlist_remove(&list, element, (void **)&data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Inserting 012 just before the tail of the list\n");

*data = 12;
if (dlist_ins_prev(&list, dlist_tail(&list), data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Iterating and removing the fourth element\n");

element = dlist_head(&list);
element = dlist_next(element);
element = dlist_prev(element);
element = dlist_next(element);
element = dlist_prev(element);
element = dlist_next(element);
element = dlist_next(element);
element = dlist_next(element);

if (dlist_remove(&list, element, (void **)&data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Inserting 013 before the first element\n");

*data = 13;
if (dlist_ins_prev(&list, dlist_head(&list), data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Removing an element at the head of the list\n");

if (dlist_remove(&list, dlist_head(&list), (void **)&data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Inserting 014 just after the head of the list\n");
*data = 14;

if (dlist_ins_next(&list, dlist_head(&list), data) != 0)
   return 1;

print_list(&list);

fprintf(stdout, "Inserting 015 two elements after the head of the list\n");

if ((data = (int *)malloc(sizeof(int))) == NULL)
   return 1;

*data = 15;
element = dlist_head(&list);
element = dlist_next(element);

if (dlist_ins_next(&list, element, data) != 0)
   return 1;

print_list(&list);

i = dlist_is_head(dlist_head(&list));
fprintf(stdout, "Testing dlist_is_head...Value=%d (1=OK)\n", i);
i = dlist_is_head(dlist_tail(&list));
fprintf(stdout, "Testing dlist_is_head...Value=%d (0=OK)\n", i);
i = dlist_is_tail(dlist_tail(&list));
fprintf(stdout, "Testing dlist_is_tail...Value=%d (1=OK)\n", i);
i = dlist_is_tail(dlist_head(&list));
fprintf(stdout, "Testing dlist_is_tail...Value=%d (0=OK)\n", i);

/*****************************************************************************
*                                                                            *
*  Destroy the doubly-linked list.                                           *
*                                                                            *
*****************************************************************************/

fprintf(stdout, "Destroying the list\n");
dlist_destroy(&list);

return 0;

}
Пример #14
0
void dlist_remove_tail(dlist *d)
{
  dlist_remove(d, dlist_tail(d));
}
Пример #15
0
int enqueue(Queue *queue, const void *data) {

   return dlist_ins_next(queue, dlist_tail(queue), data);
}