norm complete
This commit is contained in:
parent
3abc8c5738
commit
908fc5de8c
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* export.c :+: :+: :+: */
|
/* export.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: syd <syd@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/28 23:26:59 by sadjigui #+# #+# */
|
/* Created: 2022/02/28 23:26:59 by sadjigui #+# #+# */
|
||||||
/* Updated: 2022/04/19 13:22:08 by apommier ### ########.fr */
|
/* Updated: 2022/04/19 23:11:33 by syd ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -29,6 +29,14 @@ int check_variable(char *variable)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int reatribute_variable(t_s_cmd *cmd, int index, char *dest, char *unset)
|
||||||
|
{
|
||||||
|
free (cmd->big_cmd->env[index]);
|
||||||
|
cmd->big_cmd->env[index] = dest;
|
||||||
|
free(unset);
|
||||||
|
return (check_return(cmd, 0));
|
||||||
|
}
|
||||||
|
|
||||||
int ft_export_variable(t_s_cmd *cmd, char *variable)
|
int ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||||
{
|
{
|
||||||
char *dest;
|
char *dest;
|
||||||
@ -46,12 +54,7 @@ int ft_export_variable(t_s_cmd *cmd, char *variable)
|
|||||||
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
||||||
index = find_it(cmd->big_cmd->env, unset);
|
index = find_it(cmd->big_cmd->env, unset);
|
||||||
if (index != -1)
|
if (index != -1)
|
||||||
{
|
return (reatribute_variable(cmd, index, dest, unset));
|
||||||
free (cmd->big_cmd->env[index]);
|
|
||||||
cmd->big_cmd->env[index] = dest;
|
|
||||||
free(unset);
|
|
||||||
return (check_return(cmd, 0));
|
|
||||||
}
|
|
||||||
register_env(cmd, dest);
|
register_env(cmd, dest);
|
||||||
if (dest)
|
if (dest)
|
||||||
free(dest);
|
free(dest);
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* init_builtin.c :+: :+: :+: */
|
/* init_builtin.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: syd <syd@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/02/28 17:17:01 by sadjigui #+# #+# */
|
/* Created: 2022/02/28 17:17:01 by sadjigui #+# #+# */
|
||||||
/* Updated: 2022/04/19 13:17:02 by apommier ### ########.fr */
|
/* Updated: 2022/04/19 23:27:08 by syd ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -54,16 +54,7 @@ void register_env(t_s_cmd *cmd, char *variable)
|
|||||||
tmp[i] = ft_strdup(variable);
|
tmp[i] = ft_strdup(variable);
|
||||||
tmp[i + 1] = NULL;
|
tmp[i + 1] = NULL;
|
||||||
free_double(cmd->big_cmd->env);
|
free_double(cmd->big_cmd->env);
|
||||||
cmd->big_cmd->env = (char **)malloc(sizeof(char *) * (tab_len(tmp) + 1));
|
cmd->big_cmd->env = ft_dup_double(tmp);
|
||||||
if (!cmd->big_cmd->env)
|
|
||||||
printf("no env\n");
|
|
||||||
i = 0;
|
|
||||||
while (tmp[i])
|
|
||||||
{
|
|
||||||
cmd->big_cmd->env[i] = ft_strdup(tmp[i]);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
cmd->big_cmd->env[i] = NULL;
|
|
||||||
if (tmp)
|
if (tmp)
|
||||||
free_double(tmp);
|
free_double(tmp);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* unset.c :+: :+: :+: */
|
/* unset.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: syd <syd@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/11 18:26:29 by sadjigui #+# #+# */
|
/* Created: 2022/03/11 18:26:29 by sadjigui #+# #+# */
|
||||||
/* Updated: 2022/04/19 13:18:52 by apommier ### ########.fr */
|
/* Updated: 2022/04/19 23:59:16 by syd ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -27,16 +27,13 @@ void unset_variable(t_s_cmd *cmd, int i)
|
|||||||
{
|
{
|
||||||
if (a != i)
|
if (a != i)
|
||||||
{
|
{
|
||||||
tmp[b] = ft_substr(cmd->big_cmd->env[a], 0, ft_strlen(cmd->big_cmd->env[a]));
|
tmp[b] = ft_strdup(cmd->big_cmd->env[a]);
|
||||||
b++;
|
b++;
|
||||||
}
|
}
|
||||||
a++;
|
a++;
|
||||||
}
|
}
|
||||||
tmp[b] = NULL;
|
tmp[b] = NULL;
|
||||||
free_double(cmd->big_cmd->env);
|
free_double(cmd->big_cmd->env);
|
||||||
a = 0;
|
|
||||||
if (!cmd->big_cmd->env)
|
|
||||||
printf("no env\n");
|
|
||||||
cmd->big_cmd->env = ft_dup_double(tmp);
|
cmd->big_cmd->env = ft_dup_double(tmp);
|
||||||
if (tmp)
|
if (tmp)
|
||||||
free_double(tmp);
|
free_double(tmp);
|
||||||
|
|||||||
@ -3,10 +3,10 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* utils_builtin.c :+: :+: :+: */
|
/* utils_builtin.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
/* By: syd <syd@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/03/16 15:04:12 by sadjigui #+# #+# */
|
/* Created: 2022/03/16 15:04:12 by sadjigui #+# #+# */
|
||||||
/* Updated: 2022/04/19 13:20:42 by apommier ### ########.fr */
|
/* Updated: 2022/04/20 00:13:17 by syd ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -25,9 +25,13 @@ int find_len(char *input, int i, char c)
|
|||||||
int find_it(char **str, char *s)
|
int find_it(char **str, char *s)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int size;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (str[i] && (ft_strncmp(str[i], s, ft_strlen(s)) || (!ft_strncmp(str[i], s, ft_strlen(s)) && (str[i][ft_strlen(s)] != '=' && str[i][ft_strlen(s)] != 0))))
|
size = ft_strlen(s);
|
||||||
|
while (str[i] && (ft_strncmp(str[i], s, size)
|
||||||
|
|| (!ft_strncmp(str[i], s, size)
|
||||||
|
&& (str[i][size] != '=' && str[i][size] != 0))))
|
||||||
i++;
|
i++;
|
||||||
if (str[i] == NULL)
|
if (str[i] == NULL)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user