Exemplo n.º 1
0
Arquivo: hangover.c Projeto: ahsyh/cpp
int search_list(double* list,int left, int right, int target){
	int pos;
	if(target==520)return 275;
	if(target<=50) return 0;
	if((right-left)<5)
	{
		for(pos=left;pos<right;pos++){
			if((list[pos]<target)&&(list[pos+1]>target)){
				return pos+1;
			}
		}
	}

	pos = (left+right)/2;

	if((list[pos]<target)&&(list[pos+1]>target)){
		return pos+1;
	}
	else if (list[pos+1]<=target) {
		return search_list(list, pos+1, right, target);
	}
	//else if ((list[pos]>target)&&(list[pos+1]>target)){

	return search_list(list, left, pos+1, target);
	//}

}
Exemplo n.º 2
0
/* 
 * malloc - Allocate a block with at least size bytes of payload 
 */
void *malloc(size_t size) 
{
    size_t asize;      /* Adjusted block size */
    void *bp;      
    if (heap_listp == 0) {
        mm_init();
    }
    /* Ignore spurious requests */
    if (size == 0)
        return NULL;

    /* Adjust block size to include overhead and alignment reqs. */
    if (size <= DSIZE)                                          
        asize = MIN_SIZE;                                        
    else
        asize = DSIZE * ((size + (3*DSIZE) + (DSIZE-1)) / DSIZE); 

    /* Search the free list for a fit */
    bp = search_list(asize);
    /* No fit found. Get more memory and place the block */
    if (bp == NULL) {
        if ((bp = extend_heap(asize)) == NULL)  
            return NULL;                                  
    }

    /* set bp as allocated and delete from list */
    set_alloc(bp);
    return bp;
} 
Exemplo n.º 3
0
int main(void){

	int i;
	mlist *mylist, *temp;

	insert_list(mylist,2);
	insert_list(mylist,5);
	insert_list(mylist,1);
	insert_list(mylist,3);

	mylist = head;

	while(mylist) {
		mylist = mylist->next;
	}

	temp = search_list(mylist,2);
	__VERIFIER_assert(temp->key==2);
	delete_list(temp);

	mylist = head;

	while(mylist) {
		mylist = mylist->next;
	}
	return 0;
}
Exemplo n.º 4
0
State*
best(State* current,State* goal,Comparator* heuristic)
{
  SortedQueue<State,Comparator> search_list(heuristic);
  State* transition;

  if ((current == 0) || (goal == 0))
    return 0;

  for(;
      ((current != 0) 
       && (current->compare(goal) != (int) State::EQUAL));
      search_list.remove(current))
    {
      for(transition = current->makeTransition(); 
	  transition != 0;
	  transition = current->makeTransition())
	{
	  if (transition)
	    transition->mark();
	  search_list.insert(transition);
	}
    }
  return current;
}
Exemplo n.º 5
0
delete_list(list **l, item_type x)
{
	list *p;			/* item pointer */
	list *pred;			/* predecessor pointer */
	list *search_list(), *predecessor_list();

	p = search_list(*l,x);
	if (p != NULL) {
		pred = predecessor_list(*l,x);
		if (pred == NULL)	/* splice out out list */
			*l = p->next;
		else
			pred->next = p->next;

		free(p);		/* free memory used by node */
	}
}
Exemplo n.º 6
0
string
kpse_path_search_list P3C(const_string, path,  const_string*, names,
                          boolean, must_exist)
{
  string *ret_list = search_list (path, names, must_exist, false);
  string ret = *ret_list;
  free (ret_list);
  return ret;
}    
Exemplo n.º 7
0
list *search_list(list *l, item_type x)
{
	if (l == NULL) return(NULL);

	if (l->item == x)
		return(l);
	else
		return( search_list(l->next, x) );
}
Exemplo n.º 8
0
int main()
{
	// Initialize a list
	struct node *head = malloc(sizeof(struct node));
	head->value = 7;
	for (int i = 7; i > 0; --i) {
		head = add_to_list(head, i);
		if (head == NULL) { return EXIT_FAILURE; }
	}

	// Delete 1 and 4
	delete_from_list(&head, 1);
	delete_from_list(&head, 4);

	// Write out the list
	for (struct node *iter = head; iter != NULL; iter = iter->next) { printf("%d ", iter->value); }
	printf("\b\n");

	// Search 5
	struct node *found = search_list(head, 5);
	if (found != NULL) { printf("%d found\n", found->value); }

	// Search 10
	found = search_list(head, 10);
	if (found == NULL) { printf("10 not found\n"); }

	// Count 7 and 2
	printf("The list contains %d seven\n", count_occurrencies(head, 7));
	printf("The list contains %d two\n", count_occurrencies(head, 2));

	// Find last 7
	struct node *last = find_last(head, 7);
	if (last->next != NULL) { fprintf(stderr, "That seven is not the last one\n"); }
	else { printf("Found %d\n", last->value); }

	// Find 1
	last = find_last(head, 1);
	if (last != NULL) { fprintf(stderr, "Found an inexistent element?!\n"); }
	else { printf("1 not found\n"); }

	// Free memory
	clear_list(head);
	return EXIT_SUCCESS;
}
int main(int argc, char *argv[])
{
    int i;
    list *l, *pred_list;
    time_t t;
    int rand_val;

    srand((unsigned) time(&t));

    /* Inserting item in a single linked list
     * O(1) to the head
     */
    l = head_list;
    for (i = 0; i < 100; i++) {
        insert_list(&l ,i);
        head_list = l;
    }


    /* print the members of the list */
    print_list(head_list);

    /* Searching item through a singly linked list */
    for (i = 0; i < 101; i++) {
        if ((l = search_list(head_list, i)) == NULL) {
            printf("Item not found: %d\n", i);
        } else {
            printf("Found item: %d\n", l->data);
        }
    }

    /* Deleting an item from the linked list */
    rand_val = rand() % 100;
    l = search_list(head_list, rand_val);
    printf("Rand data found: %d; Rand value:%d\n", l->data, rand_val);
    pred_list = find_predecessor_list(head_list, l);
    pred_list->next = l->next;
    free(l);

    print_list(head_list);

    return 0;
}
int main(void){
  int i;
  mlist *mylist, *temp;
  insert_list(mylist,2);
  insert_list(mylist,5);
  insert_list(mylist,1);
  insert_list(mylist,3);
  temp = search_list(head,2);
  __VERIFIER_assert(temp->key==1);
}
Exemplo n.º 11
0
int is_tld(unsigned char *name)
{
	char *end;
	unsigned long l;
	if (strlen(cast_const_char name) == 2 && upcase(name[0]) >= 'A' && upcase(name[0]) <= 'Z' && upcase(name[1]) >= 'A' && upcase(name[1]) <= 'Z' && casestrcmp(name, cast_uchar "gz"))
		return 1;
	l = strtoul(cast_const_char name, &end, 10);
	if (!*end && l <= 255)
		return 1;
	return search_list(domain_suffix, array_elements(domain_suffix), name);
}
Exemplo n.º 12
0
static int search_list_and_wildcards(const_char_ptr const *list, int len, unsigned char *name)
{
	unsigned char *dot, *x;
	int sl;

	if (search_list(list, len, name)) return 1;

	x = stracpy(cast_uchar "*.");
	add_to_strn(&x, name);
	sl = search_list(list, len, x);
	mem_free(x);
	if (sl) return 1;

	dot = cast_uchar strchr(cast_const_char name, '.');
	if (!dot) return 0;
	x = stracpy(cast_uchar "*");
	add_to_strn(&x, dot);
	sl = search_list(list, len, x);
	mem_free(x);
	return sl;
}
Exemplo n.º 13
0
main()
{
	char c;			/* input character */
	item_type d;		/* input item */
	list *l;		/* list under construction */
	list *tmp;		/* returned list from search */
	list *search_list();
	void insert_list();

	l = init_list();

	while (scanf("%c",&c) != EOF) {
		if (tolower(c) == 'p')
			print_list(l);
		if (tolower(c) == 'i') {
			scanf("%d",&d);
printf("new item: %d\n",d);
			insert_list(&l,d);
		}
		if (tolower(c) == 's') {
			scanf("%d",&d);
			tmp = search_list(l,d);
			if (tmp == NULL) 
				printf("item %d not found\n",d);
			else
				printf("item %d found\n",d);
		}
		if (tolower(c) == 'd') {
			scanf("%d",&d);
                        tmp = search_list(l,d);
                        if (tmp == NULL)
                                printf("item to delete %d not found\n",d);
			else
				printf("item %d deleted\n",d);
			delete_list(&l,d);
		}
	}
}
Exemplo n.º 14
0
/*
 * searches hash table for first instance of "value"
 * -returns actual struct_of_ints node when found, NULL if not found
 */
linked_list* find (hash_table* table, char* value) {

    if (table) {
      /* determine bucket value may be in */
        int bucket_num = map(table, value);

      /* search corresponding bucket's linked list (using search_list function) */


      /* return matching node or NULL if not found */

      return search_list(table->table[bucket_num], value);
    } else return NULL;
}
Exemplo n.º 15
0
/*------------------------------------------------------------------------------------------------------------
   get_old_positions()
        Funcao que percorre uma lista alterando os valores da posicao antiga de cada no de acordo com a posicao
	em que eles sao encontrados na outra lista
        - Parametros
          LIST* : lista "velha"
          LIST* : lista "nova"
        - Retorno
          int : 0 - falha; 1 - sucesso
*/
int get_old_positions(LIST *old_list, LIST *new_list){
	if(old_list != NULL && new_list != NULL){
		int i;
		NODE *aux;

		// Mecanismo de busca semelhante a print_list()
		for(i = 1; (aux = get_node(new_list, i)) != NULL; i++){
			// Caso esse id nao esteja presente na lista antiga, recebera -1 na posicao antiga
			aux->old_position = search_list(old_list, aux->ID);
		}
		return 1;
	}

	return 0;
}
Exemplo n.º 16
0
list *search_list(list *head_list, const item_type f_data) 
{
    list *iter;
    if (head_list == NULL) {
        return NULL;
    }

    iter = head_list;

    if (iter->data == f_data) {
        return iter;
    } else {
        return search_list(iter->next, f_data);
    }

}
Exemplo n.º 17
0
Arquivo: mm.c Projeto: adel-qod/malloc
/// <summary> 
/// Searches each list(starting from list_num) for a big-enough free block 
/// </summary>
/// <param name='list_num'> 
/// The index of the list where the search will start from 
/// </param>
/// <param name='size'> The size of the block we need, in bytes </param>
/// <return>
/// A properely aligned pointer to the beginning of the block
/// or NULL in failure
/// </return>
static uint8_t *extract_free_block(int list_num, size_t size)
{
    uint8_t *data;
    /* Search this list, if you can't find a free-block, search all larger 
     * ones */
    for(int i = list_num; i < FREE_LISTS_COUNT; i++) {
        DEBUG_PRINT("Searching list[%d] for block of size %zd\n", i
                                                                , size);
        if((data = search_list(i, size)) != NULL) {
            DEBUG_PRINT("Found block in list[%d]\n", i);
            return data;
        }
    }
    DEBUG_PRINT("%s\n", "returning NULL");
    return NULL;
}
Exemplo n.º 18
0
int main(int argc, char* argv[])
{
    iNode *header, *result;
    int   searchValue = 2;
    iNode a, b, c;
    a.value = 1;
    b.value = 2;
    c.value = 3;
    a.next  = &b;
    b.next  = &c;
    c.next  = NULL;
    header  = &a;
    result  = search_list(header, &searchValue, &compare_int);
    printf("The value of the node is: %d\n", result->value);
     
    return 0;
}
Exemplo n.º 19
0
Arquivo: hangover.c Projeto: ahsyh/cpp
int main(void)
{
	int size;
	int pos;
	para_t *iter;

	size = f(520);
	read_para();

	iter = g_begin;
	while(iter!=NULL){
		pos = search_list(list,0, size,iter->val);
		printf("%d card(s)\n",pos+1);
		iter = iter->next;
	}

	return 0;
}
Exemplo n.º 20
0
/**@brief this function receives an arp message from outside and processes it
 * @param fins_received is the pointer to the fins frame which has been received by the ARP module
 */
void arp_in(struct finsFrame *fins_received){

	struct ARP_message *arp_msg_ptr;

	fins_arp_in = fins_received;

	/**request or reply received from the network and as transmitted by the ethernet stub*/
	if (fins_arp_in->dataOrCtrl == DATA && (fins_arp_in->destinationID.id == (unsigned char) ARPID))
	{
		fins_to_arp(fins_arp_in, packet);  //extract arp hdr from the fins frame
		host_to_net(packet);               //convert it into the right format (e.g. htons issue etc.)
		arp_msg_ptr = &arp_msg;
		arp_hdr_to_msg(packet, arp_msg_ptr);  //convert the hdr into an internal ARP message (e.g. use uint64_t instead of unsigned char)

		print_msgARP(arp_msg_ptr);

		if (check_valid_arp(arp_msg_ptr)==1){

			update_cache(arp_msg_ptr);

			if ((arp_msg_ptr->target_IP_addrs==interface_IP_addrs) && (arp_msg_ptr->operation==ARPREQUESTOP))
				arp_out(REPLYDATA);//generate reply
			else if ((arp_msg_ptr->target_IP_addrs==interface_IP_addrs) && (arp_msg_ptr->operation==ARPREPLYOP))
			{	target_IP_addrs = arp_msg.sender_IP_addrs;
				arp_out(REPLYCONTROL);//generate fins control carrying neighbor's MAC address
			}
		}
	}
	else if ((fins_arp_in->dataOrCtrl == CONTROL) && (fins_arp_in->ctrlFrame.opcode == WRITEREQUEST)
			&& (fins_arp_in->destinationID.id == (unsigned char) ARPID))
	{/**as a request received from the ethernet stub-- IP address is provided in this fins control frame*/

		memcpy(fins_IP_address, fins_arp_in->ctrlFrame.paramterValue, PROTOCOLADDRSLEN);
		target_IP_addrs = gen_IP_addrs(fins_IP_address[0],fins_IP_address[1],fins_IP_address[2],fins_IP_address[3]);

		/**request initiated by the ethernet stub*/
		if (search_list(ptr_cacheHeader, target_IP_addrs)==0)//i.e. not found
			arp_out(REQUESTDATA); //generate arp request for MAC address and send out to the network
		else
			arp_out(REPLYCONTROL);//generate fins control carrying MAC address foe ethernet
	}

	print_cache();
}
Exemplo n.º 21
0
void add_to_alloc_list(const void *ptr,
                       const size_t pl_size,
                       const size_t bk_size) {
  if (ptr == NULL) return;
  assert(!addr_is_allocated(ptr));
  assert(search_list(alloc_list, ptr) == NULL);
  assert(pl_size < bk_size);
  HeapStruct* new_node = (HeapStruct*)malloc(sizeof(HeapStruct));
  new_node->bk_head = get_hdrp(ptr);
  new_node->bk_tail = (char*)get_hdrp(ptr) + bk_size;
  new_node->pl_head = ptr;
  new_node->pl_tail = (char*)ptr + pl_size;
  new_node->bk_size = bk_size;
  new_node->pl_size = pl_size;
  new_node->next = alloc_list; // insert it in the front of the list
  new_node->index = -1;
  alloc_list = new_node;
  assert(new_node->pl_tail - new_node->pl_head == pl_size);
  assert(new_node->bk_tail - new_node->bk_head == bk_size);
  assert(new_node->bk_head < new_node->pl_head);
  assert(new_node->bk_tail >= new_node->pl_tail);
  assert(new_node->pl_tail < (char*)heap_tail);
}
Exemplo n.º 22
0
void find_dir(void)
{
	system("cls");
	int l=MAX_LIST,num,m=0;
	char choose='y';
	team *head,*fp,*p;
	FILE *fout;
	fp=head=find_list();
	if((fout=fopen("F:\\lol_info_table.dat","rb"))==NULL)
	 {
	 	printf("Open the file error!!!\n");
	 	exit(-1);
	 }
	while(!feof(fout))
	{
		if(fread(fp,sizeof(team)-4,1,fout)==1)
		m++;
		fp=fp->next;
	}
	fclose(fout);
	while(choose=='y'||choose=='Y')
	{
		printf("Input the number you want to find:\n");
		scanf("%d",&num);
		getchar();
		p=search_list(head,num,m);	
	    if(p!=NULL)
		{
	   		printf("\nThe loler's information:\n");
	   		printf("Num:%d\tName:%s\tAge:%d\tLocation:%s\n",p->num,p->name,p->age,p->add);
		}
		else 
			printf("Not find!\n");
		printf("Do you want again?\n(y\\n)\n");
		scanf("%c",&choose);
	}
}
Exemplo n.º 23
0
int main(int argc, char const *argv[]) {
	struct LinkList* list = create_list();

	append_list(list, 1);
	insert_list(list, 2, 0);
	push_list(list, 10);
	show_list(list);

	int data = pop_list(list);
	printf("pop data is %d\n", data);
	show_list(list);

	push_list(list, 10);
	push_list(list, 11);
	push_list(list, 10);
	push_list(list, 11);
	show_list(list);

	remove_list(list, 1);
	show_list(list);

	remove_data_list(list, 10);
	show_list(list);

	remove_all_data_list(list, 11);
	show_list(list);

	struct Node* node = get_node_list(list, 0);
	printf("data is %d\n", node->data);

	int index = search_list(list, 2);
	printf("index is %d\n", index);

	destory_list(list);
	return 0;
}
Exemplo n.º 24
0
int del_list(struct sockaddr_in ip)
{
	struct list_ips *prev = NULL;
	struct list_ips *del = NULL;

	printf("SERVER: starting del_list()\n");

	del = search_list(ip, &prev);

	if(del == NULL)
		return -1;
	else{
		if(prev != NULL)
			prev->next = del->next;

		if(del == cur)
			cur = prev;
		else if(del == head)
			head = del->next;
	}

	free(del);
	return 0;
}
Exemplo n.º 25
0
/*
 * We use a simple lookup table to simulate manual enrollment
 * of certs by the CA.  This is the case where an operator
 * needs to review each cert request and approve it (e.g.
 * auto-enrollment is off).
 *
 * Return 1 if a match was found and the enrollment operation
 * should proceed.  Return 0 if no match was found, in which
 * case we'll add the public key from the cert request into
 * our lookup table so it can be correlated later.
 *
 * Windows: Rewriting to forgo the use of search.h API
 * lookup table will be implemented as a basic linked list
 */
static int lookup_pkcs10_request(unsigned char *pkcs10, int p10_len)
{
    X509_REQ *req = NULL;
    BIO *in = NULL;
    BIO *out = NULL;
    BIO *b64;
    EVP_PKEY *pkey = NULL;
    BUF_MEM *bptr;
    int rv;
    LOOKUP_ENTRY *l;
    LOOKUP_ENTRY *n;

    /*
     * Decode the request into an X509_REQ structure
     */
    b64 = BIO_new(BIO_f_base64());
    in = BIO_new_mem_buf(pkcs10, p10_len);
    in = BIO_push(b64, in);
    if ((req = d2i_X509_REQ_bio(in, NULL)) == NULL) {
        /* Unable to parse the request, just let this fall through
         * and the enrollment will fail */
        rv = 1;
        goto DONE;
    }

    /*
     * Get the public key from the request, this will be our index into
     * the lookup table.  Frankly, I'm not sure how a real CA
     * would do this lookup.  But this should be good enough for
     * testing the retry-after logic.
     */
    pkey = X509_PUBKEY_get(req->req_info->pubkey);
    if (!pkey) {
        rv = 1;
        goto DONE;
    }
    out = BIO_new(BIO_s_mem());
    PEM_write_bio_PUBKEY(out, pkey);
    BIO_get_mem_ptr(out, &bptr);

    /*
     * see if we can find a match for this public key
     */
    n = malloc(sizeof(LOOKUP_ENTRY));
    n->data = malloc(bptr->length);
    n->length = bptr->length;
    memcpy(n->data, bptr->data, n->length);
    n->next = NULL;
    l = search_list(lookup_root, n);
    if (l) {
        /* We have a match, allow the enrollment */
        rv = 1;
        lookup_root = delete_lookup_entry(lookup_root, n);
        printf("\nRemoving key from lookup table:\n");
        dumpbin((char*)n->data, n->length);
        free(n->data);
        free(n);
    }
    else {
        /* Not a match, add it to the list and return */

        if (lookup_root == NULL) {
            /*
             * Initialize the list
             */
            lookup_root = n;
        }
        else {
            add_entry(lookup_root, n);
        }
        rv = 0;
        printf("\nAdding key to lookup table:\n");
        dumpbin((char*)n->data, n->length);
    }
    DONE:
    if (out)
        BIO_free_all(out);
    if (in)
        BIO_free_all(in);
    if (req)
        X509_REQ_free(req);
    if (pkey)
        EVP_PKEY_free(pkey);

    return (rv);
}
Exemplo n.º 26
0
void gui_SetWindowStyle(PA_PluginParameters params, BOOL isEx)
{
	LONG				StyleCurr = 0, StyleNew = 0, action = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG
	HWND				hWnd = NULL;
	HMENU				hSysMenu;
	pLL					thisLink = NULL, previousLink = NULL;
	LONG				hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG

	hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal handle array
	action = PA_GetLongParameter(params, 2);

	if (isEx){ // WJF 9/16/15 #43731
		hWnd = handleArray_retrieve((DWORD)hWndIndex);
	}
	else {
		hWnd = (HWND)hWndIndex;
	}

	if (IsWindow(hWnd)) {
		StyleCurr = GetWindowLong(hWnd, GWL_STYLE);
		StyleNew = StyleCurr;

		if (0 != (action & RW_DISABLE_MIN)){
			StyleNew = StyleNew & ~WS_MINIMIZEBOX;
		}

		if (0 != (action & RW_ENABLE_MIN)){
			StyleNew = StyleNew | WS_MINIMIZEBOX;
		}

		if (0 != (action & RW_DISABLE_MAX)){
			StyleNew = StyleNew & ~WS_MAXIMIZEBOX;
		}

		if (0 != (action & RW_ENABLE_MAX)){
			StyleNew = StyleNew | WS_MAXIMIZEBOX;
		}

		if (0 != (action & RW_DISABLE_CLOSE)){
			hSysMenu = GetSystemMenu(hWnd, 0);
			if (hSysMenu != NULL) {
				EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
			}
		}

		if (0 != (action & RW_ENABLE_CLOSE)){
			hSysMenu = GetSystemMenu(hWnd, 0);
			if (hSysMenu != NULL) {
				EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
			}
		}

		if (0 != (action & RW_DISABLE_RESIZE)){
			// subClass procedure must be in place
			if (processHandles.wpProToolsOrigProc == NULL) {
				PA_ReturnLong(params, -2);
				return;
			}

			if (startOfList == NULL) {
				init_list(&startOfList);
			}

			// insert item in linked list -- if not already there
			if (!search_list(&startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd)) {
				thisLink = (pLL)insert_list(&startOfList);
				if (thisLink == NULL) {
					PA_ReturnLong(params, -2);
					return;
				}
				else {
					thisLink->hWnd = hWnd;
					thisLink->dataLong1 = RW_NO_SIZE; // sub proc uses other number
					thisLink->type = LL_Restrict;
					thisLink->wpProc = processHandles.wpProToolsOrigProc;
				}
			}
		}

		if (0 != (action & RW_ENABLE_RESIZE)){
			// no subclass or no list head, we're done
			if ((NULL != processHandles.wpProToolsOrigProc) && (NULL != startOfList)) {
				delete_list(&startOfList, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd);
			}
		}

		if (StyleNew != StyleCurr){
			if (0 == SetWindowLong(hWnd, GWL_STYLE, StyleNew)){
				PA_ReturnLong(params, -2);
				return;
			}
			else {
				// notify windows we changed the style
				SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
			}
		}
	}
	// when we end up here all is oke
	PA_ReturnLong(params, 0);
}
Exemplo n.º 27
0
LRESULT APIENTRY ProToolsProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	LONG_PTR			action = 0, command = 0, hitArea = 0;
	pLL					currentLink, prevLink;
	RECT				rect, clientRect, workingAreaRect;
	LONG				x = 0, y = 0, xFrame, yFrame; // WJF 6/30/16 Win-21 LONG_PTR -> LONG
	LONG				mnuItemCount, i; // WJF 6/30/16 Win-21 LONG_PTR -> LONG
	HMENU				hMenu;
	BOOL				bFuncReturn;
	LPMINMAXINFO		lpmmi; //01/18/03
	static LONG_PTR			InCommand = 0; // 01/18/03
	POINT				pt; // 01/19/03
	LPWINDOWPOS			lpwp;
	LPNCCALCSIZE_PARAMS	lpcalcsize;
	static HWND			currentChildMaxed = NULL, prevChildMaxed = NULL;
	//char*				minimizedWindows[32];
	char				title[128];
	INT					n = 0, err = 0; // WJF 6/30/16 Win-21 INT_PTR -> INT
	INT					minimizedPerRow; // REB 8/11/08 #16207 // WJF 6/30/16 Win-21 INT_PTR -> INT

	currentLink = NULL;
	prevLink = NULL;

	if (toolBarRestrictions.toolBarOnDeck == 1) { // 01/17/03
		xFrame = GetSystemMetrics(SM_CXSIZEFRAME);
		yFrame = GetSystemMetrics(SM_CYSIZEFRAME);
		// REB 8/11/08 #16207
		minimizedPerRow = ((GetSystemMetrics(SM_CXVIRTUALSCREEN) - (toolBarRestrictions.clientOffsetx + toolBarRestrictions.left + toolBarRestrictions.right)) / GetSystemMetrics(SM_CXMINSPACING));
		//err = GetWindowText(hwnd, title , 128); //**DEBUG**
		switch (uMsg)
		{
		case WM_SYSCOMMAND: //this tells a subsequent WM_GETMINMAXINFO command
			// that it is okay to proceed if we are in the process of a maximize command.
			command = wParam & 0xFFF0;
			if (SC_MAXIMIZE == command) {
				InCommand = IN_SYSCOMMAND_MAX;
				GetWindowRect(hwnd, &toolBarRestrictions.origWindowRect);
				GetWindowRect(windowHandles.MDIhWnd, &rect);
				toolBarRestrictions.clientOffsetx = rect.left;
				toolBarRestrictions.clientOffsety = rect.top;
				currentChildMaxed = hwnd;
				if (IsZoomed(hwnd) == 0){ // REB 8/11/08 #16207
					//minimizePositions[toolBarRestrictions.numMinimized] = 0;
					err = GetWindowText(hwnd, title, 128);
					for (n = 0; n < SMLBUF; n++) {
						if (strcmp(toolBarRestrictions.minimizedWindows[n], title) == 0){
							strcpy(toolBarRestrictions.minimizedWindows[n], "");
							//break;
						}
					}
				}
			}
			// REB 8/11/08 #16207
			if (SC_MINIMIZE == command) {
				InCommand = IN_SYSCOMMAND_MIN;
				GetWindowRect(hwnd, &toolBarRestrictions.origWindowRect);
				GetWindowRect(windowHandles.MDIhWnd, &rect);

				//Debug
				//GetWindowRect(windowHandles.MDIs_4DhWnd, &rect);
				//GetWindowRect(windowHandles.fourDhWnd, &rect);
				//End Debug

				toolBarRestrictions.clientOffsetx = rect.left;
				toolBarRestrictions.clientOffsety = rect.top;
			}

			if (SC_RESTORE == command) { //|| (toolBarRestrictions.appBeingMaxed > 0)) {
				InCommand = IN_SYSCOMMAND_RESTORE;
				if (IsZoomed(hwnd) != 0){ // REB 8/11/08 #16207 Only clear these if we are restoring a window that was already maximized.
					currentChildMaxed = NULL;
					// REB 3/26/10 #22878 Move the previous window back.
					MoveWindow(prevChildMaxed, toolBarRestrictions.previousWindowRect.left, toolBarRestrictions.previousWindowRect.top, (toolBarRestrictions.previousWindowRect.right - toolBarRestrictions.previousWindowRect.left), (toolBarRestrictions.previousWindowRect.bottom - toolBarRestrictions.previousWindowRect.top), 1);
					prevChildMaxed = NULL;
				}
				else{
					err = GetWindowText(hwnd, title, 128);
					for (n = 0; n < SMLBUF; n++) {
						if (strcmp(toolBarRestrictions.minimizedWindows[n], title) == 0){
							strcpy(toolBarRestrictions.minimizedWindows[n], "");
							//break;
						}
					}
				}
				toolBarRestrictions.appBeingMaxed = 0;
			}
			//if (SC_NEXTWINDOW == command) {
			//toolBarRestrictions.appBeingMaxed = XCHANGING_MAX_WINDOWS;
			//}

			if (SC_CLOSE == command) {
				if (IsZoomed(hwnd) == 0){ // REB 8/11/08 #16207
					err = GetWindowText(hwnd, title, 128);
					for (n = 0; n < SMLBUF; n++) {
						if (strcmp(toolBarRestrictions.minimizedWindows[n], title) == 0){
							strcpy(toolBarRestrictions.minimizedWindows[n], "");
							//break;
						}
					}
				}
				break;
			};

			break;

		case WM_WINDOWPOSCHANGING:

			lpwp = (LPWINDOWPOS)lParam;

			GetWindowRect(windowHandles.MDIhWnd, &rect);

			if ((InCommand == IN_SYSCOMMAND_MAX) && (toolBarRestrictions.appWindowState == APP_MAXIMIZED)) {
				lpwp->x = lpwp->x - toolBarRestrictions.clientOffsetx - toolBarRestrictions.left;
				lpwp->y = lpwp->y - toolBarRestrictions.clientOffsety - toolBarRestrictions.top - yFrame;
				lpwp->cx = toolBarRestrictions.origWindowRect.right - toolBarRestrictions.origWindowRect.left;
				lpwp->cy = toolBarRestrictions.origWindowRect.bottom - toolBarRestrictions.origWindowRect.top;
				return 0;
			}
			// REB 8/11/08 #16207
			if ((InCommand == IN_SYSCOMMAND_MIN)){  // Minimizing the windows
				err = GetWindowText(hwnd, title, 128);
				for (n = 0; n < SMLBUF; n++) {
					if ((strcmp(toolBarRestrictions.minimizedWindows[n], "") == 0) || (strcmp(toolBarRestrictions.minimizedWindows[n], title) == 0)){
						strcpy(toolBarRestrictions.minimizedWindows[n], title);
						break;
					}
				}

				lpwp->x = toolBarRestrictions.clientOffsetx + toolBarRestrictions.left + ((n % minimizedPerRow)  * GetSystemMetrics(SM_CXMINSPACING));

				SystemParametersInfo(SPI_GETWORKAREA, 0, &workingAreaRect, 0);
				lpwp->y = workingAreaRect.bottom - yFrame - toolBarRestrictions.clientOffsety - toolBarRestrictions.bottom - (((n / (minimizedPerRow)) + 1) * GetSystemMetrics(SM_CYMINSPACING));

				return 0;
			}

			if ((toolBarRestrictions.appBeingMaxed == APP_MAXIMIZING) ||
				(toolBarRestrictions.appBeingMaxed == APP_RESTORING) ||
				(toolBarRestrictions.appBeingMaxed == APP_SIZING_W_CHLDMAX)) {
				lpwp->x = toolBarRestrictions.left - xFrame;
				lpwp->y = toolBarRestrictions.top - yFrame;
				lpwp->cx = rect.right - rect.left + (2 * xFrame) - toolBarRestrictions.left - toolBarRestrictions.right;
				lpwp->cy = rect.bottom - rect.top + (2 * yFrame) - toolBarRestrictions.top - toolBarRestrictions.bottom;
				return 0;
			}

			if (currentChildMaxed == hwnd) { //(toolBarRestrictions.appBeingMaxed == (LONG_PTR)hwnd) {
				lpwp->x = toolBarRestrictions.left - xFrame;
				lpwp->y = toolBarRestrictions.top - yFrame;
				lpwp->cx = rect.right - rect.left + (2 * xFrame) - toolBarRestrictions.left - toolBarRestrictions.right;
				lpwp->cy = rect.bottom - rect.top + (2 * yFrame) - toolBarRestrictions.top - toolBarRestrictions.bottom;
				return 0;
			}

			if (toolBarRestrictions.top > 0){  // AMS 8/29/14 #39693 If its a top toolbar, prevent windows from being able to be placed behind the toolbar NOTE: This fix does not work in Windows versions 8 or newer
				if (lpwp->y < toolBarRestrictions.top){
					lpwp->y = toolBarRestrictions.top - 1;
				}
			}
			break;

		case WM_GETMINMAXINFO:
			if ((InCommand == IN_SYSCOMMAND_MAX) || (toolBarRestrictions.appBeingMaxed > 0) ||
				(currentChildMaxed == hwnd)) {
				lpmmi = (LPMINMAXINFO)lParam;

				lpmmi->ptMaxSize.x = lpmmi->ptMaxSize.x - toolBarRestrictions.left - toolBarRestrictions.right;
				lpmmi->ptMaxSize.y = lpmmi->ptMaxSize.y - toolBarRestrictions.top - toolBarRestrictions.bottom;
				lpmmi->ptMaxPosition.x = -xFrame + toolBarRestrictions.left; // maxPosition x&y seem to be static values -- hmmm!
				lpmmi->ptMaxPosition.y = -yFrame + toolBarRestrictions.top;
				lpmmi->ptMaxTrackSize.x = lpmmi->ptMaxTrackSize.x - toolBarRestrictions.left - toolBarRestrictions.right;
				lpmmi->ptMaxTrackSize.y = lpmmi->ptMaxTrackSize.y - toolBarRestrictions.top - toolBarRestrictions.bottom;

				return 0; // return 0 telling OS that we have processed this command
			} // end if
			break;

		case WM_NCCALCSIZE:
			if (((currentChildMaxed != NULL) || (prevChildMaxed != NULL)) && ((BOOL)wParam == TRUE)) {
				lpcalcsize = (LPNCCALCSIZE_PARAMS)lParam;
				lpwp = lpcalcsize->lppos;
				rect = lpcalcsize->rgrc[0];
				clientRect = lpcalcsize->rgrc[1];
				toolBarRestrictions.appBeingMaxed = 0; //new
			}
			break;

		case WM_NCACTIVATE:
			if ((currentChildMaxed != NULL) && (currentChildMaxed != hwnd)) {
				//bFuncReturn = IsZoomed(currentChildMaxed);
				// REB 3/26/10 #22878 Here we need to capture the size of the newly activated window before it's resized to the max.
				// This window will become the new original window and we'll save the previous window position to be resized later.
				if (wParam){
					toolBarRestrictions.previousWindowRect = toolBarRestrictions.origWindowRect;
					GetWindowRect(hwnd, &toolBarRestrictions.origWindowRect);
					prevChildMaxed = currentChildMaxed;
					currentChildMaxed = hwnd;
				}
				toolBarRestrictions.appBeingMaxed = (LONG_PTR)currentChildMaxed; //was XCHANGING_MAX_WINDOWS
			}
			break;

		case WM_SETFOCUS: // msg received by window getting focus
			//if (prevChildMaxed == (HWND)wParam) {
			//use the following in lieu of XCHANGING.. to restore all on window change
			//SendMessage((HWND)wParam, WM_SYSCOMMAND, SC_RESTORE, 0L);
			//use this to keep maxed window when using CRTL-TAB.  But 4D has an ugy bug in window
			//  resize when called from a menu (Bring to Front).
			//toolBarRestrictions.appBeingMaxed = XCHANGING_MAX_WINDOWS;
			break;

		case WM_SIZE:
			if (toolBarRestrictions.appBeingMaxed != APP_SIZING_W_CHLDMAX) {
				toolBarRestrictions.appBeingMaxed = 0;
			}
			InCommand = 0;
			break;

		case WM_SIZING:
		case WM_MOVING: // restrict sizing or moving to prevent
			GetClientRect(windowHandles.MDIhWnd, &clientRect);
			//clientRect.right contains width of client area
			//clientRect.bottom contains height of client area
			//convert this rect to screen coordinates for comparison to movingRect
			pt.x = clientRect.left;
			pt.y = clientRect.top;
			ClientToScreen(windowHandles.MDIhWnd, &pt);
			clientRect.left = pt.x;
			clientRect.top = pt.y;
			pt.x = clientRect.right;
			pt.y = clientRect.bottom;
			ClientToScreen(windowHandles.MDIhWnd, &pt);
			clientRect.right = pt.x;
			clientRect.bottom = pt.y;

			clientRect.left += toolBarRestrictions.left;
			if (toolBarRestrictions.trackingRestriction == 0) {
				clientRect.top += toolBarRestrictions.top;
			}
			else {
				clientRect.top += toolBarRestrictions.trackingRestriction;
			}
			clientRect.right -= toolBarRestrictions.right;
			clientRect.bottom -= toolBarRestrictions.bottom;
			ClipCursor(&clientRect);
			break;

		case WM_EXITSIZEMOVE:
			rect.left = 0;
			rect.top = 0;
			rect.right = GetSystemMetrics(SM_CXVIRTUALSCREEN);// REB 6/6/08 #16838 (Fix Provided by Keith White)
			rect.bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN);// REB 6/6/08 #16838 (Fix Provided by Keith White)
			ClipCursor(&rect);
			break;
		default:
			if ((uMsg != WM_ERASEBKGND) && (uMsg != WM_NCPAINT) && (uMsg != WM_PAINT) && (uMsg != WM_IME_SETCONTEXT) && (uMsg != WM_IME_NOTIFY) && (uMsg != WM_SETFOCUS) && (uMsg != WM_NCACTIVATE) && (uMsg != WM_KILLFOCUS) && (uMsg != WM_GETTEXT)){
				break;
			};
		} // end switch (uMsg)
	} // end if (toolBarRestrictions.toolBarOnDeck == 1)

	if (startOfList != NULL) {
		if ((uMsg == WM_SYSCOMMAND) || (uMsg == WM_NCHITTEST) || (uMsg == WM_INITMENU)) {
			if (search_list(&startOfList, &currentLink, &prevLink, LL_hWnd, LL_Restrict, (LONG_PTR *)&hwnd)) {
				action = (LONG)currentLink->dataLong1; // WJF 6/30/16 Win-21 Cast to LONG

				switch (uMsg)
				{
				case (WM_SYSCOMMAND) :
					command = wParam & 0xFFF0;
					switch (command)
					{
					case (SC_SIZE) :
						if (RW_NO_SIZE == (action & RW_NO_SIZE)) {
							wParam = 0x000F;
						}
						break;

					case (SC_MOVE) :
						if (RW_NO_MOVE == (action & RW_NO_MOVE)) {
							wParam = 0x000F;
						}
						break;

					case (SC_MINIMIZE) :
						if (RW_NO_MIN == (action & RW_NO_MIN)) {
							wParam = 0x000F;
						}
						break;

					case (SC_MAXIMIZE) :
						if (RW_NO_MAX == (action & RW_NO_MAX)) {
							wParam = 0x000F;
						}
						break;
					}  // end switch

					break;

				case (WM_NCHITTEST) :
					if (RW_NO_SIZE == (action & RW_NO_SIZE)) {
						hitArea = DefWindowProc(hwnd, uMsg, wParam, lParam);
						if ((hitArea >= HTLEFT) && (hitArea <= HTBOTTOMRIGHT)) {
							uMsg = HTNOWHERE;
						}
						else {
							// test for coordinates of lower right
							GetWindowRect(hwnd, &rect);
							x = LOWORD(lParam);
							y = HIWORD(lParam);
							if ((x <= rect.right) && (x >= (rect.right - 25)) &&
								(y <= rect.bottom) && (y >= (rect.bottom - 25))) {
								uMsg = HTNOWHERE;
							}
						}
					}
					break;

				case (WM_INITMENU) :

					hMenu = GetSystemMenu(hwnd, FALSE);

					if (RW_NO_SIZE == (action & RW_NO_SIZE)) {
						bFuncReturn = EnableMenuItem(hMenu, SC_SIZE, MF_BYCOMMAND | MF_GRAYED);
					}
					if (RW_NO_MOVE == (action & RW_NO_MOVE)) {
						bFuncReturn = EnableMenuItem(hMenu, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
					}
					if (RW_NO_MIN == (action & RW_NO_MIN)) {
						bFuncReturn = EnableMenuItem(hMenu, SC_MINIMIZE, MF_BYCOMMAND | MF_GRAYED);
					}
					if (RW_NO_MAX == (action & RW_NO_MAX)) {
						bFuncReturn = EnableMenuItem(hMenu, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
					}
					if (RW_NO_NEXT == (action & RW_NO_NEXT)) {
						mnuItemCount = GetMenuItemCount(hMenu);
						for (i = (mnuItemCount - 1); i >= 0; i--)
						{
							if (GetMenuItemID(hMenu, i) == SC_NEXTWINDOW) {
								bFuncReturn = DeleteMenu(hMenu, SC_NEXTWINDOW, MF_BYCOMMAND);
								// is next higher menu item a separator line?
								if (GetMenuItemID(hMenu, i - 1) == 0) {
									bFuncReturn = DeleteMenu(hMenu, i - 1, MF_BYPOSITION);
								}
							}
							else if (GetMenuItemID(hMenu, i) == SC_PREVWINDOW) {
								bFuncReturn = DeleteMenu(hMenu, SC_PREVWINDOW, MF_BYCOMMAND);
								// is next higher menu item a separator line?
								if (GetMenuItemID(hMenu, i - 1) == 0) {
									bFuncReturn = DeleteMenu(hMenu, i - 1, MF_BYPOSITION);
								}
							}
						}
					} // end if (RW_NO_NEXT == (action & RW_NO_NEXT))

					break;

				case (WM_DESTROY) :
					delete_list(&startOfList, LL_hWnd, LL_Restrict, (LONG_PTR *)&hwnd);
					break;
				} // end switch (uMsg)
			} // end if (search_list( &startOfList, &currentLink, &prevLink, LL_hWnd, LL_Restrict, (LONG_PTR *) &hwnd))
		} // end if ((uMsg == WM_SYSCOMMAND) || (uMsg == WM_NCHITTEST) || (uMsg == WM_INITMENU))
	} // end if (startOfList != NULL)

	return CallWindowProc(processHandles.wpProToolsOrigProc, hwnd, uMsg, wParam, lParam);
}
Exemplo n.º 28
0
void gui_RestrictWindow(PA_PluginParameters params, BOOL isEx)
{
	LONG				action = 0, returnValue = 0, styleChg = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG
	HWND				hWnd = NULL;
	HMENU				hSysMenu;
	pLL					thisLink = NULL, previousLink = NULL;
	LONG				hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG

	// subClass procedure must be in place
	if (processHandles.wpProToolsOrigProc == NULL) {
		PA_ReturnLong(params, -2);
		return;
	}

	hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal array
	action = PA_GetLongParameter(params, 2);

	if (isEx){ // WJF 9/16/15 #43731
		hWnd = handleArray_retrieve((DWORD)hWndIndex);
	}
	else {
		hWnd = (HWND)hWndIndex;
	}

	if (IsWindow(hWnd)) {  // 09/09/02 more action values now so removed restriction
		returnValue = GetWindowLong(hWnd, GWL_STYLE);

		// eliminate sizing cursor and Window's sizing border
		switch (action)
		{
		case (RW_NO_MIN) :
			if ((returnValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) {
				styleChg = returnValue ^ WS_MINIMIZEBOX;
				returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg);
			}
			break;

		case (RW_NO_MAX) :
			if ((returnValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) {
				styleChg = returnValue ^ WS_MAXIMIZEBOX;
				returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg);
			}
			break;

		case (RW_NO_CLOSE) :
			hSysMenu = GetSystemMenu(hWnd, 0);
			if (hSysMenu != NULL) {
				EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
			}
			break;

		case (RW_RESTORE_CLOSE) :
			hSysMenu = GetSystemMenu(hWnd, 0);
			if (hSysMenu != NULL) {
				EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
			}
			break;
		}

		if (startOfList == NULL) {
			init_list(&startOfList);
		}
		// insert item in linked list -- if not already there
		if (!search_list(&startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd)) {
			thisLink = (pLL)insert_list(&startOfList);
			if (thisLink == NULL) {
				PA_ReturnLong(params, -1); // could not add to list - get out
				return;
			}
		}
		else {
			PA_ReturnLong(params, (LONG)hWnd); // return window handle if already in list // WJF 6/30/16 Win-21 Changed cast from LONG_PTR -> LONG
			return;
		}

		thisLink->hWnd = hWnd;
		thisLink->dataLong1 = action;
		thisLink->type = LL_Restrict;
		thisLink->wpProc = processHandles.wpProToolsOrigProc;
		returnValue = length_list(startOfList);
	}

	PA_ReturnLong(params, returnValue);
}
Exemplo n.º 29
0
/*
 * 实现不分类型查找 单链表
 * 这个函数 传递一个链表root指针 value 和一个函数 变可以实现 不分类型查找
 * compare函数写的时候 要符合一定的规范
 */
Node *search_list(Node *node, void const *value,
                  int (*compare)(void const *, void const *))
{
    while(node != NULL) {
        if( compare(&node->value, value)==0)
            break;
        node = node -> link;
    }
    return node;
}
/*
 * 写一个compare函数做例子      这个实现了查找整形的数
 */
int compare_ints(void const *a, void const *b)
{
    if( *(int *)a == *(int *)b)     //这里要强制类型转换
        return 0;
    else
        return 1;
}

//使用这两个函数:
desired_node = search_list(root ,&desired_value,
                           compare_ints);

Exemplo n.º 30
0
int 
main(int argc, char **argv)
{
	FILE *fp;
	char buf[MAX_LINE];
	int count=0;
	int serv_port;
	int max_sending_window_size;
	const int on=1;
	struct socket_descripts sock_desc[10];
	int sock_count = 0;
	struct ifi_info *ifi, *ifihead;
	int sockfd;
	struct sockaddr_in *sa;
	int i = 0;
	fp=fopen("server.in","r");

	if(fp == NULL)
	{
		printf("ERROR MSG: No server.in file!\n");
		exit(1);
	}

	while(fgets(buf, MAX_LINE -1, fp) != NULL)
	{
		if(count == 0)
			serv_port = atoi(buf);
		else if(count == 1)
			max_sending_window_size = atoi(buf);
		count++;
	}
	fclose(fp);

	for (ifihead = ifi = Get_ifi_info_plus( AF_INET, 1);
                ifi != NULL; 
		ifi = ifi->ifi_next) {

		/* bind unicast adress */
		sockfd = Socket(AF_INET, SOCK_DGRAM, 0);
		Setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,&on, sizeof(on));

		sa = (struct sockaddr_in *) ifi->ifi_addr;
		sa->sin_family = AF_INET;
		sa->sin_port = htons(serv_port);

		Bind(sockfd, (SA *) sa, sizeof(*sa));

		sock_desc[sock_count].sockfd = sockfd;
		sock_desc[sock_count].ip_addr = sa;
		sock_desc[sock_count].net_mask = (struct sockaddr_in *)ifi->ifi_ntmaddr;

		//printf("SERVER: sockdesc[%d]\n", sock_count);
		printf("SERVER: IP: %s\n", Sock_ntop_host(sock_desc[sock_count].ip_addr, sizeof(struct in_addr)));
		printf("SERVER: Network mask: %s\n", Sock_ntop_host(sock_desc[sock_count].net_mask, sizeof(struct in_addr)));
		//printf("SERVER: sockdesc[%d]\n", sock_count); 
		sock_count++;
	}
	
	int maxfd;
	fd_set rset;
	int nready;
	int len;
	char recvline[MAXLINE];	
	struct sockaddr_in cliaddr, child_server_addr, server_addr, sock_store;
	
	int n;
	int server_len;
	char IPserver[MAXLINE];
	int pid;
	socklen_t serv_len, store_len;
	struct list_ips* r = NULL;

	maxfd=sock_desc[0].sockfd;
	for(i=0;i < sock_count; i++)
	{
		if(maxfd < sock_desc[i].sockfd)
			maxfd = sock_desc[i].sockfd;
	}

	for( ; ; )
	{
		FD_ZERO(&rset);
		for(i = 0; i < sock_count; i++)
			FD_SET(sock_desc[i].sockfd, &rset);

		//printf("SERVER: waiting using select()\n");
		
		if( (nready=select(maxfd+1, &rset, NULL, NULL, NULL)) < 0 )
		{
			if (errno == EINTR){
				continue;
			}else{
				printf("ERROR MSG: server select error\n");
				exit(0);
			}
		}


		
		for(i=0; i < sock_count; i++)
		{
			if(FD_ISSET(sock_desc[i].sockfd, &rset))
			{
				char filename[MAXLINE];
				int client_window_size;
				len = sizeof(cliaddr);
				
				//printf("SERVER: before revefrom func()\n");	
				n = recvfrom(sock_desc[i].sockfd, recvline, MAXLINE, 0, (SA *) &cliaddr, &len);
				sscanf(recvline, "%s %d", filename, &client_window_size);
				//printf("%s %d\n", filename, client_window_size);
				//printf("SERVER: first message is recevied: %s\n", recvline);
				
				r = search_list(cliaddr, NULL);
				if( r != NULL)
					continue;

				server_len = sizeof(server_addr);	
				if( getsockname( sock_desc[ i ].sockfd, (SA *)&server_addr, &server_len ) < 0 )
				{
					printf( "SERVER: getsockname error\n" );
					exit(1);
				}      
				inet_ntop( AF_INET, &(server_addr.sin_addr), IPserver, MAXLINE);
				//printf("SERVER: IPserver after receving filename: %s\n", IPserver);

				
				inet_pton( AF_INET, IPserver, &child_server_addr.sin_addr );	
				child_server_addr.sin_family = AF_INET;
				child_server_addr.sin_port = htonl(0);
			
				add_list(cliaddr);

				if ( (pid = fork() ) == 0)
				{
					int j;
					for(j=0; j < sock_count; j++)
					{
						if(i!=j)
							close(sock_desc[j].sockfd);
					}
					//printf("%d %d\n", max_sending_window_size, client_window_size);
					max_sending_window_size = min(max_sending_window_size, client_window_size);
					handshake(sock_desc[i].sockfd,&child_server_addr, sizeof(child_server_addr), &cliaddr, sizeof(cliaddr),  filename, max_sending_window_size );
					del_list(cliaddr);
					exit(0);
				}
			}
		}
	}
}