Ejemplo n.º 1
1
Archivo: main.c Proyecto: vquesnel/FdF
int			main(int ac, char **av)
{
	int		fd;
	t_env	*env;

	if (ac != 2)
	{
		ft_putstr("Usage: ./fdf <filename>\n");
		return (0);
	}
	if (!(ft_strstr(av[1], ".fdf")))
		ft_error("\033[31;1mFile isn't a fdf map.\033[0m");
	if ((fd = open(av[1], O_RDONLY)) < 0)
		ft_error("\033[31;1mError when openning file.\033[0m");
	env = init_env(fd);
	close(fd);
	fdf(env);
	mlx_hook(env->win, 2, 3, key_funct, env);
	mlx_hook(env->win, 17, 1l << 17, close_win, env);
	mlx_mouse_hook(env->win, mouse_funct, env);
	mlx_loop(env->mlx);
	return (0);
}
Ejemplo n.º 2
0
int		print_str_padded(char *str, t_vars *vars, char *prefix)
{
	size_t	len_str;
	int		padding;
	char	*string;

	string = ft_strdup(str);

	len_str = ft_strlen(string);
	padding = vars->padding - len_str;
	if (prefix)
		padding -= ft_strlen(prefix);
	if (padding > 0 && HAS_FLAG_ZERO(vars->flags))
		string = add_padding(string, (size_t)padding, vars);
	if (prefix)
		ft_str_renew(&string, ft_strjoin(prefix, string)); // not opti
	if (padding > 0 && !HAS_FLAG_ZERO(vars->flags))
		string = add_padding(string, (size_t)padding, vars);
	len_str = ft_strlen(string);
	ft_putstr(string);
	vars->precision = -1;
	return (len_str);
}
Ejemplo n.º 3
0
void		ft_putlst(t_list **list)
{
	t_list		*cursor;

	if (list && *list)
	{
		cursor = *list;
		while (cursor)
		{
			ft_putstr((char *)cursor->content);
			if (cursor->next)
			{
				ft_putchar(' ');
				cursor = cursor->next;
			}
			else
			{
				ft_putchar('\n');
				return ;
			}
		}
	}
}
Ejemplo n.º 4
0
void	ft_putnbr(int n)
{
	if (n == -2147483648)
	{
		ft_putstr("-2147483648");
		return ;
	}
	if (n < 0)
	{
		write(1, "-", 1);
		n = 0 - n;
	}
	if (n > 9)
	{
		ft_putnbr(n / 10);
		ft_putnbr(n % 10);
	}
	else
	{
		n += 48;
		write(1, &n, 1);
	}
}
Ejemplo n.º 5
0
int			parse_dir(t_list **list, char *str, int *pos)
{
	(void)g_op_tab;
	while (str[(*pos)] && (str[(*pos)] == ' ' || str[(*pos)] == '\t'))
		(*pos)++;
	if (str[(*pos)] == '%')
	{
		(*pos)++;
		if (str[(*pos)] == ':')
		{
			(*pos)++;
			ft_putstr(&str[*pos]);
			if (dir_label(str, pos, list) == FALSE)
				return (FALSE);
		}
		else if (dir_nb(str, pos) == FALSE)
			return (FALSE);
		(*list)->type_arg = T_DIR;
		return (TRUE);
	}
	else
		return (FALSE);
}
Ejemplo n.º 6
0
void			list_print(t_select_list *list)
{
	int			i;
	int			width;
	t_lst_col	*col;

	ft_trmclr();
	width = ft_trmwidth();
	col = list->cols;
	while (col)
	{
		width -= col->width;
		col = col->next;
	}
	if (width > 0)
	{
		i = 0;
		while (list_print_line(list, i))
			i++;
	}
	else
		ft_putstr("Window is too small to display the select list");
}
Ejemplo n.º 7
0
void	ft_nbrendl(int n)
{
	if (n == -2147483648)
		ft_putstr("-2147483648");
	else
	{
		if (n < 0)
		{
			ft_putchar('-');
			n = -n;
		}
		if (n >= 10)
		{
			ft_putnbr(n / 10);
			ft_putnbr(n % 10);
		}
		else
		{
			ft_putchar(n + '0');
		}
	}
	ft_putchar('\n');
}
Ejemplo n.º 8
0
int						create_client(char *addr, int port)
{
	int					sock;
	struct protoent		*proto;
	struct sockaddr_in	sin;

	proto = getprotobyname("tcp");
	if (proto == 0)
		return (-1);
	sock = socket(PF_INET, SOCK_STREAM, proto->p_proto);
	sin.sin_family = AF_INET;
	sin.sin_port = htons(port);
	if (ft_strnstr(addr, "Localhost", 9) != NULL)
		sin.sin_addr.s_addr = inet_addr("127.0.0.1");
	else
		sin.sin_addr.s_addr = inet_addr(addr);
	if (connect(sock, (const struct sockaddr *)&sin, sizeof(sin)) == -1)
	{
		ft_putstr("Connect error\n");
		exit(2);
	}
	return (sock);
}
Ejemplo n.º 9
0
void	enter(t_list **list, t_list **current)
{
	int		flag;
	int		space;

	space = 0;
	*current = *list;
	flag = 0;
	term_command(CAP_CLEAR_SCREEN);
	while (*current != *list || flag == 0)
	{
		if ((*current)->select == 1)
		{
			if (space > 0)
				ft_putchar(' ');
			space++;
			ft_putstr((*current)->str);
		}
		*current = (*current)->next;
		flag++;
	}
	esc(list, current);
}
Ejemplo n.º 10
0
void	print(t_lst *lst, int skip, int a, char *path)
{
	if (!lst)
		return ;
	if (a && lst->info.name[0] == '.')
		print(lst->next, skip, a, path);
	else
	{
		if (skip == 'f' && lst->info.perm[0] != 'd')
			print(lst->next, skip, a, path);
		else
		{
			if (skip == 'd' && lst->info.perm[0] == 'd')
				print(lst->next, skip, a, path);
			else
			{
				ft_putstr(lst->info.name);
				ft_putchar('\n');
				print(lst->next, skip, a, path);
			}
		}
	}
}
Ejemplo n.º 11
0
int	ft_printf(const char *format, ...)
{
	va_list list;
	va_list cp;
	int		ret;

	ret = 0;
	if (check_exstr(format))
	{
		va_start(list, format);
		va_copy(cp, list);
		if (ft_strchr(format, '%'))
			ret = found_flags(format, list);
		else
		{
			ft_putstr(format);
			ret = ft_strlen(format);
		}
		va_end(list);
		va_end(cp);
	}
	return (ret);
}
Ejemplo n.º 12
0
void	recursive(char *path, int *state, int n)
{
	struct dirent	*dir;
	DIR				*yolo;
	t_ls			*a;

	pathnames(path, state, n);
	if (!(yolo = opendir(path)))
	{
		ft_putstr("./ft_ls: ");
		perror(path);
	}
	else
	{
		a = NULL;
		while ((dir = readdir(yolo)))
			a = filla(state, a, path, dir);
		closedir(yolo);
		a = sorta(a, state);
		print(a, state, path, findmax(a, path, state));
		recursive2(a, state, path);
	}
}
Ejemplo n.º 13
0
int				print_regular(t_formater *fmt, t_printf *pf)
{
	int		ret;
	int		is_nega;
	int		size;

	ret = 0;
	is_nega = pf->fmt_str[0] == '-' ? 1 : 0;
	if (is_nega)
		pf->prefix = ft_strdup("-");
	if (is_signed(fmt) && fmt->flag & F_BLANK && !is_neg(pf->fmt_str))
	{
		ret += ft_putchar(' ');
		fmt->width -= 1;
	}
	size = final_size(fmt->width, ft_strlen(is_nega? pf->fmt_str + 1 : \
				pf->fmt_str) + ft_strlen(pf->prefix));
	if (!(fmt->flag & F_MINUS) && !(fmt->flag & F_ZERO))
		ret += print_n_char(' ', size);
	ret += ft_putstr(pf->prefix);
	ret += print_reg2(fmt, pf, size);
	return (ret);
}
Ejemplo n.º 14
0
int			main(int argc, char **argv)
{
	t_rt		s_rt;

	if (argc == 3)
	{
		s_rt.s_eye.x = -3000;
		s_rt.s_eye.y = 0;
		s_rt.s_eye.z = 0;
		s_rt.s_rot.x = 0;
		s_rt.s_rot.y = 0;
		s_rt.s_rot.z = 0;
		s_rt.mode = 0;
		init_mlx(&s_rt);
		load_scene(&s_rt, argv);
		raytracing(&s_rt);
		launch_mlx(&s_rt);
		mlx_loop(s_rt.mlx_ptr);
	}
	else
		ft_putstr("Usage : ./rtv1 misc/objects.rt misc/spots.rt\n", 2);
	return (EXIT_SUCCESS);
}
Ejemplo n.º 15
0
static void	ft_display_col(void)
{
	int i;

	i = 0;
	ft_putstr("     ");
	while (i < g_col)
	{
		if (i < 10)
		{
			ft_putchar(' ');
			ft_putnbr(i + 1);
			ft_putchar(' ');
		}
		else
		{
			ft_putnbr(i + 1);
			ft_putchar(' ');
		}
		++i;
	}
	ft_putchar('\n');
}
Ejemplo n.º 16
0
int				print_str_regular(t_formater *fmt, t_printf *pf)
{
	int		ret;
	int		c_size;
	char	c;

	c = '\0';
	ret = 0;
	if (fmt->flag & F_ZERO)
		c = '0';
	else if (fmt->width > 0)
		c = ' ';
	c_size = fmt->width - (fmt->modifier == F_SL || fmt->type == T_GS ? \
		   	ft_strunilen(pf->w_str) : ft_strlen((char *)pf->w_str));
	c_size = c_size < 0 ? 0 : c_size;
	if (!(fmt->flag & F_MINUS))
		ret += print_n_char(c, c_size);
	ret += fmt->modifier == F_SL || fmt->type == T_GS ? \
		   ft_putstruni(pf->w_str) : ft_putstr((char *)pf->w_str) ;
	if (fmt->flag & F_MINUS)
		ret += print_n_char(c, c_size);
	return (ret);
}
Ejemplo n.º 17
0
void	ft_putnbr(int nb)
{
	if (nb > 2147483647 || nb < -2147483648)
		return ;
	if (nb == -2147483648)
	{
		ft_putstr("-2147483648");
		return ;
	}
	if (nb < 0)
	{
		nb = nb * -1;
		ft_putchar('-');
	}
	if (nb < 10)
	{
		ft_putchar(nb + 48);
		return ;
	}
	ft_putnbr(nb / 10);
	ft_putchar((nb % 10) + 48);
	return ;
}
Ejemplo n.º 18
0
int	ft_aff_pointer(char *finder, va_list op, t_elem list)
{
	void	*ptr;
	int		i;

	i = 0;
	(void)finder;
	ptr = va_arg(op, void *);
	if (list.width > 3 && list.minus == 0
	&& list.width > ft_lenbr_base((long long)ptr, 16) + 2)
		i = ft_putnchar(' ', list.width
			- ft_lenbr_base((long long)ptr, 16) - 2);
	i += ft_putstr("0x");
	if (ptr != 0)
		i += ft_putnbr_base((long long)ptr, 16, 0);
	else if (!list.point && !list.sharp)
		i += ft_putchar('0');
	if (list.width > 3 && list.minus != 0
	&& list.width > ft_lenbr_base((long long)ptr, 16) + 2)
		i += ft_putnchar(' ', list.width
			- ft_lenbr_base((long long)ptr, 16) - 2);
	return (i);
}
Ejemplo n.º 19
0
void	print_tab(t_data *data)
{
	int		x;
	int		y;

	x = -1;
	while (++x < HEIGHT)
	{
		y = -1;
		while (++y < WIDTH)
		{
			if (data->tab[x][y] != 0)
				ft_putchar(data->tab[x][y]);
			else
				ft_putchar('_');
			ft_putchar(' ');
		}
		ft_putchar('\n');
	}
	ft_putstr("il y a ");
	ft_putnbr(data->nb_player);
	ft_putendl(" en jeu.");
}
Ejemplo n.º 20
0
void			archive_print(t_env *env, t_archive *archive, int a)
{
	t_ar_file_list	*lst;

	(void)a;
	ft_putstr("Archive : ");
	ft_putendl(archive->file->name);
	if (!check_reorder_symdef(archive))
		return ;
	lst = archive->files;
	while (lst)
	{
		if (env->params.a)
			archive_print_file_header(&lst->file.header);
		if (ft_strcmp(lst->file.name, SYMDEF)
				&& ft_strcmp(lst->file.name, SYMDEF_SORTED))
		{
			if (env->params.t || env->params.d)
				archive_print_file(env, archive, &lst->file);
		}
		lst = lst->next;
	}
}
Ejemplo n.º 21
0
static void		ft_list_texture(t_texture *t)
{
	int		i;
	int		x;
	int		y;

	t->list_text = (int ***)ft_memalloc(sizeof(int **) * 8);
	i = -1;
	while (++i <= 7)
	{
		x = t->list_img[i]->size.x;
		t->list_text[i] = (int **)ft_memalloc(sizeof(int *) * x);
		while (x--)
		{
			y = t->list_img[i]->size.y;
			t->list_text[i][x] = (int *)ft_memalloc(sizeof(int) * y);
			while (y--)
				t->list_text[i][x][y] = ft_get_pixel_image(t->list_img[i],
				ft_make_pt(x, y));
		}
	}
	ft_putstr("List texture tab : DONE\n");
}
Ejemplo n.º 22
0
void	ftpf_write_di_param(t_ftpf_env *e)
{
	if (e->isneg)
		ft_putchar(CONV_MINUS);
	if (e->param->ll == LLONG_MIN)
		ft_putstr("9223372036854775808");
	else
	{
		if (e->conversion == 'd' || e->conversion == 'i')
		{
			if (!e->mod[0] && e->param->i != INT_MIN)
				ft_putnbr_ll(ft_abs(e->param->i));
			else if (!ft_strcmp(e->mod, "h"))
				ft_putnbr(ft_abs(e->param->sh));
			else if (!ft_strcmp(e->mod, "hh"))
				ft_putnbr(ft_abs(e->param->sc));
			else
				ft_putnbr_ll(ft_abs_ll(e->param->ll));
		}
		else if (e->conversion == 'D')
			ft_putnbr_ll(ft_abs_ll(e->param->ll));
	}
}
Ejemplo n.º 23
0
static void	ft_linear_cycle(t_anthill *ah, int ants)
{
	t_list	*elem;
	int		first;

	first = 1;
	elem = ah->bst_path;
	while (elem)
	{
		if (ants - (*(t_room**)elem->content)->lgt > 0 &&
				ants - (*(t_room**)elem->content)->lgt <= ah->ants)
		{
			if (!first)
				ft_putchar(' ');
			first = 0;
			ft_putchar('L');
			ft_putnbr(ants - (*(t_room**)elem->content)->lgt);
			ft_putchar('-');
			ft_putstr((*(t_room**)elem->content)->name);
		}
		elem = elem->next;
	}
}
Ejemplo n.º 24
0
int		ft_checkp1a1(t_numb *e, char *s1)
{
	int	cnt;

	cnt = 0;
	if (e->w < 0)
		e->w = -(e->w);
	e->g = ft_strlen(s1);
	if (e->pr > (int)ft_strlen(s1))
	{
		while ((e->w - (e->pr + 2)) > 0)
		{
			cnt++;
			ft_putchar(' ');
			(e->w)--;
		}
	}
	else
		cnt = cnt + ft_checkp1a1a(e);
	ft_putstr("0x");
	ft_putstrad3(e->pr, s1);
	return (cnt);
}
Ejemplo n.º 25
0
int		main(void)
{
	t_list	*list;
	char	c;
	int		width;
	int		height;
	int		*solution;

	list = 0;
	solution = (int*)(malloc(sizeof(int) * (5)));
	while (read(0, &c, 1))
		ft_list_push_back(&list, c);
	if ((dimensions(list, &height, &width)) == 0 || width == 0)
		ft_putstr("Error 404 ./rush-0X not found... idiot!\n");
	else
	{
		solution = rush_loop(solution, list, height, width);
		print_results(solution, width, height);
	}
	ft_list_clear(&list);
	free(solution);
	return (0);
}
Ejemplo n.º 26
0
static void		handle_rtn(t_elem *list, struct termios *backup)
{
	t_elem	*tmp;
	int		first_print;
	int		nbr_elem;

	nbr_elem = list->prev->pos_list;
	first_print = 1;
	restore_backup_term(backup);
	tmp = list;
	while (nbr_elem--)
	{
		if (tmp->selected)
		{
			if (!first_print)
				ft_putchar(' ');
			ft_putstr(tmp->name);
			first_print = 0;
		}
		tmp = tmp->next;
	}
	free_list(list);
}
Ejemplo n.º 27
0
void	ft_putnbr(int n)
{
	if (n < -2147483647)
	{
		ft_putstr("-2147483648");
		return ;
	}
	if (n < 0)
	{
		n = n * -1;
		ft_putchar('-');
	}
	if (n <= 9)
	{
		n = n + 48;
		ft_putchar(n);
	}
	else
	{
		ft_putnbr(n / 10);
		ft_putchar(n % 10 + '0');
	}
}
Ejemplo n.º 28
0
int				main(int argc, char **argv)
{
	t_stack	*stack;
	char	*tmp;
	int		size;

	if (argc < 2)
		error_fn(argv[0], 0);
	if (argc == 2)
		tmp = argv[1];
	if (argc > 2)
		tmp = get_string(argc, argv);
	check_string(tmp, argc);
	init_struct(&stack, tmp, argc);
	size = get_tab(tmp, stack);
	init_stack_b(stack, size);
	if ((size == 1 || check_sort_tab(stack, size) == 0))
		ft_putstr("");
	else
		size > 80 ? quick_sort(stack, size) : bubble_sort(stack, size);
	free_stack(stack);
	return (0);
}
Ejemplo n.º 29
0
char			*ft_analyser(char *cmd, t_mlist *mlist)
{
	int			pid;
	char		*res;
	char		buf[BUFF_SIZE];
	int			len;
	int			pfd[2];

	ft_bzero(buf, BUFF_SIZE);
	pipe(pfd);
	pid = fork();
	if (pid == 0)
	{
		signal(SIGINT, SIG_DFL);
		close(pfd[0]);
		res = ft_son(cmd, mlist);
		dup2(pfd[1], 1);
		ft_putstr(res);
		free(res);
		exit(EXIT_SUCCESS);
	}
	else
	{
		signal(SIGINT, ft_sighand2);
		close(pfd[1]);
		dup2(pfd[0], 0);
		while ((len = read(0, buf, BUFF_SIZE - 1)) > 0)
			buf[len] = '\0';
		wait(NULL);
		close(pfd[0]);
		dup2((ft_reset_std())[0], 0);
		if (buf[0] == '\0')
			return (NULL);
		return (ft_strdup(buf));
	}
	return (NULL);
}
Ejemplo n.º 30
0
static void
assert_gt_result(const t_infin_number *a, const t_infin_number *b, int result)
{
	if (infin_number_gt(a, b) != result)
	{
		ft_putstr(TST_RED);
		ft_putstr("     ERROR:");
		ft_putstr(TST_NRM);
		ft_putstr(" Expected ");
		print_infin_number(a);
		if (!result)
			ft_putstr(" not");
		ft_putstr(" to be greater than ");
		print_infin_number(b);
		ft_putendl("");
		ft_test_assertion_fail();
	}
}