예제 #1
0
END_TEST

START_TEST(test_list_insert)
{
    list_t *list = list_new();
    
    fail_unless(list_first(list) == NULL,
                "First of empty list should be NULL");
    fail_unless(list_last(list) == NULL, "Last of empty list should be NULL");
    
    list_insert(list, (void*)1);

    void *adr = list_entry_data(list_first(list));
    fail_unless(adr == (void*)1,
        "Data in first of list should be 1 (value is %x)",
        (unsigned)adr);
    
    adr = list_entry_data(list_last(list));
    fail_unless(adr == (void*)1,
        "Data in last of list should be 1 (value is %x)",
        (unsigned)adr);

    list_insert(list, (void*)2);

    adr = list_entry_data(list_first(list));
    fail_unless(adr == (void*)2,
        "List insertion failed, first of list should be 2 (value is %x)",
        (unsigned)adr);
    adr = list_entry_data(list_last(list));
    fail_unless(adr == (void*)1,
        "List insertion failed, last of list should be 1 (value is %x)",
        (unsigned)adr);

    list_delete(list);
}
예제 #2
0
static struct nsa_token *
la2_trap(List *ntoks, struct nsa_parser *p)
{
  if (list_len(ntoks) 
      && ((struct nsa_token*)list_last(ntoks))->type == NSA_T_GRAPHEME
      && hash_find(p->context->la2_tokens,nsa_grapheme_text(list_last(ntoks))))
    return list_pop(ntoks);
  else
    return NULL;
}
예제 #3
0
파일: list.c 프로젝트: dyama/supoo
/* リストの末尾から要素を取り出す */
value* list_pop(value* list)
{
  if (!list->size) {
    fprintf(stderr, "List has no elements.\n");
    return NULL;
  }
  value* res = list_ref(list, list_last(list));
  if (res) {
    res = value_copy(res);
  }
  list_resize(list, list_last(list));
  return res;
}
예제 #4
0
파일: queue.c 프로젝트: nirbenabu/Homework
/**
* Gets the last node from queue and remove it. Data needs to get free manually!!!
* Input: Queue* q - pointer to the queue
* Output: void* - pointer to value
**/
void* queue_dequeue(Queue* q) { /* Use the list function, backup memory before deletion,
                                !!!data should be freed manually!!! */
    if(queue_size(q)>0) {
      if(q == NULL)
        return NULL;
      Node* n = list_last(&q->l);
      int size = 4; /* 4 Bytes is the size of void* */
      void* data = (void*)malloc(size);
      memcpy(data, list_value(list_last(&q->l)), size);
      list_delete(&q->l, n);

      return data;
    } else
        return 0;
}
예제 #5
0
bool compile_project_execute_with_directory_name (CompileProject *project, 
                                                  const char *directory_name, 
                                                  bool bootstrap)
{
	Compile *compile = NULL;
	ListNode *node;

	if (!project) {
		compile_debug_invalid_arguments ();
		return false;
	}
	if (!directory_name) {
		compile_debug_invalid_arguments ();
		return false;
	}
	for (node = list_last (project->sorted); !compile && node; node = list_previous (node)) {
		if (string_equals (((Compile *)node->data)->directory->name, directory_name)) {
			compile = node->data;
		}
	}
	if (!compile) {
		compile_debug_invalid_value ();
		return false;
	}
	if (!included_libraries_are_up_to_date (project, compile)) {
		return false;
	}
	if (!compile_execute (compile, bootstrap)) {
		return false;
	}
	return true;
}
예제 #6
0
파일: list.c 프로젝트: vmiklos/darcsstats
/** Adds a new item to the list.
 * @param list which will be appended
 * @param data pointer to be added
 * @return the list pointer
 */
DSList* list_add(DSList *list, void *data)
{
	DSList *ptr, *lp;

	/* gr, haven't used list_new() yet */
	ptr = list;
	if(ptr == NULL)
	{
		ptr = list_new();
		if (!ptr)
			return(NULL);
	}

	lp = list_last(ptr);
	/* if this is not the first item */
	if(lp != ptr || lp->data != NULL)
	{
		lp->next = list_new();
		/* malloc failure */
		if(lp->next == NULL)
			return(NULL);
		lp->next->prev = lp;
		lp->last = NULL;
		lp = lp->next;
	}

	lp->data = data;
	ptr->last = lp;

	return(ptr);
}
예제 #7
0
int ta_waitall() {
	struct node *mainthread_node = list_pop(ready);//The last item of the ready queue holds the currently running thread. Since the main thread is running and we wish it to go to sleep, we need to "pop" it off the ready queue, and give the CPU to the next thread in queue.
	if(list_empty(ready) && list_sem_all_empty(sem_list)){
		return 0;
	}
	
	if(list_empty(ready) && !list_sem_all_empty(sem_list)){
		return -1;
	}

	while(!list_empty(ready)){
		swapcontext(&mainthread, list_last(ready)->threadContext);
		list_delete(ready); 
	}

	list_append_node(mainthread_node, ready);//main thread is back in ready queue and running

	list_clear(ready);
	free(ready);

	if(list_sem_all_empty(sem_list)){
		list_sem_destroy_list(sem_list);
		return 0;
	}//end if
	else{
		list_sem_destroy_list(sem_list);
		return -1;
	}//end else
	
}
예제 #8
0
int main(void)
{
	int i;
	struct list_node *head;
	struct list_node *node;

	init_list(&head);

	for (i = 1; i < 10; ++i)
	{
		node = malloc(sizeof(struct list_node));
		node->node_data = i; 
		node->next = NULL;
		list_append(node, head);
	}

	list_print(head);
	printf("head->node_data = %d\n", head->node_data);

	list_reverse(head);
	list_print(head);
	printf("the last 3th node data:%d\n", list_last(head, 3)->node_data);

	list_destroy(head);

	return 0;
}
예제 #9
0
void
layout_arrange(void) {
    Win *w;
    List *l, *ll;
    Layout *lo;
    Laydata *ld;
    unsigned int i, j, len;

    if(!(lo = layout_get(var.layout)))
        return;
    for(l = list_first(data.wins); l; l = l->next) {
        w = (Win*)l->ptr;
        if(!(w->tag & data.tag))
            XMoveWindow(data.dpy, w->win, w->x, (data.height * 2));
        else if(w->type & FULL)
            return;
        else if(w->type & FLOAT)
            XMoveWindow(data.dpy, w->win, w->x, w->y);
    }
    j = win_len(data.tag, NORMAL) - 1;
    if(win_first(data.tag, NORMAL, &l, &w))
        for(i = 0; w; win_next(data.tag, NORMAL, &l, &w), i++) {
            if(!(l = list_nth(lo->data, i)))
                l = list_last(lo->data);
            len = list_len(l);
            j = lo->tile ? MIN(len, j) : j;
            l = (List*)l->ptr;
            if(!(ll = list_nth(l, (j - i))))
                ll = list_last(l);
            ld = (Laydata*)ll->ptr;
            w->w = ((ld->width * data.width) / 100);
            w->h = ((ld->height * data.height) / 100);
            w->x = ((ld->x * data.width) / 100);
            w->x += var.gap_left + ROUND(var.gap_win / 2) - var.border_width;
            w->y = ((ld->y * data.height) / 100);
            w->y += var.gap_top + ROUND(var.gap_win / 2) - var.border_width;
            if(!lo->tile || i != len - 1) {
                w->w -= var.gap_win;
                w->h -= var.gap_win;
                win_resize(w);
            } else {
                tile(w, w->x, w->y, w->w, w->h, ld->col, ld->row);
                break;
            }
        }
}
예제 #10
0
파일: list.c 프로젝트: catompiler/stm32libs
void list_rforeach2_second(list_t* list, void (*proc)(void* item_data, void* user_data), void* user_data)
{
    list_item_t* item = list_last(list);
    
    while(item){
        proc(list_item_data(item), user_data);
        
        item = list_prev(item);
    }
}
예제 #11
0
파일: list.c 프로젝트: catompiler/stm32libs
void list_rforeach(list_t* list, void (*proc)(void* item_data))
{
    list_item_t* item = list_last(list);
    
    while(item){
        proc(list_item_data(item));
        
        item = list_prev(item);
    }
}
예제 #12
0
파일: symbol.c 프로젝트: richteer/cs445
void stab_add_type(struct stab *st, char *name, struct ast_type *ty) {
    if (stab_has_local_type(st, name)) {
        span_err("%s is already defined", NULL, name);
    } else {
        size_t type = stab_resolve_type(st, name, ty);
        hash_insert(((struct stab_scope *)list_last(st->chain))->types, YOLO name, YOLO type);
    }
    //? stab_abort(st);
    return;
}
예제 #13
0
파일: list.c 프로젝트: timsjostrand/lodge
/**
 * Inserts an element last in a list.
 *
 * @param list	The list to add the element to.
 * @param e	The element to add.
 */
void list_append_element(struct list *list, struct element *e)
{
	struct element *last = list_last(list);
	struct element *last_old_next = last->next;

	e->next = last_old_next;	/* This is list->head. */
	e->prev = last;
	last->next = e;
	last_old_next->prev = e;
}
예제 #14
0
파일: decoder.c 프로젝트: bemkap/lzw
void decode (FILE *fin, int size, FILE *fout)
{
  Decoder *dec = dec_new ();
  List *word, *entry;
  unsigned int code;
  uchar chr;

  chr = fgetc (fin);
  fputc (chr, fout);

  word = list_new (chr);
  for (; size > 1; size--) {
    chr = fgetc (fin);
    if (dec->nbits > MAX_BITS) {
      dec = dec_reset (dec);
      list_destroy (word);
      word = list_new (chr);
      fputc (chr, fout);
    } else {
      /* Se agrega el nuevo caracter al buffer. */
      dec->bitbuffer.buffer  = (dec->bitbuffer.buffer << 8) | chr;
      dec->bitbuffer.length += 8;
      
      while (dec->bitbuffer.length >= dec->nbits) {
	dec->bitbuffer.length -= dec->nbits;
	code = dec->bitbuffer.buffer >> dec->bitbuffer.length;
	dec->bitbuffer.buffer &= (1 << dec->bitbuffer.length) - 1;

	if (code < dec->charbuffer.nelem) { /* El código está en el diccionario. */
	  entry = dec->charbuffer.buffer[code];
	  fputl (entry, fout);

	  /* Agrega word + entry[0] al diccionario. */
	  word = list_prepend (word, entry->data);
	  dec_add_word (dec, word);

	  list_destroy (word);
	  word = NULL;

	  for (; entry != NULL; entry = entry->next)
	    word = list_prepend (word, entry->data);
	} else {
	  /* Agrega word + word[0] al diccionario. */
	  word = list_prepend (word, list_last (word));
	  dec_add_word (dec, word);

	  fputl (dec->charbuffer.buffer[dec->charbuffer.nelem-1], fout);
	}
      }
    }
  }

  list_destroy (word);
  dec_destroy  (dec);
}
예제 #15
0
void
layout_resize(int winc, int hinc) {
    Win *w;
    List *l, *ll;
    Layout *lo;
    Laydata *ld;
    int x, y, width, height;
    unsigned int i, j;

    if(!data.current || !(lo = layout_get(var.layout)))
        return;
    i = win_index(data.tag, NORMAL, data.current);
    j = win_len(data.tag, NORMAL) - 1;
    x = y = width = height = 0;
    if(win_first(data.tag, NORMAL, &l, &w))
        for(;w;) {
            if(!(l = list_nth(lo->data, i)))
                l = list_last(lo->data);
            j = lo->tile ? MIN(list_len(l), j) : j;
            l = (List*)l->ptr;
            if(!(ll = list_nth(l, (j - i))))
                ll = list_last(l);
            ld = (Laydata*)ll->ptr;
            if(!x && !y && !width && !height) {
                x = ld->x;
                y = ld->y;
                width = ld->width;
                height = ld->height;
                if(height >= 100)
                    hinc = 0;
                if(width >= 100)
                    winc = 0;
                i = 0;
                continue;
            }
            resize(x, width, &ld->x, (int*)&ld->width, winc);
            resize(y, height, &ld->y, (int*)&ld->height, hinc);
            win_next(data.tag, NORMAL, &l, &w);
            ++i;
        }
    layout_arrange();
}
예제 #16
0
파일: list.c 프로젝트: dyama/supoo
/* リストの末尾に要素を追加する */
value* list_push(value* list, value* item)
{
  if (list == NULL) {
    fprintf(stderr, "List is null.\n");
    return NULL;
  }
  list = list_resize(list, list->size + 1);
  int last_index = list_last(list);
  list->a[last_index] = item;
  return list;
}
예제 #17
0
파일: symbol.c 프로젝트: richteer/cs445
void stab_add_func(struct stab *st, char *name, struct ast_type *sig) {
    assert(sig->tag == TYPE_FUNCTION);
    if (stab_has_local_func(st, name)) {
        span_err("%s is already defined", NULL, name);
    } else {
        size_t type = stab_resolve_complex_type(st, name, sig);
        hash_insert(((struct stab_scope *)list_last(st->chain))->funcs, YOLO name, YOLO type);
    }
    //? stab_abort(st);
    return;
}
예제 #18
0
파일: test.c 프로젝트: mion/virtual-sim
void test_list(void) {
    int i, arr[MAX];
    int k, s;
    list *l = EMPTY_LIST;

    generate(arr, MAX);

    for (i = 0; i < MAX; i++) {
        l = list_create(arr[i], 0);

        assert(l != EMPTY_LIST);
        assert(l->key == arr[i]);
        assert(list_count(l) == 1);
        assert(list_contains(l, arr[i]));

        l = list_destroy(l);

        assert(l == EMPTY_LIST);
    }
    for (i = 0; i < MAX; i++) {
        l = list_insert(l, arr[i], arr[i]);
        assert(list_contains(l, arr[i]));
    }
    assert(list_ordered(l));
    for (i = 0; i < MAX; i++) {
        l = list_remove_first(l, &k, &s);
        assert(list_ordered(l));
    }
    l = list_destroy(l);

    l = list_insert(l, 5, 0);
    l = list_insert(l, 4, 1);
    l = list_insert(l, 1, 2);
    l = list_insert(l, 2, 6);
    l = list_insert(l, 7, 4);
    l = list_insert(l, 0, 5);
    list_print(l);

    l = list_insert(l, 20, 10);
    l = list_insert(l, 25, -1);
    l = list_insert(l, 30, 3);
    list_print(l);

    l = list_remove_first(l, &k, &s);
    s = 15;
    l = list_insert(l, k, s);
    list_print(l);

    printf("count: %d\n", list_count(l));
    printf("last: %d\n", list_last(l)->key);

    l = list_destroy(l);
}
UQueue *queue_push(UQueue *queue, void *data)
{
    if (!queue)
        return NULL;

    queue->tail = list_last(list_append(queue->tail, data));

    if (!queue->head)
        queue->head = queue->tail;

    ++queue->size;
    return queue;
}
예제 #20
0
DLL *list_copy(DLL *x) {
  int i, j, size = list_length(x);
  DLL *xp, *l = (DLL *)my_malloc((size+1) * sizeof(DLL));
  for (i=0, j=1, xp=x; i<size; i++, j++, xp=xp->next) {
    l[i].next = &l[j];
    l[j].prev = &l[i];
    l[i].val = xp->val;
  }
  l[0].prev = &l[size];
  l[size].next = &l[0];
  l[size].val = list_last(x)->val;
  return(l);
}
예제 #21
0
void
nsa_ucount(struct nsa_parser *p)
{
  List *newtoks = list_create(LIST_DOUBLE);
  struct nsa_token *t;
  for (t = list_first(p->toks); t; t = list_next(p->toks))
    {
      if (t->type == NSA_T_GRAPHEME)
	{
	  if (grapheme_num(t))
	    {
	      struct nsa_token *c = new_token();
	      struct nsa_token *la2 = la2_trap(newtoks,p);
	      int nkids = 1;
	      if (la2)
		++nkids;
	      c->d.c = new_count();
	      c->type = NSA_T_COUNT;
	      c->children = new_children(nkids);
	      if (la2)
		{
		  c->children[0] = la2;
		  c->children[1] = t;
		}
	      else
		c->children[0] = t;
	      
	      *c->d.c = *nsa_parse_count(grapheme_num(t),la2 ? -1 : 1);
	      list_add(newtoks,c);
	      if (grapheme_unit(t))
		{
		  struct nsa_token *tu = create_unit(p, grapheme_unit(t), NULL);
		  if (tu)
		    list_add(newtoks,tu);
		  else
		    fprintf(stderr,"unknown unit in count-unit grapheme `%s'\n",
			    nsa_grapheme_text(t));
		}
	    }
	  else if (!newtoks->last
		   || ((struct nsa_token*)list_last(newtoks))->type != NSA_T_UNIT)
	    list_add(newtoks,create_unit(p, (const char *)nsa_grapheme_text(t), t));
	  else
	    list_add(newtoks,t);
	}
      else
	list_add(newtoks,t);
    }
  list_free(p->toks,NULL);
  p->toks = newtoks;
}
예제 #22
0
void teste_linked_list() {
	List list = list_create(&test_getKey, &test_compareKeys, LIST_NO_FREE);
	int zero=0, a=1, b=2, c=3, d=4, e=5;
	list_push(list, &e);
	list_push(list, &d);
	list_push(list, &c);
	list_push(list, &b);
	list_push(list, &a);
	list_remove(list, &e);
	list_remove(list, &d);
	printf("%d\n", *(int *)list_last(list));

	printf("%d\n", list_size(list));
}
예제 #23
0
void script_delete(struct script *script)
{
	struct list_entry *o;

	assert(script);

	while ((o = list_last(&script->sections))) {
		struct script_section *section = container_of(o,
			       struct script_section, sections);

		script_section_delete(section);
	}

	free(script);
}
예제 #24
0
파일: context.c 프로젝트: hackereye/c-pluff
CP_HIDDEN void cpi_destroy_all_contexts(void) {
	cpi_lock_framework();
	if (contexts != NULL) {
		lnode_t *node;
		
		while ((node = list_last(contexts)) != NULL) {
			cpi_unlock_framework();
			cp_destroy_context(lnode_get(node));
			cpi_lock_framework();
		}
		list_destroy(contexts);
		contexts = NULL;
	}
	cpi_unlock_framework();
}
예제 #25
0
void wsman_repos_notification_dispatcher(WsContextH cntx, SubsRepositoryEntryH entry, int subsNum)
{
	WsmanMessage *wsman_msg = wsman_soap_message_new();
	if(wsman_msg == NULL) return;
	unsigned char *strdoc = entry->strdoc;
	u_buf_construct(wsman_msg->request, strdoc, entry->len, entry->len);
	dispatch_inbound_call(cntx->soap, wsman_msg, NULL);
	wsman_soap_message_destroy(wsman_msg);
	if(list_count(cntx->subscriptionMemList) > subsNum) {
		lnode_t *node = list_last(cntx->subscriptionMemList);
		WsSubscribeInfo *subs = (WsSubscribeInfo *)node->list_data;
		//Update UUID in the memory
		strncpy(subs->subsId, entry->uuid+5, EUIDLEN);
	}
}
예제 #26
0
bool compile_project_execute (CompileProject *project, bool bootstrap)
{
	ListNode *node;

	if (!project) {
		compile_debug_invalid_arguments ();
		return false;
	}
	for (node = list_last (project->sorted); node; node = list_previous (node)) {
		if (!compile_execute (node->data, bootstrap)) {
			return false;
		}
	}
	return true;
}
예제 #27
0
파일: list.c 프로젝트: dyama/supoo
/* リストの先頭から要素を取り出す */
value* list_shift(value* list)
{
  if (!list->size) {
    fprintf(stderr, "List has no elements.\n");
    return NULL;
  }
  value* res = list_ref(list, 0);
  if (res) {
    res = value_copy(res);
  }
  for (int i=0; i<list->size - 1; i++) {
    list->a[i] = list->a[i + 1];
  }
  list_resize(list, list_last(list));
  return res;
}
예제 #28
0
void script_section_delete(struct script_section *section)
{
	struct list_entry *o;

	assert(section);

	while ((o = list_last(&section->entries))) {
		struct script_entry *entry = container_of(o,
			       struct script_entry, entries);

		script_entry_delete(entry);
	}

	if (!list_empty(&section->sections))
		list_remove(&section->sections);
}
예제 #29
0
static bool sort_libraries (CompileProject *project, Compile *compile)
{
	Compile *library;
	ListNode *node;

	for (node = list_last (project->sorted); node; node = list_previous (node)) {
		library = node->data;
		if (!tree_search (compile->libraries, (Object *)library->directory)) {
			continue;
		}
		if (!list_append (compile->libraries_sorted, library->directory)) {
			compile_debug_operation_failed ();
			return false;
		}
	}
	return true;
}
예제 #30
0
/** Add endpoint to the list and queue.
 *
 * @param[in] instance List to use.
 * @param[in] endpoint Endpoint to add.
 *
 * The endpoint is added to the end of the list and queue.
 */
void endpoint_list_add_ep(endpoint_list_t *instance, ohci_endpoint_t *ep)
{
	assert(instance);
	assert(ep);
	usb_log_debug2("Queue %s: Adding endpoint(%p).\n", instance->name, ep);

	fibril_mutex_lock(&instance->guard);

	ed_t *last_ed = NULL;
	/* Add to the hardware queue. */
	if (list_empty(&instance->endpoint_list)) {
		/* There are no active EDs */
		last_ed = instance->list_head;
	} else {
		/* There are active EDs, get the last one */
		ohci_endpoint_t *last = list_get_instance(
		    list_last(&instance->endpoint_list), ohci_endpoint_t, link);
		last_ed = last->ed;
	}
	/* Keep link */
	ep->ed->next = last_ed->next;
	/* Make sure ED is written to the memory */
	write_barrier();

	/* Add ed to the hw queue */
	ed_append_ed(last_ed, ep->ed);
	/* Make sure ED is updated */
	write_barrier();

	/* Add to the sw list */
	list_append(&ep->link, &instance->endpoint_list);

	ohci_endpoint_t *first = list_get_instance(
	    list_first(&instance->endpoint_list), ohci_endpoint_t, link);
	usb_log_debug("HCD EP(%p) added to list %s, first is %p(%p).\n",
		ep, instance->name, first, first->ed);
	if (last_ed == instance->list_head) {
		usb_log_debug2("%s head ED(%p-0x%0" PRIx32 "): %x:%x:%x:%x.\n",
		    instance->name, last_ed, instance->list_head_pa,
		    last_ed->status, last_ed->td_tail, last_ed->td_head,
		    last_ed->next);
	}
	fibril_mutex_unlock(&instance->guard);
}