コード例 #1
0
ファイル: btree_rb.c プロジェクト: NobleGaz/PHP
/*
 * Append a string representation of the entire node to orig and return it.
 * This is used to produce debugging information if check_redblack_tree() finds
 * a problem with a red-black binary tree.
 */
static char *append_node(char * orig, BtRbNode *pNode, int indent)
{
  char buf[128];
  int i;

  for( i=0; i<indent; i++ ){
      orig = append_val(orig, " ");
  }

  sprintf(buf, "%p", pNode);
  orig = append_val(orig, buf);

  if( pNode ){
    indent += 3;
    if( pNode->isBlack ){
      orig = append_val(orig, " B \n");
    }else{
      orig = append_val(orig, " R \n");
    }
    orig = append_node( orig, pNode->pLeft, indent );
    orig = append_node( orig, pNode->pRight, indent );
  }else{
    orig = append_val(orig, "\n");
  }
  return orig;
}
コード例 #2
0
   Document::Document( const char* NamespaceString, const char* prefix, const char* type, const char* Declaration )
      : Declaration( Declaration )
      , prefix( prefix )
      , root( 0 )
   {
      // xml declaration. TODO: use parameter
      ::rapidxml::xml_node<>* decl = allocate_node( ::rapidxml::node_declaration );
      decl->append_attribute( allocate_attribute( "version", "1.0" ) );
      decl->append_attribute( allocate_attribute( "encoding", "utf-8" ) );
      append_node( decl );

      if ( type )
      {
         // root node
         root = allocate_node( ::rapidxml::node_element, PrefixType( type ) );

         ::std::string temp( "xmlns" );
         if ( ::strlen( prefix ) != 0 )
         {
            temp.append( ":" );
            temp.append( prefix );
         }
         root->append_attribute( allocate_attribute( allocate_string( temp.c_str(), temp.size()+1 ), NamespaceString ) );
         append_node( root );
      }
   }
コード例 #3
0
ファイル: main.c プロジェクト: zydeon/mosal
void init_tables( ){
	/**
	 * Allocates memory for the DP table and
	 * initialize the base cases.
	 */		
	
	int i;

	Q = (Pareto_set **) malloc( (M+1) * sizeof(Pareto_set *) );
	S = (Pareto_set **) malloc( (M+1) * sizeof(Pareto_set *) );
	T = (Pareto_set **) malloc( (M+1) * sizeof(Pareto_set *) );

	for(i=0; i<M+1 ; i++){
		Q[i] = (Pareto_set *) malloc( (N+1) * sizeof(Pareto_set) );
		S[i] = (Pareto_set *) malloc( (N+1) * sizeof(Pareto_set) );
		T[i] = (Pareto_set *) malloc( (N+1) * sizeof(Pareto_set) );
	}


	Q[0][0] = create_list( );
	append_node( Q[0][0], 0, 0, NULL, '\0' );
	/* base cases */
	for( i = 1; i <= M; ++i ){
		S[i][0] = create_list(); append_node( S[i][0], 0, INT_MAX, NULL, '-' );	/* against DP table definition (wrong position of gap if traceback is done) */
		Q[i][0] = create_list(); append_node( Q[i][0], 0, 1, Q[i-1][0]->next, 'u' );
		prune( Q[i][0], i, 0, 'u' );
	}
	for( i = 1; i <= N; ++i ){
		T[0][i] = create_list(); append_node( T[0][i], 0, INT_MAX, NULL, '-' );	/* against DP table definition (wrong position of gap if traceback is done) */
		Q[0][i] = create_list(); append_node( Q[0][i], 0, 1, Q[0][i-1]->next, 'l' );				
		prune( Q[0][i], 0, i, 'l' );
	}

}
コード例 #4
0
ファイル: iptables.c プロジェクト: LastRitter/llconf
static
void parse_iptables_rules(struct cnfnode *cn_table, struct confline *cl)
{
	struct cnfnode *cn_chain, *cn;
	const char *p = cl->line;
	char buf[256];

	/* -A */
	dup_next_word_b(&p, buf, sizeof(buf)-1);

	/* chain: */
	dup_next_word_b(&p, buf, sizeof(buf)-1);
	cn_chain = create_cnfnode(buf);

	/* options: */
	while(*p && isspace(*p)) p++;
	while(*p){
		char option[64];
		int inv = 0;

		if(*p == '!'){
			inv = 1;
			p++;
			while(*p && isspace(*p)) p++;
		}

		dup_next_word_b(&p, option, sizeof(option)-1);
		cn = create_cnfnode(option);

		while(*p && isspace(*p)) p++;
		if(*p == '!'){
			inv = 1;
			p++;
			while(*p && isspace(*p)) p++;
		}

		dup_next_word_b(&p, buf, sizeof(buf)-1);
		cnfnode_setval(cn, buf);
		append_node(cn_chain, cn);

		if(inv){
			struct cnfnode *cn_inv;
			cn_inv = create_cnfnode("inv");
			append_node(cn, cn_inv);
		}

		while(*p && isspace(*p)) p++;
	}
	append_node(cn_table, cn_chain);
}
コード例 #5
0
ファイル: table.c プロジェクト: LastRitter/llconf
struct cnfnode *parse_table(struct cnfmodule *cm, FILE *fptr)
{
	struct cnfnode *cn_root, *cn_top, *cn;
	struct confline *cl, *cl_root;
	char *cols[32];
	int ncols, i;
	int sep = -1;

	cl_root = read_conflines(fptr);

	cn_root = create_cnfnode("(root)");

	if(cm && cm->opt_root){
		if((ncols = parse_table_options(cm->opt_root, cols, 32, &sep)) <= 0){
			fprintf(stderr, "need 'cols' option for table module\n");
			return NULL;
		}
	}else{
		fprintf(stderr, "need 'cols' option for table module\n");
		return NULL;
	}

	for(cl = cl_root; cl; cl = cl->next){
		const char *p = cl->line;
		char buf[strlen(p)+1];

		while(*p && isspace(*p)) p++;
		if(*p && *p != '#'){
			cn_top = parse_table_line(&p, cols, ncols, sep);
			if(cn_top)
				append_node(cn_root, cn_top);

		}else if(*p == '#'){
			cn = create_cnfnode(".comment");
			cnfnode_setval(cn, dup_next_line_b(&p, buf, sizeof(buf)-1));
			append_node(cn_root, cn);
		}else if(!*p){
			cn = create_cnfnode(".empty");
			cnfnode_setval(cn, "");
			append_node(cn_root, cn);
		}
	}

	for(i = 0; i < ncols; i++)
		if(cols[i]) free(cols[i]);


	destroy_confline_list(cl_root);
	return cn_root;
}
コード例 #6
0
ファイル: table.c プロジェクト: LastRitter/llconf
struct cnfnode *parse_table_line(const char **pp, char **cols, int ncols, int sep)
{
	struct cnfnode *cn_top, *cn;
	int i = 0;
	const char *p = *pp;
	char buf[strlen(p)+1];

	if(sep == -1){
		cn_top = create_cnfnode(dup_next_word_b(&p, buf, sizeof(buf)-1));
		while(*p && isspace(*p)) p++;
	}else{
		cn_top = create_cnfnode(dup_line_until_b(&p, sep, buf, sizeof(buf)-1));
		if(*p) p++;
	}
	
	i = 1;
	while(*p && i < ncols-1){
		cn = create_cnfnode(cols[i++]);
		if(sep == -1){
			cnfnode_setval(cn, dup_next_word_b(&p, buf, sizeof(buf)-1));
			while(*p && isspace(*p)) p++;
		}else{
			cnfnode_setval(cn, dup_line_until_b(&p, sep, buf, sizeof(buf)-1));
			if(*p) p++;
		}
		append_node(cn_top, cn);
	}
	
	while(*p && i < ncols-1){
		cn = create_cnfnode(cols[i++]);
		if(sep == -1){
			cnfnode_setval(cn, dup_next_word_b(&p, buf, sizeof(buf)-1));
			while(*p && isspace(*p)) p++;
		}else{
			cnfnode_setval(cn, dup_line_until_b(&p, sep, buf, sizeof(buf)-1));
			if(*p) p++;
		}
		append_node(cn_top, cn);
	}

	if(*p){
		cn = create_cnfnode(cols[i++]);
		cnfnode_setval(cn, dup_next_line_b(&p, buf, sizeof(buf)-1));
		append_node(cn_top, cn);
	}

	*pp = p;
	return cn_top;
}
コード例 #7
0
ファイル: ini.c プロジェクト: ITh4cker/DECAF
struct cnfnode *parse_ini(struct cnfmodule *cm, FILE *fptr)
{
	struct cnfnode *cn_top, *cn;
	struct confline *cl, *cl_root;
	int cmt_char = '#';

	cl_root = read_conflines(fptr);

	cn_top = create_cnfnode("(root)");

	if(cm && cm->opt_root){
		parse_ini_options(cm->opt_root, &cmt_char);
	}

	for(cl = cl_root; cl;){
		const char *p = cl->line;
		char buf[1024];

		while(*p && isspace(*p)) p++;
		if(*p){
			if(*p == '['){
				char *q = buf;

				p++;
				while(*p && isspace(*p)) p++;
				while(*p && (*p != ']') && q < buf+sizeof(buf)-1) *(q++) = *(p++);
				*q = 0;

				cn = create_cnfnode(buf);
				append_node(cn_top, cn);

				cl = parse_ini_section(cl, cn, cmt_char);
			}else{
				p = cl->line;
				cn = create_cnfnode(".comment");
				cnfnode_setval(cn, dup_next_line_b(&p, buf, sizeof(buf)-1));
				append_node(cn_top, cn);
				cl = cl->next;
			}
		}else{
			cn = create_cnfnode(".empty");
			cnfnode_setval(cn, "");
			append_node(cn_top, cn);
			cl = cl->next;
		}
	}
	destroy_confline_list(cl_root);
	return cn_top;
}
コード例 #8
0
ファイル: SpecialFolder.cpp プロジェクト: fin-alice/bb4nt
void join_folders(SpecialFolderItem *i1st)
{
	SpecialFolderItem *i2nd;
	if (i1st) while (NULL != (i2nd = (SpecialFolderItem *)i1st->next))
	{
		if (0 == _tcsicmp(i1st->m_pszTitle, i2nd->m_pszTitle))
		{
			if (i1st->m_ItemID == MENUITEM_ID_SF && i2nd->m_ItemID == MENUITEM_ID_SF)
			{
				// if both are folders
				if (i2nd->m_pidl_list->v)
				{
					append_node(&i1st->m_pidl_list, i2nd->m_pidl_list);
					i2nd->m_pidl_list = NULL;
				}
			join:
				i1st->next = i2nd->next, delete i2nd;
				continue;
			}

			if (i1st->m_ItemID != MENUITEM_ID_SF && i2nd->m_ItemID != MENUITEM_ID_SF)
			{
				// if both are not folders
				goto join;
			}
		}
		i1st = i2nd;
	}
}
コード例 #9
0
//===========================================================================
void MessageManager_Register(HWND hwnd, const UINT* messages, bool add)
{
    UINT msg;
    while (0 != (msg = *messages++))
    {
        struct MsgMap *mm = (struct MsgMap *)assoc(msgs, (void*)msg);
        if (mm) {
            if (remove_assoc(&mm->winmap, hwnd))
                --mm->count;

        } else if (add) {
            mm = c_new(struct MsgMap);
            mm->msg = msg;
            append_node (&msgs, mm);
            // these are the messages that expect return values and
            // are handled differently in 'MessageManager_Send()'
            mm->send_mode = BB_DRAGTODESKTOP == msg || BB_GETBOOL == msg;
        }

        if (add) {
            struct winmap *w = c_new(struct winmap);
            w->hwnd = hwnd;
            cons_node(&mm->winmap, w);
            ++mm->count;
            dbg_msg("add", hwnd, msg);

        } else if (mm) {
            if (NULL == mm->winmap)
                remove_item(&msgs, mm);
            dbg_msg("del", hwnd, msg);
        }
    }
コード例 #10
0
extern int threadCreate(thFuncPtr funcPtr, void *argPtr) {
    interruptDisable();

    // Create a thread structure for the user function
    thread_t *t = (thread_t *) malloc(sizeof(thread_t));
    getcontext(&t->context);
    // Make a stack for it
    t->context.uc_stack.ss_sp = malloc(STACK_SIZE);
    t->context.uc_stack.ss_size = STACK_SIZE;
    t->context.uc_stack.ss_flags = 0;
    t->context.uc_link = &start->t->context;
    // Add other details
    t->func = funcPtr;
    t->arg = argPtr;
    t->done = 0;
    t->id = ++thread_count;
    makecontext(&t->context, (void (*)(void)) runThread, 1, t);

    // Create the node structure
    node_t *newnode = (node_t *) malloc(sizeof(node_t));
    newnode->t = t;
    // Add it to the list
    append_node(newnode);
    // Run it (or something else)
    threadYieldInternal();

    interruptEnable();
    return newnode->t->id;
}
コード例 #11
0
Model_t *Model_add_component (Model_t *head, Model_t *x,  /*{{{*/
                              unsigned int *elem, float *elem_abund, unsigned int num_elems)
{
   Model_t *m = new_model_node ();

   if ((m == NULL) || (x == NULL))
     return NULL;

   m->temperature = x->temperature;
   m->density = x->density;
   m->vturb = x->vturb * 1.e5;    /* km/s -> cm/s */
   m->norm = x->norm * 1.e14;
   m->redshift = x->redshift;
   m->metal_abund = x->metal_abund;

   if (-1 == set_rel_abund (m, x->metal_abund, elem_abund, elem, num_elems))
     {
        free_model_node (m);
        return NULL;
     }

   if (head == NULL)
     head = m;
   else if (-1 == append_node (m, head))
     {
        free_model_node (m);
        return NULL;
     }

   return head;
}
コード例 #12
0
ファイル: btree_rb.c プロジェクト: NobleGaz/PHP
/*
 * Print a representation of a node to stdout. This function is only included
 * so you can call it from within a debugger if things get really bad.  It
 * is not called from anyplace in the code.
 */
static void print_node(BtRbNode *pNode)
{
    char * str = append_node(0, pNode, 0);
    printf("%s", str);

    /* Suppress a warning message about print_node() being unused */
    (void)print_node;
}
コード例 #13
0
ファイル: Pidl.cpp プロジェクト: Jmos/bbclean-xzero450
//================================================
struct pidl_node *copy_pidl_list(const struct pidl_node *old_pidl_list)
{
	const struct pidl_node *p;
	struct pidl_node *new_pidl_list = NULL;
	dolist (p, old_pidl_list)
		append_node(&new_pidl_list, new_node(duplicateIDlist(p->v)));
	return new_pidl_list;
}
コード例 #14
0
ファイル: simpleList.c プロジェクト: trejoel/Ch03
int main(void) {
	int num = 0;
	int input = 1;
	int retval = 0;
	//struct NODE *llist;
	miNodo *llist;
	

	llist = (struct NODE *)malloc(sizeof(struct NODE));
	llist->number = 0;
	llist->next = NULL;
	
	while(input != 0) {
		printf("\n-- Menu Selection --\n");
		printf("0) Quit\n");
		printf("1) Insert\n");
		printf("2) Delete\n");
		printf("3) Search\n");
		printf("4) Display\n");
		scanf("%d", &input);
		
		switch(input) {
			case 0: 
			default:
				printf("Goodbye ...\n");
				input = 0;
				break;
			case 1:
				printf("Your choice: `Insertion'\n");
				printf("Enter the value which should be inserted: ");
				scanf("%d", &num);
				append_node(llist, num);
				break;
			case 2:
				printf("Your choice: `Deletion'\n");
				printf("Enter the value which should be deleted: ");
				scanf("%d", &num);
				delete_node(llist, num);
				break;
			case 3:
				printf("Your choice: `Search'\n");
				printf("Enter the value you want to find: ");
				scanf("%d", &num);
				if((retval = search_value(llist, num)) == -1)
					printf("Value `%d' not found\n", num);
				else
					printf("Value `%d' located at position `%d'\n", num, retval);
				break;
			case 4:
				printf("You choice: `Display'\n");
				display_list(llist);
				break;
		} /* switch */
	} /* while */
	
	free(llist);
	return(0);
}
コード例 #15
0
ファイル: ipsec.c プロジェクト: ITh4cker/DECAF
struct cnfnode *parse_ipsec(struct cnfmodule *cm, FILE *fptr)
{
	struct cnfnode *cn_root, *cn;
	struct confline *cl, *cl_root;

	cl_root = read_conflines(fptr);

	cn_root = create_cnfnode("(root)");

	for(cl = cl_root; cl;){
		const char *p = cl->line;
		char buf[strlen(p)+1];

		while(*p && isspace(*p)) p++;
		if(*p){
			if(strncmp("config", p, 6) == 0){
				cn = create_cnfnode("config");
				append_node(cn_root, cn);
				cl = parse_ipsec_stanza(cl, cn);
			}
			else if(strncmp("conn", p, 4) == 0){
				cn = create_cnfnode("conn");
				append_node(cn_root, cn);
				cl = parse_ipsec_stanza(cl, cn);
			}
			else if(strncmp("include", p, 7) == 0){
				cn = create_cnfnode("include");
				append_node(cn_root, cn);
				cl = parse_ipsec_include(cl, cn);
			}else{
				cn = create_cnfnode(".comment");
				cnfnode_setval(cn, dup_next_line_b(&p, buf, sizeof(buf)-1));
				append_node(cn_root, cn);
				cl = cl->next;
			}
		}else{
			cn = create_cnfnode(".empty");
			cnfnode_setval(cn, "");
			append_node(cn_root, cn);
			cl = cl->next;
		}
	}
	destroy_confline_list(cl_root);
	return cn_root;
}
コード例 #16
0
ファイル: iproute.c プロジェクト: ITh4cker/DECAF
struct cnfnode *parse_iproute(struct cnfmodule *cm, FILE *fptr)
{
	struct cnfnode *cn_root, *cn_top, *cn;
	struct confline *cl, *cl_root;

	cl_root = read_conflines(fptr);

	cn_root = create_cnfnode("(root)");

	for(cl = cl_root; cl; cl = cl->next){
		char buf[256];
		const char *p = cl->line;

		if(*p && *p != '#'){
			dup_next_word_b(&p, buf, sizeof(buf)-1);
			
			cn_top = create_cnfnode(buf);
			
			skip_spaces(&p);
			/* simple assumption that args are key, spaces, value repeated.
			   This is no true for all ip arguments. */
			while(*p){
				dup_next_word_b(&p, buf, sizeof(buf)-1);
				cn = create_cnfnode(buf);
				dup_next_word_b(&p, buf, sizeof(buf)-1);
				cnfnode_setval(cn, buf);
				skip_spaces(&p);
				append_node(cn_top, cn);
			}
			append_node(cn_root, cn_top);

		}else if(*p == '#'){
			cn = create_cnfnode(".comment");
			cnfnode_setval(cn, dup_next_line_b(&p, buf, 255));
			append_node(cn_root, cn);
		}else{
			cn = create_cnfnode(".empty");
			cnfnode_setval(cn, "");
			append_node(cn_root, cn);
		}
	}

	destroy_confline_list(cl_root);
	return cn_root;
}
コード例 #17
0
ファイル: o_sllist.c プロジェクト: nettee/code_history
list list_copy(const list p)
{
    list ls = make_nil();
    for (node *q = p; q != NULL; q = q->next) {
        node *pnew = copy_node(q);
        append_node(&ls, pnew);
    }
    return ls;
}
コード例 #18
0
ファイル: TestList.c プロジェクト: Blurred-9L/NodesAndLinks
int main(){
    List list;
    List list2;
    int i;
    
    init_list( &list );
    printf( "Empty: %d\n", empty_list( list ) );
    for( i = 1; i <= 5; i++ ){
        append_node( &i, sizeof( int ), list );
        printf( "Length: %d | ", length( list ) );
        print_list( list );
    }
    for( i = 6; i <= 10; i++ ){
        insert_front( &i, sizeof( int ), list );
        printf( "Length: %d | ", length( list ) );
        print_list( list );
    }
    printf( "Empty: %d\n", empty_list( list ) );
    printf( "First: %d\n", get_int( list_op_first( list ) -> data ) );
    printf( "Last:  %d\n", get_int( list_op_last( list ) -> data ) );
    printf( "Second to last: %d\n", get_int( list_op_prev( list_op_last( list ), list ) -> data ) );
    printf( "Second element: %d\n", get_int( get_elem_at( 1, list ) -> data ) );
    
    place_after( &i, sizeof( int ), get_elem_at( 1, list ), list );
    print_list( list );
    i++;
    insert_at( &i, sizeof( int ), 2, list );
    print_list( list );
    i++;
    insert_at( &i, sizeof( int ), 0, list );
    print_list( list );
    
    init_list( &list2 );
    for( i = 100; i > 95; i-- ){
        insert_front( &i, sizeof( int ), list2 );
    }
    append_list( list, &list2 );
    free( list2 );
    print_list( list );
    
    printf( "Erasing 5th element...\n" );
    erase_at( 4, list );
    print_list( list );
    printf( "Erasing 1st element...\n" );
    erase_at( 0, list );
    print_list( list );
    printf( "Erasing last element...\n" );
    erase_node( list_op_last( list ), list );
    print_list( list );
    printf( "Erasing 3rd element...\n" );
    erase_node( get_elem_at( 2, list ), list );
    print_list( list );
    
    clear_list( &list );
    
    return 0;
}
コード例 #19
0
ファイル: compile_regexp.c プロジェクト: AndreasSong/femto
error_t add_character_node(thompson_nfa_description_t* dst, alpha_t character)
{
  thompson_nfa_node_t node;
  node.character = character;
  node.character_set = NULL;
  node.num_epsilon = 0;
  node.epsilon_dst = NULL;
  return append_node(dst, &node);
}
コード例 #20
0
ファイル: compile_regexp.c プロジェクト: AndreasSong/femto
error_t add_epsilon_node(thompson_nfa_description_t* dst)
{
  thompson_nfa_node_t node;
  node.character = INVALID_ALPHA;
  node.character_set = NULL;
  node.num_epsilon = 0;
  node.epsilon_dst = NULL;
  return append_node(dst, &node);
}
コード例 #21
0
ファイル: pair.c プロジェクト: ITh4cker/DECAF
struct cnfnode *parse_pair(struct cnfmodule *cm, FILE *fptr)
{
	struct cnfnode *cn_root, *cn = NULL;
	struct confline *cl, *cl_root;
	int sep = -1;

	cl_root = read_conflines(fptr);

	cn_root = create_cnfnode("(root)");

	if(cm && cm->opt_root){
		parse_pair_options(cm->opt_root, &sep);
	}

	for(cl = cl_root; cl; cl = cl->next){
		char buf[256];
		const char *p = cl->line;

		while(*p && isspace(*p)) p++;
		if(*p){
			if(*p != '#'){
				cn = parse_pair_line_sep(&p, sep);
				if(cn)
					append_node(cn_root, cn);

			}else if(*p == '#'){
				cn = create_cnfnode(".comment");
				cnfnode_setval(cn, dup_next_line_b(&p, buf, 255));
				append_node(cn_root, cn);
			}else{
				cn = create_cnfnode(".unparsed");
				cnfnode_setval(cn, cl->line);
				append_node(cn_root, cn);
			}
		}else{
			cn = create_cnfnode(".empty");
			cnfnode_setval(cn, "");
			append_node(cn_root, cn);
		}
      
	}
	destroy_confline_list(cl_root);
	return cn_root;
}
コード例 #22
0
ファイル: driver.cpp プロジェクト: moneyease/prep
int _list () {
	node* head = NULL;
//	node* head2 = NULL;
	int i = 0;// 'A';
	//int count = 0;
	while (i<10)
		append_node(&head,i++);
i--;
	while (i>=0)
		append_node(&head,i--);

#if 0
	insert_node(&head,11);
	insert_node(&head,0);
	insert_node(&head,100);
#endif
	print_node(head);
    //even_odd_merge(head);
	list_mirror (head);
    //reverse_sublist (&head, 5, 6);
	print_node(head);
	printf ("Total # of node is %d\n",count_node(head));
//	print_node(head2);
//	printf ("Total # of node is %d\n",count_node(head2));
//    node* result = merge_lists(head, head2);
//	print_node(result);
//	printf ("Total # of node is %d\n",count_node(result));
	// print_nth_node_from_last_rec(head,3,count);
	// prepend_node(&head,i++);
	// prepend_node(&head,i);
	// head = reverse_list(head);
	// reverse_list(&head);
	// print_node(head);
	// print_nth_node_from_last_rec(head,3,count);
	// printf ("Total # of node is %d\n",count_node(head));
	// printf ("loop %s detected\n",detect_loop (head)? "is":"is not");
	// delete_node(&head,i);
	// printf ("Total # of node is %d\n",count_node(head));
	// delete_node_by_addr(head);
	// printf ("5th node from last is %d\n",print_nth_node_from_last (head,5));
	// print_node(head);
	// printf ("Total # of node is %d\n",count_node(head));
	return 0;
}
コード例 #23
0
ファイル: syslogng.c プロジェクト: ITh4cker/DECAF
struct cnfnode *parse_syslogng(struct cnfmodule *cm, FILE *fptr)
{
	struct cnfnode *cn_top, *cn_root;
	struct confline *cl, *cl_root;

	cl_root = read_conflines(fptr);

	cn_root = create_cnfnode("(root)");

	for(cl = cl_root; cl;){
		const char *p = cl->line;
		char buf[256];

		cl = _skip_spaces(cl, &p);
		if(!*p) break;
		if(*p){
			dup_next_word_b(&p, buf, sizeof(buf)-1);

			append_node(cn_root, cn_top = create_cnfnode(buf));

			if((strcmp(buf, "options") == 0) || (strcmp(buf, "log") == 0)){
				cl = parse_syslogng_options(cn_top, cl, p);
			}else if((strcmp(buf, "source") == 0) ||
				 (strcmp(buf, "destination") == 0)){
				struct cnfnode *cn_top1;

				cl = _skip_spaces(cl, &p);
				dup_next_word_b(&p, buf, sizeof(buf)-1);
				append_node(cn_top, cn_top1 = create_cnfnode(buf));
				cl = parse_syslogng_options(cn_top1, cl, p);
			}else if(strcmp(buf, "filter") == 0){
				struct cnfnode *cn_top1;

				cl = _skip_spaces(cl, &p);
				dup_next_word_b(&p, buf, sizeof(buf)-1);
				append_node(cn_top, cn_top1 = create_cnfnode(buf));
				cl = parse_syslogng_filter(cn_top1, cl, p);
			}
			if(cl) cl = cl->next;
		}
	}
	destroy_confline_list(cl_root);
	return cn_root;
}
コード例 #24
0
ファイル: linked_list.c プロジェクト: slagyr/8LU
void run_test() {
	total = 0;

	node* head = new_node(42);
	append_node(head, new_node(24));
	append_node(head, new_node(89));
	append_node(head, new_node(11));

	walk_nodes(total_nodes, head);

	free_node_list(head);

	if (total == 166) {
		printf("passed\n");
	}
	else {
		printf("expected total = 166, got %d\n", total);
	}
}
コード例 #25
0
ファイル: mymem.c プロジェクト: ohmygod12121212/schoolwork
static node_t* get_free_node()
{
	if (!heap->free_node)
	{
		append_node();
	}
	node_t* ret = heap->free_node;
	heap->free_node = ret->next;
	return ret;
}
コード例 #26
0
ファイル: job.c プロジェクト: SOII-2016/ghostshell
int run_bg(int pid, int pgid, char *name)
{
	int i;
	list_node_t *job = append_node(jobs);
	job->value = malloc(sizeof(job_t));
	job->value->pid = pid;
	job->value->pgid = pgid;
	job->value->status = 0;
	strcpy(job->value->name, name);
	return set_job_background(job);
}
コード例 #27
0
ファイル: main.c プロジェクト: zydeon/mosal
void init_dynamic_tables( ){
	/**
	 * Allocates memory for the all the DP tables and
	 * initialize the its base cases.
	 */
	
	int i, j;

	Q = (Pareto_set **) malloc( 2 * sizeof(Pareto_set *) );
	T = (Pareto_set **) malloc( 2 * sizeof(Pareto_set *) );

	for(i=0; i<2 ; i++){
		Q[i] = (Pareto_set *) malloc( (N+1) * sizeof(Pareto_set) );
		T[i] = (Pareto_set *) malloc( (N+1) * sizeof(Pareto_set) );

		/* allocate memory */
		for( j = 0; j < N+1; ++j ){
			Q[i][j].scores = (VMG *) malloc(MAX_STATES * sizeof(VMG));
			Q[i][j].num = 0;
			T[i][j].scores = (VMG *) malloc(MAX_STATES * sizeof(VMG));
			T[i][j].num = 0;			
		}
	}
	S = (Pareto_set *) malloc( (N+1) * sizeof(Pareto_set) );
	for( i = 0; i < N+1; ++i ){
		S[i].scores = (VMG *)malloc( MAX_STATES * sizeof(VMG));
		S[i].num = 0;
	}


	/* base cases */
	append_node( &Q[0][0], 0, 0 );
	for( i = 1; i <= N; ++i ){
		append_node( &T[0][i], 0, INT_MAX );	/* against DP table definition (wrong position of gap if traceback is done) */

		append_node( &Q[0][i], 0, 1 );				
		prune( &Q[0][i], 0, i, 'l' );
	}

	append_node( &S[0], 0, INT_MAX); 	/* against table definition	(wrong position of gap if traceback is done) */
}
コード例 #28
0
ファイル: test-0140.c プロジェクト: jpokorny/predator
int main()
{
    // NOTE: two nodes should be enough to trigger DLS abstraction by default
    //       and consequently the spurious memory leak in the end
    LIST_HEAD(list);
    append_node(&list);
    append_node(&list);

    // plot heap in each iteration
    struct node *pos;
    list_for_each_entry(pos, &list, embedded_head)
        ___sl_plot(NULL);

    // plot heap after list_for_each_entry() -- an off-value should be there
    ___sl_plot(NULL);

    // use list_entry()
    free(list_entry(list.next, struct node, embedded_head));
    free(list_entry(list.prev, struct node, embedded_head));
    return 0;
}
コード例 #29
0
ファイル: compilerAPI.c プロジェクト: eschluter/c-compiler
void process_p_declaration (TYPE t, char * id) {
	char * idcpy;
	int baseoffset;
	// calculate base pointer offset
	baseoffset = 8 + (4 * sts->current_scope->paramslist->size);
	// for function parameter declarations
	st_insert_id (sts, id, PARAM, t, baseoffset, NULL);
	// make copy of id name
	idcpy = strcpy( (char*)malloc(strlen(id)+1), id );
	// fill the paramslist
	append_node (sts->current_scope->paramslist, idcpy, PARAM, t, baseoffset, NULL);
}
コード例 #30
0
ファイル: entry.c プロジェクト: ITh4cker/DECAF
/** Add a branch to a tree.
 * Add a branch to an existing tree of nodes. If part of the tree already exists,
 * and do_merge==1, the remainder will be created. For example, if path is
 * "iface/eth0/address", and "iface/eth0" already exists and do_merge==1, just "address"
 * will be appended to "iface/eth0". If do_merge==0, a whole new subtree, starting with "iface"
 * will be appended.
 * @param [in] cn_root pointer to the root of the tree
 * @param [in] path the path to append to
 * @param [in] do_merge flag as described above
 * @return pointer to the last newly created node
 */
struct cnfnode *cnf_add_branch(struct cnfnode *cn_root, const char *path, int do_merge)
{
	struct cnfnode *cn = NULL, *cn_parent;
	const char *p;
  
	cn_parent = cn_root;
	p = path;
	while(*p){
		char dname[256], *q;
		const char *p0;
#if 0		
		q = dname;
		while(*p && (*p != '/') && (*p != '=') && (q < dname+255)) *q++ = *p++;
		*q = 0;
#else
		q = dname;
		p0 = p;
		while(*p && ((*p != '/' && *p != '=') || (p > p0 && p[-1] == '\\')) &&
		      (q < dname+255)){
			if(*p == '\\')
				p++;
			else
				*(q++) = *(p++);
		}
		*q = 0;
#endif
		cn = NULL;
		if(do_merge){
			for(cn = cn_parent->first_child; cn; cn = cn->next){
				if(strcmp(cn->name, dname) == 0){
					break;
				}
			}
		}
		if(cn == NULL){
			append_node(cn_parent, cn = create_cnfnode(dname));
		}
		cn_parent = cn;

		if(*p == '='){
			char buf[256];
			p++;
			if(*p)
				cnfnode_setval(cn, dup_next_line_b(&p, buf, 255));
			else
				cnfnode_setval(cn, "");
			break;
		}else if(*p == '/'){
			p++;
		}else break;
	}
	return cn;
}