Example #1
0
t_list		*add_list(t_list *list)
{
	t_list		*ret;
	t_stru		*stru;
	int			exp;

	ret = NULL;
	stru = (t_stru*)ft_strnew(sizeof(t_stru));
	while (list)
	{
		stru->multi = STRU->multi * STRU->sign;
		stru->exp = STRU->exp;
		stru->sign = 1;
		while (list->next && STRU->exp == STRU_NEXT->exp)
		{
			stru->multi += STRU_NEXT->multi * STRU_NEXT->sign;
			list = list->next;
		}
		if (stru->multi != 0.0)
			ft_lstaddend(stru, sizeof(t_stru), &ret);
		ft_bzero(stru, sizeof(t_stru));
		list = list->next;
	}
	if (ret == NULL)
		ft_lstaddend(stru, sizeof(t_stru), &ret);
	return (ret);
}
Example #2
0
t_list	*ft_lstsplit(char const *s, char c)
{
	t_list	*lst_begin;
	char	*str;
	char	*tmp;
	int		x;

	if (!s)
		return (NULL);
	str = (char *)s;
	lst_begin = NULL;
	while (*str)
	{
		x = 0;
		while (*str == c && *str)
			str++;
		if (!*str)
			break ;
		while (str[x] != c && str[x])
			x++;
		tmp = ft_strndup(str, x);
		ft_lstaddend(&lst_begin, ft_lstnew(tmp, ft_strlen(tmp) * sizeof(char)));
		str = &str[x];
	}
	return (lst_begin);
}
Example #3
0
static void	renvoie(t_liste **lst_f, int *opt, struct dirent *lrd, char *arg)
{
	struct stat	*llstat;

	llstat = (struct stat*)malloc(sizeof(struct stat));
	if (opt[0] == 1 || opt[4] == 1 || opt[5] == 1)
		lstat(ft_path(arg, lrd->d_name), llstat);
	if (opt[1] == 1 || lrd->d_name[0] != '.')
		ft_lstaddend(lst_f, ft_ajt_lst(lrd, llstat, opt, arg));
}
Example #4
0
int					write_void_byte(t_list **bytes_end)
{
	t_list			*tmp;
	unsigned char	zero;

	zero = 0;
	if (!(tmp = ft_lstnew(&zero, sizeof(unsigned char))))
		return (0);
	ft_lstaddend(bytes_end, tmp);
	return (1);
}
Example #5
0
t_list	*ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
	t_list *new_lst;
	t_list *tmp_nod;

	new_lst = NULL;
	if (lst == NULL || f == NULL)
		return (NULL);
	while (lst != NULL)
	{
		tmp_nod = ft_noddup(lst, NULL);
		ft_lstaddend(&new_lst, ft_noddup((*f)(tmp_nod), NULL));
		lst = lst->next;
		free(tmp_nod->content);
		free(tmp_nod);
		tmp_nod = NULL;
	}
	ft_lstaddend(&new_lst, NULL);
	return (new_lst);
}
Example #6
0
void		add_to_queue(t_env *env, void (*method)(t_env *env))
{
	t_list		*list;

	list = ft_lstnewfrom(method, sizeof(method));
	pthread_mutex_lock(&env->queuemutex);
	if (!env->queue)
		env->queue = list;
	else
		ft_lstaddend(env->queue, list);
	pthread_mutex_unlock(&env->queuemutex);
}
Example #7
0
static t_list		*get_cut(t_list **list, int fd, int *ret)
{
	t_list	*lst;
	char	*buf;

	if (!(buf = (char *)malloc(sizeof(char) * (BUF_SIZE + 1))))
		return (NULL);
	*ret = read(fd, buf, BUF_SIZE);
	buf[BUF_SIZE] = '\0';
	lst = ft_lstln(buf, BUF_SIZE);
	ft_lstaddend(list, lst);
	return (lst);
}
Example #8
0
int		argument_is_in_quotes(char *line, t_list **list, int x)
{
	char	*str;
	int		y;

	if (!(y = dist_to_next_quote(line + x, line[x])))
		return (0);
	else if (y == 1)
	{
		ft_lstaddend(list, ft_lstnew(ft_strdup(""), 1));
		return (x + 2);
	}
	else
	{
		if (!(str = ft_strndup(line + x, y + 1)))
			return (0);
		ft_lstaddend(list, ft_lstnew(str, ft_strlen(str) + 1));
		free(str);
		y++;
	}
	return (x + y);
}
Example #9
0
static int		read_to_lst(t_fd *fdatas)
{
	t_list	*new_lst;
	char	*buffer;

	buffer = (char *)malloc(BUFF_SIZE + 1);
	if (buffer == NULL)
		return (-1);
	new_lst = ft_lstln(buffer, BUFF_SIZE);
	if (new_lst == NULL)
		return (-1);
	ft_lstaddend(&(fdatas->lst), new_lst);
	return (read(fdatas->fd, (char *)(new_lst->content), BUFF_SIZE));
}
Example #10
0
t_list	*ft_lstsplit(char const *s, char c)
{
	t_list	*lst;
	char	**ssplit;
	size_t	i;

	i = 0;
	ssplit = ft_strsplit(s, c);
	lst = ft_lstnew(ssplit[i], ft_strlen(ssplit[i]));
	if (lst == NULL)
		return (NULL);
	while (ssplit[i + 1])
	{
		i++;
		ft_lstaddend(&lst, ft_lstnew(ssplit[i], ft_strlen(ssplit[i])));
	}
	return (lst);
}
Example #11
0
int				gnl_aux(int const fd, t_list **prest, t_list **plst, int *pj)
{
	char			*s;
	int				i;

	s = malloc(BUFF_SIZE);
	if (s == NULL)
		return (-1);
	i = read(fd, s, BUFF_SIZE);
	if (i > 0)
	{
		*pj = split(s, (size_t)i, prest);
		ft_lstaddend(s, ((*pj) < 0 ? (size_t)i : (size_t)(*pj)), plst);
		i = 1;
	}
	free(s);
	return (i);
}
Example #12
0
t_list	*ft_lststrsplit(char const *str, char c)
{
    char	**tab;
    t_list	*newlst;
    t_list	*newelem;

    tab = ft_strsplit(str, c);
    newlst = ft_lstnew(*tab, ft_strlen(*tab) + 1);
    tab++;
    while (*tab)
    {
        newelem = ft_lstnew(*tab, ft_strlen(*tab) + 1);
        ft_lstaddend(&newlst, newelem);
        tab++;
    }
    ft_memdel((void**)tab);
    return (newlst);
}
Example #13
0
t_list	*ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
	t_list		**fresh_lst;
	t_list		*new_link;

	if (!(fresh_lst = ((t_list**)malloc(sizeof(t_list *)))))
		return (NULL);
	*fresh_lst = NULL;
	while (lst != NULL)
	{
		if (!(new_link = (t_list*)malloc(sizeof(t_list))))
			return (NULL);
		new_link = f(lst);
		ft_lstaddend(fresh_lst, new_link);
		free(new_link);
		lst = lst->next;
	}
	return (*fresh_lst);
}
Example #14
0
const char	*handle_nonmodulo(const char *format, t_list *output)
{
	char	*modulo_pos;
	char	*stock;
	t_list	*lst;

	modulo_pos = ft_strchr(format, '%');
	if (modulo_pos == format)
		return (format);
	if (modulo_pos)
		stock = ft_strsub(format, 0, modulo_pos - format);
	else
		stock = ft_strdup(format);
	if (!(lst = ft_lstnew(NULL, 0)))
		exit(myerror("Null malloc"));
	lst->content = (void*)stock;
	lst->content_size = 1;
	ft_lstaddend(output, lst);
	return (format + ft_strlen(stock));
}
Example #15
0
t_list			*ft_strsplitlst(char const *s, char c)
{
	t_list	*res;
	t_list	*temp;
	int		i;
	int		len;

	i = 0;
	res = NULL;
	while (s[i] != '\0')
	{
		if (s[i] != c)
		{
			len = ft_sizeofcontent(s, c, i);
			temp = ft_lstnew((void *)ft_strsub(s, i, len), len + 1);
			res = ft_lstaddend(&res, temp);
			while (s[i] != c && s[i] != '\0')
				i++;
		}
		else
			i++;
	}
	return (res);
}