Ejemplo n.º 1
0
int				parsing(t_env *data)
{
	char	*line;
	int		ret;

	line = NULL;
	while (!(data->ants))
		get_ants(data, line);
	while ((ret = get_next_line(0, &line)))
	{
		if (!check_line(&line, data))
		{
			if (!can_start(data))
				parsing_error(data, line);
			ft_strdel(&line);
			ft_putchar('\n');
			return (solve(data));
		}
		ft_putendl(line);
		ft_strdel(&line);
	}
	if (ret == -1)
		ft_error("read");
	ft_putchar('\n');
	if (!can_start(data))
		parsing_error(data, line);
	return (solve(data));
}
Ejemplo n.º 2
0
static void		get_ants(t_env *data, char *line)
{
	int		i;

	i = 0;
	if (get_next_line(0, &line) == -1)
		ft_error("read");
	if (line[0] == '#')
	{
		if (!ft_strcmp(line, "##start") || !ft_strcmp(line, "##end"))
			parsing_error(data, line);
	}
	else
	{
		while (line[i])
		{
			if (!ft_isdigit(line[i]))
				parsing_error(data, line);
			i++;
		}
		data->ants = ft_atoi(line);
		if (!data->ants)
			parsing_error(data, line);
	}
	ft_putendl(line);
	ft_strdel(&line);
}
Ejemplo n.º 3
0
Archivo: check.c Proyecto: bndao/fillit
int					checked(char *s)
{
	size_t		j;

	j = 0;
	while (s[j])
	{
		if (s[j] != '.' && s[j] != '#' && s[j] != '\n')
			ft_error();
		j++;
	}
	if (!check_d_line(s))
		ft_error();
	if (s[ft_strlen(s) - 2] == '\n')
		ft_error();
	return (1);
}
Ejemplo n.º 4
0
char		*ft_scaninput(t_conf *config)
{
	char			*cmdline;
	t_ctlinput		ctl;

	cmdline = NULL;
	ft_termios();
	if (!(ctl.termsize = (struct winsize*)ft_memalloc(sizeof(struct winsize))))
		ft_error(NULL, GET_TERM_SIZE, EXIT);
	if (ioctl(0, TIOCGWINSZ, ctl.termsize) == -1)
		ft_error(NULL, GET_TERM_SIZE, EXIT);
	ft_scan(&cmdline, config, ctl);
	ft_termios();
	ft_putchar('\n');
	free(ctl.termsize);
	return (cmdline);
}
Ejemplo n.º 5
0
void		*ft_xmalloc(size_t size)
{
	void	*res;

	if ((res = (void*)malloc(size)) == NULL)
		ft_error("malloc: Impossible d'allouer la memoire.");
	return (res);
}
Ejemplo n.º 6
0
static void		ft_creat_map(t_a *a)
{
	int			y;
	int			x;

	if (!(a->map = (char **)ft_memalloc(sizeof(char *) * a->max_y)))
		ft_error("Probleme Malloc");
	y = -1;
	while (++y < a->max_y)
	{
		if (!(a->map[y] = (char *)ft_memalloc(sizeof(char) * a->max_x)))
			ft_error("Probleme Malloc");
		x = -1;
		while (++x < a->max_x)
			a->map[y][x] = '\0';
	}
}
Ejemplo n.º 7
0
int		main(int argc, char **argv)
{
	t_env	e;

	if (argc != 2)
		ft_error("usage : ./fdf file");
	e.map = ft_readmap(argv[1]);
	if (!(e.mlx = mlx_init()))
		ft_error("Fail to init mlx");
	if (!(e.win = mlx_new_window(e.mlx, IMG_X, IMG_Y, "fdf")))
		ft_error("Fail to create Mlx New Window");
	e.zoom = 20;
	mlx_key_hook(e.win, key_hook, &e);
	mlx_expose_hook(e.win, expose_hook, &e);
	mlx_loop(e.mlx);
	return (EXIT_SUCCESS);
}
Ejemplo n.º 8
0
void		fract_new_image(t_a *a)
{
	int		e;

	mlx_clear_window(a->mlx, a->win);
	if (!(a->img = mlx_new_image(a->mlx, MAX_X, MAX_Y)))
		ft_error("Problem of Mlx New Image 1");
	a->data = mlx_get_data_addr(a->img, &a->b, &a->l, &e);
	if (a->data == NULL)
		ft_error("Problem of Get_Data Image 1");
	a->b /= 8;
	if (!(a->img_2 = mlx_new_image(a->mlx, MAX_X, 200)))
		ft_error("Problem of Mlx New Image 2");
	a->data_2 = mlx_get_data_addr(a->img_2, &a->b_2, &a->l_2, &e);
	if (a->data == NULL)
		ft_error("Problem of Get_Data Image 2");
}
Ejemplo n.º 9
0
int			ft_connect(char *addr, int port)
{
	int		sock;

	if ((sock = s_creat_client(addr, port)) == -1)
		ft_error("find server.\n", 0);
	return (sock);
}
Ejemplo n.º 10
0
static int usage(char c)
{
  char    msg[1024];

  ft_sprintf(msg, "Illegal option -- %c\nUsage: cd [-L|P] [rep]", c);
  ft_error(msg);
  return (-1);
}
Ejemplo n.º 11
0
static void		set_canon_vmin(int tty, struct termios *term)
{
	term->c_lflag &= ~(ICANON | ECHO);
	term->c_cc[VMIN] = 1;
	term->c_cc[VTIME] = 0;
	if (tcsetattr(tty, TCSADRAIN, term) == -1)
		ft_error(GETATTR);
}
Ejemplo n.º 12
0
int		ft_open(char *file)
{
	int		fd;

	if ((fd = open(file, O_RDONLY)) == -1)
		ft_error(1);
	return (fd);
}
Ejemplo n.º 13
0
static void	ft_exe_cmd_path(char **spt, char **envp)
{
	char	*str;

	str = ft_strnew_path(spt[0], envp);
	if (execve(str, spt, envp) == -1)
		ft_error(spt[0], ": command not found");
	ft_strdel(&str);
}
Ejemplo n.º 14
0
static int	od_error(int code, char *dirname, char *message, char *func)
{
	if (errno == code)
	{
		ft_error("%s: %s: %s\n", func, dirname, message);
		return (errno);
	}
	return (0);
}
Ejemplo n.º 15
0
struct dirent		*ft_readdir(DIR *handle)
{
	struct dirent	*ent;

	if (!(ent = readdir(handle)))
	{
		if (errno == EOVERFLOW)
			ft_error("%s: one of the values in the structure to be returned, "
					"cannot be represented correctly.\n", __FUNCTION__);
		else if (errno == EBADF)
			ft_error("%s: the dir handle does not refer to an open "
					"directory stream.\n", __FUNCTION__);
		else if (errno == ENOENT)
			ft_error("%s: the current position of the directory "
					"strean is invalid.\n", __FUNCTION__);
	}
	return (ent);
}
Ejemplo n.º 16
0
int		ft_create_server(int port, char *str)
{
	int					sock;
	struct protoent		*proto;
	struct sockaddr_in	sina;

	proto = getprotobyname("tcp");
	if (proto == NULL)
		ft_error(str, 1);
	sock = socket(PF_INET, SOCK_STREAM, proto->p_proto);
	sina.sin_family = AF_INET;
	sina.sin_port = htons(port);
	sina.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(sock, (const struct sockaddr *)&sina, sizeof(sina)) == -1)
		ft_error(str, 1);
	listen(sock, 42);
	return (sock);
}
Ejemplo n.º 17
0
int		main(int argc, char *argv[])
{
	struct s_grid	*grid;

	if (ft_precheck(argc, argv) == 0)
	{
		ft_error();
		return (0);
	}
	grid = ft_create_grid(argv);
	if (fill_grid(grid, 0, 0) == 0)
	{
		ft_error();
		return (0);
	}
	ft_print_grid(grid);
	return (0);
}
Ejemplo n.º 18
0
void			ft_check_args(char **argv, t_client *c)
{
	int			i;

	i = 1;
	if (argv[i][0] != '-')
		ft_error("ERROR bad argument.");
	while (argv[i])
	{
		if (argv[i][0] == '-' && argv[i + 1] && argv[i + 1][0] != '-')
		{
			ft_fill_client(argv, i, c);
			i += 2;
		}
		else
			ft_error("ERROR bad argument.");
	}
}
Ejemplo n.º 19
0
void	error_fn3(char *reason, t_stack *stack)
{
	if (stack->a)
		ft_memdel((void**)&stack->a);
	if (stack->arg > 2)
		ft_strdel(&(stack->str));
	ft_memdel((void**)&stack);
	ft_error(reason);
}
Ejemplo n.º 20
0
Archivo: main.c Proyecto: jdG-/zap
static int				create_server(t_game game)
{
	struct protoent		*proto;
	struct sockaddr_in	sin;

	if ((proto = getprotobyname("tcp")) == 0)
		ft_error("ERROR getprotobyname.");
	if ((game.sock = socket(PF_INET, SOCK_STREAM, proto->p_proto)) == -1)
		ft_error("ERROR socket.");
	sin.sin_family = AF_INET;
	sin.sin_port = htons(game.port);
	sin.sin_addr.s_addr = htonl(INADDR_ANY);
	if (bind(game.sock, (const struct sockaddr*)&sin, sizeof(sin)) == -1)
		ft_error("ERROR bind.");
	if (listen(game.sock, MAX_CLI) == -1)
		ft_error("ERROR listen.");
	return (game.sock);
}
Ejemplo n.º 21
0
int			check_nblem(t_lem_env *env, char *s)
{
	if (is_nblem(s))
		env->nblem = ft_atoi(s);
	if (env->nblem <= 0)
		return (ft_error(env, 1));
	env->r.nbline += add_file(env, s);
	return (ft_add_state(env));
}
Ejemplo n.º 22
0
Archivo: init.c Proyecto: Strade288/42
t_env			*init_env(char *path)
{
	t_env		*e;

	if (!(e = (t_env *)malloc(sizeof(t_env))))
		ft_error(1, NULL, "Not enough memory.\n");
	if (!(e->mlx = mlx_init()))
		ft_error(1, e, "Mlx fail init.\n");
	if (!(e->win = mlx_new_window(e->mlx, WIDTH, HEIGHT, NAME)))
		ft_error(1, e, "Win fail init.\n");
	if (!init_scene(e, path))
		ft_error(1, e, "Wrong file format.\n");
	e->x_ratio = 0.5 / (double)WIDTH;
	e->y_ratio = 0.35 / (double)HEIGHT;
	init_events(e);
	init_types(e);
	init_screen(e->mlx, &e->screen, WIDTH, HEIGHT);
	return (e);
}
Ejemplo n.º 23
0
void	ft_store(char *av, t_map *list)
{
	int		fd;

	if ((fd = open(av, O_RDONLY)) == -1)
		ft_error("Error Opening\n");
	ft_findwh(fd, list);
	fd = open(av, O_RDONLY);
	ft_zvalue(fd, list);
}
Ejemplo n.º 24
0
int		init_var_n_check(char *line, int *i, t_pos *pos_i, int *i_cpy)
{
	if (!line || ft_isunixspec(*line) ||
		ft_isunixspec(line[ft_strlen(line) - 1]))
		return (ft_error(PEOP, NULL, -1), 0);
	*i = -1;
	*pos_i = POS(-1, -1);
	*i_cpy = 0;
	return (1);
}
Ejemplo n.º 25
0
int				ft_verif_is_number(char *s)
{
	int			i;

	i = -1;
	while (s[++i])
	{
		if (!ft_isdigit(s[i]))
		{
			if (i == 0 && s[i] == '-')
				return (ft_error("Avoid negative number", "", -1));
			else
				return (ft_error("Put a numeric parameters", "", -1));
		}
	}
	if (i > 9)
		return (ft_error("Put a parameters lower to 999999999", "", -1));
	return (0);
}
Ejemplo n.º 26
0
int	ft_wait(void)
{
	char	*ptr;

	ptr = NULL;
	if (get_next_line(0, &ptr) < 0)
		ft_error("fail to wait");
	ft_memdel((void**)&ptr);
	return(1);
}
Ejemplo n.º 27
0
static int	matrice_visit0(t_lem_env *env, int *i, int *j, int *k)
{
	if (env->r.start == 0 || env->r.end == 0)
		return (ft_error(env, 1));
	if (env->r.state == 1)
	{
		env->room = ft_strsplit(env->str, '\n');
		room_swap(env);
		if (test_room(env) == 0)
			return (ft_error(env, 1));
		matrice_init(env);
		matrice_zero(env);
		visit_init(env);
	}
	*i = 0;
	*j = -1;
	*k = -1;
	return (1);
}
Ejemplo n.º 28
0
t_piece	*ft_name(char c)
{
	t_piece	*piece;

	piece = malloc(sizeof(t_piece));
	if (!piece)
		ft_error();
	piece->name = c;
	return (piece);
}
Ejemplo n.º 29
0
t_swap		*ft_init_list(char *av)
{
    t_swap	*ptr;

    if (!(ptr = malloc(sizeof(t_swap))))
        ft_error();
    ptr->next = NULL;
    ptr->data = ft_atoi(av);
    return (ptr);
}
Ejemplo n.º 30
0
static void	ft_dup_fds(char *op, char *ampersand, char *file, int *fd)
{
	int	tmpfd;

	if (ampersand && op[0] == '>' && -1 == dup2(fd[1], fd[0]))
		ft_error(SHNAME, "bad file descriptor", ft_st_itoa(fd[0]), CR_ERROR);
	else if (ampersand && op[0] == '<' && -1 == dup2(fd[0], fd[1]))
		ft_error(SHNAME, "bad file descriptor", ft_st_itoa(fd[1]), CR_ERROR);
	else if (!ampersand)
	{
		if (!(tmpfd = ft_redirectpipe(file, NULL, op)))
			return ;
		if (op[0] == '>' && -1 == dup2(tmpfd, fd[0]))
			ft_error(SHNAME, "bad file descriptor", ft_st_itoa(fd[0]), 1);
		else if (op[0] == '<' && -1 == dup2(fd[0], tmpfd))
			ft_error(SHNAME, "bad file descriptor", ft_st_itoa(fd[0]), 1);
		close(tmpfd);
	}
}