diff options
| author | salad <fmoenne-@student.le-101.fr> | 2020-04-30 14:06:35 +0200 | 
|---|---|---|
| committer | salad <fmoenne-@student.le-101.fr> | 2020-04-30 14:06:35 +0200 | 
| commit | 886a1125f558a791ab367d8a4dddd4f05bc9f1dd (patch) | |
| tree | f14006e4e5bf8b5a62adbd1fbaadf4496d10ceb5 | |
| parent | no inval read, *fin leaking (diff) | |
| download | 42-minishell-886a1125f558a791ab367d8a4dddd4f05bc9f1dd.tar.gz 42-minishell-886a1125f558a791ab367d8a4dddd4f05bc9f1dd.tar.bz2 42-minishell-886a1125f558a791ab367d8a4dddd4f05bc9f1dd.tar.xz 42-minishell-886a1125f558a791ab367d8a4dddd4f05bc9f1dd.tar.zst 42-minishell-886a1125f558a791ab367d8a4dddd4f05bc9f1dd.zip | |
alesgut (not gut)
Diffstat (limited to '')
| -rw-r--r-- | sa.lut | 2 | ||||
| -rw-r--r-- | src/ft_m_loop.c | 64 | 
2 files changed, 35 insertions, 31 deletions
| @@ -0,0 +1,2 @@ +salut les potes +' diff --git a/src/ft_m_loop.c b/src/ft_m_loop.c index cc83617..6e649b6 100644 --- a/src/ft_m_loop.c +++ b/src/ft_m_loop.c @@ -20,8 +20,11 @@  #include "ft_p_line.h"  #include "ft_s_lcom.h" +  static char -*ft_strjoin_m(char *s1, char *s2) +	*ft_strjoin_m(char *s1, +				  char *s2, +				  uint8_t mode)  {  	size_t	i;  	size_t	j; @@ -37,46 +40,45 @@ static char  		return (NULL);  	while (++i < size1)  		dst[i] = s1[i]; -    dst[i] = '\n'; -    i++; +	(mode == 0) ? dst[i++] = '\n' : 0;  	while (++j < size2)  		dst[i + j] = s2[j];  	dst[i + j] = '\0'; -	ft_memdel((void*)&s1); +	(mode == 0) ? ft_memdel((void*)&s1) : ft_memdel((void*)&s2);  	return (dst);  } -uint8_t -    ft_m_loop_cont(t_msh *msh, char *line, char *quote) +void +	ft_m_loop_cont(t_msh *msh, +				   char *line, +				   char *quote, +                   int8_t gnl)  { -    int8_t	gnl; -    uint16_t	len;      char	*prog;      char	*buf;      char	*fin; -    if (!(prog = ft_calloc(ft_strlen(line) + 1, sizeof(char)))) -        return (0); -    ft_memcpy(prog, line, (quote - line)); -    if (!(buf = ft_strdup(line + (quote - line) + 1))) -        return (0); -    gnl = 1; -	while (gnl > 0 && ((!(quote = ft_strrchr(buf, '\"'))) && (!(quote = ft_strrchr(buf, '\''))))) -    { -        ft_m_cont_prompt(); -        len = ft_strlen(buf); -        gnl = get_next_line(STDIN_FILENO, &line); -        buf = ft_strjoin_m(buf, line); -        ft_memdel((void*)&line); -    } -    fin = ft_strtrim(buf, "\"'"); -    ft_memdel((void*)&buf); -    fin = ft_strjoin(prog, fin); -    ft_p_line(fin, msh); -    ft_memdel((void*)&prog); -    ft_e_lcom(msh); -    ft_lcom_clear(&msh->curr); -    return (1); +	if (!(prog = ft_calloc(ft_strlen(line) + 1, sizeof(char))) || +		!(buf = ft_strdup(line + (quote - line) + 1))) +		return ; +	ft_memcpy(prog, line, (quote - line)); +	while (gnl > 0 && ((!(quote = ft_strrchr(buf, '\"'))) && +					   (!(quote = ft_strrchr(buf, '\''))))) +	{ +		ft_m_cont_prompt(); +		gnl = get_next_line(STDIN_FILENO, &line); +		buf = ft_strjoin_m(buf, line, 0); +		ft_memdel((void*)&line); +	} +	fin = ft_strtrim(buf, "\"'"); +	ft_memdel((void*)&buf); +	fin = ft_strjoin_m(prog, fin, 1); +	ft_p_line(fin, msh); +    ft_printf("fin : %s\n", fin); +	ft_memdel((void*)&prog); +	ft_memdel((void*)&fin); +	ft_e_lcom(msh); +	ft_lcom_clear(&msh->curr);  }  uint8_t @@ -102,7 +104,7 @@ uint8_t              }              else              { -                ft_m_loop_cont(msh, line, quote); +                ft_m_loop_cont(msh, line, quote, 1);                  if (line != NULL)                      ft_memdel((void*)&line);              } | 
