Пример #1
0
char	*ft_itodate(char *i)
{
	char	*date;
	int		len;

	date = NULL;
	if ((len = ft_strlen(i)) % 2 == 1)
		i = ft_strfjoin("0", i, 0, 1);
	len = ft_strlen(i);
	if (len >= 2)
		date = ft_strsub(i, len - 2, 2);
	if (len >= 2 + 2)
	{
		date = ft_strfjoinnchar(date, -1, '/');
		date = ft_strfjoin(date, ft_strsub(i, len - 4, 2), 1, 1);
	}
	if (len >= 2 + 2 + 2)
	{
		date = ft_strfjoinnchar(date, -1, '/');
		if (len >= 4 + 2 + 2)
			date = ft_strfjoin(date, ft_strsub(i, 0, 4), 1, 1);
		else
			date = ft_strfjoin(date, ft_strsub(i, 0, 2), 1, 1);
	}
	free(i);
	return (date);
}
Пример #2
0
static int	ft_gnl_deleg(char **save, char **buffer, char **line)
{
	size_t		size;
	char		*next;

	if (*save != NULL)
		*save = ft_strfjoin(save, buffer, 1);
	else
		*save = ft_strdup(*buffer);
	if ((int)ft_strcchr(*save, '\n') != -1)
	{
		size = ft_strcchr(*save, '\n');
		if (size < ft_strlen(*save))
		{
			next = ft_strsub(*save, 0, size);
			*line = ft_strfjoin(line, &next, 3);
			*save = ft_strfsub(save, size + 1, ft_strlen(*save) - size, 1);
		}
		else
			*line = ft_strfjoin(line, save, 3);
		free(*buffer);
		return (1);
	}
	else
		*line = ft_strfjoin(line, save, 3);
	return (0);
}
Пример #3
0
static int		get_buf(int const fd, char **lines, t_fd *current)
{
	ssize_t		red;
	char		buf[BUFF_SIZE + 1];
	int			i;

	while ((red = read(fd, buf, BUFF_SIZE)))
	{
		if (red == -1)
			return (-1);
		buf[red] = '\0';
		if (ft_strchr(buf, '\n'))
		{
			i = 0;
			if (get_bufn(lines, current, buf) == 1)
				return (1);
			while (buf[i] != '\0' && buf[i] != '\n')
			{
				*lines = ft_strfjoin(*lines, ft_chartostar(buf[i]), 3);
				i++;
			}
			current->res = ft_strdup(&(ft_strchr(buf, '\n'))[1]);
			return (1);
		}
		*lines = ft_strfjoin(*lines, buf, 1);
	}
	return ((*lines != NULL) ? 1 : red);
}
Пример #4
0
char	*ft_sandwichfjoin(char **path1, char *path2, char *sandwich)
{
	char	*path;

	if (!path1 || !*path1 || !path2)
		return (NULL);
	if (!sandwich)
		return (ft_strfjoin(path1, path2));
	if (!(path = ft_strfjoin(path1, sandwich)))
		return (NULL);
	if (!(path = ft_strfjoin(&path, path2)))
		return (NULL);
	return (path);
}
static int		add_line(char **line, char **mem, char *str)
{
	int		len;

	if ((len = ft_strchri(str, '\n')) >= 0)
	{
		if (!(*line = ft_strfjoin(*line, ft_strsub(str, 0, len), TRUE, TRUE)))
			return (EX_ERROR);
		*mem = &str[len] + 1;
		return (EX_SUCCESS);
	}
	if (!(*line = ft_strfjoin(*line, str, TRUE, FALSE)))
		return (EX_ERROR);
	return (EX_CONTINUE);
}
Пример #6
0
static int		minishell(t_sh *sh)
{
	char	**cmds;
	char	*cmd;
	int		res;

	res = 0;
	ft_putstr("$>");
	while (get_next_line(0, &cmd))
	{
		sh->last_res = res;
		cmd = ft_strfjoin(cmd, " ");
		cmds = ft_str_to_tab(cmd);
		res = minishell_boot(sh, sh->env_list, cmds);
		if (cmd)
			free(cmd);
		if (cmds)
			ft_free_tab(cmds);
		cmds = NULL;
		ft_putstr("$>");
	}
	if (sh->env_list)
	{
		ft_lstdel(&sh->env_list, &minishell_builtins_unsetenv_free);
		free(sh->env_list);
	}
	return (res);
}
Пример #7
0
int				get_next_line(int const fd, char **line)
{
	static char		*buffer;
	char			buf[BUFF_SIZE + 1];
	int				ret;

	*line = NULL;
	buffer = ((!buffer) ? ft_strnew(BUFF_SIZE + 1) : buffer);
	if (ft_gnl_setline(&buffer, line) == 1)
		return (1);
	while ((ret = read(fd, buf, BUFF_SIZE)))
	{
		buf[ret] = '\0';
		if (ft_strichr(buf, '\n') >= 0)
		{
			ft_strcpy(buffer, buf);
			return (ft_gnl_setline(&buffer, line));
		}
		*line = ft_strfjoin(*line, ft_strdup(buf));
	}
	free(buffer);
	if (ft_strlen(*line) > 0)
		return (1);
	if (ret <= 0)
		return (ret);
	return (0);
}
Пример #8
0
int				get_next_line(int const fd, char **line)
{
	size_t			i;
	static t_list	*fds = NULL;
	char			*tmp;
	t_fd			*current;

	if (line == NULL || BUFF_SIZE <= 0)
		return (-1);
	*line = NULL;
	current = get_current_fd(fd, &fds);
	if (current->res && current->res[0])
	{
		i = 0;
		while (current->res[i] && current->res[i] != '\n')
			*line = ft_strfjoin(*line, ft_chartostar(current->res[i++]), 3);
		if (i == 0)
			*line = ft_strnew(0);
		if ((tmp = ft_strchr(&current->res[i], '\n')))
		{
			current->res = ft_strcpy(current->res, &tmp[1]);
			return (1);
		}
		current->res = NULL;
	}
	return (get_buf(fd, line, current));
}
Пример #9
0
int				ft_gnl(const int fd, char **line)
{
	static t_file	*myfile;
	t_file			*fptr;
	char			buf[BUFF_SIZE + 1];
	int				res;

	if (fd < 0 || !(line) || read(fd, buf, 0) < 0)
		return (-1);
	fptr = move_to_file(fd, &myfile);
	while ((res = read(fd, buf, BUFF_SIZE)))
	{
		buf[res] = '\0';
		fptr->str = ft_strfjoin(&fptr->str, buf);
		if (ft_strchr(buf, '\n'))
			break ;
	}
	if (res < BUFF_SIZE && !(ft_strlen(fptr->str)))
	{
		delete_current_file(&myfile, fptr, line);
		return (0);
	}
	buffer_update(fptr, line);
	return (1);
}
Пример #10
0
void	ft_cplace(int row, int column)
{
	char	*tmp;
	char	*tmp2;
	char	*tmp3;

	if (row < 1 || column < 1)
		return ;
	tmp = ft_itoa(row);
	tmp2 = ft_itoa(column);
	tmp3 = ft_strjoin("\033[", tmp);
	tmp3 = ft_strfjoin(&tmp3, ";");
	tmp3 = ft_strfjoin(&tmp3, tmp2);
	tmp3 = ft_strfjoin(&tmp3, "H");
	write(1, tmp3, ft_strlen(tmp3));
	free(tmp);
	free(tmp2);
	free(tmp3);
}
Пример #11
0
char	*ft_ftoa(double n)
{
	int		one;
	double	two;
	int		state;
	char	*ret;
	char	*ptr;

	state = (n < 0) ? 1 : 0;
	ret = ft_itoa(n);
	ptr = ft_strdup(".");
	ret = ft_strfjoin(&ret, &ptr, 3);
	n *= state ? -1 : 1;
	one = (int)n;
	two = n - one;
	while (++state && (size_t)state < (sizeof(n) - 1))
		two *= 10;
	ptr = ft_itoa((int)two);
	ret = ft_strfjoin(&ret, &ptr, 3);
	return (ret);
}
Пример #12
0
static int		get_bufn(char **lines, t_fd *current, char *buf)
{
	size_t	i;

	i = 0;
	if (buf[i] == '\n')
	{
		buf[i] = '\0';
		*lines = ft_strfjoin(*lines, ft_chartostar(buf[i]), 3);
		current->res = ft_strdup(&(ft_strchr(buf, '\0'))[1]);
		return (1);
	}
	return (0);
}
Пример #13
0
char *ft_dtoa(double x)
{
    char	*value;
    char	*intpart;
    char	*fracpart;
    int		maxpreci;

    intpart = ft_itoa((int)x);
    x -= (int)x;
    maxpreci = 6;
    while (x - ((int)x) != 0 && maxpreci)
    {
        x *= 10;
        maxpreci--;
    }
    fracpart = ft_itoa((int)x);
    value = ft_strfjoin(intpart, ft_strjoin(".", fracpart));
    free(intpart);
    free(fracpart);
    return (value);
}
Пример #14
0
static int		ft_gnl_setline(char **buffer, char **line)
{
	int				i;

	i = ft_strichr(*buffer, '\n');
	if (i < 0 && *line == NULL)
	{
		*line = ft_strdup(*buffer);
		return (0);
	}
	else if (i == 0 && *line == NULL)
		*line = ft_strnew(1);
	else if (i > 0)
	{
		if (*line == NULL)
			*line = ft_strsub(*buffer, 0, i);
		else
			*line = ft_strfjoin(*line, ft_strsub(*buffer, 0, i));
	}
	ft_strcpy(*buffer, ft_strchr(*buffer, '\n') + 1);
	return (1);
}
Пример #15
0
int		ft_sdkn_putinfos(t_game *game, int hits, int reset, int val)
{
	char		*str;
	char		*tmp;
	static int	h;
	static int	r;

	if (val == 1)
		h = hits;
	else if (val == 2)
		r = reset;
	else if (val == 3)
		return (h);
	else if (val == 4)
		return (r);
	else if (val == -1)
	{
		h += hits;
		r += reset;
	}
	else if (val == -2)
		h += hits;
	else if (val == -3)
		r += reset;
	if (val != 0)
		return (0);
	tmp = ft_itoa(h);
	str = ft_strfjoin2("Nombre de coups (", &tmp, 1);
	str = ft_strfjoin1(&str, ") - Nombre d'essais (", 1);
	tmp = ft_itoa(r);
	str = ft_strfjoin(&str, &tmp, 3);
	str = ft_strfjoin1(&str, ")", 1);
	ft_sdkn_putcmt(game->image.surf, str, -1, WIN_H - 25);
	free(str);
	return (0);
}