Esempio n. 1
0
static t_block		*split_block(t_block *block, size_t size)
{
	t_block				*next_block;

	ft_printf("split_block\tblock_size: %d\trequest_size: %d\n", block->size, size);
	if (block->size == size)
	{
		block->free = false;

		ft_printf(C_RED"\tReturned splitless ptr: %p\tsize of block = %8d\n"C_RESET, block, block->size);
		
		return (block);
	}
	next_block = (void *)(block + 1) + size;
	*next_block = (t_block){DLST_HEAD_NULL,
		block->size - (size + META_SIZE), true};
	dlst_add_head(&next_block->block_node, &block->block_node);
	block->size = size;
	block->free = false;

	ft_printf(C_CYAN"\tNext block adress: %p is_free: %d size of block = %8d\n"C_RESET, next_block, next_block->free, next_block->size);
	ft_printf(C_RED"\tReturned ptr: %p\tsize of block = %8d\n"C_RESET, block, block->size);
	return (block);
}
Esempio n. 2
0
int			get_path(t_rooms *end, t_rooms *start)
{
	t_open		*open_list;
	t_close		*close_list;

	open_list = init_open(end);
	close_list = NULL;
	algo_path(start, open_list, close_list);
	if (start->weight == INT_MAX)
	{
		ft_printf("ERROR\n");
		exit(0);
	}
	return (1);
}
Esempio n. 3
0
void	lst_print_b(t_list *list)
{
	t_list		*current;

	if (!list)
		return ;
	current = list;
	while (current)
		current = current->next;
	while (current)
	{
		ft_printf("%s\n", current->content);
		current = current->prev;
	}
}
Esempio n. 4
0
int		main(void)
{
	int		nb;
	char	ca;
	char	*str;

	nb = 2;
	(void)ca;
	(void)str;
	ft_putnbr(ft_printf("%10s is a string\n", ""));
	ft_putchar('\n');
	ft_putnbr(printf("%10s is a string\n", ""));
	ft_putchar('\n');
/*
    ft_printf("%.0s is a string\n", "this");
	printf("%.0s is a string\n", "this");

    ft_printf("%5.2s is a string\n", "this");
	printf("%5.2s is a string\n", "this");

    ft_printf("%10s is a string\n", "");
	printf("%10s is a string\n", "");
	//d
	ft_putnbr(printf("%1.2zd|%9.7jd|% 8hhd|% 9.7hd|%-+14.5ld|%-14.5lld\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));
	ft_putnbr(ft_printf("%1.2zd|%9.7jd|% 8hhd|% 9.7hd|%-+14.5ld|%-14.5lld\n\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));

	//o
	ft_putnbr(printf("%#1.2zo|%9.7jo|%#8hho|%09.7ho|%-4.5lo|%-14.5llo\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));
	ft_putnbr(ft_printf("%#1.2zo|%9.7jo|%#8hho|%09.7ho|%-4.5lo|%-14.5llo\n\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));

	//x
	printf("%#4.3zx|%0#20.7jx|%#8hhx|%09.7hx|%-4.5lx|%-14.5llx\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb);
	ft_printf("%#4.3zx|%0#20.7jx|%#8hhx|%09.7hx|%-4.5lx|%-14.5llx\n\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb);

	//X
	printf("%2.1zX|%#-20.7jX|%#8hhX|%#9.7hX|%-4.5lX|%-14.5llX\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb);
	ft_printf("%2.1zX|%#-20.7jX|%#8hhX|%#9.7hX|%-4.5lX|%-14.5llX\n\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb);

	//u
	ft_putnbr(printf("%2.1zu|%-20.7ju|%8hhu|%9.7hu|%-4.5lu|%-14.5llu\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));
	ft_putnbr(ft_printf("%2.1zu|%-20.7ju|%8hhu|%9.7hu|%-4.5lu|%-14.5llu\n\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));

	//O
	ft_putnbr(printf("%2.1zO|%-20.7jO|%8hhO|%9.7hO|%-4.5lO|%-14.5llO\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));
	ft_putnbr(ft_printf("%2.1zO|%-20.7jO|%8hhO|%9.7hO|%-4.5lO|%-14.5llO\n\n", (size_t)nb, (intmax_t)nb, (signed char)nb, (short)nb, (long)nb, (long long)nb));
*/
	return (0);
}
Esempio n. 5
0
File: main.c Progetto: sbenning42/42
int					main(int arg_c, char **arg_v, char **env_p)
{
	t_hook_input	hook;
	char			*input;

	if (hook_open(&hook))
		exit(EXIT_FAILURE);
	input = hook_input(&hook);
	ft_printf("[%s]\n", input);
	if (hook_close(&hook))
		exit(EXIT_FAILURE);
	return (0);
	(void)arg_c;
	(void)arg_v;
	(void)env_p;
}
Esempio n. 6
0
void			ft_error_msg(int error, char *str, int i, int arg_size)
{
	if (error == 0)
	{
		ft_putstr("Exit: Malloc failed");
		exit(1);
	}
	else if (error == 1)
		ft_conversion_error(str, i, arg_size);
	else if (error == -1)
	{
		ft_printf("%d error", i);
		(i > 1) ? ft_putchar('s') : 0;
		ft_putendl(" generated.");
	}
}
Esempio n. 7
0
void	lem_in(t_data *data, t_env *env)
{
	t_data	rooms[env->room_count + 1];
	int		room[env->room_count + 1];

	ant_hill(data, rooms, env->room_count);
	env->room_count++;
	env->room = room;
	env->maze = rooms;
	if (is_end(*env) == 0)
	{
		ft_printf("error: no path found");
		exit(0);
	}
	algo(env);
}
Esempio n. 8
0
int				sh_help(t_info *info)
{
    int			i;

    (void)info;
    ft_putendl("Gwoodwar Minishell");
    ft_putendl("Type program names and arguments, press enter.");
    ft_putendl("Here are the built in:");
    i = 0;
    while (i < sh_nb_builtin())
    {
        ft_printf("     %s,\n", g_builtin_str[i]);
        i++;
    }
    return (1);
}
Esempio n. 9
0
void				*malloc_reg(size_t size, t_zone *zone)
{
	t_chunk				*chunk;
	t_block				*block;

	block = available_block_in_zone(zone, size);
	if (block == NULL)
	{
		ft_printf("no_block_available\tcreating chunk...\n");
		chunk = create_chunk(zone);
		if (chunk == NULL)
			return (NULL);
		block = available_block_in_chunk(chunk, size);
	}
	return (split_block(block, size) + 1);
}
Esempio n. 10
0
int	ft_option_bigd(unsigned int nbr, unsigned int count)
{
	while (nbr < count)
	{
		ft_printf("===================================================\n");
		ft_printf("==================== Option D =====================\n");
		printf(C_GREEN"[ PRINTF ]\t:  %D"C_NONE"\n", nbr);
		ft_printf("[ ft_printf ]\t:  %D\n", nbr);
		ft_printf("===================================================\n");
		ft_printf("==================== Option u =====================\n");
		printf(C_GREEN"[ PRINTF ]\t:  %u"C_NONE"\n", nbr);
		ft_printf("[ ft_printf ]\t:  %u\n", nbr);
		ft_printf("===================================================\n");
		ft_printf("===================================================\n");
		nbr++;
	}
	return (0);
}
Esempio n. 11
0
double		ft_dot_inf(t_vect3 *v1, t_vect3 *v2, char axe)
{
	double		dot;

	if (axe == 'x')
		dot = v1->y * v2->y + v1->z * v2->z;
	else if (axe == 'y')
		dot = v1->x * v2->x + v1->z * v2->z;
	else if (axe == 'z')
		dot = v1->x * v2->x + v1->y * v2->y;
	else
	{
		ft_printf("ERROR !\n");
		exit(0);
	}
	return (dot);
}
Esempio n. 12
0
static int	loop_get_st_rd(int sockfd, int size, int *pos, char *buff)
{
	int		ask_size;
	int		ret;

	ask_size = size - *pos;
	if (ask_size > NET_BUFF_SIZE)
		ask_size = NET_BUFF_SIZE;
	ret = read(sockfd, buff, ask_size);
	if (ret < 0)
	{
		ft_printf("%rError #1\n");
		return (-1);
	}
	*pos += ret;
	return (ret);
}
Esempio n. 13
0
static void		print_winner(t_arena *arena)
{
	t_player	*p;
	t_player	*best;

	best = arena->players;
	p = arena->players;
	while (p != NULL)
	{
		if (p->last_live >= best->last_live)
			best = p;
		p = p->next;
	}
	ft_printf("The fight has ended with the last survivor dying at cycle %d.\n"
		"The winner is %s ! Its last words : \"%s\".\n",
		best->last_live, best->name, best->comment);
}
Esempio n. 14
0
File: main.c Progetto: ninja00/cor1
void		print_finish(t_vm *vm)
{
	t_bin	*win;
	int		tmp;

	win = who_win(vm);
	if (win->num_plyr < 0)
		tmp = (-1 * win->num_plyr);
	else
		tmp = win->num_plyr;
	ft_printf("Contestant %d (%s), has won !\n", tmp, win->prog_name); // merde si on a fait un -n
	if (vm->verbose & 32 || vm->dump > 0)
	{
		//print_t_cpu(vm);
		print_core(vm);
	}
}
Esempio n. 15
0
static t_block		*available_block_in_zone(t_zone *zone, size_t size)
{
	t_dlst				*it;
	t_chunk				*chunk;
	t_block				*block;

	it = zone->chunks_head.next;
	while (it != &zone->chunks_head)
	{
		ft_printf(C_GREEN"\tChunk adress: %p\n"C_RESET, it);
		chunk = CONTAINEROF(it, t_chunk, chunk_node);
		if ((block = available_block_in_chunk(chunk, size)))
			return (block);
		it = it->next;
	}
	return (NULL);
}
Esempio n. 16
0
int			ft_listen(int port)
{
	int					sockfd;
	socklen_t			lg;

	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd < 0)
	{
		ft_printf("%rServer could not init socket\n");
		return (-1);
	}
	if (init_socket(sockfd, port) < 0)
		return (-1);
	lg = (socklen_t)sizeof(struct sockaddr_in);
	loop_listen(lg, sockfd);
	return (0);
}
Esempio n. 17
0
void 				get_hosts_addr()
{
	struct hostent	*host;
	struct in_addr	ip;

	for (t_addr *ptr = globals.addresses; ptr != NULL; ptr = ptr->next) {
		host = gethostbyname(ptr->name);
		ip.s_addr = (host) ? *((uint32_t *)host->h_addr_list[0]) : inet_addr(ptr->name);
		if (ip.s_addr != INADDR_NONE)
			ft_memcpy(ptr->hostaddr, inet_ntoa(ip), sizeof(ptr->hostaddr));
		else {
			ptr->error = hstrerror(h_errno);
			ft_printf("Failed to resolve \"%s\": %s\n", ptr->name, ptr->error);
			globals.addresses_nb--;
		}
	}
}
Esempio n. 18
0
int		ft_put_part_ia(t_tray *tray, int nb)
{
	int		i;

	i = 0;
	while (tray->tab[i] != NULL)
	{
		if (tray->tab[i][nb] != '.')
			break ;
		i++;
	}
	if (i == 0)
		return (0);
	tray->tab[i - 1][nb] = 'O';
	ft_printf("-> HAL put on %d\n\n", nb);
	return (1);
}
Esempio n. 19
0
static int				command_absolute(char **argv, t_sh *datas)
{
	pid_t				pid;
	int					ret;

	pid = fork();
	if (pid > 0)
	{
		wait(&ret);
		datas->ret_err = ret & 0xFF;
		datas->ret_val = (ret & 0xFF00) >> 8;
		if (datas->ret_err)
			error_process(datas->ret_err);
		else
			ft_printf("%{F}(%d)%{!F} ",
					(datas->ret_val) ? 1 : 2, (int)datas->ret_val);
	}
Esempio n. 20
0
int			delete_in_env(t_cmd *cmd, char ***envp)
{
	int		i;

	if (cmd->arg[1] == NULL)
	{
		ft_printf("%rError: Too few arguments\n");
		return (1);
	}
	i = 1;
	while ((cmd->arg)[i] != NULL)
	{
		env_match((cmd->arg)[i], envp);
		i = i + 1;
	}
	return (0);
}
Esempio n. 21
0
int	ft_option_d(int nbr, int b)
{
	printf("option_d = %d et %d\n", nbr, b);
	while (nbr < b)
	{
		ft_printf("===================================================\n");
		ft_printf("==================== Option d  ====================\n");
		printf(C_GREEN"[ PRINTF ]\t:  %d"C_NONE"\n", nbr);
		ft_printf("[ ft_printf ]\t:  %d\n", nbr);
		ft_printf("===================================================\n");
		ft_printf("==================== Option i =====================\n");
		printf(C_GREEN"[ PRINTF ]\t:  %i"C_NONE"\n", nbr);
		ft_printf("[ ft_printf ]\t:  %i\n", nbr);
		ft_printf("===================================================\n");
		ft_printf("===================================================\n");
		nbr++;
	}
	return (0);
}
Esempio n. 22
0
void	aff_tab_e(char **tab)
{
	int		i;

	i = 0;
	if (!tab)
		return ;
	while (tab[i])
	{
		if (!ft_strchr(tab[i], '='))
			ft_printf("%s=''\n", tab[i]);
		else if (ft_strncmp(tab[i], "_=", 2))
			ft_putendl(tab[i]);
		else if (!ft_strcmp(tab[i], THE_CREED))
			ft_putendl("_=export");
		i++;
	}
}
Esempio n. 23
0
t_value		json_get(t_json *x, char *str)
{
	t_value value;
	char *split;
	
	while (x != NULL)
	{
		split = ft_strchr(str,'.');
		if (split == NULL && ft_strcmp(str, x->key) == 0)
			return (x->value);
		else if (split != NULL && ft_strncmp(str, x->key, split - str) == 0)
			return json_get(x->value.data.obj, split + 1);
		x = x->next;
	}
	ft_printf("error in the json scene\n");
	exit(0);
	return (value);
}
Esempio n. 24
0
File: main.c Progetto: ninja00/cor1
void	print_t_plr(t_list_player *lplr)
{
	t_list_player *tmp;
	tmp = lplr;
	char *buff;

	buff= NULL;
	while (tmp)
	{
		ft_printf("__dans BIN __\nnumplr:%u\n", tmp->plr->num_plyr);
		print_magic(*tmp->plr, buff);
		print_prog_name(*tmp->plr);
		print_prog_size(*tmp->plr, buff);
		print_comment(*tmp->plr);
		print_prog(*tmp->plr);
		tmp = tmp->next;
	}
}
Esempio n. 25
0
static void		all_forward(t_path *begin, t_path *end_room)
{
	t_path *ptr;

	ptr = end_room->prev;
	while (!(ptr->cur_ant))
		ptr = ptr->prev;
	while (ptr != begin && ptr->cur_ant)
	{
		ft_printf("L%i-%s ", ptr->cur_ant, ptr->next->room->name);
		if (ptr->next == end_room)
			(end_room->gone_ant)++;
		else
			ptr->next->cur_ant = ptr->cur_ant;
		ptr->cur_ant = 0;
		ptr = ptr->prev;
	}
}
Esempio n. 26
0
int		nm_macho(char *f, char *ptr, uint8_t mask)
{
	t_sym						**sym_lst;
	t_sect						**sect_lst;

	sym_lst = malloc(sizeof(t_sym *));
	sect_lst = malloc(sizeof(t_sect *));
	*sym_lst = NULL;
	*sect_lst = NULL;
	if (f)
		ft_printf("\n%s:\n", f);
	if (parse_lc(sym_lst, sect_lst, ptr, mask) == -1)
		return (EXIT_FAILURE);
	sort_sym_lst(sym_lst);
	disp_sym_lst(*sym_lst, *sect_lst);
	free_lists(sym_lst, sect_lst);
	return (EXIT_SUCCESS);
}
Esempio n. 27
0
int			li_get_ants(char *line, t_lem *lst)
{
	int		nb;

	get_next_line(0, &line);
	ft_printf("%s\n", line);
	nb = ft_atoi(line);
	if (nb <= 0)
	{
		lst->error = 1;
		lst->ants = nb;
		free(line);
		return (0);
	}
	lst->ants = nb;
	free(line);
	return (1);
}
Esempio n. 28
0
static int		ft_is_option(char *opt)
{
	if (*opt != '-')
		return (0);
	opt++;
	while (*opt)
	{
		if (*opt != 'i')
		{
			ft_printf("%$%s%$", ERROR_CLR\
				, "usage: env [-i] [name=value ...] [utility [argument ...]]"
				, TEXT_CLR);
			return (0);
		}
		opt++;
	}
	return (1);
}
Esempio n. 29
0
void	dirs(t_list **list, t_frmt *frmt)
{
	t_list	*files;
	t_file	*file;

	files = *list;
	while (files && frmt->is_upper_r)
	{
		file = (t_file *)files->data;
		if (file->permissions[0] == 'd' && file->sub_dirs)
		{
			ft_printf("\n%s\n", file->path);
			display_files(&file->sub_dirs, frmt);
		}
		file = NULL;
		files = files->next;
	}
}
Esempio n. 30
0
void	color(t_dircont *dc)
{
	if (dc->type[0] == '-')
		ft_printf("%-s", dc->name);
	else if (dc->type[0] == 'd')
		ft_printf("\033[36m%-s\033[0m", dc->name);
	else if (dc->type[0] == 'l')
		ft_printf("\033[35m%-s\033[0m", dc->name);
	else if (dc->type[0] == 'p')
		ft_printf("%-s", dc->name);
	else if (dc->type[0] == 'b')
		ft_printf("\033[7;34;36m%-s\033[0m", dc->name);
	else if (dc->type[0] == 'l')
		ft_printf("%-s", dc->name);
	else if (dc->type[0] == 'c')
		ft_printf("\033[27;34;43m%-s\033[0m", dc->name);
}