Compare commits

...

5 Commits

Author SHA1 Message Date
Camille Chauvet
d4cead2b0f clean: .env_fill.c.swp remove 2023-02-17 13:25:37 +01:00
Camille Chauvet
61cd1209ff Merge branch 'master' into camille 2023-02-17 13:24:52 +01:00
Camille Chauvet
642af26133 fix: leak with > but no file 2023-02-17 13:21:50 +01:00
Camille Chauvet
38e1b9834f Merge branch 'camille' 2023-02-17 13:08:06 +01:00
Etienne Rey-bethbeder
8b771d6615 Ajout d'une fonction t_list -> char** nommé 'env_to_strs' 2023-02-17 13:06:16 +01:00
8 changed files with 42 additions and 10 deletions

Binary file not shown.

Binary file not shown.

6
cmds.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 14:17:26 by cchauvet #+# #+# */
/* Updated: 2023/02/17 13:06:35 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 13:09:13 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -101,10 +101,8 @@ static int ft_cmds_fill(t_list **cmds, t_list **env, const char *line)
return (0);
}
t_list **ft_parse_cmds(char *line, t_list **env)
t_list **ft_parse_cmds(char *line, t_list **env, int infile, int outfile)
{
int infile;
int outfile;
t_list **cmds;
cmds = malloc(sizeof(t_list *));

33
env.c
View File

@ -6,7 +6,7 @@
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/02 14:39:56 by erey-bet #+# #+# */
/* Updated: 2023/02/16 16:24:21 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 13:05:29 by erey-bet ### ########.fr */
/* */
/* ************************************************************************** */
@ -205,7 +205,8 @@ int set_value_by_key(char *key, char *value, t_list **head)
int create_value_by_key(char *key, char *value, t_list **head)
{
t_env *content;
t_env *content;
if (set_value_by_key(key, value, head) == 0)
return (0);
content = ft_calloc(1, sizeof(t_env));
@ -217,6 +218,25 @@ int create_value_by_key(char *key, char *value, t_list **head)
return (0);
}
char **env_to_strs(t_list **head)
{
t_list *current;
t_env *content;
char **env;
int i;
current = *head;
env = ft_calloc(ft_lstsize(*head), sizeof(char *));
i = 0;
while (current->content)
{
content = current->content;
env[i++] = ft_strmerger(3, content->key, "=", content->value);
current = current->next;
}
return (env);
}
t_list **init_env(char **env)
{
t_list **head;
@ -241,3 +261,12 @@ t_list **init_env(char **env)
}
return (head);
}
/*int main(int argc, char *argv[], char **env)
{
t_list **new;
new = init_env(env);
ft_printf("%S", env_to_strs(new));
return (0);
}*/

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 17:52:10 by cchauvet #+# #+# */
/* Updated: 2023/02/16 17:52:29 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 13:19:09 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -33,6 +33,7 @@ static int ft_infile_is_valid(const char *line)
if (tab[i][0] == '<')
{
ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]);
ft_freer_tab_ultimate(1, tab);
return (0);
}
ft_freer_tab_ultimate(1, tab);

4
main.c
View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/16 15:16:14 by cchauvet #+# #+# */
/* Updated: 2023/02/17 13:05:54 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 13:13:19 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -45,6 +45,7 @@ int main(int ac, char **av, char **env)
ft_lstclear(data.env, env_del);
free(data.env);
free(line);
return (1);
}
infile = ft_infile(line);
if (infile == -2)
@ -53,6 +54,7 @@ int main(int ac, char **av, char **env)
ft_lstclear(data.env, env_del);
free(data.env);
free(line);
return (1);
}
cmds = ft_parse_cmds(line, data.env, infile, outfile);
if (cmds == NULL)

View File

@ -6,7 +6,7 @@
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/15 18:01:07 by cchauvet #+# #+# */
/* Updated: 2023/02/16 17:53:28 by cchauvet ### ########.fr */
/* Updated: 2023/02/17 13:19:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
@ -32,6 +32,7 @@ static int ft_outfile_is_valid(const char *line)
if (tab[i][0] == '>')
{
ft_eprintf("minishell: %s: must be followed by an infile\n", tab[i]);
ft_freer_tab_ultimate(1, tab);
return (0);
}
ft_freer_tab_ultimate(1, tab);

View File

@ -71,7 +71,8 @@ static int ft_special_char_dub(const char *str)
}
i = i + y;
}
i++;
else
i++;
}
return (0);
}