Merge branch 'sadjigui'
This commit is contained in:
commit
3931c09970
@ -104,9 +104,10 @@ int find_len(char *input, int i, char c);
|
|||||||
void lone_export(t_s_cmd *cmd);
|
void lone_export(t_s_cmd *cmd);
|
||||||
void find_variable(char *variable, t_s_cmd *cmd);
|
void find_variable(char *variable, t_s_cmd *cmd);
|
||||||
int find_it(char **str, char *s);
|
int find_it(char **str, char *s);
|
||||||
|
int check_variable(char *variable);
|
||||||
|
|
||||||
//real builtin
|
//real builtin
|
||||||
void print_env(char **tab);
|
void print_env(t_cmd *cmd);
|
||||||
void ft_env(t_s_cmd *cmd, char **env);
|
void ft_env(t_s_cmd *cmd, char **env);
|
||||||
void ft_exit(t_s_cmd *cmd);
|
void ft_exit(t_s_cmd *cmd);
|
||||||
void ft_export(t_s_cmd *cmd);
|
void ft_export(t_s_cmd *cmd);
|
||||||
|
|||||||
@ -111,6 +111,8 @@ void change_path(t_s_cmd *cmd)
|
|||||||
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
if (tab)
|
||||||
|
free_double(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
void reboot_pwd(t_s_cmd *cmd, int i)
|
void reboot_pwd(t_s_cmd *cmd, int i)
|
||||||
@ -145,7 +147,7 @@ void open_directory(t_s_cmd *cmd)
|
|||||||
char **str;
|
char **str;
|
||||||
int j;
|
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")], '/');
|
str = ft_split(cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")], '/');
|
||||||
j = double_size(str);
|
j = double_size(str);
|
||||||
@ -167,9 +169,9 @@ void open_directory(t_s_cmd *cmd)
|
|||||||
return ;
|
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")]));
|
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 (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, "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);
|
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);
|
reboot_pwd(cmd, j);
|
||||||
if (chdir(cmd->args[1]) == 0)
|
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);
|
change_path(cmd);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -195,20 +200,3 @@ void open_directory(t_s_cmd *cmd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_pwd(t_s_cmd *cmd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
char p[1024];
|
|
||||||
char *str;
|
|
||||||
|
|
||||||
i = 1;
|
|
||||||
str = getcwd(p, sizeof(p));
|
|
||||||
if (!str)
|
|
||||||
{
|
|
||||||
cmd->big_cmd->err_var = 1;
|
|
||||||
ft_putstr_fd("Minishell: pwd: Not found\n", 2);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
ft_putendl_fd(p, 1);
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -32,7 +32,7 @@ int is_builtin(char *cmd)
|
|||||||
void call_builtin(t_cmd *cmd)
|
void call_builtin(t_cmd *cmd)
|
||||||
{
|
{
|
||||||
if (!ft_strcmp(cmd->current_s_cmd->cmd, "env"))
|
if (!ft_strcmp(cmd->current_s_cmd->cmd, "env"))
|
||||||
print_env(cmd->env);
|
print_env(cmd);
|
||||||
if (!ft_strcmp(cmd->current_s_cmd->cmd, "export"))
|
if (!ft_strcmp(cmd->current_s_cmd->cmd, "export"))
|
||||||
ft_export(cmd->current_s_cmd);
|
ft_export(cmd->current_s_cmd);
|
||||||
if (!ft_strcmp(cmd->current_s_cmd->cmd, "unset"))
|
if (!ft_strcmp(cmd->current_s_cmd->cmd, "unset"))
|
||||||
|
|||||||
@ -12,21 +12,42 @@
|
|||||||
|
|
||||||
#include "../../includes/minishell.h"
|
#include "../../includes/minishell.h"
|
||||||
|
|
||||||
void print_env(char **tab)
|
void print_env(t_cmd *cmd)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (tab)
|
if (cmd->current_s_cmd->nb_args > 1)
|
||||||
{
|
{
|
||||||
while (tab[i])
|
ft_putstr_fd("Minishell: env: '", 2);
|
||||||
{
|
ft_putstr_fd(cmd->current_s_cmd->args[1], 2);
|
||||||
if (ft_strchr(tab[i], '='))
|
ft_putstr_fd("': No such file or directory\n", 2);
|
||||||
{
|
// 127
|
||||||
ft_putstr_fd(tab[i], 1);
|
|
||||||
ft_putstr_fd("\n", 1);
|
|
||||||
}
|
}
|
||||||
|
else if (cmd->env)
|
||||||
|
{
|
||||||
|
while (cmd->env[i])
|
||||||
|
{
|
||||||
|
if (ft_strchr(cmd->env[i], '='))
|
||||||
|
ft_putendl_fd(cmd->env[i], 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ft_pwd(t_s_cmd *cmd)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
char p[1024];
|
||||||
|
char *str;
|
||||||
|
|
||||||
|
i = 1;
|
||||||
|
str = getcwd(p, sizeof(p));
|
||||||
|
if (!str)
|
||||||
|
{
|
||||||
|
cmd->big_cmd->err_var = 1;
|
||||||
|
ft_putstr_fd("Minishell: pwd: Not found\n", 2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ft_putendl_fd(p, 1);
|
||||||
|
}
|
||||||
@ -17,47 +17,37 @@ int check_variable(char *variable)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
if (!ft_isalpha(variable[i]))
|
if (!ft_isalpha(variable[i]) && variable[i] != '_')
|
||||||
return(0);
|
return(1);
|
||||||
i++;
|
i++;
|
||||||
while(variable[i] != '=')
|
while(variable[i] && variable[i] != '=')
|
||||||
{
|
{
|
||||||
if(!ft_isalnum(variable[i]))
|
if(!ft_isalnum(variable[i]) && variable[i] != '_')
|
||||||
return(0);
|
return(1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return(1);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// char *define_double_quotes(char *value)
|
// char *check_value(char *value)
|
||||||
// {
|
// {
|
||||||
// int i;
|
// int i;
|
||||||
// char *dest;
|
// char *dest;
|
||||||
//
|
|
||||||
// i = find_len(value, 0, '=') + 2;
|
// i = find_len(value, 0, '=') + 1;
|
||||||
// if (value[i] == '"')
|
// 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");
|
||||||
|
|
||||||
char *check_value(char *value)
|
// }
|
||||||
{
|
// return (dest);
|
||||||
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)
|
void ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||||
{
|
{
|
||||||
@ -66,22 +56,23 @@ void ft_export_variable(t_s_cmd *cmd, char *variable)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
i = 0;
|
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 ;
|
return ;
|
||||||
}
|
}
|
||||||
// printf("jojo\n");
|
// dest = check_value(variable);
|
||||||
dest = check_value(variable);
|
dest = ft_strdup(variable);
|
||||||
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
||||||
printf("%s\n", unset);
|
|
||||||
while (cmd->big_cmd->env[i] != NULL)
|
while (cmd->big_cmd->env[i] != NULL)
|
||||||
{
|
{
|
||||||
if (ft_strncmp(unset, cmd->big_cmd->env[i], ft_strlen(unset)) == 0)
|
if (ft_strncmp(unset, cmd->big_cmd->env[i], ft_strlen(unset)) == 0)
|
||||||
{
|
{
|
||||||
free(cmd->big_cmd->env[i]);
|
free(cmd->big_cmd->env[i]);
|
||||||
cmd->big_cmd->env[i] = dest;
|
cmd->big_cmd->env[i] = dest;
|
||||||
// find_variable(unset, cmd);
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
@ -89,14 +80,8 @@ void ft_export_variable(t_s_cmd *cmd, char *variable)
|
|||||||
register_env(cmd, dest);
|
register_env(cmd, dest);
|
||||||
if (dest)
|
if (dest)
|
||||||
free(dest);
|
free(dest);
|
||||||
// if (unset)
|
if (unset)
|
||||||
// free(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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_export(t_s_cmd *cmd)
|
void ft_export(t_s_cmd *cmd)
|
||||||
|
|||||||
@ -54,7 +54,10 @@ void print_export(char *tmp)
|
|||||||
str1 = ft_substr(tmp, 0, find_len(tmp, i, '='));
|
str1 = ft_substr(tmp, 0, find_len(tmp, i, '='));
|
||||||
i = find_len(tmp, 0, '=') + 1;
|
i = find_len(tmp, 0, '=') + 1;
|
||||||
str2 = ft_substr(tmp, i, find_len(tmp, i, '\0'));
|
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(str1);
|
||||||
free(str2);
|
free(str2);
|
||||||
|
|
||||||
|
|||||||
@ -108,15 +108,15 @@ void ft_env(t_s_cmd *cmd, char **env)
|
|||||||
cmd->big_cmd->env[i] = NULL;
|
cmd->big_cmd->env[i] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int find_pwd(t_s_cmd *cmd)
|
// int find_pwd(t_s_cmd *cmd)
|
||||||
{
|
// {
|
||||||
int i;
|
// int i;
|
||||||
|
|
||||||
i = 0;
|
// i = 0;
|
||||||
while (cmd->big_cmd->env[i] && ft_strncmp(cmd->big_cmd->env[i], "PWD=", 4) != 0)
|
// while (cmd->big_cmd->env[i] && ft_strncmp(cmd->big_cmd->env[i], "PWD=", 4) != 0)
|
||||||
i++;
|
// i++;
|
||||||
return (i);
|
// return (i);
|
||||||
}
|
// }
|
||||||
|
|
||||||
void init_s_cmd(t_s_cmd *cmd, char **env)
|
void init_s_cmd(t_s_cmd *cmd, char **env)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -58,21 +58,29 @@ void unset_variable(t_s_cmd *cmd, int i)
|
|||||||
|
|
||||||
void find_variable(char *variable, t_s_cmd *cmd)
|
void find_variable(char *variable, t_s_cmd *cmd)
|
||||||
{
|
{
|
||||||
char *str;
|
// char *str;
|
||||||
int i;
|
int i;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
i = 0;
|
i = find_it(cmd->big_cmd->env, variable);
|
||||||
str = ft_strjoin(variable, "=");
|
// str = ft_strjoin(variable, "=");
|
||||||
j = 0;
|
j = 0;
|
||||||
while (str[j])
|
if (check_variable(variable) == 1)
|
||||||
j++;
|
{
|
||||||
while (cmd->big_cmd->env[i] && !(ft_strncmp(cmd->big_cmd->env[i], str, j) == 0))
|
ft_putstr_fd("Minishell: unset: `", 2);
|
||||||
i++;
|
ft_putstr_fd(variable, 2);
|
||||||
|
ft_putstr_fd("': not a valid identifier\n", 2);
|
||||||
|
// 2
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
// 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))
|
if (i == tab_len(cmd->big_cmd->env))
|
||||||
return ;
|
return ;
|
||||||
unset_variable(cmd, i);
|
unset_variable(cmd, i);
|
||||||
free(str);
|
// free(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ft_unset(t_s_cmd *cmd)
|
void ft_unset(t_s_cmd *cmd)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user