예제 #1
0
/*
* 函数:control_regist
* 函数功能:注册处理函数
* 函数参数:文件描述符, send_packet指针
* 返回值:无
*/
void control_regist(int fd, send_packet* recvPack){
    assert(NULL != recvPack);
    printf("%s %s\n", recvPack->user_name, recvPack->user_passwd);    
    link_p curr_head = user_head->next;
    while(curr_head != user_head){
        if(0 == strcmp(((user_p)(curr_head->value_p))->name,
                       recvPack->user_name)){
            send_packet sendPack;
            sendPack.data_type = 13; 
            write(fd, &sendPack, sizeof(sendPack));
            return;
        }
        curr_head = curr_head->next;
    }

    user_p newUserStruct = (user_p)calloc(1, sizeof(user_n));
    strcpy(newUserStruct->name, recvPack->user_name);
    strcpy(newUserStruct->passwd, recvPack->user_passwd);
    memset(newUserStruct->ip, 0, sizeof(newUserStruct->ip));
    newUserStruct->linkTime = 0;
    newUserStruct->fd = -1;
    newUserStruct->online_flag = 0;
    if(1 ==add_link(user_head, creat_newUserNode(newUserStruct))){
        send_packet sendPack;
        sendPack.data_type = 11; 
        write(fd, &sendPack, sizeof(sendPack));
    }
}
예제 #2
0
void linked_list<T>::add(T element) {
    // add a new link at the end of the list, set tail accordingly
    add_link(tail, element);
    tail = tail->next;
    list_size++;
    modified = true;
}
예제 #3
0
li_object * g1_path_object_class::message(li_symbol * message_name,
										  li_object * message_params,
										  li_environment * env)
{
	li_class_context context(vars);

	if (message_name==on.get() || message_name==off.get())
	{
		active() = on.get();
	}
	else if (message_name==s_add_link.get())
	{
		g1_object_class * o=li_g1_ref::get(message_params,env)->value();
		g1_path_object_class * path = g1_path_object_class::cast(o);

		if (path)
		{
			add_link(G1_ALLY, path);
			path->add_link(G1_ENEMY, this);
		}
	}
	else if (message_name==s_remove_link.get())
	{
		g1_object_class * o=li_g1_ref::get(message_params,env)->value();
		g1_path_object_class * path = g1_path_object_class::cast(o);

		if (path)
		{
			remove_link(G1_ALLY, path);
			path->remove_link(G1_ENEMY, this);
		}
	}

	return 0;
}
예제 #4
0
int main(int argc, const char *argv[])
{
    V_NODE *head = NULL;
    int flag = 0;
    
    print_test();
    head = load_link();
    while(!flag)
    {
       
        print_list();
        switch(get_choice())
        {
            case 1:
                head = add_link(head);
                break;
            case 2:
                head = delete_link(head);
                break;
            case 3:
                print_link(head);
                break;
            case 4:
                flag = 1 ;
                save_link(head);
                break;
            default :
                break;
        }
    }
    return 0;
}
예제 #5
0
파일: recursive.c 프로젝트: overedge/FT_LS
int				recur_list(t_file **file, t_file **dir, t_env *e)
{
	t_file		*tmp;
	t_file		*tmp2;
	struct stat info_file;
	t_file		*dirtmp;

	dirtmp = NULL;
	tmp = *file;
	tmp2 = *dir;
	while (tmp)
	{
		if (!good_file(tmp->str, e))
		{
			if (lstat(tmp->total, &info_file) != 0)
				error_dir(tmp->str, e);
			if (S_ISDIR(info_file.st_mode & S_IFMT))
				add_link(tmp->total, ".", &dirtmp);
		}
		tmp = tmp->next;
	}
	if (dirtmp)
		return (merge_list(dir, &dirtmp));
	else
		return (0);
}
예제 #6
0
void campaign_tree_view::OnAddRepeat() 
{
	if (add_link(Context_mission, Context_mission)) {
		MessageBox("Too many links exist.  Can't add any more.");
		return;
	}
}
예제 #7
0
void campaign_tree_view::OnEndOfCampaign() 
{
	if ( add_link(Context_mission, -1) ) {
		MessageBox("Too many links exist.  Cannot add any more.");
		return;
	}
}
예제 #8
0
파일: routing.c 프로젝트: alvarop/cwRoute
/*******************************************************************************
 * @fn    void add_links_from_table( int8_t rssi_table[][MAX_DEVICES+1] )
 *
 * @brief Generate dijkstra links from cleaned up table
 * ****************************************************************************/
void add_links_from_table( energy_t rssi_table[][MAX_DEVICES+1] )
{
  uint16_t col_index, row_index, source, destination;


  for( row_index = 0; row_index < ( MAX_DEVICES ); row_index++ )
  {

    for( col_index = row_index + 1; col_index < ( MAX_DEVICES+1 ); col_index++ )
    {

      source = row_index;
      destination = col_index;

      // Make sure the access point has the correct address
      if( 0 == source )
      {
        source = AP_NODE_ID;
      }
      if( 0 == destination )
      {
        destination = AP_NODE_ID;
      }

      // Add link
      add_link( source, destination, link_power_table[row_index][col_index] );
    }
  }
}
예제 #9
0
파일: tag.cpp 프로젝트: asimonov-im/wesnoth
class_tag::class_tag(const config & cfg)
	: name_(cfg["name"].str())
	, min_(cfg["min"].to_int())
	, max_(cfg["max"].to_int())
	, super_("")
	, tags_()
	, keys_()
	, links_()
{
		if (max_ < 0){
			max_ = INT_MAX;
		}
		if (cfg.has_attribute("super")){
			super_ = cfg["super"].str();
		}
		foreach (const config &child, cfg.child_range("tag")) {
			class_tag child_tag (child);
			add_tag(child_tag);
		}
		foreach (const config &child, cfg.child_range("key")) {
			class_key child_key (child);
			add_key(child_key);
		}
		foreach (const config &link, cfg.child_range("link")) {
			std::string link_name = link["name"].str();
			add_link(link_name);
		}
}
예제 #10
0
int main(int argc, const char *argv[])
{
	stu *head=NULL;

	stu *p=delete_link(add_link(head));
	print_link(p);
	return 0;
}
예제 #11
0
    S2GraphManager(common::Coordinator < common::DoubleTime >* coordinator,
                   const paradevs::common::NoParameters& parameters) :
        paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
                                                             parameters),
        a("a2", common::NoParameters()), b("b2", common::NoParameters())
    {
        add_child(&a);
        add_child(&b);

        a.add_in_port("in");
        a.add_out_port("out");
        b.add_in_port("in");
        coordinator->add_in_port("in");

        add_link(&a, "out", &b, "in");
        add_link(coordinator, "in", &a, "in");
    }
예제 #12
0
int main(int c, char **argv)
{
	NODE pp[3];
	int i;
	for(i=0;i<3;i++) init_node(pp+i,-1,"A");
	//need a flag to echo whether or not a node had been initized
	//to control the access to uninitial node
	//(add_link,dsp_node,del_link,etc)
	//
	//every node need a unique number to specify the init status
	//to be compared with a number list(inc list)
	//to add a necessary col to a node !(no. type etc..
	add_link(pp,0,pp+2);
	add_link(pp,0,pp+1);
	add_link(pp+1,0,pp+2);
	for(i=0;i<3;i++) dsp_node(pp+i);
	return 0;
}
예제 #13
0
파일: tag.cpp 프로젝트: asimonov-im/wesnoth
void class_tag::append_super(const class_tag &tag,const std::string & path){
	add_keys(tag.keys_);
	add_links(tag.links_);
	for (tag_map::const_iterator i = tag.tags_.begin();i!=tag.tags_.end();++i){
		links_.erase(i->first);
		add_link(path + "/" + i->first);

	}
}
예제 #14
0
    TwoModelsGraphManager(common::Coordinator < common::DoubleTime >*
                          coordinator,
                          const paradevs::common::NoParameters& parameters) :
        paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
                                                             parameters),
        a("a", common::NoParameters()),
        b("b", common::NoParameters()),
        c("c", common::NoParameters()),
        d("d", common::NoParameters()),
        e("e", common::NoParameters()),
        f("f", common::NoParameters()),
        g("g", common::NoParameters()),
        h("h", common::NoParameters())
    {
        add_child(&a);
        add_child(&b);
        add_child(&c);
        add_child(&d);
        add_child(&e);
        add_child(&f);
        add_child(&g);
        add_child(&h);

        a.add_out_port("out");
        b.add_in_port("in");
        b.add_out_port("out");
        c.add_in_port("in");
        c.add_out_port("out");
        d.add_in_port("in");
        d.add_out_port("out");
        e.add_in_port("in");
        e.add_out_port("out");
        f.add_in_port("in");
        f.add_out_port("out");
        g.add_in_port("in");
        g.add_out_port("out");
        h.add_in_port("in");
        h.add_out_port("out");

        add_link(&a, "out", &d, "in");
        add_link(&b, "out", &d, "in");
        add_link(&b, "out", &e, "in");
        add_link(&c, "out", &e, "in");
        add_link(&d, "out", &f, "in");
        add_link(&e, "out", &f, "in");
        add_link(&e, "out", &g, "in");
        add_link(&f, "out", &h, "in");
        add_link(&g, "out", &h, "in");
    }
예제 #15
0
static void from_args(t_args *args, char *str)
{
	t_item *file;

	file = NULL;
	file = new_link(str, NULL, args);
	if (args->items)
		add_link(&(args->items), file, args->options->U);
	else
		args->items = file;
}
예제 #16
0
파일: network.c 프로젝트: marlonpuc/newman
void config_gen(void){
    int i, j;      aux1 = 2 * L;
    int v1, v2;

    for (i=1; i<aux1; i+=2) {   //Tiras verticais de elos horizontais
        ranD = gsl_rng_uniform(r);
        if(ranD<delta) 
            p = pB;
        else           
            p = pG;
    
        for (j=i; j<2*N; j+=aux1) {
            ranD = gsl_rng_uniform(r);
            if (ranD<p) {
                v1 = j/2;
                v2 = v1 + 1 - !((v1 + 1)%L) * L;
                
                add_link(v1, v2);
            }
        }
    }
    
    
    for (i=0; i<2*N; i+=aux1) {   //Tiras horizontais de elos verticais
        ranD = gsl_rng_uniform(r);
        if(ranD<delta) 
            p = pB;
        else           
            p = pG;
        
        for (j=i; j<i+aux1; j+=2) {
            ranD = gsl_rng_uniform(r);
            if (ranD<p) {
                v1 = j/2;
                v2 = (v1 + L)%N;
                
                add_link(v1, v2);
            }
        }
    }
}
예제 #17
0
t_tab	*get_in_list(char ***dim)
{
	t_tab	*list;
	int		index;

	list = NULL;
	index = 0;
	while (dim[index])
	{
		list = add_link(list, dim[index]);
		++index;
	}
	return (list);
}
예제 #18
0
    FlatGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
                     const paradevs::common::NoParameters& parameters) :
        paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
                                                          parameters),
        a1("a1", common::NoParameters()), b1("b1", common::NoParameters()),
        a2("a2", common::NoParameters()), b2("b2", common::NoParameters())
    {
        add_child(&a1);
        add_child(&b1);
        add_child(&a2);
        add_child(&b2);

        a1.add_out_port("out");
        b1.add_in_port("in");
        b1.add_out_port("out");
        a2.add_in_port("in");
        a2.add_out_port("out");
        b2.add_in_port("in");

        add_link(&a1, "out", &b1, "in");
        add_link(&b1, "out", &a2, "in");
        add_link(&a2, "out", &b2, "in");
    }
예제 #19
0
    RootGraphManager(common::Coordinator < common::DoubleTime >* coordinator,
                     const paradevs::common::NoParameters& parameters) :
        paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
                                                             parameters),
        S1("S1", paradevs::common::NoParameters(),
           paradevs::common::NoParameters()),
        S2("S2", paradevs::common::NoParameters(),
           paradevs::common::NoParameters())
    {
        add_child(&S1);
        add_child(&S2);

        add_link(&S1, "out", &S2, "in");
    }
예제 #20
0
파일: mksfs.c 프로젝트: 151706061/ucore_lab
void
open_dir(struct sfs_fs *sfs, struct cache_inode *current, struct cache_inode *parent) {
    DIR *dir;
    if ((dir = opendir(".")) == NULL) {
        open_bug(sfs, NULL, "opendir failed.\n");
    }
    add_entry(sfs, current, current, ".");
    add_entry(sfs, current, parent, "..");
    struct dirent *direntp;
    while ((direntp = readdir(dir)) != NULL) {
        const char *name = direntp->d_name;
        if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
            continue ;
        }
        if (name[0] == '.') {
            continue ;
        }
        if (strlen(name) > SFS_MAX_FNAME_LEN) {
            open_bug(sfs, NULL, "file name is too long: %s\n", name);
        }
        struct stat *stat = safe_lstat(name);
        if (S_ISLNK(stat->st_mode)) {
            add_link(sfs, current, name, stat->st_ino);
        }
        else {
            int fd;
            if ((fd = open(name, O_RDONLY)) < 0) {
                open_bug(sfs, NULL, "open failed: %s\n", name);
            }
            if (S_ISDIR(stat->st_mode)) {
                add_dir(sfs, current, name, dirfd(dir), fd, stat->st_ino);
            }
            else if (S_ISREG(stat->st_mode)) {
                add_file(sfs, current, name, fd, stat->st_ino);
            }
            else {
                char mode = '?';
                if (S_ISFIFO(stat->st_mode)) mode = 'f';
                if (S_ISSOCK(stat->st_mode)) mode = 's';
                if (S_ISCHR(stat->st_mode)) mode = 'c';
                if (S_ISBLK(stat->st_mode)) mode = 'b';
                show_fullpath(sfs, NULL);
                warn("unsupported mode %07x (%c): file %s\n", stat->st_mode, mode, name);
            }
            close(fd);
        }
    }
    closedir(dir);
}
예제 #21
0
파일: backend.c 프로젝트: cosmochefe/Oberon
void write_branch_link(item_t *item, bool forward)
{
  if (forward) {
    fpos_t position;
    fgetpos(output_file, &position);
    add_link(create_link(position), &item->links);
    write_line(BACKEND_FORWARD_LABEL);
  }
  else {
    if (item->label)
      write_line(item->label);
    else
      write_line("GOD_KNOWS_WHERE!");
  }
}
예제 #22
0
void linked_list<T>::add(int position, T element) {
    if(position < 0 || position > list_size)
        throw invalid_position_exception();

    // when "appending" call the add(x) method
    if(position == list_size) {
        add(element);
        return;
    }

    // move a link pointer to the desired position (point to link "position")
    link* current = move(head, position); 
    add_link(current, element); // place new link between "position" and "position + 1"
    list_size++;
    modified = true;
}
예제 #23
0
int main(){
  int len, m;

  scanf("%u %u", &len, &m);
  getchar();

  int** matstat;
  matstat = (int**) malloc(len*sizeof(int*));
  int i, j;
  for(i=0;i<len; i++){
    matstat[i] = (int*) calloc(len, sizeof(int));
    }

  add_link(matstat, 1,2);
  print_adjmat(matstat, len);
}
예제 #24
0
t_list	*ft_list_push_params(int ac, char **av)
{
	t_list	*list;
	int		i;

	i = 2;
	if (ac == 1)
		return (NULL);
	list = ft_create_elem(av[1]);
	while (i < ac)
	{
		list = add_link(list, av[i]);
		i++;
	}
	return (list);
}
예제 #25
0
파일: cgo.c 프로젝트: Happy-Ferret/cgo
void handle_directory_line(char *line)
{
    int     i;
    char    *lp, *last, *fields[4];

    /* tokenize */
    for (i = 0; i < 4; i++)
        fields[i] = NULL;
    last = &line[1];
    for (lp = last, i = 0; i < 4; lp++) {
        if (*lp == '\t' || *lp == '\0') {
            fields[i] = last;
            last = lp + 1;
            if (*lp == '\0')
                break;
            *lp = '\0';
            i++;
        }
    }
    /* determine listing type */
    switch (line[0]) {
        case 'i':
        case '3':
            printf("   %s\n", fields[0]);
            break;
        case '.':   /* some gopher servers use this */
            puts("");
            break;
        case '0':
        case '1':
        case '5':
        case '7':
        case '8':
        case '9':
        case 'g':
        case 'I':
        case 'p':
        case 'h':
        case 's':
            add_link(line[0], fields[0], fields[2], fields[3], fields[1]);
            break;
        default:
            printf("miss [%c]: %s\n", line[0], fields[0]);
            break;
    }
}
예제 #26
0
파일: test_route.c 프로젝트: yi5971/teapot
int main(int argc, char *argv[])
{
	int opt, op = 0, context = 0;

	while((opt = getopt(argc, argv, "adgLAR"))!=-1)
	{
		switch (opt){
		case 'a':
			op = TYPE_OP_ADD;
			break;
		case 'd':
			op = TYPE_OP_DEL;
			break;
		case 'g':
			op = TYPE_OP_GET;
			break;
		case 'L':
			context = TYPE_CONTEXT_LINK;
			break;
		case 'A':
			context = TYPE_CONTEXT_ADDR;
			break;
		case 'R':
			context = TYPE_CONTEXT_ROUTE;
			break;
		}
	}

	if(!op || !context){
		Usage(argv[0]);
		return -1;
	}

	if(context == TYPE_CONTEXT_LINK){
		switch (op){
		case TYPE_OP_ADD:
			add_link();
			break;
		case TYPE_OP_DEL:
			del_link();
			break;
		}
	}

	return 0;
}
예제 #27
0
/*
 * 函数:load_releaseRecord
 * 函数功能:读取发行记录链表
 * 函数参数:链表头指针, 保存路径
 * 返回值:成功返回1, 不成功返回-1
 * */
int load_releaseRecord(link_p head, char* path){
    if(NULL == head || NULL == path){
        printf("The point is NULL !\n");
        return -1;
    }

    FILE* pfile = fopen(path, "rb");//路径要改
    if(NULL == pfile){
        system("touch ./data/releaseRecord.db");
        return 1;
    }
    while(1){
        link_p releaseRecord_temp = (link_p)calloc(1, sizeof(link_n));
        if(NULL == releaseRecord_temp){
            printf("Get memory fail!\n");
            return -1;
        }
        release_p release_node = (release_p)calloc(1, sizeof(release_n));
        if(NULL == release_node){
            printf("Get memory error!\n");
            return -1;
        }
        releaseRecord_temp->value_p = release_node;
        releaseRecord_temp->value_size = sizeof(release_n);

        releaseRecord_temp->prev = NULL;
        releaseRecord_temp->next =NULL;
        int flag = fread(releaseRecord_temp->value_p, sizeof(release_n), 1, pfile);
        if(1 != flag){
            fclose(pfile);
            pfile = NULL;
            releaseRecord_temp = NULL;
            return 1;
        }
        if(1 != add_link(head, releaseRecord_temp)){
            fclose(pfile);
            pfile = NULL;
            releaseRecord_temp = NULL;
            printf("Read error!\n");
            return -1; 
        }
    }
}
예제 #28
0
/*
 * -------------------------------------
 * Dispatch one event
 * -------------------------------------
 */
void dispatch_event(struct es* es)
{
	assert(es);

	switch (es->ev) {
		case _es_link:
			add_link(es->peer0, es->port0, es->peer1, es->port1,
				es->cost, es->name);
			break;
		case _ud_link:
			ud_link(es->name, es->cost);
			break;
		case _td_link:
			del_link(es->name);
			break;
		default:
			printf("[es]\t\tUnknown event!\n");
			break;
	}

}
예제 #29
0
    GeneratorGraphManager(common::Coordinator < common::DoubleTime >*
                          coordinator,
                          const paradevs::common::NoParameters& parameters) :
        paradevs::pdevs::GraphManager < common::DoubleTime >(coordinator,
                                                             parameters),
        g1("G1", common::NoParameters()),
        g2("G2", common::NoParameters()),
        m("g", common::NoParameters())
    {
        add_child(&g1);
        add_child(&g2);
        add_child(&m);

        g1.add_out_port("out");
        g2.add_out_port("out");
        m.add_in_port("in");
        m.add_out_port("out");

        add_link(&g1, "out", &m, "in");
        // add_link(&g2, "out", &m, "in");
    }
예제 #30
-8
파일: topology.c 프로젝트: stwn/kuliax
static void add1link(int n, int **grid, int nnodes, BOOL **adj)
{
    int		from, to;
    int		x, y;
    int		dx, dy;

    for(;;) {
	x	= (int)nrand48(xsubi)%n;
	y	= (int)nrand48(xsubi)%n;
	if(grid[x][y] == UNKNOWN)
	    continue;
	from	= grid[x][y];
	if(NP[from].nlinks == MAXDEGREE)
	    continue;

	do {
	    dx	= ((int)nrand48(xsubi)%3)-1;		/* dx:  -1, 0, +1 */
	    dy	= ((int)nrand48(xsubi)%3)-1;		/* dy:  -1, 0, +1 */
	}
#if	RANDOM_DIAGONALS
	while(dx == 0 && dy == 0);
#else
	while(iabs(dx) == iabs(dy));
#endif

	x	+= dx;
	y	+= dy;
	while(x>=0 && x<n && y>=0 && y<n) {
	    if(grid[x][y] != UNKNOWN) {
		to	= grid[x][y];
		if(NP[to].nlinks == MAXDEGREE || adj[from][to] == TRUE)
		    break;
		add_link(LT_POINT2POINT, from, to, NULL);
		adj[from][to] = adj[to][from] = TRUE;
		return;
	    }
	    x	+= dx;
	    y	+= dy;
	}
    }
}