示例#1
0
int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld)
{
	unsigned int i;
	int error;
	git_buf tree = GIT_BUF_INIT;

	assert(bld);

	sort_entries(bld);

	/* Grow the buffer beforehand to an estimated size */
	git_buf_grow(&tree, bld->entries.length * 72);

	for (i = 0; i < bld->entries.length; ++i) {
		git_tree_entry *entry = bld->entries.contents[i];

		if (entry->removed)
			continue;

		git_buf_printf(&tree, "%o ", entry->attr);
		git_buf_put(&tree, entry->filename, entry->filename_len + 1);
		git_buf_put(&tree, (char *)entry->oid.id, GIT_OID_RAWSZ);
	}

	if (git_buf_oom(&tree)) {
		git_buf_free(&tree);
		return git__throw(GIT_ENOMEM, "Not enough memory to build the tree data");
	}

	error = git_odb_write(oid, git_repository_database(repo), tree.ptr, tree.size, GIT_OBJ_TREE);
	git_buf_free(&tree);

	return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write tree");
}
示例#2
0
文件: rom.c 项目: mrzzzrm/mooboy
static int poll_dir() {
    DIR *dir;
    struct dirent *ent;
    int e;

    clear();

    dir = opendir(cwd);
    if(dir == NULL) {
        return 0;
    }

    for(e = 0; (ent = readdir(dir)) != NULL;) {
        direntry_t *direntry;
        if(strcmp(ent->d_name, ".") == 0) {
            continue;
        }

        direntry = malloc(sizeof(*direntry));
        direntry->is_file = ent->d_type == DT_REG;

        if(strcmp(ent->d_name, "..") == 0) {
            direntry->name = strdup(ent->d_name);
            menu_new_listentry_button(list, direntry->name, e, parent_dir);
        }
        else {
            if(direntry->is_file) {
                if(is_romfile(ent->d_name)) {
                    direntry->name = strdup(ent->d_name);
                    menu_new_listentry_button(list, direntry->name, e, load_rom);
                }
                else {
                    continue;
                }
            }
            else {
                if(ent->d_name[0] != '.') {
                    direntry->name = malloc(strlen(ent->d_name) + 1 + 1);
                    sprintf(direntry->name, "%s/", ent->d_name);
                    menu_new_listentry_button(list, direntry->name, e, change_dir);
                }
                else {
                    continue;
                }
            }
        }
        direntries = realloc(direntries, sizeof(*direntries) * (list->num_entries));
        direntries[list->num_entries - 1] = direntry;
        e++;
    }

    closedir(dir);
    sort_entries();

    load_selected_element();

    return 1;
}
示例#3
0
文件: highscore.cpp 项目: Aksej/ia
std::vector<Highscore_entry> entries_sorted()
{
    std::vector<Highscore_entry> entries;
    read_file(entries);

    if (!entries.empty())
    {
        sort_entries(entries);
    }

    return entries;
}
示例#4
0
文件: highscore.cpp 项目: Aksej/ia
void run_highscore_screen()
{
    std::vector<Highscore_entry> entries;
    read_file(entries);

    if (entries.empty())
    {
        popup::show_msg("No High Score entries found.", false);
        return;
    }

    sort_entries(entries);

    int top_nr = 0;
    draw(entries, top_nr);

    const int LINE_JUMP           = 3;
    const int NR_LINES_TOT        = entries.size();
    const int MAX_NR_LINES_ON_SCR = SCREEN_H - 3;

    //Read keys
    while (true)
    {
        draw(entries, top_nr);

        const Key_data& d = input::input();

        if (d.key == '2' || d.sdl_key == SDLK_DOWN || d.key == 'j')
        {
            top_nr += LINE_JUMP;

            if (NR_LINES_TOT <= MAX_NR_LINES_ON_SCR)
            {
                top_nr = 0;
            }
            else
            {
                top_nr = std::min(NR_LINES_TOT - MAX_NR_LINES_ON_SCR, top_nr);
            }
        }

        if (d.key == '8' || d.sdl_key == SDLK_UP || d.key == 'k')
        {
            top_nr = std::max(0, top_nr - LINE_JUMP);
        }

        if (d.sdl_key == SDLK_SPACE || d.sdl_key == SDLK_ESCAPE)
        {
            break;
        }
    }
}
示例#5
0
文件: pbap.c 项目: ghent360/bluez
static int generate_response(void *user_data)
{
	struct pbap_session *pbap = user_data;
	GSList *sorted;
	GSList *l;
	uint16_t max = pbap->params->maxlistcount;

	DBG("");

	if (max == 0) {
		/* Ignore all other parameter and return PhoneBookSize */
		uint16_t size = g_slist_length(pbap->cache.entries);

		pbap->obj->firstpacket = TRUE;
		pbap->obj->apparam = g_obex_apparam_set_uint16(
							pbap->obj->apparam,
							PHONEBOOKSIZE_TAG,
							size);

		return 0;
	}

	/*
	 * Don't free the sorted list content: this list contains
	 * only the reference for the "real" cache entry.
	 */
	sorted = sort_entries(pbap->cache.entries, pbap->params->order,
				pbap->params->searchattrib,
				(const char *) pbap->params->searchval);

	/* Computing offset considering first entry of the phonebook */
	l = g_slist_nth(sorted, pbap->params->liststartoffset);

	pbap->obj->buffer = g_string_new(VCARD_LISTING_BEGIN);
	for (; l && max; l = l->next, max--) {
		const struct cache_entry *entry = l->data;
		char *escaped_name = g_markup_escape_text(entry->name, -1);

		g_string_append_printf(pbap->obj->buffer,
			VCARD_LISTING_ELEMENT, entry->handle, escaped_name);

		g_free(escaped_name);
	}

	pbap->obj->buffer = g_string_append(pbap->obj->buffer,
							VCARD_LISTING_END);
	g_slist_free(sorted);

	return 0;
}
示例#6
0
void
polyglot_book_get_move(const struct book *book,
			const struct position *position,
			size_t msize, move moves[msize])
{

	moves[0] = 0;
	if (msize < 2)
		return;

	struct entry entries[msize - 1];
	struct search search = {.entries = entries,
				.count = 0,
				.max_count = msize - 1,
				.file = book->file,
				.size = book->polyglot_book.size, };

	enum player side;

	side = white;
	search.key = position_polyglot_key(position, side);
	if (get_entries(&search) != 0)
		search.count = 0;

	if (search.count == 0) {
		side = black;
		search.key = position_polyglot_key(position, side);
		if (get_entries(&search) != 0) {
			search.count = 0;
		}

		if (search.count == 0)
			return;
	}

	sort_entries(search.count, entries);

	pick_legal_moves(&search, position, side, moves);
}

size_t
polyglot_book_size(const struct book *book)
{
	return book->polyglot_book.size;
}
示例#7
0
文件: tree.c 项目: sakari/libgit2
const git_tree_entry *git_treebuilder_get(git_treebuilder *bld, const char *filename)
{
	int idx;
	git_tree_entry *entry;

	assert(bld && filename);

	sort_entries(bld);
	idx = git_vector_bsearch2(&bld->entries, entry_search_cmp, filename);
	if (idx == GIT_ENOTFOUND)
		return NULL;

	entry = git_vector_get(&bld->entries, idx);
	if (entry->removed)
		return NULL;

	return entry;
}
示例#8
0
文件: tree.c 项目: sakari/libgit2
int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld)
{
	size_t i, size = 0;
	char filemode[MAX_FILEMODE_BYTES + 1 + 1];
	git_odb_stream *stream;
	int error;

	assert(bld);

	sort_entries(bld);

	for (i = 0; i < bld->entries.length; ++i) {
		git_tree_entry *entry = bld->entries.contents[i];

		if (entry->removed)
			continue;

		snprintf(filemode, sizeof(filemode), "%o ", entry->attr);
		size += strlen(filemode);
		size += entry->filename_len + 1;
		size += GIT_OID_RAWSZ;
	}

	if ((error = git_odb_open_wstream(&stream, git_repository_database(repo), size, GIT_OBJ_TREE)) < GIT_SUCCESS)
		return error;

	for (i = 0; i < bld->entries.length; ++i) {
		git_tree_entry *entry = bld->entries.contents[i];

		if (entry->removed)
			continue;

		snprintf(filemode, sizeof(filemode), "%o ", entry->attr);
		stream->write(stream, filemode, strlen(filemode));
		stream->write(stream, entry->filename, entry->filename_len + 1);
		stream->write(stream, (char *)entry->oid.id, GIT_OID_RAWSZ);
	} 

	error = stream->finalize_write(oid, stream);
	stream->free(stream);

	return error;
}
示例#9
0
文件: highscore.cpp 项目: Aksej/ia
void on_game_over(const bool IS_WIN)
{
    std::vector<Highscore_entry> entries = entries_sorted();

    final_score_ = new Highscore_entry(cur_time().time_str(Time_type::minute, true),
                                       map::player->name_a(),
                                       dungeon_master::xp(),
                                       dungeon_master::clvl(),
                                       map::dlvl,
                                       map::player->ins(),
                                       IS_WIN,
                                       player_bon::bg());

    entries.push_back(*final_score_);

    sort_entries(entries);

    write_file(entries);
}
示例#10
0
void node::send_to_playlist(bool replace)
{
	static_api_ptr_t<playlist_manager> api;
	const bool select = !!cfg_add_items_select;
	api->activeplaylist_undo_backup();
	if (replace) api->activeplaylist_clear();
	else if (select) api->activeplaylist_clear_selection();
	if (cfg_add_items_use_core_sort) api->activeplaylist_add_items_filter(entries, select);
	else
	{
		sort_entries();
		api->activeplaylist_add_items(entries, bit_array_val(select));
	}

	if (select && !replace)
	{
		unsigned num = api->activeplaylist_get_item_count();
		if (num > 0)
		{
			api->activeplaylist_set_focus_item(num - 1);
		}
	}
}
示例#11
0
void flat(void)
{
char iroom[80],iphone[80],add_quit;
char option,sortopt,exit_opt;
int phone_check,room_check,delete_check,sort_check,list_check;
int iroom_search,iroom_del;
int int_iroom,total_entries;
int error_iphone,error_iroom;
long int longint_iphone;
long int iphone_search;
long int iphone_del;


strcpy(dbload, "DATABASE ERROR...");

do
 {
  do
   { option = menu_flat();
     if (option == '1')
     {  current_e_add=0;
	for (i=total_entry; i < MAXDB; i++)
	{   clrscr();
	    remakescreen();
	    screen_draw_flat();
	    gotoxy(1,4);
	    printf("## ADD NEW ENTRY ##");
	    gotoxy(1,25);
	    cprintf("Please Add Your Entry, leave blank to reach to Main Menu..");
	    gotoxy(1,6);
	    printf("Enter Room  Number[%3d]: ",i+1);
	    gets(iroom);

	    if (iroom[0] == '\0' )
	    {  gotoxy(1,25);
	       cprintf("You chose to quit: Entry %d was not added to the database.",i+1);
	       getch();
	       break;
	    }
	    printf("Enter Phone Number[%3d]: ",i+1);
	    gets(iphone);

	    if (iphone[0] == '\0')
	    {  gotoxy(1,25);
	       cprintf("You chose to quit: Entry %d was not added to the database.",i+1);
	       getch();
	       break;
	    }

	    error_iroom = chkdig(iroom,4);
	    error_iphone = chkdig(iphone,8);

	    while(error_iroom != 0)
	    {	if (error_iroom == -1)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("## ADD NEW ENTRY ##");
		   gotoxy(1,25);
		   cprintf("Error: Room  Number - out of Range, Your entry was greater than 4 digits. ");
		   gotoxy(1,6);
		   printf("Renter Room  Number[%3d]: ",i+1);
		   gets(iroom);
		}
		if (error_iroom == -2)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("*** Add Entry ***");
		   gotoxy(1,25);
		   cprintf("Error: Room  Number - Character(s) detected, character(s) are not allowed.");
		   gotoxy(1,6);
		   printf("Renter Room  Number[%3d]: ",i+1);
		   gets(iroom);
		}
		error_iroom = chkdig(iroom,4);
	    }
	    while(error_iphone !=0)
		{	if (error_iphone == -1)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("## ADD NEW ENTRY ##");
		   gotoxy(1,25);
		   cprintf("Error: Phone Number - out of Range, Your entry was greater than 8 digits. ");
		   gotoxy(1,6);
		   printf("Room  Number[%3d] Entry: %s",i+1,iroom);
		   gotoxy(1,7);
		   printf("Renter Phone Number[%3d]: ",i+1);
		   gets(iphone);
		}
		if (error_iphone == -2)
		{  clrscr();
		   remakescreen();
		   screen_draw_flat();
		   gotoxy(1,4);
		   printf("## ADD NEW ENTRY ##");
		   gotoxy(1,25);
		   cprintf("Error: Phone Number - Character(s) detected, character(s) are not allowed.");
		   gotoxy(1,6);
		   printf("Room  Number[%3d] Entry: %s",i+1,iroom);
		   gotoxy(1,7);
		   printf("Renter Phone Number[%3d]: ",i+1);
		   gets(iphone);
		}
		error_iphone = chkdig(iphone,8);
	    }
	    if (error_iroom == 0 && error_iphone == 0)
	    {  int_iroom = atoi(iroom);
	       longint_iphone = atol(iphone);

	       current_e_add++;
	       add_entry(int_iroom,longint_iphone);
	    }
	}
	if (total_entry == MAXDB)
	{  gotoxy(1,25);
	   cprintf("\aDatabase is full!: %d entries were added, ",total_entry);
	   cprintf("that is the Maximum No. I can hold.");
	   getch();
	}
     }
     else
     if (option == '2')
     {  del_entry = 0; 	clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Delete Entry ##");
	gotoxy(1,6);
	printf("Enter room  number to delete: ");
	scanf("%d",&iroom_del);
	flushall();

	printf("Enter phone number to delete: ");
	scanf("%ld",&iphone_del);
	flushall();

	delete_check = delete_entry(iroom_del,iphone_del);

	if (delete_check == 0)
	{  gotoxy(1,25);
	   cprintf("Successful: There are presently %d entries in the database, ",total_entry);
	   cprintf("deleted %d.",del_entry);
	   getch();
	}
	if (delete_check == -1) 
	{  gotoxy(1,25);
	   cprintf("Error: The Room No./Phone No. Your looking for was Not Found.                  ");
	   getch();
	}

     }
     else
     if (option == '3')
     {  phone_found = 0;
	clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Find Room Number ##");

	gotoxy(1,6);
	printf("Enter the phone number to search for: ");
	scanf("%ld",&iphone_search);
	flushall(); 

	phone_check = find_phone_number(iphone_search);

	if (phone_check == 0)
	{  gotoxy(1,25);
	   cprintf("Successful: There are presently %d entries in the database, ",total_entry);

	   printf("found %d.",phone_found);
	   getch();
	}
	if (phone_check == -1) 
	{  gotoxy(1,25);
	   cprintf("Error: The Phone No. Your looking for was Not Found.");
	   getch();
	}
     }
     else
     if (option == '4')
     {  room_found = 0;
	clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Find Phone Number ##");

	gotoxy(1,6);
	printf("Enter the room number to search for: ");
	scanf("%d",&iroom_search);
	flushall();

	room_check = FindRoom(iroom_search);

	if (room_check == 0) 
	{  gotoxy(1,25);
	   cprintf("Successful: There are presently %d entries in the database, ",total_entry);
	   cprintf("found %d.",room_found);
	   getch();
	}
	if (room_check == -1) 
	{  gotoxy(1,25);
	   cprintf("Error: The Room No. Your looking for was Not Found.");
	   getch();
	}

     }
     else
     if (option == '5')
     {  clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## ListAll ##\n\n");

	list_check = ListAll();

	if (list_check == 0)
	{  gotoxy(1,25);
	   cprintf("List Sucuessful");
	   getch();
	}
	if (list_check == -1)
	{
	   gotoxy(1,25);
	   cprintf("Empty List");
	   getch();
	}
     }
     else
     if (option == '6')
     {  total_entries = GeTotalEntries();
	gotoxy(1,25);
	cprintf("There are presently %d entries stored in the Database.",total_entries);
	getch();
     }
     else
     if (option == '7') 
   {  clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Sort All Entries ##");
	gotoxy(1,6);
	printf("Press 'A' to sort database in [A]scending order");
	gotoxy(1,7);
	printf("Press 'D' to sort database in [D]escending order.");
	gotoxy(1,9);
	printf("Note: Database is sorted by phone no. entries.");
	sortopt = getch();
	flushall();

	sort_check = sort_entries(sortopt);
	getch();
	if (sort_check == 0)
	{  gotoxy(1,25);
	   cprintf("Database was successfully Sorted.                                      ");
	   getch();
	}
	if (sort_check == -1)
	{  gotoxy(1,25);
	   cprintf("Database was not sorted - Database is empty!");
	   getch();
	}
     }
     else
     if (option == '8') 
     {  clrscr();
	remakescreen();
	screen_draw_flat();
	gotoxy(1,4);
	printf("## Load Database ##");
	loaddatabase();
     }
     else
     if (option == '9')
     {  gotoxy(1,25);
	cprintf("Do you really want to exit?, Press 'Y' to confirm, anykey to cancel");
	exit_opt = getch();
	flushall();
	if (exit_opt == 'y' || exit_opt == 'Y')
	{  clrscr();
	   remakescreen();
	   screen_draw_flat();
	   gotoxy(1,4);
	   printf("## Exit To system ##\n\n");
	   menu_exit();
	}
     }
     else 
     {  gotoxy(1,25);
	cprintf("Error: Invalid option! Select an option between 1 and 9");
	getch();
	flushall();
     }
   }while  (option > '9' || option < '1' );
 }while (option != '`'); 
}
示例#12
0
/*
	Please see cidrmerge.h
*/
unsigned int optimize(struct entry *addr,unsigned int len,int do_sort)
{
	unsigned int i,cur;
	unsigned int tmp_net;
	#ifdef LIBRARY_DEBUG
	char debug_buf[MAXLINE];
	unsigned int step=0;

	print_debug(STDOUT,debug_buf,"START optimize\n");
	#endif

	i=0;   /*pointer to last valid position*/
	cur=1; /*pointer to next addr to analize*/

	if (len <= 1)
	{
		/* empty or sigle element array is optimized by definition.*/
		return len;
	}

	if (do_sort)
	{
		sort_entries(addr,len);
	}

	/*Find first valid address and move it to first position*/
	while ((addr[0].prefix==INVALID_PREFIX) && (cur<len))
	{
		#ifdef LIBRARY_DEBUG
		printf ("SEARCH FIRST I: %d CUR: %d\n",i,cur);
		#endif
		if (addr[cur].prefix!=INVALID_PREFIX)
		{
			addr[0].network=addr[cur].network;
			addr[0].prefix=addr[cur].prefix;
			addr[cur].prefix=INVALID_PREFIX;
		}
		cur++;
	}

	while (cur<len)
	{
		#ifdef LIBRARY_DEBUG
		printf ("STEP: %u I: %d CUR: %d\n",step++,i,cur);
		#endif
		#ifdef LIBRARY_DEBUG_FULL
		print_addresses(STDOUT,addr,len,NULL,0);
		#endif

		/*check for expanded networks, they can never conflicts*/
		if (addr[cur].prefix>=EXPANDED_PREFIX)
		{
			#ifdef LIBRARY_DEBUG
			printf ("COPY EXPANDED I: %d CUR: %d\n",i,cur);
			#endif
			i++;
			addr[i].network=addr[cur].network;
			addr[i].prefix=addr[cur].prefix;
			cur++;
			while ((addr[i].prefix>=EXPANDED_PREFIX) && (cur<len))
			{
				#ifdef LIBRARY_DEBUG
				printf ("COPY ADDR[CUR] FOR EXPANDED I: %d CUR: %d\n",i,cur);
				#endif
				if (addr[cur].prefix!=INVALID_PREFIX)
				{
					i++;
					if (cur != i)
					{
						addr[i].network=addr[cur].network;
						addr[i].prefix=addr[cur].prefix;
						addr[cur].prefix=INVALID_PREFIX;
					}
				}
				cur++;
			}
		}
		else
		{
			/*If this test will fail we just skip addr[cur]*/
			if ((addr[cur].prefix<=32)&&((addr[cur].network&TONETMASK(addr[i].prefix))!=addr[i].network))
			{
				tmp_net=TONETMASK(addr[i].prefix-1);

				if ( (addr[i].prefix==addr[cur].prefix) && ( (addr[i].network&tmp_net) == (addr[cur].network&tmp_net) ) )
				{
					#ifdef LIBRARY_DEBUG
					printf ("COLLAPSE I: %d CUR: %d\n",i,cur);
					#endif

					if (i>0)
					{
						addr[cur].prefix=addr[i].prefix-1;
						addr[cur].network&=tmp_net;
						i--;
					}
					else
					{
						addr[i].prefix=addr[i].prefix-1;
						addr[i].network&=tmp_net;
						cur++;
					}
				}
				else
				{
					i++;

					addr[i].network=addr[cur].network;
					addr[i].prefix=addr[cur].prefix;

					cur++;
				}
			}
			else
			{
				#ifdef LIBRARY_DEBUG
				printf ("SKIP CUR: %d\n",cur);
				#endif

				cur++;
			}
		}
	}

	#ifdef LIBRARY_DEBUG
	print_debug(STDOUT,debug_buf,"END optimize\n");
	#endif

	if (addr[i].prefix!=INVALID_PREFIX)
	{
		return i+1;
	}
	else
	{
		return i;
	}
}
示例#13
0
/*
	Please see cidrmerge.h
*/
unsigned int apply_whitelist(struct entry *addr,struct entry **expanded_list,struct entry *white,unsigned int len1,unsigned int len2,unsigned int *size_expanded,int do_sort)
{
	unsigned int i1,i2,invalid,tmp,expanded_index=0;
	uint32_t supermask;
	struct entry tmp_entry;
	#ifdef LIBRARY_DEBUG
	char debug_buf[MAXLINE];
	unsigned int step=0;
	print_debug(STDOUT,debug_buf,"START apply_whitelist\n");
	#endif


	if (do_sort)
	{
		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"Sorting entries\n");
		#endif
		sort_entries(addr,len1);
		sort_entries(white,len2);
	}

	i1=i2=0;
	while ((i1<len1)&&(i2<len2))
	{
		#ifdef LIBRARY_DEBUG
		print_debug(STDOUT,debug_buf,"STEP=%u I1=%d I2=%d\n",step++,i1,i2);
		#endif
		#ifdef LIBRARY_DEBUG_FULL
		print_addresses(STDOUT,addr,len1,NULL,0);
		#endif

		supermask=TONETMASK(addr[i1].prefix)&TONETMASK(white[i2].prefix);

		if ((addr[i1].prefix<=32)&&(addr[i1].network&supermask)==(white[i2].network&supermask))
		{
			#ifdef LIBRARY_DEBUG
			print_debug(STDOUT,debug_buf,"CONFLICT\n");
			print_address(STDOUT,addr[i1].network,addr[i1].prefix);
			print_address(STDOUT,white[i2].network,white[i2].prefix);
			#endif
			if (addr[i1].prefix<white[i2].prefix)
			{
				/*we have to expand the network*/

				/*invalidate all addr[i1] subnetworks */
				invalid=i1+1;
				while ((invalid<len1)&&(addr[invalid].network&supermask)==(white[i2].network&supermask))
				{
					/*address is already present in the expanded network, just drop it*/
					#ifdef LIBRARY_DEBUG
					print_debug(STDOUT,debug_buf,"INVALIDATING ");
					print_address(STDOUT,addr[invalid].network,addr[invalid].prefix);
					#endif
					addr[invalid].prefix=INVALID_PREFIX;

					invalid++;
				}

				invalid-=i1+1; /*invalid represents the number of invalidated positions*/

				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"INVALID %u LEN1 %u\n",invalid,len1);
				#endif

				tmp=i2;
				i2+=1;
				while ( (i2<len2) && ((addr[i1].network&supermask)==(white[i2].network&supermask)) )
				{
					i2++;
				}

				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"EXPAND expanded_index %u whitelist elements: %u num expand %d\n",expanded_index,i2-tmp,white[tmp].prefix-addr[i1].prefix);
				#endif

				tmp_entry.network=addr[i1].network;
				tmp_entry.prefix=addr[i1].prefix;

				addr[i1].prefix=EXPANDED_PREFIX+white[tmp].prefix-addr[i1].prefix;
				addr[i1].network=expanded_index;
				/* expanded positions are clean and optimized */
				expand(expanded_list,tmp_entry,&(white[tmp]),i2-tmp,white[tmp].prefix-tmp_entry.prefix,&expanded_index,size_expanded);

				i1+=invalid+1;

				#ifdef LIBRARY_DEBUG
				print_debug(STDOUT,debug_buf,"END MAIN EXPAND expanded_index %u i1: %u i2: %u\n",expanded_index,i1,i2);
				#endif

			}
			else
			{
				/*just invalidating entry i1*/
				#ifdef LIBRARY_DEBUG
				printf ("INVALIDATING ");
				print_address(STDOUT,addr[i1].network,addr[i1].prefix);
				#endif
				addr[i1].prefix=INVALID_PREFIX;
				i1++;
			}

		}
		else if ((addr[i1].prefix==INVALID_PREFIX)||(addr[i1].network&supermask)<=(white[i2].network&supermask))
		{
			i1++;
		}
		else
		{
			i2++;
		}
	}
	#ifdef LIBRARY_DEBUG
	print_debug(STDOUT,debug_buf,"END apply_whitelist\n");
	#endif
	return expanded_index;
}