segfault cd after unset PWD after changed fint_it
This commit is contained in:
parent
5bdde9b3da
commit
c2f08b31e3
@ -111,6 +111,8 @@ void change_path(t_s_cmd *cmd)
|
||||
|
||||
i++;
|
||||
}
|
||||
if (tab)
|
||||
free_double(tab);
|
||||
}
|
||||
|
||||
void reboot_pwd(t_s_cmd *cmd, int i)
|
||||
@ -145,7 +147,7 @@ void open_directory(t_s_cmd *cmd)
|
||||
char **str;
|
||||
int j;
|
||||
|
||||
if (find_it(cmd->big_cmd->env, "PWD"))
|
||||
if (find_it(cmd->big_cmd->env, "PWD") != -1)
|
||||
{
|
||||
str = ft_split(cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")], '/');
|
||||
j = double_size(str);
|
||||
@ -167,9 +169,9 @@ void open_directory(t_s_cmd *cmd)
|
||||
return ;
|
||||
}
|
||||
char *p = ft_substr(cmd->big_cmd->env[find_it(cmd->big_cmd->env, "HOME")], 5, ft_strlen(cmd->big_cmd->env[find_it(cmd->big_cmd->env, "HOME")]));
|
||||
printf("%s\n", p);
|
||||
// printf("%s\n", p);
|
||||
if (chdir(p) == 0)
|
||||
if (find_it(cmd->big_cmd->env, "PWD"))
|
||||
if (find_it(cmd->big_cmd->env, "PWD") != -1)
|
||||
{
|
||||
cmd->big_cmd->env[find_it(cmd->big_cmd->env, "OLDPWD")] = ft_strjoin("OLD", cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")]);
|
||||
cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")] = ft_strjoin("PWD=", p);
|
||||
@ -182,8 +184,11 @@ void open_directory(t_s_cmd *cmd)
|
||||
reboot_pwd(cmd, j);
|
||||
if (chdir(cmd->args[1]) == 0)
|
||||
{
|
||||
if (find_it(cmd->big_cmd->env, "PWD"))
|
||||
if (find_it(cmd->big_cmd->env, "PWD") != -1)
|
||||
{
|
||||
change_path(cmd);
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -29,36 +29,26 @@ int check_variable(char *variable)
|
||||
return(0);
|
||||
}
|
||||
|
||||
// char *define_double_quotes(char *value)
|
||||
// char *check_value(char *value)
|
||||
// {
|
||||
// int i;
|
||||
// char *dest;
|
||||
//
|
||||
// i = find_len(value, 0, '=') + 2;
|
||||
|
||||
// i = find_len(value, 0, '=') + 1;
|
||||
// if (value[i] == '"')
|
||||
// dest = ft_substr()
|
||||
// {
|
||||
// printf("wait\n");
|
||||
// dest = ft_strdup(" ");
|
||||
// // dest = define_double_quotes(value);
|
||||
// }
|
||||
// else{
|
||||
// dest = ft_substr(value, 0, find_len(value, 0, ' '));
|
||||
// // printf("brrrrrrr------\n");
|
||||
|
||||
// }
|
||||
// return (dest);
|
||||
// }
|
||||
|
||||
char *check_value(char *value)
|
||||
{
|
||||
int i;
|
||||
char *dest;
|
||||
|
||||
i = find_len(value, 0, '=') + 1;
|
||||
if (value[i] == '"')
|
||||
{
|
||||
printf("wait\n");
|
||||
dest = ft_strdup(" ");
|
||||
// dest = define_double_quotes(value);
|
||||
}
|
||||
else{
|
||||
dest = ft_substr(value, 0, find_len(value, 0, ' '));
|
||||
// printf("brrrrrrr------\n");
|
||||
|
||||
}
|
||||
return (dest);
|
||||
}
|
||||
|
||||
void ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
{
|
||||
char *dest;
|
||||
@ -74,16 +64,15 @@ void ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
// 1
|
||||
return ;
|
||||
}
|
||||
dest = check_value(variable);
|
||||
// dest = check_value(variable);
|
||||
dest = ft_strdup(variable);
|
||||
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
||||
printf("%s\n", unset);
|
||||
while (cmd->big_cmd->env[i] != NULL)
|
||||
{
|
||||
if (ft_strncmp(unset, cmd->big_cmd->env[i], ft_strlen(unset)) == 0)
|
||||
{
|
||||
free(cmd->big_cmd->env[i]);
|
||||
cmd->big_cmd->env[i] = dest;
|
||||
// find_variable(unset, cmd);
|
||||
return ;
|
||||
}
|
||||
i++;
|
||||
@ -91,14 +80,8 @@ void ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
register_env(cmd, dest);
|
||||
if (dest)
|
||||
free(dest);
|
||||
// if (unset)
|
||||
// free(unset);
|
||||
// if (check_variable(v_v[0]) == 1)
|
||||
// {
|
||||
// tmp = ft_strdup(v_v[1]);
|
||||
// free(v_v[1]);
|
||||
// v_v[1] = check_value(tmp);
|
||||
// }
|
||||
if (unset)
|
||||
free(unset);
|
||||
}
|
||||
|
||||
void ft_export(t_s_cmd *cmd)
|
||||
|
||||
@ -108,15 +108,15 @@ void ft_env(t_s_cmd *cmd, char **env)
|
||||
cmd->big_cmd->env[i] = NULL;
|
||||
}
|
||||
|
||||
int find_pwd(t_s_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
// int find_pwd(t_s_cmd *cmd)
|
||||
// {
|
||||
// int i;
|
||||
|
||||
i = 0;
|
||||
while (cmd->big_cmd->env[i] && ft_strncmp(cmd->big_cmd->env[i], "PWD=", 4) != 0)
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
// i = 0;
|
||||
// while (cmd->big_cmd->env[i] && ft_strncmp(cmd->big_cmd->env[i], "PWD=", 4) != 0)
|
||||
// i++;
|
||||
// return (i);
|
||||
// }
|
||||
|
||||
void init_s_cmd(t_s_cmd *cmd, char **env)
|
||||
{
|
||||
|
||||
@ -69,7 +69,6 @@ void find_variable(char *variable, t_s_cmd *cmd)
|
||||
// j++;
|
||||
// while (cmd->big_cmd->env[i] && !(ft_strncmp(cmd->big_cmd->env[i], str, j) == 0))
|
||||
// i++;
|
||||
|
||||
if (i == tab_len(cmd->big_cmd->env))
|
||||
return ;
|
||||
unset_variable(cmd, i);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user