예제 #1
0
파일: eval.c 프로젝트: S010/misc
struct list    *
get_list_el(const struct expr * e, int i)
{
	int             n;
	const struct list *l;

	if (!e || e->t != LLIST || i >= list_len(e))
		return NULL;

	for (l = e->v.list, n = 0; l != NULL, n < i; l = l->next, ++n)
		 /* empty */ ;

	return (struct list *) l;
}
예제 #2
0
bool test_delete_list() {
  
  
  node_t *head = NULL;
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 2);
  
  free_list(&head);
  
  assert(list_len(head) == 0);
  return head == NULL;
}
예제 #3
0
파일: main.c 프로젝트: spocklogic/tunez-am
int main() {
	node* table[26];
	int c = 0;
	while(c < 26) {
		table[c] = 0;
		c++;
	}
	srand(time(NULL));
	printf("List function testing\n\n");
	node *list = (node *)malloc(sizeof(node));
	strcpy(list->name,"singing in the rain");
	strcpy(list->artist,"john");
	list->next = NULL;
	insert_lexic(list, "tomato sauce", "joshua");
	insert_lexic(list, "potatoes", "joshua");
	insert_lexic(list, "quiet", "joshua");
	printf("List length (after adding 4 nodes in order): %d\n\n", list_len(list));
	printf("Print list:\n");
	print_list(list);
	printf("\nFind song (quiet):\n");
	print_list(find_song(list, "quiet"));
	printf("\nFind artist (joshua):\n");
	print_list(find_artist(list, "joshua"));
	printf("\nRandom Nodes:\n");
	print_list(randomn(list));
	print_list(randomn(list));
	print_list(randomn(list));
	print_list(randomn(list));
	printf("\nSpecific Library Functions:\nAdding 5 songs:\n");
	add_song(table, "hello", "john");
	add_song(table, "goodbye", "james");
	add_song(table, "fish", "john");
	add_song(table, "star", "patrick");
	add_song(table, "jean-luc", "picard");
	printf("\nPrint letter function:\n");
	print_let(table, 'p');
	printf("\nPrint library function:\n");
	print_lib(table);
	printf("\nPrint artist (john) function:\n");
	print_art(table, "john");
	del_song(findlib_song(table, "hello"), table);
	printf("Deleted hello by john\n");
	print_art(table, "john");
	printf("\nShuffle List (6 songs):\n");
	shuffle(table, 6);
	printf("\nDelete library:\n");
	del_lib(table);
	print_lib(table);
	return 0;
}
예제 #4
0
bool test_remove_dups2() {
  
  node_t *head = NULL;
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 2);
  add_node(&head, 2);
  add_node(&head, 1);

  
  
  
  remove_list_dups2(head);
  
  assert(list_len(head) == 2);
  
  //traverse_node(head, print_node);
  
  return list_len(head) == 2;
  
  
}
예제 #5
0
파일: list.c 프로젝트: dougfales/macvim
/*
 * Return TRUE when two lists have exactly the same values.
 */
    int
list_equal(
    list_T	*l1,
    list_T	*l2,
    int		ic,	/* ignore case for strings */
    int		recursive)  /* TRUE when used recursively */
{
    listitem_T	*item1, *item2;

    if (l1 == NULL || l2 == NULL)
	return FALSE;
    if (l1 == l2)
	return TRUE;
    if (list_len(l1) != list_len(l2))
	return FALSE;

    for (item1 = l1->lv_first, item2 = l2->lv_first;
	    item1 != NULL && item2 != NULL;
			       item1 = item1->li_next, item2 = item2->li_next)
	if (!tv_equal(&item1->li_tv, &item2->li_tv, ic, recursive))
	    return FALSE;
    return item1 == NULL && item2 == NULL;
}
예제 #6
0
bool test_add_node() {
  
  bool test_result = true;
  
  node_t *head = NULL;
  add_node(&head, 1);
  assert(head->val == 1);
  assert(list_len(head) == 1);
  add_node(&head, 2);
  assert(list_len(head) == 2);
  
  assert(find_node(head, 1) != NULL);
  assert(find_node(head, 2) != NULL);
  assert(find_node(head, 3) == NULL);
  add_node(&head, 3);
  
  //traverse_node(head, print_node);
  
  assert(find_node(head, 3) != NULL);
  assert(find_node(head, 3)->next->val == 3);
  
  return test_result && find_node(head, 3) != NULL;
}
예제 #7
0
파일: clisp.c 프로젝트: meesokim/z88dk
/* Evaluate arguments */
long
eval_args(long func, long arg, long av[2], int n)
{
  long  x, y;

  if ((n != FTYPE_ANY_ARGS) && (n != list_len(arg)))
    return err_msg(errmsg_ill_nargs, 1, func);

  switch (n){

  case 0:
    av[0] = TAG_NIL;
    break;

  case 1:
    if ((av[0] = l_eval(l_car(arg))) < 0)
      return -1;
    break;

  case 2:
    if ((av[0] = l_eval(l_car(arg))) < 0)
      return -1;
    if (gc_protect(av[0]) < 0)
      return -1;
    if ((av[1] = l_eval(l_car(l_cdr(arg)))) < 0)
      return -1;
    gc_unprotect(av[0]);
    break;

  case FTYPE_ANY_ARGS:   /* return evaluated arguments as a list */
    if (D_GET_TAG(arg) != TAG_CONS){
      av[0] = TAG_NIL;
    } else {
      if ((x = l_eval(l_car(arg))) < 0)
        return -1;
      if ((av[0] = y = l_cons(x, TAG_NIL)) < 0)
        return -1;
      if (gc_protect(av[0]) < 0)
        return -1;
      for (arg = l_cdr(arg); D_GET_TAG(arg) == TAG_CONS; arg = l_cdr(arg)){
        if ((x = l_eval(l_car(arg))) < 0)
          return -1;
        rplacd(y, l_cons(x, TAG_NIL)); 
        y = l_cdr(y);
      }
      gc_unprotect(av[0]);
    }
  }
  return av[0];
}
예제 #8
0
파일: bearerbox.c 프로젝트: armic/erpts
static void empty_msg_lists(void)
{
    Msg *msg;

#ifndef NO_WAP

    if (list_len(incoming_wdp) > 0 || list_len(outgoing_wdp) > 0)
	warning(0, "Remaining WDP: %ld incoming, %ld outgoing",
	      list_len(incoming_wdp), list_len(outgoing_wdp));

    info(0, "Total WDP messages: received %ld, sent %ld",
	 counter_value(incoming_wdp_counter),
	 counter_value(outgoing_wdp_counter));
#endif
    
    while((msg = list_extract_first(incoming_wdp))!=NULL)
	msg_destroy(msg);
    while((msg = list_extract_first(outgoing_wdp))!=NULL)
	msg_destroy(msg);

    list_destroy(incoming_wdp, NULL);
    list_destroy(outgoing_wdp, NULL);

    counter_destroy(incoming_wdp_counter);
    counter_destroy(outgoing_wdp_counter);
    
    
#ifndef NO_SMS

    /* XXX we should record these so that they are not forever lost...
     */
    if (list_len(incoming_sms) > 0 || list_len(outgoing_sms) > 0)
	debug("bb", 0, "Remaining SMS: %ld incoming, %ld outgoing",
	      list_len(incoming_sms), list_len(outgoing_sms));

    info(0, "Total SMS messages: received %ld, sent %ld",
	 counter_value(incoming_sms_counter),
	 counter_value(outgoing_sms_counter));

#endif

    list_destroy(incoming_sms, msg_destroy_item);
    list_destroy(outgoing_sms, msg_destroy_item);
    
    counter_destroy(incoming_sms_counter);
    counter_destroy(outgoing_sms_counter);
}
예제 #9
0
//find the middle node
node_t *getMidNode( node_t *head)
{
    int len=list_len(head);
    node_t *node=head;
    int i=0;
    while(node->next)
    {
        if(i==len/2)
        {
          return node;
        }
        i++;
        node=node->next;
    }
}
예제 #10
0
bool test_free_list() {
  node_t *head = NULL;
  add_node(&head, 1);
  add_node(&head, 2);
  add_node(&head, 3);
  add_node(&head, 4);
  add_node(&head, 5);
  add_node(&head, 6);
  
  free_list(&head);
  if (head == NULL && list_len(head) == 0)
    return 1;
  else
    return 0;
}
예제 #11
0
파일: wtp_init.c 프로젝트: armic/erpts
void wtp_initiator_shutdown(void)
{
    gw_assert(initiator_run_status == running);
    initiator_run_status = terminating;
    list_remove_producer(queue);
    gwthread_join_every(main_thread);

    debug("wap.wtp", 0, "wtp_initiator_shutdown: %ld init_machines left",
          list_len(init_machines));
    list_destroy(init_machines, init_machine_destroy);
    list_destroy(queue, wap_event_destroy_item);

    counter_destroy(init_machine_id_counter);
    timers_shutdown();
}
예제 #12
0
//Find the reciprocal of the k-th element
node_t * getRec_k_th(node_t *head,int k)
{
    node_t *n=head;
    int i=0;
    int len=list_len(head);
    if(k<0||k>len-1)
        return 0;
    while(len-i-1!=k)
    {
        n=n->next;
        i++;
       
    }
    return n;
    
}
예제 #13
0
cellpoint apply_proc(cellpoint arglst)
{
	int len;
	args_push(arglst);
	len = get_integer(list_len());
	if (len < 2){
		printf("Error: the procedure \"apply\" expects at least 2 arguments.\n");
		error_handler();
	}
	check_arg_type("apply", "first", car(arglst), PROCEDURE_T);

	args_push(a_false);
	args_push(combine_args(cdr(arglst)));
	args_push(car(arglst));
	return apply();
}
예제 #14
0
파일: parse.c 프로젝트: armic/erpts
int parse_pop_limit(ParseContext *context)
{
    long *elem;

    gw_assert(context != NULL);

    if (context->limit_stack == NULL || list_len(context->limit_stack) == 0) {
        context->error = 1;
        return -1;
    }

    elem = list_extract_first(context->limit_stack);
    context->limit = *elem;
    gw_free(elem);
    return 0;
}
예제 #15
0
파일: urltrans.c 프로젝트: armic/erpts
URLTranslation *urltrans_find_username(URLTranslationList *trans, 
				       Octstr *name)
{
    URLTranslation *t;
    int i;

    gw_assert(name != NULL);
    for (i = 0; i < list_len(trans->list); ++i) {
	t = list_get(trans->list, i);
	if (t->type == TRANSTYPE_SENDSMS) {
	    if (octstr_compare(name, t->username) == 0)
		return t;
	}
    }
    return NULL;
}
예제 #16
0
파일: eval.c 프로젝트: S010/misc
int
is_valid_lambda_expr(const struct expr * e)
{
	struct list    *l;

	if (!e || e->t != LLIST || list_len(e) < 3)
		return 0;

	if (!e->v.list->v || e->v.list->v->t != LATOM || !e->v.list->v->v.atom || !e->v.list->v->v.atom->v || strcmp(e->v.list->v->v.atom->v, "lambda") != 0)
		return 0;
	if (!is_valid_p_expr(e->v.list->next->v))
		return 0;
	if (!e->v.list->next->next->v)
		return 0;

	return 1;
}
예제 #17
0
파일: vector.c 프로젝트: lienhua34/CSchemer
//one arg: arglst
cellpoint vector(void)
{
    int len, i=0;
	
	args_push(args_ref(1));
	len = get_integer(list_len());
    reg = make_vector(len, NIL);
	stack_push(&vars_stack, args_ref(1));
    while (is_false(is_null(stack_top(&vars_stack)))){
		vector_set(reg, i, car(stack_top(&vars_stack)));
		++i;
		stack_push(&vars_stack, cdr(stack_pop(&vars_stack)));
    }
	stack_pop(&vars_stack);
	args_pop(1);
    return reg;
}
예제 #18
0
파일: eval.c 프로젝트: S010/misc
int
is_function_call_expr(const struct expr * e)
{
	if (!e || e->t != LLIST || e->v.list == NULL)
		return 0;

	if (!e->v.list->v || e->v.list->v->t != LLIST || e->v.list->v->v.list == NULL || e->v.list->v->v.list->v == NULL || e->v.list->v->v.list->v->t != LATOM || e->v.list->v->v.list->v->v.atom == NULL || e->v.list->v->v.list->v->v.atom->v == NULL)
		return 0;

	if (strcmp(e->v.list->v->v.list->v->v.atom->v, "lambda") != 0)
		return 0;

	if (list_len(e->v.list->v) < 3 || e->v.list->v->v.list->next->v == NULL || e->v.list->v->v.list->next->v->t != LLIST)
		return 0;

	return 1;
}
예제 #19
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;
            }
        }
}
예제 #20
0
파일: test-list.c 프로젝트: tdenniston/fred
int main() {
  item * tail;
  int i;

  head = newItem(1);
  tail = head;
  printf(" NODE VAL: %d\n", tail->val);
  for(i=2;i<=20;i++) {
    tail->next = newItem(i);
    tail = tail->next;
    printf(" NODE VAL: %d\n", tail->val);
  }
  printf("Linked list length is now: %d\n", list_len(head));
  printf ("Ok we crossed the limit."
          "  Let's go back to just before the list had size 10.\n");
  return 0;
}
예제 #21
0
bool test_remove_node() {
  
  node_t *head = NULL;
  add_node(&head, 2);
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 2);
  add_node(&head, 4);
  add_node(&head, 1);
  add_node(&head, 1);
  
  remove_node(&head, 1);
  
  //traverse_node(head, print_node);
  
  return list_len(head) == 3 && find_node(head, 1) == NULL;
}
예제 #22
0
파일: strlist.c 프로젝트: pz239/code_libs
/* 创建字符串链表 */
T strlist_new(const char *file)
{
    FILE *fp = efopen(file, "r");; /*模式串文件*/

    T strlist;

    NEW0(strlist);
    strlist->file = strdup(file);
    strlist->list = list_new(NULL);
    strlist->min_strlen = MAX_STR_LEN;
    
    uint64_t line_num = 0;
    char buf[MAX_STR_LEN+1]; /*模式串缓存,包括换行符*/
    
    while (fgets(buf, sizeof(buf), fp)) {
      line_num++;
      char *line_break = strchr(buf, '\n'); /*换行符指针*/
        if (line_break) *line_break = '\0';
	
	Str_Len_T len = strlen(buf);
        if (len) { /*非空行*/
	    /* 插入链表末尾 */
	    list_push_back(strlist->list, strdup(buf));
	    
	    if (len < strlist->min_strlen)
		strlist->min_strlen = len;
	    else if (len > strlist->max_strlen)
		strlist->max_strlen = len;

            strlist->total_strlen += len;
            strlist->strlen_num[len]++;
        } 
    }
    
    //printf("Total line: %ld\n", line_num);
    strlist->str_num = list_len(strlist->list);
     /*计算平均串长*/
    strlist->avg_strlen = (double) strlist->total_strlen / strlist->str_num;
    /* 计算串长标准差 */
    strlist->strlen_sd = cal_sd(strlist);
    
    efclose(fp);
    
    return strlist;
}
예제 #23
0
파일: state_gen.c 프로젝트: GZJ/regex
// ------------------------------ generate nfa node ------------------------------
static inline size_t _node_new(struct reg_pattern* pattern){
  size_t len = list_len(pattern->state_list);
  struct reg_node v = {
    .node_pos = len+1,
    .merge_pos = 0,
    .is_end = 0,
    .subset_tag = 0,
    .subset = NULL,
    .edges = list_new(sizeof(struct _reg_path), DEF_EDGE),
  };
  size_t idx = list_add(pattern->state_list, &v);
  return idx + 1;
}

static inline void _node_tag(struct reg_pattern* pattern, size_t node_pos, int tag){
  assert(node_pos);
  state_node_pos(pattern, node_pos)->subset_tag = tag;
}
예제 #24
0
파일: t_opt.c 프로젝트: elominp/zappy
static bool
opts_are_valid(t_opt *o)
{
  if ((o->x_size * o->y_size) > MAX_TILE_NUMBER)
    {
      ERR(RED"Requested map size must be < %d  total"WHITE, MAX_TILE_NUMBER);
      return (false);
    }
  if (o->time > 1000)
    return (ERR(RED"-t opt must be < 1000\n"WHITE), false);
  if (list_len(o->teams) < 2)
    return (ERR(RED"need a team, add one or more with -n !\n"WHITE), false);
  if (o->port >= 0xFFFF || !o->port)
    return (ERR(RED"You need to define a port number (-p)\n"WHITE), false);
  if (o->port > 0xFFFF)
    return (ERR(RED"Port number should be < 65536\n"WHITE), false);
  return (true);
}
예제 #25
0
void test_remove_dups() {
  
  
  node_t *head = NULL;
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 1);
  add_node(&head, 2);
  add_node(&head, 2);

  
  
  node_t *new_head = remove_list_dups(&head);
  
  assert(list_len(new_head) == 2);
  
  traverse_node(new_head, print_node);
  
}
예제 #26
0
파일: urltrans.c 프로젝트: armic/erpts
int urltrans_add_one(URLTranslationList *trans, CfgGroup *grp)
{
    URLTranslation *ot;
    long i;
    List *list, *list2;
    Octstr *alias;
    
    ot = create_onetrans(grp);
    if (ot == NULL)
	return -1;
		
    list_append(trans->list, ot);
    
    list2 = dict_get(trans->names, ot->name);
    if (list2 == NULL) {
    	list2 = list_create();
	dict_put(trans->names, ot->name, list2);
    }
    list_append(list2, ot);

    if (ot->keyword == NULL || ot->type == TRANSTYPE_SENDSMS)
    	return 0;

    list = dict_get(trans->dict, ot->keyword);
    if (list == NULL) {
    	list = list_create();
	dict_put(trans->dict, ot->keyword, list);
    }
    list_append(list, ot);

    for (i = 0; i < list_len(ot->aliases); ++i) {
	alias = list_get(ot->aliases, i);
	list = dict_get(trans->dict, alias);
	if (list == NULL) {
	    list = list_create();
	    dict_put(trans->dict, alias, list);
	}
	list_append(list, ot);
    }


    return 0;
}
예제 #27
0
파일: eval.c 프로젝트: S010/misc
struct expr    *
null(struct expr * e, struct context * ctx)
{
	struct expr    *a, *re;

	if (!e || list_len(e) < 2) {
		free_expr(e);
		return empty_list();
	}
	a = eval(e->v.list->next->v, ctx);

	if (is_empty_list(a))
		re = atom_t();
	else
		re = empty_list();

	full_free_expr(a);
	return re;
}
예제 #28
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();
}
예제 #29
0
파일: urltrans.c 프로젝트: armic/erpts
/*
 * checks if the number of passed words matches the service-pattern defined in the
 * translation. returns 0 if arguments are okay, -1 otherwise.
 */
static int check_num_args(URLTranslation *t, List *words)
{
    const int IS_OKAY = 0;
    const int NOT_OKAY = -1;
    int n;

    
    n = list_len(words);
    /* check number of arguments */
    if (t->catch_all)
        return IS_OKAY;
    
    if (n - 1 == t->args)
        return IS_OKAY;

    if (t->has_catchall_arg && n - 1 >= t->args)
        return IS_OKAY;

    return NOT_OKAY;
}
예제 #30
0
파일: wap-maps.c 프로젝트: armic/erpts
void wap_map_destroy(void) 
{
    long i;
    struct url_map_struct *entry;

    if (url_map != NULL) {
        for (i = 0; i < list_len(url_map); i++) {
            entry = list_get(url_map, i);
            octstr_destroy(entry->name);
            octstr_destroy(entry->url);
            octstr_destroy(entry->map_url);
            octstr_destroy(entry->send_msisdn_query);
            octstr_destroy(entry->send_msisdn_header);
            octstr_destroy(entry->send_msisdn_format);
            gw_free(entry);
        }
        list_destroy(url_map, NULL);
    }
    url_map = NULL;
}