cd and unset
This commit is contained in:
parent
0ea63d6d6c
commit
5bdde9b3da
@ -17,16 +17,16 @@ int check_variable(char *variable)
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (!ft_isalpha(variable[i]))
|
||||
return(0);
|
||||
if (!ft_isalpha(variable[i]) && variable[i] != '_')
|
||||
return(1);
|
||||
i++;
|
||||
while(variable[i] != '=')
|
||||
while(variable[i] && variable[i] != '=')
|
||||
{
|
||||
if(!ft_isalnum(variable[i]))
|
||||
return(0);
|
||||
if(!ft_isalnum(variable[i]) && variable[i] != '_')
|
||||
return(1);
|
||||
i++;
|
||||
}
|
||||
return(1);
|
||||
return(0);
|
||||
}
|
||||
|
||||
// char *define_double_quotes(char *value)
|
||||
@ -66,12 +66,14 @@ void ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (check_variable(variable) == 0)
|
||||
if (check_variable(variable) == 1)
|
||||
{
|
||||
printf("Voir bash\n");
|
||||
ft_putstr_fd("Minishell: export: ", 2);
|
||||
ft_putstr_fd(variable, 2);
|
||||
ft_putstr_fd(": not a valid identifier\n", 2);
|
||||
// 1
|
||||
return ;
|
||||
}
|
||||
// printf("jojo\n");
|
||||
dest = check_value(variable);
|
||||
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
||||
printf("%s\n", unset);
|
||||
|
||||
@ -54,7 +54,10 @@ void print_export(char *tmp)
|
||||
str1 = ft_substr(tmp, 0, find_len(tmp, i, '='));
|
||||
i = find_len(tmp, 0, '=') + 1;
|
||||
str2 = ft_substr(tmp, i, find_len(tmp, i, '\0'));
|
||||
printf("declare -x %s=\"%s\"\n", str1, str2);
|
||||
printf("declare -x %s", str1);
|
||||
if (next_space(str2, 0) != '\0')
|
||||
printf("=\"%s\"", str2);
|
||||
printf("\n");
|
||||
free(str1);
|
||||
free(str2);
|
||||
|
||||
|
||||
@ -58,21 +58,22 @@ void unset_variable(t_s_cmd *cmd, int i)
|
||||
|
||||
void find_variable(char *variable, t_s_cmd *cmd)
|
||||
{
|
||||
char *str;
|
||||
// char *str;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
i = 0;
|
||||
str = ft_strjoin(variable, "=");
|
||||
i = find_it(cmd->big_cmd->env, variable);
|
||||
// str = ft_strjoin(variable, "=");
|
||||
j = 0;
|
||||
while (str[j])
|
||||
j++;
|
||||
while (cmd->big_cmd->env[i] && !(ft_strncmp(cmd->big_cmd->env[i], str, j) == 0))
|
||||
i++;
|
||||
// while (str[j])
|
||||
// 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);
|
||||
free(str);
|
||||
// free(str);
|
||||
}
|
||||
|
||||
void ft_unset(t_s_cmd *cmd)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user