예제 #1
0
파일: ft_strsplit.c 프로젝트: Arubinu/alum1
static void	ft_while(int **n, char ***tab, const char *s, char c)
{
	int		len;

	len = 0;
	while (*(s + **n))
	{
		if (*(s + **n) == c)
		{
			if (*(s + **n + 1) != c)
			{
				*(*n + 1) += 1;
				len = ft_strclen(s + **n + 1, c);
				*(*tab + *(*n + 1)) = ft_strnew(len + 1);
			}
		}
		else if ((!**n && *s != c) || (**n && *(s + **n - 1) == c))
		{
			*(*n + 1) += (*(*n + 1) < 0) ? 1 : 0;
			*(*tab + *(*n + 1)) = ft_strcut(s + **n, c);
			**n += ft_strclen(s + **n, c) - 1;
		}
		**n += 1;
	}
	return ;
}
예제 #2
0
char        *ft_file_get_contents(char *filename, int offset, int len)
{
    char    *buffer;
    char    *ctn;
    char    *tmpCtn;
    int     fd;
    size_t  resRead;

    if ((fd = ft_fopen(filename, "r")) <= 0)
        return (NULL);
    buffer = ft_strnew(1024);
    ctn = ft_strnew(1024);
    while ((resRead = read(fd, buffer, 1024)) > 0)
    {
        if (resRead < 1024)
            buffer[resRead] = '\0';
        tmpCtn = ft_strnew(ft_strlen(ctn) + resRead);
        tmpCtn = ft_strcpy(tmpCtn, ctn);
        tmpCtn = ft_strcat(tmpCtn, buffer);
        ctn = tmpCtn;
    }
    if (offset != 0 && (int)(ft_strlen(ctn)) > offset)
        ctn = ft_strcut(ctn, offset);
    if (len != 0)
        ctn = ft_strcutend(ctn, len);
    return (ctn);
}
예제 #3
0
int					get_next_line(int const fd, char **line)
{
	static t_line	*begin = NULL;
	int				test;
	char			*tmp;

	test = -1;
	if (fd < 0 || !line || read(fd, NULL, 0) < 0
		|| (test = ft_findread(&begin, begin, fd, FIND)) <= 0)
		return ((fd < 0 ? ft_gnl_reset(&begin) : test));
	*line = ft_memalloc(1);
	while (!(test = ft_strcut(DATA, '\n', RET))
		&& (tmp = *line)
		&& (*line = ft_strjoin(*line, DATA))
		&& (RET = ft_findread(&begin, begin, fd, READ))
		&& ft_freegiveone((void **)&tmp))
		if (!(*line))
			return (-1);
	if (RET && test)
	{
		tmp = *line;
		*line = ft_strjoin(*line, DATA);
		free(tmp);
		RET = RET - test;
		ft_strncpy(DATA, DATA + test, RET);
	}
	return ((RET ? 1 : ft_free_line(&begin, begin)));
}
예제 #4
0
파일: strtrim.c 프로젝트: DylanLEBLOND/C
void		ft_trimdigit(char *s, int pos)
{
	int		i;

	if (!s)
		return ;
	if (s[pos] == '.')
		ft_strcut(s);
	ft_trimechap(s, pos);
	if (s[pos] == '-')
		ft_strcut(s);
	i = pos;
	while (s[i] && ft_isdigit(s[i]))
		i++;
	while (s[pos] && s[i])
	{
		s[pos++] = s[i];
		i++;
	}
	while (s[pos])
		s[pos] = '\0';
}
예제 #5
0
char	*build_cmd(char **env, char *cmd, int lret)
{
	char	*tmp;

	cmd = sup_replace(cmd);
	cmd = ft_strcut(cmd, ' ');
	if (env && *env)
	{
		tmp = ft_strdup(cmd);
		free(cmd);
		cmd = replace_env(env, tmp, lret);
		free(tmp);
	}
	return (cmd);
}