Ejemplo n.º 1
0
Archivo: section.c Proyecto: jdG-/nm
void		sec_64(int ncmds, struct load_command *lc, t_lst **section)
{
	unsigned int				j;
	int							k;
	struct section_64			*sec;
	struct segment_command_64	*seg;

	*section = NULL;
	k = 1;
	while (ncmds >= 0)
	{
		if (lc->cmd == LC_SEGMENT_64)
		{
			j = -1;
			seg = (struct segment_command_64*)lc;
			sec = (struct section_64*)((void *)seg + sizeof(*seg));
			while (++j < seg->nsects)
			{
				add_lst(section, new_lst_sec(sec->sectname, k++));
				sec = (void *)sec + sizeof(*sec);
			}
		}
		if (ft_strcmp(seg->segname, SEG_OBJC) == 0)
			break ;
		lc = lc->cmdsize + (void*)lc;
		ncmds--;
	}
}
Ejemplo n.º 2
0
Archivo: section.c Proyecto: jdG-/nm
void		sec_32_cigam(int ncmds, struct load_command *lc, t_lst **section)
{
	unsigned int				j;
	int							k;
	struct section				*sec;
	struct segment_command		*seg;

	*section = NULL;
	k = 1;
	while (ncmds >= 0)
	{
		if (lc->cmd && swap_uint32(lc->cmd) == LC_SEGMENT)
		{
			j = -1;
			seg = (struct segment_command*)lc;
			sec = (struct section*)((void *)seg + sizeof(*seg));
			while (++j < swap_uint32(seg->nsects))
			{
				add_lst(section, new_lst_sec(sec->sectname, k++));
				sec = (void *)sec + sizeof(*sec);
			}
		}
		if (ft_strcmp(seg->segname, SEG_OBJC) == 0)
			break ;
		lc = swap_uint32(lc->cmdsize) + (void*)lc;
		ncmds--;
	}
}
Ejemplo n.º 3
0
static void *coalesce(void *ptr)
{
    size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(ptr)));
    size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(ptr)));
    size_t size = GET_SIZE(HDRP(ptr));

    if (prev_alloc && next_alloc) {                 /* Case 1 */
        printf("Go into case 1\n");
        add_lst(ptr);
        return ptr;
    }

    else if (prev_alloc && !next_alloc) {           /* Case 2 */
        size += GET_SIZE(HDRP(NEXT_BLKP(ptr)));
        printf("Go into case 2\n");
        remove_lst(NEXT_BLKP(ptr));
        PUT(HDRP(ptr), PACK(size, 0));
        PUT(FTRP(ptr), PACK(size,0));
        add_lst(ptr);
    }

    else if (!prev_alloc && next_alloc) {           /* Case 3 */
        printf("Go into case 3\n");
        size += GET_SIZE(HDRP(PREV_BLKP(ptr)));
        PUT(FTRP(ptr), PACK(size, 0));
        PUT(HDRP(PREV_BLKP(ptr)), PACK(size, 0));
        ptr = PREV_BLKP(ptr);
        remove_lst(ptr);
        add_lst(ptr);
    }

    else {                                          /* Case 4 */
        printf("Go into case 4\n");
        size += GET_SIZE(HDRP(PREV_BLKP(ptr))) +
        GET_SIZE(FTRP(NEXT_BLKP(ptr)));
        remove_lst(NEXT_BLKP(ptr));
        PUT(HDRP(PREV_BLKP(ptr)), PACK(size, 0));
        PUT(FTRP(NEXT_BLKP(ptr)), PACK(size, 0));
        ptr = PREV_BLKP(ptr);
        remove_lst(ptr);
        add_lst(ptr);
    }
    return ptr;
}
Ejemplo n.º 4
0
static t_list	*init_lst(void)
{
	t_list	*lst;

	lst = NULL;
	add_lst(&lst, LINEMATE, "linemate");
	add_lst(&lst, DERAUMERE, "deraumere");
	add_lst(&lst, SIBUR, "sibur");
	add_lst(&lst, MENDIANE, "mendiane");
	add_lst(&lst, PHIRAS, "phiras");
	add_lst(&lst, THYSTAME, "thystame");
	add_lst(&lst, FOOD, "nourriture");
	add_lst(&lst, EGG, "oeuf");
	add_lst(&lst, PLAYER, "joueur");
	return (lst);
}
int cache_insert( struct file_data *data)
{
	int hash = hash_func(8192,data->file_name);
	struct hash_node *curr;
	curr = cache[hash];
	if(curr->flag ==0){
		cache_current_size=cache_current_size+data->file_size;
		curr->data->file_name = Malloc(MAXLINE);
		strncpy(curr->data->file_name, data->file_name,MAXLINE);
		curr->data->file_buf = Malloc(data->file_size);
		strncpy(curr->data->file_buf, data->file_buf,data->file_size);
		curr->data->file_size = data->file_size;
		curr->flag =1;
		curr->next=NULL;

	}

	else{
	while(curr){
		if(curr->flag == 1){
			if(strcmp(curr->data->file_name,data->file_name)==0){
				return 0; // do nothing
			}
			if(curr->next==NULL)	
				break;
			curr=curr->next;
		}
		else if(curr->flag == 2){	// it has been deleted
			if(curr->next == NULL)
				break;
			curr= curr->next;
		}

	}	
		cache_current_size=cache_current_size+data->file_size;
		struct hash_node* temp = (struct hash_node *)malloc(sizeof(struct hash_node));
		temp->data = malloc(sizeof(struct file_data));
		temp->data->file_name = Malloc(MAXLINE);
		strncpy(temp->data->file_name,data->file_name,MAXLINE);
		temp->data->file_buf = Malloc(data->file_size);
		strncpy(temp->data->file_buf, data->file_buf,data->file_size);
		temp->data->file_size = data->file_size;
		temp->flag =1;
		temp->next = NULL;
		curr->next =temp;
	}

	LST_queue = add_lst(LST_queue,data);

	return 0;
}
Ejemplo n.º 6
0
Archivo: test.c Proyecto: Zebu78/perso
t_calendar	*update_calendar(char *buffer, jsmntok_t	tokens[MAX_TOK])
{
	char 		*tmp_s = malloc(4096);
	char 		*tmp_e = malloc(4096);
	char		*result = malloc(4096);
	t_calendar	*lst = NULL;
	int 		i = 0;

	memcpy(result, buffer + (int)tokens[i].start, (int)tokens[i].end - (int)tokens[i].start);
	result[(int)tokens[i].end - (int)tokens[i].start] = '\0';
	while (strcmp(result, "Building") && i < MAX_TOK)
	{
		memcpy(result, buffer + (int)tokens[i].start, (int)tokens[i].end - (int)tokens[i].start);
		result[(int)tokens[i].end - (int)tokens[i].start] = '\0';
		if (!strcmp(result, "End"))
		{
			sprintf(tmp_e, "%.19s", buffer + tokens[i - 1].start + 8);
			sprintf(tmp_s, "%.19s", buffer + tokens[i - 1].start + 66);
			lst = add_lst(lst, tmp_s, tmp_e);
		}
		i++;
	}
	return (lst);
}