Exemple #1
0
void extinction()
{   
   sort(population.begin(), population.end(), fun_for_sort_members);
      
   for (size_t i = psize ; i < population.size() ; i++)
     {
	delete_member(population[i]);
     }
   population.resize(psize);
}
Exemple #2
0
int main()
{
	int ch1,ch2,ch3=1;
	long int ids;
	printf("\nWelcome to Lybrari!!\nThis simple library management software is a part of our project to demonstrate the working of the make utility.\n\nMenu:\n****\nPlease select one of the following options\n");
	do
	{
		printf("1: Add/Delete a member\n2: Add/Remove a book from the library\n3: Book Transactions\n");
		scanf("%d",&ch1);
		switch(ch1)
		{
			case 1:
				printf("\nSubmenu:\n*******\n1: Add a member\n2: Delete a member\n");
				scanf("%d",&ch2);
				switch(ch2)
				{
					case 1:
						insert_member();
						break;
					case 2:
						printf("\nEnter the ID of the member to be deleted: ");
						scanf("%ld",&ids);
						delete_member(ids);
						break;
					default: printf("\nWrong input!! Please enter options 1 or 2");
				}
				break;
			case 2:
				printf("\nSubmenu:\n*******\n1: Add a book\n2: Remove a book\n");
				scanf("%d",&ch2);
				switch(ch2)
				{
					case 1:
						addbook();
						break;
					case 2:
						printf("\nEnter the ID of the book to be deleted: ");
	                                        scanf("%ld",&ids);
						delbook(ids);
						break;
					default: printf("\nWrong input!! Please enter options 1 or 2");
				}
				break;
			case 3:
				book_trans();
				break;
			default: printf("\nWrong choice!! Enter a n option between 1 and 3");
		}
		printf("\nDo you want to continue? [1/0]: ");
		scanf("%d",&ch3);
	}while(ch3==1);
}
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;
}
/*
 * check_members - check that every members of a group exist
 *
 *	If an error is detected, *errors is incremented.
 *
 *	The user will be prompted for the removal of the non-existent
 *	user.
 *
 *	If any changes are performed, the return value will be 1,
 *	otherwise check_members() returns 0.
 *
 *	fmt_info, fmt_prompt, and fmt_syslog are used for logging.
 *	  * fmt_info must contain two string flags (%s): for the group's
 *	    name and the missing member.
 *	  * fmt_prompt must contain one string flags (%s): the missing
 *	    member.
 *	  * fmt_syslog must contain two string flags (%s): for the
 *	    group's name and the missing member.
 */
static int check_members (const char *groupname,
                          char **members,
                          const char *fmt_info,
                          const char *fmt_prompt,
                          const char *fmt_syslog,
                          int *errors)
{
	int i;
	int members_changed = 0;

	/*
	 * Make sure each member exists
	 */
	for (i = 0; NULL != members[i]; i++) {
		/* local, no need for xgetpwnam */
		if (getpwnam (members[i]) != NULL) {
			continue;
		}
		/*
		 * Can't find this user. Remove them
		 * from the list.
		 */
		*errors += 1;
		printf (fmt_info, groupname, members[i]);
		printf (fmt_prompt, members[i]);

		if (!yes_or_no (read_only)) {
			continue;
		}

		SYSLOG ((LOG_INFO, fmt_syslog, members[i], groupname));
		members_changed = 1;
		delete_member (members, members[i]);

		/* Rewind in case of removal */
		i--;
	}

	return members_changed;
}
Exemple #5
0
static int remove_member(struct cw_conference* conf, struct cw_conf_member* member ) 
{
    // check for member
    if ( member == NULL )
    {
	cw_log( LOG_WARNING, "unable to remove NULL member\n" ) ;
	return -1 ;
    }

    // check for conference
    if ( conf == NULL )
    {
    	cw_log( LOG_WARNING, "unable to remove member from NULL conference\n" ) ;
    	return -1 ;
    }

    //
    // loop through the member list looking for the requested member
    //

    struct cw_conf_member *member_list = conf->memberlist ;
    struct cw_conf_member *member_temp = NULL ;

    while ( member_list != NULL ) 
    {
    	if ( member_list == member ) 
    	{
	    //
	    // if this is the first member in the linked-list,
	    // skip over the first member in the list, else
	    //
	    // point the previous 'next' to the current 'next',
	    // thus skipping the current member in the list	
	    //	
	    if ( member_temp == NULL )
		conf->memberlist = member->next ;
	    else 
		member_temp->next = member->next ;

	    manager_event(
		EVENT_FLAG_CALL, 
		APP_CONFERENCE_MANID"Leave", 
		"Channel: %s\r\n",
		member->channel_name
	    ) ;

	    // delete the member
	    delete_member( member ) ;
			
	    conf->membercount --;
	    cw_log( CW_CONF_DEBUG, "removed member from conference, name => %s\n", conf->name) ;
			
	    break ;
	}
		
	// save a pointer to the current member,
	// and then point to the next member in the list
	member_temp = member_list ;
	member_list = member_list->next ;
    }
	
    // return -1 on error, or the number of members 
    // remaining if the requested member was deleted
    return conf->membercount ;
}
Exemple #6
0
int member_exec( struct cw_channel* chan, int argc, char **argv ) {
    int left = 0 ;
    int res;

    struct cw_conference  *conf   	= NULL;
    struct cw_conf_member *member	= NULL;
    struct cw_frame *f		= NULL;

    cw_log( CW_CONF_DEBUG, "Launching NConference %s\n", "$Revision: 5349 $" ) ;

    if (chan->_state != CW_STATE_UP)
	if ( (res = cw_answer( chan )) )
	{
    	    cw_log( LOG_ERROR, "unable to answer call\n" ) ;
    	    return -1 ;
	}

    member = create_member( chan, argc, argv ) ;

    // unable to create member, return an error
    if ( member == NULL ) 
    {
	cw_log( LOG_ERROR, "unable to create member\n" ) ;
	return -1 ;
    }

    //
    // setup CallWeaver read/write formats
    //
     cw_log(CW_CONF_DEBUG, 
              "CHANNEL INFO, CHANNEL => %s, DNID => %s, CALLER_ID => %s, ANI => %s\n",
              chan->name  ?  chan->name  :  "----",
              chan->cid.cid_dnid  ?  chan->cid.cid_dnid  :  "----",
              chan->cid.cid_num  ?  chan->cid.cid_num  :  "----",
              chan->cid.cid_ani  ?  chan->cid.cid_ani  :  "----");

    cw_log(CW_CONF_DEBUG, 
    	 	 "CHANNEL CODECS, CHANNEL => %s, NATIVE => %d, READ => %d, WRITE => %d\n", 
	    	 chan->name,
             chan->nativeformats,
             member->read_format,
             member->write_format);

    if ( cw_set_read_format( chan, member->read_format ) < 0 )
    {
    	cw_log( LOG_ERROR, "unable to set read format.\n" ) ;
    	delete_member( member ) ;
    	return -1 ;
    } 

    // for right now, we'll send everything as slinear
    if ( cw_set_write_format( chan, member->write_format ) < 0 )
    {
    	cw_log( LOG_ERROR, "unable to set write format.\n" ) ;
    	delete_member( member ) ;
    	return -1 ;
    }

    //
    // setup a conference for the new member
    //

    conf = start_conference( member ) ;
	
    if ( conf == NULL )
    {
	cw_log( LOG_ERROR, "unable to setup member conference\n" ) ;
	delete_member( member) ;
	return -1 ;
    } else {
	if (conf->is_locked && (member->type != MEMBERTYPE_MASTER) ) {
	    if ( strcmp(conf->pin,member->pin) ) {
		conference_queue_sound(member,"conf-locked");
		conf_play_soundqueue( member ); 
		member->force_remove_flag = 1 ;
	    }
	}  else {
	    member->conf = conf;
	    if ( member->type == MEMBERTYPE_MASTER )
		conf->auto_destroy = member->auto_destroy;
	}
    }

    if ( member->type == MEMBERTYPE_MASTER ) {
	conf->auto_destroy = member->auto_destroy;
	if ( strlen( member->pin ) > 0 ) {
	    strncpy(conf->pin,member->pin,sizeof(conf->pin));
	    cw_log( CW_CONF_DEBUG, "Conference pin set to => %s\n", conf->pin ) ;
	}
    }

    //
    // process loop for new member ( this runs in it's own thread
    //
	
    cw_log( CW_CONF_DEBUG, "begin member event loop, channel => %s\n", chan->name ) ;

    // Activate the generator for the channel.
    res = cw_conf_member_genactivate( member );
    if ( !res ) {
	member->force_remove_flag = 1;
	cw_log( CW_CONF_DEBUG, "member marked for removal => %s\n", chan->name ) ;
    }

    //Play the join info messages
    if (!member->force_remove_flag && !member->quiet_mode) {
	conference_queue_sound( member, "conf-youareinconfnum" );
	conference_queue_number( member, member->id );
    }

    // The member at the very beginningis speaking
    member->is_speaking = 1 ;
    // tell conference_exec we're ready for frames
    member->active_flag = 1 ;

    //Main loop.
    while ( !member->force_remove_flag || member->soundq != NULL )
    {
	usleep(1000);

	// make sure we have a channel to process
	if ( chan == NULL )
	{
	    cw_log( LOG_NOTICE, "member channel has closed\n" ) ;
	    break ;
	}

	//-----------------//
	// INCOMING FRAMES //
	//-----------------//

	if ( member->force_remove_flag == 1 ) {
	    // break to the loop
	    break;
	}

	// wait for an event on this channel
	int waittime = ( member->framelen == 0 ) ? CW_CONF_WAITFOR_TIME : member->framelen;

	left = cw_waitfor( chan, waittime ) ;

	f = NULL;

	if ( left < 0 )
	{
	    // an error occured	
	    cw_log( 
		LOG_NOTICE, 
		"an error occured waiting for a frame, channel => %s, error => %d\n", 
		chan->name, left
		) ;
	}
	else if ( left == 0 )
	{
	    // No frame avalaible
	    member->lostframecount ++;

	    // We have lost a frame.
	    // In this case, we queue some silence
	    // Sothat if we keep loosing frames,
	    // there will be no glitching in the conference.
	    // Set the speaking state to 0.
	    if ( member->lostframecount == 1 ) {
		queue_incoming_silent_frame(member,1);
	    }
	    member->is_speaking = 0;
	}
	else if ( left > 0 ) 
	{
	    // a frame has come in before the latency timeout 
	    // was reached, so we process the frame

	    // let's reset the lost frame count
	    if ( member->lostframecount ) {
		member->lostframecount = 0;
		// If vad is not enabled, then set the speaking state back to 1
		if ( !member->enable_vad )
		    member->is_speaking = 1;
	    }
	    
	    f = cw_read( chan ) ;
			
	    if ( f == NULL ) 
	    {
		cw_log( CW_CONF_DEBUG, "unable to read from channel, channel => %s. Got Hangup.\n", chan->name ) ;
		queue_incoming_silent_frame(member,5);
		member->is_speaking = 0;
		break ;
	    } 
	    else {
/*
		cw_log( CW_CONF_DEBUG, 
			"Read (PRE dsp), channel => %s, datalen: %d samplefreq: %ld len: %ld samples %d class: %d\n", 
			chan->name, f->datalen, member->samplefreq, f->len, f->samples, f->subclass) ;
*/
		if ( member->samplefreq == 0 && f->samples != 0 )
		{
		    if ( ( f->len == 0 ) && ( f->datalen == 320 ) && ( f->samples == 160 ) )
			member->framelen = 20;				// This is probably chan_zap not setting the correct len.
		    else
			member->framelen   = f->len;			// frame length in milliseconds
		    member->datalen    = f->datalen;			// frame length in milliseconds
		    member->samples    = f->samples;			// number of samples in framelen
		    member->samplefreq = (int)(member->samples/member->framelen)*1000;	// calculated sample frequency
		    cw_log( CW_CONF_DEBUG, "MEMBER FRAME DATA: datalen %d  samples %d  len(ms) %ld, offset: %d \n", f->datalen, f->samples, f->len, f->offset );

/*
		    // Try to initialize the smoother, only once
		    queue_incoming_silent_frame(member);
		    if ( member->smooth_size_in < 0 ) {
			member->smooth_size_in = f->samples ;
			cw_log( CW_CONF_DEBUG, "Initializing Smooother.\n");
			member->inSmoother = cw_smoother_new(member->smooth_size_in); 
			if ( member->inSmoother == NULL )
			    cw_log( CW_CONF_DEBUG, "Smoother initialization failed\n");
		    }
*/

		} 

		if ( 
			    ( (member->framelen != f->len      ) && ( f->len !=0     ) ) 
				|| 
			    ( (member->samples  != f->samples  ) && ( f->samples !=0 )  && ( f->len !=0     ) )
			) 
		{
		    cw_log( CW_CONF_DEBUG, "FRAME CHANGE  : samples %d  len(ms) %ld\n", f->samples, f->len );
		    cw_log( CW_CONF_DEBUG, "FRAME SHOULDBE: samples %d  len(ms) %ld\n", member->samples, member->framelen );
		    if (member->samples == 0 ) {
			member->framelen   = f->len;				// frame length in milliseconds
			member->datalen    = f->datalen;			// frame length in milliseconds
			member->samples    = f->samples;			// number of samples in framelen
			member->samplefreq = (int) ( f->samples/f->len)*1000;	// calculated sample frequency
		    }
		}
		
		// This fix is for chan_zap
		// Chan_zap NEVER sets framelen value.
		// Probably when adding support to 16Khz we should add a check for this.
		if ( ( member->framelen == 0 ) && ( member->datalen == 320 ) && ( member->samples == 160 ) )
		    member->framelen = 20;
		
	    }
	}

	// actually process the frame.
	res = process_incoming(member, f);

	if (member->force_remove_flag)
	    member->remove_flag = 1 ;

    }

    //
    // clean up
    //

    if ( member != NULL ) 
	member->remove_flag = 1 ;

    cw_log( CW_CONF_DEBUG, "end member event loop, time_entered => %ld -  removal: %d\n", member->time_entered.tv_sec, member->remove_flag ) ;

    //cw_log( CW_CONF_DEBUG, "Deactivating generator - Channel => %s\n", member->chan->name ) ;
    cw_generator_deactivate(chan);

    return -1 ;
		
}
Exemple #7
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);
    }
}
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*/		
Exemple #9
0
void extinction_proportional()
{   
   sort(population.begin(), population.end(), fun_for_sort_members);
   
   //make pre extinction (remove all with INF_PENALTY)
   size_t n_del = 0;
   for (size_t i = population.size() - 1 ; 
	i >= psize && population[i]->penalty == INF_PENALTY ; //remove not more than psize
	i--) 
     {
	delete_member(population[i]);
	n_del++;
     }
   population.resize(population.size() - n_del);
   
   
   if (population.size() == psize) //ok
     return;

   double min_prob = 0.02;
   double max_prob = 1; 
   double min_pen = population.front()->penalty; //probability of extinction min_prob
   double max_pen = population.back()->penalty;   //probability of extinction max_prob
   
   if (min_pen == max_pen)  //in this case we make simple extinction
     {
	extinction();
	return;
     }
//   cout<<"min/max="<<min_pen<<" "<<max_pen<<endl;
   
   double black_label = max_pen * 2;
   
   size_t ext = 0;
   
   while (ext < (population.size() - psize))  //we should kill (population.size() - psize)
     {
	size_t idx = random() % population.size();
	if (population[idx]->penalty != black_label) //if it haven't been already killed
	  {
	     double ep = min_prob + (max_prob - min_prob) *
	       (population[idx]->penalty - min_pen) / (max_pen - min_pen);
//	     cout<<ep<<" "<<population[idx]->penalty<<" "<<min_pen<<"/"<<max_pen<<endl;
	     double r = random() / double(RAND_MAX);
	     if (ep > r) 
	       {
//		  if (population[idx]->penalty == min_pen)
//		    cout<<"Best extinction "<<ep<<" "<<r<<endl;
//		  cout<<"extinction"<<endl;
		  population[idx]->penalty = black_label;
		  ext++;
	       }
	  }
     }

   extinction();
   for (size_t i = 0 ; i < population.size() ; i++)
     if (population[i]->penalty == black_label)
       {
	  cerr<<"Error | extinction_proportional | internal"<<endl;
	  exit(EXIT_FAILURE);
       }
}
int member_exec( struct ast_channel* chan, void* data ) {
    int left = 0 ;
    int res;

    struct ast_conference  *conf   	= NULL;
    struct ast_conf_member *member	= NULL;
    struct ast_frame *f		= NULL;
    struct ast_app *app = NULL;

    ast_log( AST_CONF_DEBUG, "Launching NConference %s\n", "$Revision: 2325 $" ) ;

	// make sure we have a channel to process
	if ( chan == NULL )
	{
	    ast_log( LOG_NOTICE, "member channel has closed\n" ) ;
	    return -1 ;
	}

    if (chan->_state != AST_STATE_UP)
	if ( (res = ast_answer( chan )) )
	{
    	    ast_log( LOG_ERROR, "unable to answer call\n" ) ;
    	    return -1 ;
	}

    member = create_member( chan, (const char*)( data ) ) ;

    // unable to create member, return an error
    if ( member == NULL ) 
    {
	ast_log( LOG_ERROR, "unable to create member\n" ) ;
	return -1 ;
    }

    //
    // setup Openpbx read/write formats
    //
	
    //ast_log( AST_CONF_DEBUG, 
	//	"CHANNEL INFO, CHANNEL => %s, DNID => %s, CALLER_ID => %s, ANI => %s\n", 
	//	chan->name, chan->cid.cid_dnid, chan->cid.cid_num, chan->cid.cid_ani ) ;

    ast_log( AST_CONF_DEBUG, 
		"CHANNEL CODECS, CHANNEL => %s, NATIVE => %d, READ => %d, WRITE => %d\n", 
		chan->name, chan->nativeformats, member->read_format, member->write_format ) ;


    if ( ast_set_read_format( chan, member->read_format ) < 0 )
    {
    	ast_log( LOG_ERROR, "unable to set read format.\n" ) ;
    	delete_member( member ) ;
    	return -1 ;
    } 

    // for right now, we'll send everything as slinear
    if ( ast_set_write_format( chan, member->write_format ) < 0 )
    {
    	ast_log( LOG_ERROR, "unable to set write format.\n" ) ;
    	delete_member( member ) ;
    	return -1 ;
    }

    //
    // setup a conference for the new member
    //

    conf = start_conference( member ) ;
	
    if ( conf == NULL )
    {
	ast_log( LOG_ERROR, "unable to setup member conference\n" ) ;
	delete_member( member) ;
	return -1 ;
    } else {
	if (conf->is_locked && (member->type != MEMBERTYPE_MASTER) ) {
	    if (strlen(conf->pin) == 0 || strncmp(conf->pin,member->pin,sizeof(conf->pin)) ) {
		/* Conference is Locked and an invalid PIN was entered */
		remove_member(conf, member);
		return -2 ;
	    }
	}  else {
	    member->conf = conf;
	    if ( member->type == MEMBERTYPE_MASTER )
		conf->auto_destroy = member->auto_destroy;
	}
    }

    if ( member->type == MEMBERTYPE_MASTER ) {
	conf->auto_destroy = member->auto_destroy;
	if ( strlen( member->pin ) > 0 ) {
	    strncpy(conf->pin,member->pin,sizeof(conf->pin));
	    ast_log( AST_CONF_DEBUG, "Conference pin set to => %s\n", conf->pin ) ;
	}
    }

    //
    // process loop for new member ( this runs in it's own thread
    //
	
    ast_log( AST_CONF_DEBUG, "begin member event loop, channel => %s\n", chan->name ) ;

    // Add user to monitor
    if (member->monitor) {
        const char * const monitorfilename = pbx_builtin_getvar_helper(chan, "MONITOR_FILENAME");
        if (monitorfilename) {
            ast_monitor_start(chan, NULL, monitorfilename, 1);
        } else if (chan->cdr) {
            ast_monitor_start(chan, NULL, chan->cdr->uniqueid, 1);
        } else {
            char tmpid[256];
            snprintf(tmpid, sizeof(tmpid), "chan-%x", rand());
            ast_monitor_start(chan, NULL, tmpid, 1);
        }
        if (member->monitor_join) {
            ast_monitor_setjoinfiles(chan, 1);
        }
    }

    // Run AGI script
    if (member->agi) {
        char * agi = pbx_builtin_getvar_helper(chan, "AGI_CONF_JOIN");
        if (agi) {
            app = pbx_findapp("agi");
            if (app) {
                pbx_exec(chan, app, agi, 1);
            }
        } else {
            ast_log(LOG_WARNING, "AGI requested, but AGI_CONF_JOIN missing.\n");
        }
        conf->agi = 1 ;
    }

    // Activate the generator for the channel.
    res = ast_conf_member_genactivate( member );
    if ( !res ) {
	member->force_remove_flag = 1;
	ast_log( AST_CONF_DEBUG, "member marked for removal => %s\n", chan->name ) ;
    }

    //Play the join info messages
    if (!member->force_remove_flag && !member->quiet_mode && !member->mute_incoming_sounds) {
		if (ast_strlen_zero(member->intro_sounds)) {
			conference_queue_sound( member, "conf-youareinconfnum" );
			conference_queue_number( member, member->id );
		}
    }

    // The member at the very beginningis speaking
    member->is_speaking = 1 ;
    // tell conference_exec we're ready for frames
    member->active_flag = 1 ;

    //Main loop.
    while ( !member->force_remove_flag || member->soundq != NULL )
    {
#ifdef SOLARIS
    struct timespec rqtp;
    rqtp.tv_sec = 0;
    rqtp.tv_nsec = 1000000;
    if (nanosleep(&rqtp, (struct timespec *) NULL) == -1) {
        ast_log(LOG_NOTICE, "Nanosleep timer errored.\n");
    }
#else
	usleep(1000);
#endif

	//-----------------//
	// INCOMING FRAMES //
	//-----------------//

	if ( member->force_remove_flag == 1 ) {
	    // break to the loop
	    break;
	}

	// wait for an event on this channel
	int waittime = ( member->framelen == 0 ) ? AST_CONF_WAITFOR_TIME : member->framelen;

	left = ast_waitfor( chan, waittime ) ;

	if ( left < 0 )
	{
	    // an error occured	
	    ast_log( 
		LOG_NOTICE, 
		"an error occured waiting for a frame, channel => %s, error => %d\n", 
		chan->name, left
		) ;
	}
	else if ( left == 0 )
	{
	    // No frame avalaible
	    member->lostframecount ++;

	    // We have lost a frame.
	    // In this case, we queue some silence
	    // Sothat if we keep loosing frames,
	    // there will be no glitching in the conference.
	    // Set the speaking state to 0.
	    if ( member->lostframecount == 1 ) {
		queue_incoming_silent_frame(member,1);
	    }
	    member->is_speaking = 0;
	}
	else if ( left > 0 ) 
	{
	    // a frame has come in before the latency timeout 
	    // was reached, so we process the frame

	    // let's reset the lost frame count
	    if ( member->lostframecount ) {
		member->lostframecount = 0;
		// If vad is not enabled, then set the speaking state back to 1
		if ( !member->enable_vad )
		    member->is_speaking = 1;
	    }
	    
	    f = ast_read( chan ) ;
			
	    if ( f == NULL ) 
	    {
		ast_log( AST_CONF_DEBUG, "unable to read from channel, channel => %s. Got Hangup.\n", chan->name ) ;
		queue_incoming_silent_frame(member,5);
		member->is_speaking = 0;
		break ;
	    } 
	    else {
/*
		ast_log( AST_CONF_DEBUG, 
			"Read (PRE dsp), channel => %s, datalen: %d samplefreq: %ld len: %ld samples %d class: %d\n", 
			chan->name, f->datalen, member->samplefreq, f->len, f->samples, f->subclass) ;
*/

#if 0 == 1
		if ( member->samplefreq == 0 && f->samples != 0 )
		{
		    if ( ( f->len == 0 )  && ( f->datalen == 320 ) && ( f->samples == 160 ) )
			member->framelen = 20;				// This is probably chan_zap not setting the correct len.
		    else
			member->framelen   = f->len;			// frame length in milliseconds
		    member->datalen    = f->datalen;			// frame length in milliseconds
		    member->samples    = f->samples;			// number of samples in framelen
		    member->samplefreq = (int)(member->samples/member->framelen)*1000;	// calculated sample frequency
		    ast_log( AST_CONF_DEBUG, "MEMBER FRAME DATA: datalen %d  samples %d  len(ms) %ld, offset: %d \n", f->datalen, f->samples, f->len, f->offset );
		} 

		if ( 
			    ( (member->framelen != f->len      ) && ( f->len !=0     ) ) 
				|| 
			    ( (member->samples  != f->samples  ) && ( f->samples !=0 )  && ( f->len !=0     ) )
			) 
		{
		    ast_log( AST_CONF_DEBUG, "FRAME CHANGE  : samples %d  len(ms) %ld\n", f->samples, f->len );
		    ast_log( AST_CONF_DEBUG, "FRAME SHOULDBE: samples %d  len(ms) %ld\n", member->samples, member->framelen );
		    if (member->samples == 0 ) {
			member->framelen   = f->len;				// frame length in milliseconds
			member->datalen    = f->datalen;			// frame length in milliseconds
			member->samples    = f->samples;			// number of samples in framelen
			member->samplefreq = (int) ( f->samples/f->len)*1000;	// calculated sample frequency
		    }
		}
#endif
        member->framelen = f->datalen;

		// This fix is for chan_zap
		// Chan_zap NEVER sets framelen value.
		// Probably when adding support to 16Khz we should add a check for this.
		if ( ( member->framelen == 0 ) && ( member->datalen == 320 ) && ( member->samples == 160 ) )
		    member->framelen = 20;
		
	    }
	}

	// actually process the frame.
	res = process_incoming(member, f);

	if (member->force_remove_flag)
	    member->remove_flag = 1 ;

    }

	// Run AGI script
	if (member->agi) {
		char * agi = pbx_builtin_getvar_helper(chan, "AGI_CONF_LEAVE");
		if (agi) {
			app = pbx_findapp("agi");
			if (app) {
				pbx_exec(chan, app, agi, 1);
			}
		} else {
			ast_log(LOG_WARNING, "AGI requested, but AGI_CONF_LEAVE missing.\n");
		}
	}
	if (conf->agi) 
		handle_conf_agi_end(conf->name, member);        
	member->remove_flag = 1 ;

    ast_log( AST_CONF_DEBUG, "end member event loop, time_entered => %ld -  removal: %d\n", member->time_entered.tv_sec, member->remove_flag ) ;

    //ast_log( AST_CONF_DEBUG, "Deactivating generator - Channel => %s\n", member->chan->name ) ;
    ast_generator_deactivate(chan);

	if (member->hangup_go_on) {
		ast_log(AST_CONF_DEBUG, "Hangup go on!\n");
		return 0;
	}

    return -1 ;
		
}
Exemple #11
0
/*
 * grpck - verify group file integrity
 */
int main (int argc, char **argv)
{
    int arg;
    int errors = 0;
    int deleted = 0;
    int i;
    struct commonio_entry *gre, *tgre;
    struct group *grp;
    int sort_mode = 0;

#ifdef	SHADOWGRP
    struct commonio_entry *sge, *tsge;
    struct sgrp *sgr;
    int is_shadow = 0;
#endif

    /*
     * Get my name so that I can use it to report errors.
     */
    Prog = Basename (argv[0]);

    setlocale (LC_ALL, "");
    bindtextdomain (PACKAGE, LOCALEDIR);
    textdomain (PACKAGE);

    OPENLOG ("grpck");

    /*
     * Parse the command line arguments
     */
    while ((arg = getopt (argc, argv, "qrs")) != EOF) {
        switch (arg) {
        case 'q':
            /* quiet - ignored for now */
            break;
        case 'r':
            read_only = 1;
            break;
        case 's':
            sort_mode = 1;
            break;
        default:
            usage ();
        }
    }

    if (sort_mode && read_only) {
        fprintf (stderr, _("%s: -s and -r are incompatibile\n"), Prog);
        exit (E_USAGE);
    }

    /*
     * Make certain we have the right number of arguments
     */
#ifdef	SHADOWGRP
    if (optind != argc && optind + 1 != argc && optind + 2 != argc)
#else
    if (optind != argc && optind + 1 != argc)
#endif
        usage ();

    /*
     * If there are two left over filenames, use those as the group and
     * group password filenames.
     */
    if (optind != argc) {
        grp_file = argv[optind];
        gr_name (grp_file);
    }
#ifdef	SHADOWGRP
    if (optind + 2 == argc) {
        sgr_file = argv[optind + 1];
        sgr_name (sgr_file);
        is_shadow = 1;
    } else if (optind == argc)
        is_shadow = sgr_file_present ();
#endif

    /*
     * Lock the files if we aren't in "read-only" mode
     */
    if (!read_only) {
        if (!gr_lock ()) {
            fprintf (stderr, _("%s: cannot lock file %s\n"),
                     Prog, grp_file);
            if (optind == argc)
                SYSLOG ((LOG_WARN, "cannot lock %s", grp_file));
            closelog ();
            exit (E_CANT_LOCK);
        }
#ifdef	SHADOWGRP
        if (is_shadow && !sgr_lock ()) {
            fprintf (stderr, _("%s: cannot lock file %s\n"),
                     Prog, sgr_file);
            if (optind == argc)
                SYSLOG ((LOG_WARN, "cannot lock %s", sgr_file));
            closelog ();
            exit (E_CANT_LOCK);
        }
#endif
    }

    /*
     * Open the files. Use O_RDONLY if we are in read_only mode,
     * O_RDWR otherwise.
     */
    if (!gr_open (read_only ? O_RDONLY : O_RDWR)) {
        fprintf (stderr, _("%s: cannot open file %s\n"), Prog,
                 grp_file);
        if (optind == argc)
            SYSLOG ((LOG_WARN, "cannot open %s", grp_file));
        closelog ();
        exit (E_CANT_OPEN);
    }
#ifdef	SHADOWGRP
    if (is_shadow && !sgr_open (read_only ? O_RDONLY : O_RDWR)) {
        fprintf (stderr, _("%s: cannot open file %s\n"), Prog,
                 sgr_file);
        if (optind == argc)
            SYSLOG ((LOG_WARN, "cannot open %s", sgr_file));
        closelog ();
        exit (E_CANT_OPEN);
    }
#endif

    if (sort_mode) {
        gr_sort ();
#ifdef	SHADOWGRP
        if (is_shadow)
            sgr_sort ();
#endif
        goto write_and_bye;
    }

    /*
     * Loop through the entire group file.
     */
    for (gre = __gr_get_head (); gre; gre = gre->next) {
        /*
         * Skip all NIS entries.
         */

        if (gre->line[0] == '+' || gre->line[0] == '-')
            continue;

        /*
         * Start with the entries that are completely corrupt. They
         * have no (struct group) entry because they couldn't be
         * parsed properly.
         */
        if (!gre->eptr) {

            /*
             * Tell the user this entire line is bogus and ask
             * them to delete it.
             */
            printf (_("invalid group file entry\n"));
            printf (_("delete line `%s'? "), gre->line);
            errors++;

            /*
             * prompt the user to delete the entry or not
             */
            if (!yes_or_no ())
                continue;

            /*
             * All group file deletions wind up here. This code
             * removes the current entry from the linked list.
             * When done, it skips back to the top of the loop
             * to try out the next list element.
             */
delete_gr:
            SYSLOG ((LOG_INFO, "delete group line `%s'",
                     gre->line));
            deleted++;

            __gr_del_entry (gre);
            continue;
        }

        /*
         * Group structure is good, start using it.
         */
        grp = gre->eptr;

        /*
         * Make sure this entry has a unique name.
         */
        for (tgre = __gr_get_head (); tgre; tgre = tgre->next) {

            const struct group *ent = tgre->eptr;

            /*
             * Don't check this entry
             */
            if (tgre == gre)
                continue;

            /*
             * Don't check invalid entries.
             */
            if (!ent)
                continue;

            if (strcmp (grp->gr_name, ent->gr_name) != 0)
                continue;

            /*
             * Tell the user this entry is a duplicate of
             * another and ask them to delete it.
             */
            printf (_("duplicate group entry\n"));
            printf (_("delete line `%s'? "), gre->line);
            errors++;

            /*
             * prompt the user to delete the entry or not
             */
            if (yes_or_no ())
                goto delete_gr;
        }

        /*
         * Check for invalid group names.  --marekm
         */
        if (!check_group_name (grp->gr_name)) {
            errors++;
            printf (_("invalid group name `%s'\n"), grp->gr_name);
        }

        /*
         * Workaround for a NYS libc 5.3.12 bug on RedHat 4.2 -
         * groups with no members are returned as groups with one
         * member "", causing grpck to fail.  --marekm
         */
        if (grp->gr_mem[0] && !grp->gr_mem[1]
                && *(grp->gr_mem[0]) == '\0')
            grp->gr_mem[0] = (char *) 0;

        /*
         * Make sure each member exists
         */
        for (i = 0; grp->gr_mem[i]; i++) {
            if (getpwnam (grp->gr_mem[i]))
                continue;
            /*
             * Can't find this user. Remove them
             * from the list.
             */
            errors++;
            printf (_("group %s: no user %s\n"),
                    grp->gr_name, grp->gr_mem[i]);
            printf (_("delete member `%s'? "), grp->gr_mem[i]);

            if (!yes_or_no ())
                continue;

            SYSLOG ((LOG_INFO, "delete member `%s' group `%s'",
                     grp->gr_mem[i], grp->gr_name));
            deleted++;
            delete_member (grp->gr_mem, grp->gr_mem[i]);
            gre->changed = 1;
            __gr_set_changed ();
        }
    }

#ifdef	SHADOWGRP
    if (!is_shadow)
        goto shadow_done;

    /*
     * Loop through the entire shadow group file.
     */
    for (sge = __sgr_get_head (); sge; sge = sge->next) {

        /*
         * Start with the entries that are completely corrupt. They
         * have no (struct sgrp) entry because they couldn't be
         * parsed properly.
         */
        if (!sge->eptr) {

            /*
             * Tell the user this entire line is bogus and ask
             * them to delete it.
             */
            printf (_("invalid shadow group file entry\n"));
            printf (_("delete line `%s'? "), sge->line);
            errors++;

            /*
             * prompt the user to delete the entry or not
             */
            if (!yes_or_no ())
                continue;

            /*
             * All shadow group file deletions wind up here.
             * This code removes the current entry from the
             * linked list. When done, it skips back to the top
             * of the loop to try out the next list element.
             */
delete_sg:
            SYSLOG ((LOG_INFO, "delete shadow line `%s'",
                     sge->line));
            deleted++;

            __sgr_del_entry (sge);
            continue;
        }

        /*
         * Shadow group structure is good, start using it.
         */
        sgr = sge->eptr;

        /*
         * Make sure this entry has a unique name.
         */
        for (tsge = __sgr_get_head (); tsge; tsge = tsge->next) {

            const struct sgrp *ent = tsge->eptr;

            /*
             * Don't check this entry
             */
            if (tsge == sge)
                continue;

            /*
             * Don't check invalid entries.
             */
            if (!ent)
                continue;

            if (strcmp (sgr->sg_name, ent->sg_name) != 0)
                continue;

            /*
             * Tell the user this entry is a duplicate of
             * another and ask them to delete it.
             */
            printf (_("duplicate shadow group entry\n"));
            printf (_("delete line `%s'? "), sge->line);
            errors++;

            /*
             * prompt the user to delete the entry or not
             */
            if (yes_or_no ())
                goto delete_sg;
        }

        /*
         * Make sure this entry exists in the /etc/group file.
         */
        if (!gr_locate (sgr->sg_name)) {
            printf (_("no matching group file entry\n"));
            printf (_("delete line `%s'? "), sge->line);
            errors++;
            if (yes_or_no ())
                goto delete_sg;
        }

        /*
         * Make sure each administrator exists
         */
        for (i = 0; sgr->sg_adm[i]; i++) {
            if (getpwnam (sgr->sg_adm[i]))
                continue;
            /*
             * Can't find this user. Remove them
             * from the list.
             */
            errors++;
            printf (_
                    ("shadow group %s: no administrative user %s\n"),
                    sgr->sg_name, sgr->sg_adm[i]);
            printf (_("delete administrative member `%s'? "),
                    sgr->sg_adm[i]);

            if (!yes_or_no ())
                continue;

            SYSLOG ((LOG_INFO,
                     "delete admin `%s' from shadow group `%s'",
                     sgr->sg_adm[i], sgr->sg_name));
            deleted++;
            delete_member (sgr->sg_adm, sgr->sg_adm[i]);
            sge->changed = 1;
            __sgr_set_changed ();
        }

        /*
         * Make sure each member exists
         */
        for (i = 0; sgr->sg_mem[i]; i++) {
            if (getpwnam (sgr->sg_mem[i]))
                continue;

            /*
             * Can't find this user. Remove them from the list.
             */
            errors++;
            printf (_("shadow group %s: no user %s\n"),
                    sgr->sg_name, sgr->sg_mem[i]);
            printf (_("delete member `%s'? "), sgr->sg_mem[i]);

            if (!yes_or_no ())
                continue;

            SYSLOG ((LOG_INFO,
                     "delete member `%s' from shadow group `%s'",
                     sgr->sg_mem[i], sgr->sg_name));
            deleted++;
            delete_member (sgr->sg_mem, sgr->sg_mem[i]);
            sge->changed = 1;
            __sgr_set_changed ();
        }
    }

shadow_done:
#endif				/* SHADOWGRP */

    /*
     * All done. If there were no deletions we can just abandon any
     * changes to the files.
     */
    if (deleted) {
write_and_bye:
        if (!gr_close ()) {
            fprintf (stderr, _("%s: cannot update file %s\n"),
                     Prog, grp_file);
            exit (E_CANT_UPDATE);
        }
#ifdef	SHADOWGRP
        if (is_shadow && !sgr_close ()) {
            fprintf (stderr, _("%s: cannot update file %s\n"),
                     Prog, sgr_file);
            exit (E_CANT_UPDATE);
        }
#endif
    }

    /*
     * Don't be anti-social - unlock the files when you're done.
     */
#ifdef	SHADOWGRP
    if (is_shadow)
        sgr_unlock ();
#endif
    (void) gr_unlock ();

    nscd_flush_cache ("group");

    /*
     * Tell the user what we did and exit.
     */
    if (errors)
        printf (deleted ?
                _("%s: the files have been updated\n") :
                _("%s: no changes\n"), Prog);

    exit (errors ? E_BAD_ENTRY : E_OKAY);
}