示例#1
0
node *create_session(node *state,node *sessions,long session_uid,char *protocol_name)
{
  node *base_class = get_base_class(state);
  node *session = create_class_instance(base_class);
  //reset_obj_refcount(session);
  set_obj_string(session,"name","session");
  //set_obj_string(prot_value,"value",get_obj_name(found_prot));

  node *nsession_uid = create_class_instance(base_class);
  //reset_obj_refcount(nsession_uid);
  set_obj_string(nsession_uid,"name","id");
  set_obj_int(nsession_uid,"value",session_uid);
  add_member(session,nsession_uid);
  inc_obj_refcount(nsession_uid);

  node *nsession_protocol = create_class_instance(base_class);
  //reset_obj_refcount(nsession_uid);
  set_obj_string(nsession_protocol,"name","protocol");
  set_obj_string(nsession_protocol,"value",protocol_name);
  add_member(session,nsession_protocol);
  inc_obj_refcount(nsession_protocol);

  node *sessions_items = node_GetItemByKey(sessions,"items");
  set_obj_int(session,"item_index",get_last_index(sessions_items)+1);

  node_AddItem(sessions_items,session);
  node_SetParent(session,sessions_items);
  inc_obj_refcount(session);
  return(session);
}
示例#2
0
int main(int argc, char *argv[]){
	t_member * list = NULL;
	list = t_member_alloc("ana", 1);
	get_member_value("ana",list);
	add_member("bruna", 2, list);
	//remove_member("mauro",list);
	get_member_value("bruna", list);
	add_member("carla", 3, list);
	get_member_value("carla", list);
	return 0;
} 
示例#3
0
int admin()
{
	int choice;
	printf("What function do you want?\n(1)add book\n(2)remove book\n(3)add member\n(4)remove member\n(5)member list\n(6)book list\n(7)exit\n");
	scanf("%d",&choice);
	switch(choice)
	{
		case 1:
			add_book();
			break;
		case 2:
			remove_book();
			break;
		case 3:
			add_member();
			break;
		case 4:
			remove_member();
			break;
		case 5:
			member_list();
			break;
		case 6:
			book_list();
			break;
		case 7:
			exit(0);	
	}
	return 1;
}
示例#4
0
MEMBER *read_value
(     MPL *mpl,
      PARAMETER *par,         /* not changed */
      TUPLE *tuple            /* destroyed */
)
{     MEMBER *memb;
      insist(par != NULL);
      insist(is_symbol(mpl));
      /* there must be no member with the same n-tuple */
      if (find_member(mpl, par->array, tuple) != NULL)
         error(mpl, "%s%s already defined",
            par->name, format_tuple(mpl, '[', tuple));
      /* create new parameter member with given n-tuple */
      memb = add_member(mpl, par->array, tuple);
      /* read value and assigns it to the new parameter member */
      switch (par->type)
      {  case A_NUMERIC:
         case A_INTEGER:
         case A_BINARY:
            if (!is_number(mpl))
               error(mpl, "%s requires numeric data", par->name);
            memb->value.num = read_number(mpl);
            break;
         case A_SYMBOLIC:
            memb->value.sym = read_symbol(mpl);
            break;
         default:
            insist(par != par);
      }
      return memb;
}
示例#5
0
文件: _party.c 项目: ehershey/pd
int cmd_party(string str) {
    string com, extra;
/*    if(wizardp(this_player())) return 0;  */
    if(!str) {
        help();
        return 1;
    }
    if(sscanf(str, "%s %s", com, extra) == 2) {
        switch(com) {
            case "form": return form(extra); break;
            case "leave": return leave(); break;
            case "join": return join_party(extra); break;
            case "add": return add_member(extra); break;
            case "remove": return sub(extra); break;
            case "leader": return leader(extra); break;
            case "list": return list(); break;
            case "line": return party_line(extra); break;
            default: help(); return 1; break;
        }
    }
    else {
        if(str == "leave") return leave();
        else if(str == "list") return list();
        else {
            help();
            return 1;
        }
    }
}
示例#6
0
int udp_server::recv_msg(std::string &_out_msg)
{
	struct sockaddr_in cli;
	char buf[_SIZE_];
	memset(buf, '\0',sizeof(buf));
	
	socklen_t len = sizeof(struct sockaddr_in);
	bzero(&cli, len);

	int ret = recvfrom(this->fd, buf, sizeof(buf), 0, (struct sockaddr*)&cli, &len);

	if(ret < 0)
	{
		debug_printf("recv msg error");
		return 1;
	}else{
		std::string _tmp;
		_tmp = buf;
		std::string ip = inet_ntoa(cli.sin_addr);
		if(! is_member(ip))
		{
			add_member(ip, &cli);
		}
		udp_data judge_quit;
		judge_quit.deserialize(_tmp);
		if(judge_quit.type=="command" && judge_quit.cmd=="quit")
		{
			del_member(ip);
		}
		_out_msg = buf;
	}
	return 0;	
}
void ReachingDefinitionGenerator::
add_def( ReachingDefinitions& repr, const std::string& varname, const AstNodePtr& scope,
                const std::pair<AstNodePtr,AstNodePtr>& def) const
{
   std::string scopename = scopemap.get_string(scope);
   std::string name = varname + scopename;
   add_member(repr, name, def);
}
示例#8
0
void TAO_FTEC_Group_Manager::join_group (
    const FTRT::ManagerInfo & info)
{
  TAO_FTRTEC::Log(1, ACE_TEXT("join group\n"));
  if (impl_->my_position == 0) {
    FTRTEC::Replication_Service* svc = FTRTEC::Replication_Service::instance();
    ACE_WRITE_GUARD (FTRTEC::Replication_Service, lock, *svc);
    add_member(info, IOGR_Maker::instance()->get_ref_version()+1);
  }
}
示例#9
0
文件: curl.c 项目: pez2001/node.c
void curl_binding_open(node *state)
{
  node *modules = get_modules(state);
  node *block_class = get_block_class(state);
  node *curl = curl_bind(modules);
  node *proxy = create_proxy_object(state,curl,"curl");
  inc_obj_refcount(curl);
  add_member(block_class,proxy);
  inc_obj_refcount(proxy);
  sys_add_module(state,"curl");
}
示例#10
0
文件: watchlist.c 项目: glankk/gz
void watchlist_fetch(struct menu_item *item)
{
  struct item_data *data = item->data;
  for (int i = data->members.size - 1; i >= 0; --i)
    remove_member(data, i);
  for (int i = 0; i < settings->n_watches; ++i)
    add_member(data, settings->watch_address[i], settings->watch_info[i].type,
               i, settings->watch_info[i].anchored,
               settings->watch_x[i], settings->watch_y[i],
               settings->watch_info[i].position_set);
}
示例#11
0
void websockets_binding_open(node *state)
{
  node *modules = get_modules(state);
  node *block_class = get_block_class(state);
  node *websockets = websockets_bind(modules);
  node *proxy = create_proxy_object(state,websockets,"websockets");
  inc_obj_refcount(websockets);
  add_member(block_class,proxy);
  inc_obj_refcount(proxy);
  sys_add_module(state,"websockets");
}
示例#12
0
文件: file.c 项目: pez2001/node.c
void file_binding_open(node *state)
{
  node *modules = get_modules(state);
  node *base_class = get_base_class(state);
  node *block_class = get_block_class(state);
  node *file = file_bind(base_class,modules);
  node *proxy = create_proxy_object(state,file,"file");
  inc_obj_refcount(file);
  add_member(block_class,proxy);
  inc_obj_refcount(proxy);
  sys_add_module(state,"file");
}
示例#13
0
int main() {
    
    int input_num = 0;
    char member_name[256];
    
    // 初期化処理
    initialize();
    
    while(input_num != 10){
        
        // 入力値により処理を分岐
        printf("*----------------------*\n1:前のメンバーへ移動\n2:次のメンバーへ移動\n3:今のメンバーを確認\n4:新規メンバー登録\n5:メンバー削除\n6:すべてのメンバーを確認\n10:終了\n*----------------------*\ninput number > ");
        
        // TODO 入力チェック
        scanf("%d",&input_num);
        
        switch (input_num) {
            case 1: // 前のメンバーへ移動
                prev_member();
                break;
            case 2: // 次のメンバーへ移動
                next_member();
                break;
            case 3: // 今のメンバーを確認
                disp_member();
                break;
            case 4: // 新規メンバー作成
                printf("新しく作成するメンバーの名前を入力してください。\ninput name > ");
                scanf("%s", member_name);
                add_member(member_name);
                break;
            case 5: // 今のメンバーを削除
                delete_member();
                break;
            case 6: // すべてメンバーを確認
                disp_all_members();
                break;
            case 10: // 終了
                printf("終了します。\n\n");
                break;
            default:
                printf("入力値が不正です。\n\n");
                break;
        }
    }
    
    // 終了処理
    finalize();
    
    return 0;
}
示例#14
0
struct cw_conference* start_conference( struct cw_conf_member* member ) 
{
    struct cw_conference* conf = NULL ;

    // check input
    if ( member == NULL )
    {
    	cw_log( LOG_WARNING, "unable to handle null member\n" ) ;
    	return NULL ;
    }

    // look for an existing conference
    cw_log( CW_CONF_DEBUG, "attempting to find requested conference\n" ) ;

    // acquire mutex
    cw_mutex_lock( &start_stop_conf_lock ) ;

    conf = find_conf( member->id ) ;
	
    // unable to find an existing conference, try to create one
    if ( conf == NULL )
    {
	// create a new conference
	cw_log( CW_CONF_DEBUG, "attempting to create requested conference\n" ) ;
	
	// create the new conference with one member
	conf = create_conf( member->id, member ) ;

	// return an error if create_conf() failed
	if ( conf == NULL ) 
	{
	    cw_log( LOG_ERROR, "unable to find or create requested conference\n" ) ;
	    cw_mutex_unlock( &start_stop_conf_lock ) ;
	    return NULL ;
	}
    }
    else
    {
	// existing conference found, add new member to the conference
	// once we call add_member(), this thread
	// is responsible for calling delete_member()
	//
	add_member( conf, member) ;
    }	

    // release mutex
    cw_mutex_unlock( &start_stop_conf_lock ) ;
    
    return conf ;
}
示例#15
0
文件: watchlist.c 项目: glankk/gz
static void add_button_proc(struct menu_item *item, void *data)
{
  struct item_data *item_data = data;
  uint32_t address = 0x80000000;
  enum watch_type type = WATCH_TYPE_U8;
  if (item_data->members.size > 0) {
    struct member_data *member_data = get_member(item_data,
                                                 item_data->members.size - 1);
    struct menu_item *last_watch = menu_userwatch_watch(member_data->userwatch);
    address = menu_watch_get_address(last_watch);
    type = menu_watch_get_type(last_watch);
  }
  add_member(item_data, address, type, item_data->members.size, 1, 0, 0, 0);
}
示例#16
0
void FoF::find_friends (const Zbin &zbin, Galaxy &gal, double rfriend) {
  //! Function to find galaxies linked to the galaxy in question.
  /**< Loop through kd-tree nodes */
  for(int j = 0; j < tree.node_list.size(); j++) {
    /**< Check if galaxy is compatible with kd-tree node */
    if(node_check(gal, tree.node_list[j], rfriend)) {
      /**< Loop through node members */
      for(int k = 0; k < tree.node_list[j].members.size(); k++) {
	/**< Check if galaxies are friends */
	int gal_now = tree.node_list[j].members[k].num;
	if(friendship(zbin, gal, gal_list[gal_now], rfriend)) {
	  /**< Create new cluster */
	  if(!gal.in_cluster[zbin.num]) 
	    new_cluster(zbin, gal, gal_list[gal_now]);
	  /**< Add new member to existing cluster */
	  else 
	    add_member(zbin, gal_list[gal_now], list_of_clusters[cluster_count]);
	}
      } // end of node member loop
    }
  } // end of node loop
}
示例#17
0
文件: watchlist.c 项目: glankk/gz
static int entry_activate_proc(struct menu_item *item)
{
  int row = (int)item->data;
  struct watchfile_entry *entry = vector_at(&watchfile_entries,
                                            watchfile_scroll + row);
  entry->anim_state = 1;
  uint32_t address;
  enum adex_error e = adex_eval(&entry->adex, &address);
  if (!e && (address < 0x80000000 || address >= 0x80800000 ||
             address % watch_type_size[entry->type] != 0))
  {
    e = ADEX_ERROR_ADDRESS;
  }
  if (e) {
    struct menu *menu_top = menu_get_top(watchfile_list_data->imenu);
    menu_prompt(menu_top, adex_error_name[e], "return\0", 0, NULL, NULL);
  }
  else {
    add_member(watchfile_list_data, address, entry->type,
               watchfile_list_data->members.size, 1, 0, 0, 0);
  }
  return 1;
}
示例#18
0
int main(int argc, char **argv)
{
	DIR *dir;
	struct dirent *dp;
	struct clan_array clans = CLAN_ARRAY_ZERO;
	char path[PATH_MAX];

	load_config();
	if (argc != 1) {
		fprintf(stderr, "usage: %s\n", argv[0]);
		return EXIT_FAILURE;
	}

	/* Build in memory the list of all clans with their members */
	sprintf(path, "%s/players", config.root);
	if (!(dir = opendir(path)))
		return perror(path), EXIT_FAILURE;
	while ((dp = readdir(dir))) {
		struct player player;
		struct clan *clan;

		if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
			continue;
		if (!read_player(&player, dp->d_name))
			continue;
		if (!(clan = get_clan(&clans, &player)))
			continue;
		if (!(add_member(clan, &player)))
			continue;
	}
	closedir(dir);

	write_clan_array(&clans);

	return EXIT_SUCCESS;
}
示例#19
0
文件: capture.cpp 项目: wildpea/Fit
FIT_TEST_CASE()
{
    FIT_TEST_CHECK(fit::capture(add_member(1), 2)(&add_member::add)() == 3);
    FIT_TEST_CHECK(fit::capture(add_member(1))(&add_member::add)(2) == 3);
}
示例#20
0
 /**
  * Add a member to the relation.
  *
  * @param type The type (node, way, or relation).
  * @param ref The ID of the member.
  * @param role The role of the member.
  * @param full_member Optional pointer to the member object. If it
  *                    is available a copy will be added to the
  *                    relation.
  * @throws std:length_error If role is longer than osmium::max_osm_string_length
  */
 void add_member(osmium::item_type type, object_id_type ref, const std::string& role, const osmium::OSMObject* full_member = nullptr) {
     add_member(type, ref, role.data(), role.size(), full_member);
 }
示例#21
0
int main(){
/* this function is the actual main function in my program*/
	struct name * arruser[16];
	int num_mem;/*this is the total number of members in the group*/
	char * mem[16];/* this the array which stores addresses of usernames*/
	char * pass[16];/* this array stores addresses of respective passwords*/
	char grpname[10];/* char array containing the group name*/
	char grppass[10]; /* this array contains the password of the group*/
	int user;/* this is the current user that has logged in( users index in the array)*/
	int i, j, k;/* these are some random variables to be used as counters.*/
	int state = 1;/* this acs like flag between two different switch cases which go on in an infinite loop wher only few condition can break out of it depending on the value of this flag.*/
	int choice; /*this variable selects the case in switch*/
	struct data * curr1;
	struct list * curr2;
	char buffer[10];
	char * buffer1;
	/*now to start calling functions one by one:*/
	printf("Loading...\n");
	print_line();
	j = load_file(grpname, grppass, mem, &num_mem, pass, arruser);
	if(j == 0){
	 printf(" the standard file could not be opened\n you can still go ahead with working but previous data is lost now\n");
	 }
	 if(j == 2){
	 printf(" Looks like you are a new user!\n welcome to splitwise!\n");
	 }
	 if(j == 1){
	 printf("All previous user data is now loaded!\n welcome back to splitwise!\n");
	 }
	 if(j == 4){
	 	printf(" welcome back to splitwise!\n you already have a group created\n but there are no members in this group\n please add yourself to the group first\n");
	 	printf(" please enter your username\n");
	 	scanf(" %s", buffer);
	 	mem[0] = (char * ) malloc(10);
	 	if(mem[0] == NULL){
	 		printf(" not enough memory\n");
	 		exit(1);
	 	}
	 	strcpy(mem[0], buffer);
	 	buffer1 = getpass(" hello, please enter you password\n");
	 	pass[0] = (char*)malloc(10);
	 	if(pass[0] == NULL){
	 		printf(" not enough memory\n");
	 		exit(1);
	 	}
	 	strcpy(pass[0], buffer1);
	 	printf(" you are now added to the group %s \n welcome!\n", grpname);
	 	arruser[0] = (struct name*)malloc(sizeof(struct name));
	 	arruser[0]->q = NULL;
	 	arruser[0]->p = NULL;
	 	arruser[0]->num_data = 0;
	 	arruser[0]->num_stmt = 0;
	 }
	 print_line();
	 print_home();
	 scanf("%d", &choice);
	 while(1){
	 	
	 	if(state == 1){
	 		switch(choice){
	 			case 1: 
	 				if(num_mem == 0){
	 					printf(" there aren't any group members\n");
	 					create_grp(grpname, grppass,mem, pass, &num_mem,arruser); 
	 					print_home();
	 					scanf("%d", &choice);
	 					print_line();
	 					state = 1;
	 					/* check the return values*/
	 					break;
	 				}
	 				j = login(mem, pass, &user);
	 				print_line();
	 				if(j == 0){
	 					state = 3;
	 					break;
	 				}	
	 				if(j == 1){
	 					print_menu();
	 					scanf("%d", &choice);
	 					print_line();
	 					state = 2;
	 				}
	 				break;
	 			case 2: 
					j = check_grp(grpname);
					if(j == 0){
						/* no group exists*/
						k = create_grp(grpname, grppass, mem, pass, &num_mem, arruser);
						if(k == 0){
							printf(" creating group failed\n");
							state = 3;
						}
						if(k == 1){
							print_home();
	 						scanf("%d", &choice);
							print_line();
							state = 1;
						}
					}
					else{
						printf("A group alredy exists. you cannot create multiple groups. if youi want to create a new group the current group will have to be deleted.\n press 1 to delete existing group\n press 2 to exit\n");
						scanf("%d", &k);
						print_line();
						if(k == 1){
							delete_grp(grpname, grppass, mem, pass, &num_mem, arruser);
							i = create_grp(grpname, grppass, mem, pass, &num_mem,arruser);
							if(i == 0){
							printf(" creating group failed\n");
							state = 3;
							}
							if(i == 1){
								print_home();
	 							scanf("%d", &choice);
								print_line();
								state = 1;
							}
						}
						if(k == 2){
						print_home();
						scanf("%d", &choice);
							print_line();
							state  = 1;
						}
					}
					break;
				
				case 3:
					j = check_grp(grpname);
					if(j == 0){
					;
					}
					else{
						delete_grp(grpname, grppass, mem, pass, &num_mem, arruser);
					}
					print_home();
					scanf("%d", &choice);
					print_line();
					state = 1;
					break;
				
				case 4: delete_member(grpname, grppass, mem, pass, &num_mem, arruser);
					print_home();
					scanf("%d", &choice);
					print_line();
					state = 1;
					break;
				case 5:
					state = 3;
					break;
					
				default:
						printf(" you have entered an invalid choice\n please enter again\n");
						print_home();
						scanf("%d", &choice);
						print_line();
						state = 1;
					break;
			}/* switch closed*/
		}/* if closed*/
		if( state == 2){
			switch(choice){
				case 1:
					j = add_expense(user, arruser);
					if(j == 0){
						printf(" sorry could not add any more expenses\n");
						print_menu();
	 					scanf("%d", &choice);
						print_line();
						state  = 2;
					}
					if(j == 1){
						print_menu();
	 					scanf("%d", &choice);
						print_line();
						state = 2;
					}
				break;
				 case 2:
				 	j = get_statement(user, arruser);
				 	if(j == 0){
				 		printf(" sorry, the file could no be opened\n");
				 	}
				 	print_menu();
	 				scanf("%d", &choice);
				 	print_line();
				 	state = 2;
				 	break;
				 	
				 case 3:
				 	j = split_expense(mem, arruser);
				 	print_menu();
	 				scanf("%d", &choice);
				 	print_line();
				 	state = 2;
				 	break;
				 
				 case 4:
				 	view_my_contri(user, arruser);
				 	print_menu();
	 				scanf("%d", &choice);
				 	print_line();
				 	state = 2;
				 	break;
				 	
				 case 5:
				 	j = split_expense(mem, arruser);
				 	if( j == 0){
						print_menu();
	 					scanf("%d", &choice);
						print_line();
				 		/* unsucessful*/
				 		state = 2;
				 		break;
				 	}
				 	j = add_member(grpname, grppass, mem, pass, &num_mem, arruser);
				 	if (j == 0){
				 	/* unsuccessful*/
				 		printf(" adding member was unsuccessful\n please try again\n");
				 		print_menu();
	 					scanf("%d", &choice);
				 		print_line();
				 		state = 2;
				 		break;
				 	}
				 	print_menu();
	 				scanf("%d", &choice);
				 	print_line();
				 	state = 2;
				 	break;
				 
				 case 6:
					 reset_1stmt(arruser, user);
					 printf("successful in clearing you statements!\n");
					 print_menu();
			       	 	 scanf("%d",&choice);	
			       	 	print_line();
			       	 	 state = 2;
				 	break;
				 	
				 case 7:
				 	user = -1;
				 	print_home();
				 	scanf("%d", &choice);
				 	print_line();
				 	state = 1;
				 	break;
				 
				 case 8 :
				 	state = 3;
				 	break;
				 	
				 default : printf(" you have entered a wrong choice\n please enter again\n");
				 print_menu();
	 			scanf("%d", &choice);
				print_line();
				 state = 2;
				 break;
			 }/* switch closed*/
		}/* if closed*/
		if(state == 3){
			FILE * fp;
			char data[] = "stddata";
			fp = fopen(data, "w");
			if(fp == NULL){
				printf(" file cannot be opened to store all the data you create in this session.\n sorry\n");
				return 0;
			}
			fprintf(fp, "%s\n", grpname);
			fprintf(fp, "%s\n",grppass);
			fprintf(fp, "%d\n", num_mem);
			for(i = 0; i< num_mem; i++){
				if(mem[i] != NULL){
					fprintf(fp, "%s\n", mem[i]);
					fprintf(fp, "%s\n", pass[i]);
					
				}/* if closed*/
			}
			fclose(fp);
			for(i = 0; i< num_mem; i++){
				fp = fopen(mem[i], "w+");
				fprintf(fp, "%d\n", arruser[i]->num_data);
				curr1 = arruser[i]->q;
				while(curr1){
					fprintf(fp, "%d ", curr1->amt);
					fprintf(fp, "%s\n", curr1->des);
					curr1 = curr1->n;
				}
				fprintf(fp, "%d ", arruser[i]->num_stmt);
				curr2 = arruser[i]->p;
				while(curr2){
					fprintf(fp, "%s\n", curr2->stmt);
					curr2 = curr2->next;
				}
				fclose(fp);
			}
			reset_data(arruser);
			reset_stmt(arruser);	
			for(i = 0; i < num_mem; i++){
				free(mem[i]);
				free(pass[i]);
				
			}
			break;
		}
	}/* while closed*/
	return 0;
}/* main closed*/		
示例#22
0
int main() {
    
    
    
//     boost::uuids::random_generator uuid_generator;
    
//     auto a(std::make_shared<entity>( uuid_generator() ));
//     auto c(std::make_shared<entity>());
    //std::shared_ptr<entity> a(std::make_shared<entity>());
    
    entity_store es;
    entity_ptr::global_store = &es;
    
    
    
    auto a = es.create();
    
    
    entity_ptr ap( a->id() );
    
    
    auto ax = ap.lock();
    
//     std::shared_ptr<entity> xp(es.create());
//     std::weak_ptr<entity> wp( xp );
//     std::cout << (wp.lock() == nullptr) << "\n";
    
    a->add_member( make_unique<member_type1>() );   
    //a.add_member<ID_TYPE2>( std::make_shared<member_type2>() );   
    ap.lock()->make_member<member_type2>( 7, 8 );   
//     auto b = std::make_shared<entity>(uuid_generator());
    
    auto b = es.create();
    
   // a.add_member<ID_TYPE1>( std::make_shared<member_type1>() );   
    //b.add_member<ID_TYPE3>( std::make_shared<member_type3>() );   
    b->fabricate_members( {ID_TYPE1, ID_TYPE3} );
//     b.add_member_unchecked( ID_TYPE3, std::make_shared<member_type2>() );   
    
    auto &x = a->member<ID_TYPE1>();
    member_type2 &y = a->member<member_type2>();
    
    //member_interaction<ID_TYPE1,ID_TYPE2>( a, a );
    member_interaction<ID_TYPE1,ID_TYPE3>( *a, *b );
    
    std::cout << &x << " " << &y << "\n";
    
//     entity xxx[1024];
    
//     std::cout << "size: " << sizeof( xxx ) << "\n";
    
    a->add_interaction( ID_TYPE1, a, ID_TYPE2 );
    a->add_interaction( ID_TYPE1, b, ID_TYPE3 );
    
    a->run_interactions();
    a->run_interactions();
    b.reset();
    a->run_interactions();
    
    
    a->print_info();
    
    return 0;
}
示例#23
0
static struct cw_conference* create_conf( char* name, struct cw_conf_member* member )
{
    cw_log( CW_CONF_DEBUG, "entered create_conf, name => %s\n", name ) ;	


    // allocate memory for conference
    struct cw_conference *conf = calloc(1, sizeof( struct cw_conference ) ) ;
	
    if ( conf == NULL ) 
    {
    	cw_log( LOG_ERROR, "unable to malloc cw_conference\n" ) ;
    	return NULL ;
    }

    //
    // initialize conference
    //
	
    conf->next = NULL ;
    conf->memberlist = NULL ;
    conf->membercount = 0 ;
    conf->conference_thread = CW_PTHREADT_NULL ;
    conf->is_locked = 0;
    conf->command_queue = NULL ;

    // copy name to conference
    strncpy( (char*)&(conf->name), name, sizeof(conf->name) - 1 ) ;
    // initialize mutexes
    cw_mutex_init( &conf->lock ) ;
	
    // add the initial member
    add_member( conf, member) ;
	
    //
    // prepend new conference to conflist
    //

    // acquire mutex
    cw_mutex_lock( &conflist_lock ) ;

    conf->next = conflist ;
    conflist = conf ;
    cw_log( CW_CONF_DEBUG, "added new conference to conflist, name => %s\n", name ) ;

    //
    // spawn thread for new conference, using conference_exec( conf )
    //
    // acquire conference mutexes
    cw_mutex_lock( &conf->lock ) ;
	
    if ( cw_pthread_create( &conf->conference_thread, NULL, (void*)conference_exec, conf ) == 0 ) 
    {
	// detach the thread so it doesn't leak
	pthread_detach( conf->conference_thread ) ;
	// release conference mutexes
	cw_mutex_unlock( &conf->lock ) ;
	cw_log( CW_CONF_DEBUG, "started conference thread for conference, name => %s\n", conf->name ) ;
	manager_event(
	    EVENT_FLAG_CALL, 
	    APP_CONFERENCE_MANID"ConfCreate", 
	    "Channel: %s\r\n"
	    "ConfNo: %s\r\n",
	    member->channel_name,
	    name
	) ;
    }
    else
    {
    	cw_log( LOG_ERROR, "unable to start conference thread for conference %s\n", conf->name ) ;
	conf->conference_thread = CW_PTHREADT_NULL ;

	// release conference mutexes
	cw_mutex_unlock( &conf->lock ) ;

	// clean up conference
	free( conf ) ;
	conf = NULL ;
    }

    // count new conference 
    if ( conf != NULL )
    	++conference_count ;

    conf->auto_destroy = 1;

    // release mutex
    cw_mutex_unlock( &conflist_lock ) ;

    return conf ;
}
示例#24
0
文件: Far.c 项目: danieltahara/far
int main(int argc, char** argv)
{
    // Print an error if the user invokes Far with an incorrect number of
    // arguments. There should be at least "Far key archive"
    if (argc < 3) {
        ERROR("Usage: Far key archive [name]*");
        return 1;
    }

    char* key = argv[1];
    char* archive_name = argv[2];

    int num_files = argc - 3;
    char** filenames = argv + 3;

    // Ignore trailing / in NAME arguments
    for (int i = 0; i < num_files; i++) strip_trailing_slash(filenames[i]);

    if (!strcmp(key, "r")) {
        member_list* members = make_list_recursive(filenames, num_files);
        archive_t* archive = open_archive(archive_name, true);
        member_list* processed_members =
          process_members(archive, members, replace_current_member);
        // Now that previously existing files have been deleted, add the
        // files to the end of the archive
        member_node* cur_member = members;
        while (cur_member) {
            add_member(archive, cur_member->filename);
            cur_member = cur_member->next;
        }
        delete_list(processed_members);
        close_archive(archive, true);

        delete_list(members);
        return 0;
    } else if (!strcmp(key, "x")) {
        member_list* members = make_list(filenames, num_files);
        archive_t* archive = open_archive(archive_name, false);
        member_list* processed_members =
          process_members(archive, members, extract_current_member);
        // Error handling for unprocessed NAME arguments
        for (int i = 0; i < num_files; i++) {
            char* name = filenames[i];
            if (!find_member(name, processed_members)) {
                ERROR_CREATE(name);
            }
        }
        delete_list(processed_members);
        close_archive(archive, false);

        delete_list(members);
        return 0;
    } else if (!strcmp(key, "d")) {
        member_list* members = make_list(filenames, num_files);
        archive_t* archive = open_archive(archive_name, false);
        member_list* processed_members =
          process_members(archive, members, delete_current_member);
        // Error handling for unprocessed NAME arguments
        for (int i = 0; i < num_files; i++) {
            char* name = filenames[i];
            if (!find_member(name, processed_members) &&
                !find_child(name, processed_members)) {
                ERROR_FIND(name);
            }
        }
        delete_list(processed_members);
        close_archive(archive, true);

        delete_list(members);
        return 0;
    } else if (!strcmp(key, "t")) {
        archive_t* archive = open_archive(archive_name, false);
        member_list* processed_members =
          process_members(archive, NULL, print_current_member);
        delete_list(processed_members);
        close_archive(archive, false);
        return 0;
    } else {
        ERROR("Key options: 'r', 'x', 'd', 't'");
        return 1;
    }
}
示例#25
0
void tabbing_format
(     MPL *mpl,
      SYMBOL *altval          /* not changed */
)
{     SET *set = NULL;
      PARAMETER *par;
      SLICE *list, *col;
      TUPLE *tuple;
      int next_token, j, dim = 0;
      char *last_name = NULL;
      /* read the optional <prefix> */
      if (is_symbol(mpl))
      {  get_token(mpl /* <symbol> */);
         next_token = mpl->token;
         unget_token(mpl /* <symbol> */);
         if (next_token == T_COLON)
         {  /* select the set to saturate it with data */
            set = select_set(mpl, mpl->image);
            /* the set must be simple (i.e. not set of sets) */
            if (set->dim != 0)
               error(mpl, "%s must be a simple set", set->name);
            /* and must not be defined yet */
            if (set->array->head != NULL)
               error(mpl, "%s already defined", set->name);
            /* add new (the only) member to the set and assign it empty
               elemental set */
            add_member(mpl, set->array, NULL)->value.set =
               create_elemset(mpl, set->dimen);
            last_name = set->name, dim = set->dimen;
            get_token(mpl /* <symbol> */);
            insist(mpl->token == T_COLON);
            get_token(mpl /* : */);
         }
      }
      /* read the table heading that contains parameter names */
      list = create_slice(mpl);
      while (mpl->token != T_ASSIGN)
      {  /* there must be symbolic name of parameter */
         if (!is_symbol(mpl))
            error(mpl, "parameter name or := missing where expected");
         /* select the parameter to saturate it with data */
         par = select_parameter(mpl, mpl->image);
         /* the parameter must be subscripted */
         if (par->dim == 0)
            error(mpl, "%s not a subscripted parameter", mpl->image);
         /* the set (if specified) and all the parameters in the data
            block must have identical dimension */
         if (dim != 0 && par->dim != dim)
         {  insist(last_name != NULL);
            error(mpl, "%s has dimension %d while %s has dimension %d",
               last_name, dim, par->name, par->dim);
         }
         /* set default value for the parameter (if specified) */
         if (altval != NULL)
            set_default(mpl, par, copy_symbol(mpl, altval));
         /* append the parameter to the column list */
         list = expand_slice(mpl, list, (SYMBOL *)par);
         last_name = par->name, dim = par->dim;
         get_token(mpl /* <symbol> */);
         /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
      }
      if (slice_dimen(mpl, list) == 0)
         error(mpl, "at least one parameter name required");
      get_token(mpl /* := */);
      /* skip optional comma */
      if (mpl->token == T_COMMA) get_token(mpl /* , */);
      /* read rows that contain tabbing data */
      while (is_symbol(mpl))
      {  /* read subscript list */
         tuple = create_tuple(mpl);
         for (j = 1; j <= dim; j++)
         {  /* read j-th subscript */
            if (!is_symbol(mpl))
            {  int lack = slice_dimen(mpl, list) + dim - j + 1;
               insist(tuple != NULL);
               insist(lack > 1);
               error(mpl, "%d items missing in data group beginning wit"
                  "h %s", lack, format_symbol(mpl, tuple->sym));
            }
            /* read and append j-th subscript to the n-tuple */
            tuple = expand_tuple(mpl, tuple, read_symbol(mpl));
            /* skip optional comma *between* <symbols> */
            if (j < dim && mpl->token == T_COMMA)
               get_token(mpl /* , */);
         }
         /* if the set is specified, add to it new n-tuple, which is a
            copy of the subscript list just read */
         if (set != NULL)
            check_then_add(mpl, set->array->head->value.set,
               copy_tuple(mpl, tuple));
         /* skip optional comma between <symbol> and <value> */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* read values accordingly to the column list */
         for (col = list; col != NULL; col = col->next)
         {  /* if the token is single point, no value is provided */
            if (is_literal(mpl, "."))
            {  get_token(mpl /* . */);
               continue;
            }
            /* read value and assign it to new parameter member */
            if (!is_symbol(mpl))
            {  int lack = slice_dimen(mpl, col);
               insist(tuple != NULL);
               if (lack == 1)
                  error(mpl, "one item missing in data group beginning "
                     "with %s", format_symbol(mpl, tuple->sym));
               else
                  error(mpl, "%d items missing in data group beginning "
                     "with %s", lack, format_symbol(mpl, tuple->sym));
            }
            read_value(mpl, (PARAMETER *)col->sym, copy_tuple(mpl,
               tuple));
            /* skip optional comma preceding the next value */
            if (col->next != NULL && mpl->token == T_COMMA)
               get_token(mpl /* , */);
         }
         /* delete the original subscript list */
         delete_tuple(mpl, tuple);
         /* skip optional comma (only if there is next data group) */
         if (mpl->token == T_COMMA)
         {  get_token(mpl /* , */);
            if (!is_symbol(mpl)) unget_token(mpl /* , */);
         }
      }
      /* delete the column list (it contains parameters, not symbols,
         so nullify it before) */
      for (col = list; col != NULL; col = col->next) col->sym = NULL;
      delete_slice(mpl, list);
      return;
}
示例#26
0
 /**
  * Add a member to the relation.
  *
  * @param type The type (node, way, or relation).
  * @param ref The ID of the member.
  * @param role The role of the member (\0 terminated string).
  * @param full_member Optional pointer to the member object. If it
  *                    is available a copy will be added to the
  *                    relation.
  * @throws std:length_error If role is longer than osmium::max_osm_string_length
  */
 void add_member(osmium::item_type type, object_id_type ref, const char* role, const osmium::OSMObject* full_member = nullptr) {
     add_member(type, ref, role, std::strlen(role), full_member);
 }
示例#27
0
void set_data(MPL *mpl)
{     SET *set;
      TUPLE *tuple;
      MEMBER *memb;
      SLICE *slice;
      int tr = 0;
      insist(is_literal(mpl, "set"));
      get_token(mpl /* set */);
      /* symbolic name of set must follows the keyword 'set' */
      if (!is_symbol(mpl))
         error(mpl, "set name missing where expected");
      /* select the set to saturate it with data */
      set = select_set(mpl, mpl->image);
      get_token(mpl /* <symbolic name> */);
      /* read optional subscript list, which identifies member of the
         set to be read */
      tuple = create_tuple(mpl);
      if (mpl->token == T_LBRACKET)
      {  /* subscript list is specified */
         if (set->dim == 0)
            error(mpl, "%s cannot be subscripted", set->name);
         get_token(mpl /* [ */);
         /* read symbols and construct subscript list */
         for (;;)
         {  if (!is_symbol(mpl))
               error(mpl, "number or symbol missing where expected");
            tuple = expand_tuple(mpl, tuple, read_symbol(mpl));
            if (mpl->token == T_COMMA)
               get_token(mpl /* , */);
            else if (mpl->token == T_RBRACKET)
               break;
            else
               error(mpl, "syntax error in subscript list");
         }
         if (set->dim != tuple_dimen(mpl, tuple))
            error(mpl, "%s must have %d subscript%s rather than %d",
               set->name, set->dim, set->dim == 1 ? "" : "s",
               tuple_dimen(mpl, tuple));
         get_token(mpl /* ] */);
      }
      else
      {  /* subscript list is not specified */
         if (set->dim != 0)
            error(mpl, "%s must be subscripted", set->name);
      }
      /* there must be no member with the same subscript list */
      if (find_member(mpl, set->array, tuple) != NULL)
         error(mpl, "%s%s already defined",
            set->name, format_tuple(mpl, '[', tuple));
      /* add new member to the set and assign it empty elemental set */
      memb = add_member(mpl, set->array, tuple);
      memb->value.set = create_elemset(mpl, set->dimen);
      /* create an initial fake slice of all asterisks */
      slice = fake_slice(mpl, set->dimen);
      /* read zero or more data assignments */
      for (;;)
      {  /* skip optional comma */
         if (mpl->token == T_COMMA) get_token(mpl /* , */);
         /* process assignment element */
         if (mpl->token == T_ASSIGN)
         {  /* assignment ligature is non-significant element */
            get_token(mpl /* := */);
         }
         else if (mpl->token == T_LEFT)
         {  /* left parenthesis begins either new slice or "transpose"
               indicator */
            int is_tr;
            get_token(mpl /* ( */);
            is_tr = is_literal(mpl, "tr");
            unget_token(mpl /* ( */);
            if (is_tr) goto left;
            /* delete the current slice and read new one */
            delete_slice(mpl, slice);
            slice = read_slice(mpl, set->name, set->dimen);
            /* each new slice resets the "transpose" indicator */
            tr = 0;
            /* if the new slice is 0-ary, formally there is one 0-tuple
               (in the simple format) that follows it */
            if (slice_arity(mpl, slice) == 0)
               simple_format(mpl, set, memb, slice);
         }
         else if (is_symbol(mpl))
         {  /* number or symbol begins data in the simple format */
            simple_format(mpl, set, memb, slice);
         }
         else if (mpl->token == T_COLON)
         {  /* colon begins data in the matrix format */
            if (slice_arity(mpl, slice) != 2)
err1:          error(mpl, "slice currently used must specify 2 asterisk"
                  "s, not %d", slice_arity(mpl, slice));
            get_token(mpl /* : */);
            /* read elemental set data in the matrix format */
            matrix_format(mpl, set, memb, slice, tr);
         }
         else if (mpl->token == T_LEFT)
left:    {  /* left parenthesis begins the "transpose" indicator, which
               is followed by data in the matrix format */
            get_token(mpl /* ( */);
            if (!is_literal(mpl, "tr"))
err2:          error(mpl, "transpose indicator (tr) incomplete");
            if (slice_arity(mpl, slice) != 2) goto err1;
            get_token(mpl /* tr */);
            if (mpl->token != T_RIGHT) goto err2;
            get_token(mpl /* ) */);
            /* in this case the colon is optional */
            if (mpl->token == T_COLON) get_token(mpl /* : */);
            /* set the "transpose" indicator */
            tr = 1;
            /* read elemental set data in the matrix format */
            matrix_format(mpl, set, memb, slice, tr);
         }
         else if (mpl->token == T_SEMICOLON)
         {  /* semicolon terminates the data block */
            get_token(mpl /* ; */);
            break;
         }
         else
            error(mpl, "syntax error in set data block");
      }
      /* delete the current slice */
      delete_slice(mpl, slice);
      return;
}
示例#28
0
void get_main_input(void)
{
  int c;
  int retflg;

  while (1)
    {
      oldpos[level] = position[level];
      retflg = 0;
      currow = DISPROW + 2;
      page = 1;
      toggle = num_members = moreflg = 0;
      c = getchar() & INPUT_MASK;	/* mask parity bit */
      if (c == '\r' || c == '\n')
	{
	  if (position[level] == 7)
	    c = 'q';
	  else
	    c = ascbuff[position[level]];
	  retflg = 1;
	}
      switch (c)
	{
	case 'L' & 037:	/* clear screen */
	  display_menu(main_menu);
	  break;
	case 'q':
	case 'Q':		/* quit */
	  position[level] = 7;
	  highlight(main_menu);
	  if (retflg)
	    {
	      cls();
	      return;
	    }
	  break;
	case '1':		/* show all lists */
	  position[level] = 1;
	  if (retflg)
	    show_all();
	  break;
	case '2':		/* get all members of a list */
	  position[level] = 2;
	  if (retflg)
	    list_members();
	  break;
	case '3':		/* display list which user is a recipient */
	  position[level] = 3;
	  if (retflg)
	    list_by_member();
	  break;
	case '4':		/* show description */
	  position[level] = 4;
	  if (retflg)
	    show_list_info();
	  break;
	case '5':		/* add to list */
	  position[level] = 5;
	  if (retflg)
	    add_member();
	  break;
	case '6':		/* delete */
	  position[level] = 6;
	  if (retflg)
	    delete_member();
	  break;
#ifndef _WIN32
	case 27:		/* escape */
	  c = getchar() & INPUT_MASK;
	  if (c == 91)
	    {
	      c = getchar() & INPUT_MASK;
	      if (c == 65)	/* up arrow */
		{
		  position[level]--;
		  if (!position[level])
		    position[level] = 7;
		}
	      else
		{
		  if (c == 66)	/* down arrow */
		    {
		      position[level]++;
		      if (position[level] > 7)
			position[level] = 1;
		    }
		}
	    }
#else /* _WIN32 */
	case 0xe0:
	  c = getchar() & INPUT_MASK;
	  if (c == 0x48)	/* up arrow */
	    {
	      position[level]--;
	      if (!position[level])
		position[level] = 7;
	    }
	  else
	    {
	      if (c == 0x50)	/* down arrow */
		{
		  position[level]++;
		  if (position[level] > 7)
		    position[level] = 1;
		}
	    }
#endif /* _WIN32 */
	  break;
	default:
	  printf("%c", 7);
	  break;
	}
      highlight(main_menu);
    }
}
示例#29
0
static int zunionstore_minmax(rlite *db, long keys_size, unsigned char **keys, long *keys_len, double *weights, int aggregate)
{
	rl_btree *target_scores;
	long target_scores_page, target_skiplist_page;
	rl_skiplist *target_skiplist;
	int retval;
	rl_skiplist_iterator **iterators = NULL;;
	rl_skiplist *skiplist;
	double *scores = NULL, score;
	unsigned char **members = NULL;
	long *memberslen = NULL, i;
	long position;
	RL_CALL(rl_zset_get_objects, RL_OK, db, keys[0], keys_len[0], NULL, &target_scores, &target_scores_page, &target_skiplist, &target_skiplist_page, 1, 1);
	RL_MALLOC(scores, sizeof(double) * keys_size);
	RL_MALLOC(members, sizeof(unsigned char *) * keys_size);
	for (i = 0; i < keys_size; i++) {
		members[i] = NULL;
	}
	RL_MALLOC(memberslen, sizeof(long) * keys_size);
	RL_MALLOC(iterators, sizeof(rl_skiplist_iterator *) * keys_size);
	for (i = 0; i < keys_size; i++) {
		iterators[i] = NULL;
	}

	for (i = 0; i < keys_size; i++) {
		retval = rl_zset_get_objects(db, keys[i], keys_len[i], NULL, NULL, NULL, &skiplist, NULL, 0, 0);
		if (retval == RL_NOT_FOUND) {
			iterators[i] = NULL;
			continue;
		}
		if (retval != RL_OK) {
			goto cleanup;
		}
		RL_CALL(rl_skiplist_iterator_create, RL_OK, db, &iterators[i], skiplist, 0, aggregate == RL_ZSET_AGGREGATE_MAX ? -1 : 1, 0);
		retval = rl_zset_iterator_next(iterators[i], &scores[i], &members[i], &memberslen[i]);
		if (retval != RL_OK) {
			iterators[i] = NULL;
			if (retval != RL_END) {
				goto cleanup;
			}
		}
	}

	while (1) {
		position = -1;
		for (i = 0; i < keys_size; i++) {
			if (!iterators[i]) {
				continue;
			}
			if (position == -1) {
				position = i;
				continue;
			}
			score = weights ? weights[position - 1] * scores[position] : scores[position];
			if (isnan(score)) {
				score = 0.0;
			}
			if ((aggregate == RL_ZSET_AGGREGATE_MAX && scores[i] > score) ||
			        (aggregate == RL_ZSET_AGGREGATE_MIN && scores[i] < score)) {
				position = i;
			}
		}
		if (position == -1) {
			break;
		}

		score = weights ? weights[position - 1] * scores[position] : scores[position];
		if (isnan(score)) {
			score = 0.0;
		}
		retval = add_member(db, target_scores, target_scores_page, target_skiplist, target_skiplist_page, score, members[position], memberslen[position]);
		if (retval != RL_FOUND && retval != RL_OK) {
			goto cleanup;
		}
		rl_free(members[position]);
		members[position] = NULL;

		retval = rl_zset_iterator_next(iterators[position], &scores[position], &members[position], &memberslen[position]);
		if (retval != RL_OK) {
			iterators[position] = NULL;
			if (retval != RL_END) {
				goto cleanup;
			}
		}
	}
	if (target_scores->number_of_elements == 0) {
		RL_CALL(rl_key_delete_with_value, RL_OK, db, keys[0], keys_len[0]);
	}

	retval = RL_OK;
cleanup:
	if (iterators) {
		for (i = 0; i < keys_size; i++) {
			if (iterators[i]) {
				rl_zset_iterator_destroy(iterators[i]);
			}
			rl_free(members[i]);
		}
	}
	rl_free(iterators);
	rl_free(memberslen);
	rl_free(members);
	rl_free(scores);
	return retval;
}
示例#30
0
文件: sym.c 项目: EtchedPixels/FUZIX
/**
 * declare a static variable
 * @param type
 * @param storage
 * @param mtag tag of struct whose members are being declared, or zero
 * @param otag tag of struct object being declared. only matters if mtag is non-zero
 * @param is_struct struct or union or no meaning
 * @return 1 if a function was parsed
 */
int declare_global(int type, int storage, TAG_SYMBOL *mtag, int otag, int is_struct) {
    int     dim, identity;
    char    sname[NAMESIZE];

    FOREVER {
        FOREVER {
            if (endst ())
                return 0;
            dim = 1;
            if (match ("*")) {
                identity = POINTER;
            } else {
                identity = VARIABLE;
            }
            if (!symname (sname))
                illname ();
            if (match ("(")) {
                /* FIXME: We need to deal with pointer types properly here */
                if (identity == POINTER)
                    type = CINT;
                newfunc_typed(storage, sname, type);
                /* Can't int foo(x){blah),a=4; */
                return 1;
            }
            /* FIXME: we need to deal with extern properly here */
            if (find_global (sname) > -1)
                multidef (sname);
            if (identity == VARIABLE)
                notvoid(type);
            if (match ("[")) {
                dim = needsub ();
                //if (dim || storage == EXTERN) {
                    identity = ARRAY;
                //} else {
                //    identity = POINTER;
                //}
            }
            // add symbol
            if (mtag == 0) { // real variable, not a struct/union member
                identity = initials(sname, type, identity, dim, otag);
                add_global (sname, identity, type, (dim == 0 ? -1 : dim), storage);
                if (type == STRUCT) {
                    symbol_table[current_symbol_table_idx].tagidx = otag;
                }
                break;
            } else if (is_struct) {
                // structure member, mtag->size is offset
                add_member(sname, identity, type, mtag->size, storage);
                // store (correctly scaled) size of member in tag table entry
                if (identity == POINTER)
                    type = CINT;
                scale_const(type, otag, &dim);
                mtag->size += dim;
            }
            else {
                // union member, offset is always zero
                add_member(sname, identity, type, 0, storage);
                // store maximum member size in tag table entry
                if (identity == POINTER)
                    type = CINT;
                scale_const(type, otag, &dim);
                if (mtag->size < dim)
                    mtag->size = dim;
            }
        }
        if (!match (","))
            return 0;
    }
}