Exemple #1
0
int			get_next_line(int const fd, char **line)
{
	static int		index = -1;
	static char		str[BUFF_SIZE + 4];
	static int		ret;
	int				i;

	ft_init_var(&i, line);
	ft_test_index(&index, &ret, fd, str);
	while (ret != -1 && str[i + index] != '\n' && str[i + index] != EOF)
	{
		if (i + index == ret)
		{
			if (ft_join(line, i, index, str) != -1
					&& (i = test_loop(&ret, str, fd)) == 1)
				return (0);
			if (i == -1)
				return (-1);
			index = 0;
		}
		else
			i++;
	}
	if (ret == -1 || ft_join(line, i, index, str) == -1)
		return (-1);
	index = i + index + 1;
	return (1);
}
Exemple #2
0
char				*exit_mode(t_shell *shell, char *str, int j)
{
	ft_putendl(NULL);
	if (!j)
	{
		ft_memdel((void **)&shell->hist->str);
		shell->hist->str = ft_strdup(str);
	}
	else
	{
		if (j == 2)
			ft_join(&shell->hist->str, "\n");
		ft_join(&shell->hist->str, ft_strdup(str));
	}
	return (str);
}
Exemple #3
0
int			get_next_line(int const fd, char **line)
{
	static char	*chr_ret;
	char		buf[BUFF_SIZE + 1];
	int			nb;

	if (!line)
		return (-1);
	if (fd > -1)
	{
		*line = ft_strnew(1);
		if (chr_ret != NULL)
		{
			*line = ft_strdup(chr_ret);
			free(chr_ret);
		}
		while (((chr_ret = ft_strchr(*line, '\n')) == NULL)
				&& ((nb = read(fd, buf, BUFF_SIZE)) > 0))
			ft_join(line, buf, nb);
		if (nb == 0 && chr_ret == NULL)
			return (0);
		nb = (nb == -1) ? -1 : 1;
		ft_sub(line, &chr_ret, nb);
		return (nb);
	}
	else
		return (-1);
}
Exemple #4
0
char			*ft_strjoins(char const *s1, char const *s2)
{
	int		len1;
	int		len2;
	char	*join;

	if (!s1 || !s2)
		return (NULL);
	len1 = ft_strlen(s1);
	len2 = ft_strlen(s2);
	join = ft_join(s1, s2, len1, len2);
	return (join);
}
Exemple #5
0
void				replace_word(t_line *list, char **str, int len)
{
	int				i;
	int				j;
	char			*str1;

	i = ft_strlen(*str) - 1 - len;
	j = 0;
	if (i >= 0)
		str1 = ft_strdup(&(*str)[i + 1]);
	while (i >= 0 && ft_isalnum((*str)[i]))
	{
		i--;
		j++;
	}
	if (j)
		(*str)[++i] = '\0';
	ft_join(str, list->str);
	if (!str1 || !*str1)
		ft_join(str, " ");
	else
		ft_join(str, str1);
}
Exemple #6
0
int				get_next_line(int const fd, char **line)
{
	static char	*save;
	char		buffer[BUFF_SIZE + 1];
	int			nbyte;

	if (fd < 0 || BUFF_SIZE < 1)
		return (-1);
	if (save == NULL)
		save = ft_memalloc(1);
	while (!ft_strchr(save, '\n') && (nbyte = read(fd, &buffer, BUFF_SIZE)) > 0)
	{
		buffer[nbyte] = '\0';
		save = ft_join(save, buffer);
	}
	if (nbyte == -1)
		return (-1);
	ft_gnltest(&line, &save);
	if (!save && ft_strlen(*line) == 0)
		return (0);
	return (1);
}