fix norm all files
This commit is contained in:
parent
c492d6416d
commit
0af263e106
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/21 18:30:26 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/19 12:32:13 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:15:09 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,9 +14,9 @@
|
||||
|
||||
void del_one(t_s_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
char *r;
|
||||
int i;
|
||||
int j;
|
||||
char *r;
|
||||
|
||||
if (find_it(cmd->big_cmd->env, "PWD") != -1)
|
||||
{
|
||||
@ -30,26 +30,16 @@ void del_one(t_s_cmd *cmd)
|
||||
cmd->big_cmd->env[j] = ft_strdup(r);
|
||||
else
|
||||
cmd->big_cmd->env[j] = ft_strdup("PWD=/");
|
||||
|
||||
if (r)
|
||||
free(r);
|
||||
if (r)
|
||||
free(r);
|
||||
}
|
||||
}
|
||||
|
||||
void add_one(t_s_cmd *cmd)
|
||||
{
|
||||
// char *r;
|
||||
// char *s;
|
||||
|
||||
// s = ft_strjoin(cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")], "/");
|
||||
// r = ft_strjoin(s, str);
|
||||
// // free(cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")]);
|
||||
// cmd->big_cmd->env[find_it(cmd->big_cmd->env, "PWD")] = ft_strdup(r);
|
||||
// free(r);
|
||||
// free(s);
|
||||
char p[1024];
|
||||
char *str;
|
||||
int i;
|
||||
char p[1024];
|
||||
char *str;
|
||||
int i;
|
||||
|
||||
i = find_it(cmd->big_cmd->env, "PWD");
|
||||
str = getcwd(p, sizeof(p));
|
||||
@ -59,31 +49,17 @@ void add_one(t_s_cmd *cmd)
|
||||
|
||||
void change_path(t_s_cmd *cmd)
|
||||
{
|
||||
// char **tab;
|
||||
int old;
|
||||
int pwd;
|
||||
int old;
|
||||
int pwd;
|
||||
|
||||
// tab = ft_split(cmd->args[1], '/');
|
||||
if (find_it(cmd->big_cmd->env, "OLDPWD") != -1)
|
||||
{
|
||||
pwd = find_it(cmd->big_cmd->env, "PWD");
|
||||
old = find_it(cmd->big_cmd->env, "OLDPWD");
|
||||
free(cmd->big_cmd->env[old]);
|
||||
cmd->big_cmd->env[old] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]);
|
||||
// old = 0;
|
||||
// while (tab[old])
|
||||
// {
|
||||
// if (ft_strcmp(tab[old], "..") == 0)
|
||||
// del_one(cmd);
|
||||
// else
|
||||
// old++;
|
||||
// }
|
||||
}
|
||||
add_one(cmd);
|
||||
|
||||
|
||||
// if (tab)
|
||||
// free_double(tab);
|
||||
}
|
||||
|
||||
void reboot_pwd(t_s_cmd *cmd, int i)
|
||||
@ -103,49 +79,42 @@ void reboot_pwd(t_s_cmd *cmd, int i)
|
||||
|
||||
void check_home(t_s_cmd *cmd, char *p)
|
||||
{
|
||||
int home;
|
||||
int len_home;
|
||||
int old_pwd;
|
||||
int pwd;
|
||||
int home;
|
||||
int len_home;
|
||||
int old_pwd;
|
||||
int pwd;
|
||||
|
||||
home = find_it(cmd->big_cmd->env, "HOME");
|
||||
len_home = ft_strlen(cmd->big_cmd->env[home]);
|
||||
old_pwd = find_it(cmd->big_cmd->env, "OLDPWD");
|
||||
pwd = find_it(cmd->big_cmd->env, "PWD");
|
||||
|
||||
p = ft_substr(cmd->big_cmd->env[home], 5, ft_strlen(cmd->big_cmd->env[len_home]));
|
||||
if (chdir(p) == 0)
|
||||
{
|
||||
if (find_it(cmd->big_cmd->env, "PWD") != -1)
|
||||
{
|
||||
if (find_it(cmd->big_cmd->env, "OLDPWD") != -1)
|
||||
cmd->big_cmd->env[old_pwd] = ft_strjoin("OLD", cmd->big_cmd->env[pwd]);
|
||||
cmd->big_cmd->env[pwd] = ft_strjoin("PWD=", p);
|
||||
}
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
int open_directory(t_s_cmd *cmd)
|
||||
{
|
||||
char *p;
|
||||
int j;
|
||||
char *p;
|
||||
int j;
|
||||
|
||||
p = NULL;
|
||||
if (find_it(cmd->big_cmd->env, "PWD") != -1)
|
||||
j = size_path(cmd->big_cmd->env);
|
||||
if (cmd->nb_args > 2)
|
||||
{
|
||||
// ft_putstr_fd("Minishell: cd: too many arguments\n", 2);
|
||||
// return ;
|
||||
return (cd_error(cmd, "Minishell: cd: too many arguments", 1));
|
||||
}
|
||||
if (!cmd->args[1])
|
||||
{
|
||||
if (find_it(cmd->big_cmd->env, "HOME") < 0)
|
||||
{
|
||||
// ft_putstr_fd("Minishell: cd: HOME not set\n", 2);
|
||||
// return ;
|
||||
return (cd_error(cmd, "Minishell: cd: HOME not set", 1));
|
||||
}
|
||||
check_home(cmd, p);
|
||||
}
|
||||
if (tab_len(cmd->args) == 2)
|
||||
@ -167,4 +136,3 @@ int open_directory(t_s_cmd *cmd)
|
||||
}
|
||||
return (check_return(cmd, 0));
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/11 20:52:56 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/09 04:55:48 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:19:31 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,9 +14,9 @@
|
||||
|
||||
int ft_echo(t_s_cmd *d)
|
||||
{
|
||||
int i;
|
||||
size_t j;
|
||||
int is_option;
|
||||
int i;
|
||||
size_t j;
|
||||
int is_option;
|
||||
|
||||
i = 1;
|
||||
is_option = 0;
|
||||
@ -32,6 +32,7 @@ int ft_echo(t_s_cmd *d)
|
||||
i++;
|
||||
}
|
||||
if (d->args[i])
|
||||
{
|
||||
while (d->args[i])
|
||||
{
|
||||
printf("%s", d->args[i]);
|
||||
@ -39,6 +40,7 @@ int ft_echo(t_s_cmd *d)
|
||||
printf(" ");
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (is_option == 0)
|
||||
printf("\n");
|
||||
return (check_return(d, 0));
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/09 21:09:47 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/18 03:10:15 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:22:34 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -36,8 +36,8 @@ int print_env(t_cmd *cmd)
|
||||
|
||||
int ft_pwd(t_s_cmd *cmd)
|
||||
{
|
||||
char p[1024];
|
||||
char *str;
|
||||
char p[1024];
|
||||
char *str;
|
||||
|
||||
str = getcwd(p, sizeof(p));
|
||||
if (!str)
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/15 11:23:32 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/19 09:04:57 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:17:35 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -41,7 +41,6 @@ void ft_exit(t_s_cmd *cmd)
|
||||
}
|
||||
else if (cmd->nb_args == 1)
|
||||
exit_shell(cmd->big_cmd, 0);
|
||||
|
||||
while (cmd->args[1][++i])
|
||||
{
|
||||
if ((!ft_isdigit(cmd->args[1][i]) && !(cmd->args[1][i] == '-' && ft_isdigit(cmd->args[1][i + 1]))))
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/28 23:26:59 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/09 04:59:38 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:22:08 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -18,42 +18,22 @@ int check_variable(char *variable)
|
||||
|
||||
i = 0;
|
||||
if (!ft_isalpha(variable[i]) && variable[i] != '_')
|
||||
return(1);
|
||||
return (1);
|
||||
i++;
|
||||
while(variable[i] && variable[i] != '=')
|
||||
while (variable[i] && variable[i] != '=')
|
||||
{
|
||||
if(!ft_isalnum(variable[i]) && variable[i] != '_')
|
||||
return(1);
|
||||
if (!ft_isalnum(variable[i]) && variable[i] != '_')
|
||||
return (1);
|
||||
i++;
|
||||
}
|
||||
return(0);
|
||||
return (0);
|
||||
}
|
||||
|
||||
// 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);
|
||||
// }
|
||||
|
||||
int ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
{
|
||||
char *dest;
|
||||
char *unset;
|
||||
int index;
|
||||
char *dest;
|
||||
char *unset;
|
||||
int index;
|
||||
|
||||
if (check_variable(variable) == 1)
|
||||
{
|
||||
@ -61,7 +41,6 @@ int ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
ft_putstr_fd(variable, 2);
|
||||
ft_putstr_fd("': not a valid identifier\n", 2);
|
||||
return (check_return(cmd, 1));
|
||||
|
||||
}
|
||||
dest = ft_strdup(variable);
|
||||
unset = ft_substr(dest, 0, find_len(dest, 0, '='));
|
||||
@ -84,17 +63,19 @@ int ft_export_variable(t_s_cmd *cmd, char *variable)
|
||||
int ft_export(t_s_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int j;
|
||||
|
||||
i = 1;
|
||||
j = 0;
|
||||
if (!cmd->args[i])
|
||||
lone_export(cmd);
|
||||
else if (cmd->args[i])
|
||||
{
|
||||
while (cmd->args[i])
|
||||
{
|
||||
j = ft_export_variable(cmd, cmd->args[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return (j);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/07 17:58:25 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/09 04:55:48 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:18:17 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
void ft_swap(char **a, char **b)
|
||||
{
|
||||
char *tmp;
|
||||
char *tmp;
|
||||
|
||||
tmp = *a;
|
||||
*a = *b;
|
||||
@ -23,8 +23,8 @@ void ft_swap(char **a, char **b)
|
||||
|
||||
void sort_tab(char **av)
|
||||
{
|
||||
int i;
|
||||
int x;
|
||||
int i;
|
||||
int x;
|
||||
|
||||
i = 0;
|
||||
while (av[i])
|
||||
@ -50,21 +50,18 @@ 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, ft_strlen(tmp));
|
||||
|
||||
// str2 = ft_substr(tmp, i, find_len(tmp, i, '\0'));
|
||||
printf("declare -x %s", str1);
|
||||
if (next_space(str2, 0) != '\0')
|
||||
printf("=\"%s\"", str2);
|
||||
printf("\n");
|
||||
free(str1);
|
||||
free(str2);
|
||||
|
||||
}
|
||||
|
||||
void lone_export(t_s_cmd *cmd)
|
||||
{
|
||||
char **tmp;
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
tmp = cmd->big_cmd->env;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/02/28 17:17:01 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/09 04:55:48 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:17:02 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,9 +14,9 @@
|
||||
|
||||
void ft_shlvl(char **env)
|
||||
{
|
||||
int i;
|
||||
int index;
|
||||
char *str;
|
||||
int i;
|
||||
int index;
|
||||
char *str;
|
||||
|
||||
i = 0;
|
||||
index = find_it(env, "SHLVL");
|
||||
@ -33,36 +33,27 @@ void ft_shlvl(char **env)
|
||||
env[index] = ft_strjoin("SHLVL=", str);
|
||||
free (str);
|
||||
printf("%s\n", env[index]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void register_env(t_s_cmd *cmd, char *variable)
|
||||
{
|
||||
char **tmp = NULL;
|
||||
int i;
|
||||
i = 0;
|
||||
char **tmp;
|
||||
int i;
|
||||
|
||||
// tmp = NULL;
|
||||
// printf("TABLEN %d", tab_len(cmd->big_cmd->env));
|
||||
i = 0;
|
||||
tmp = NULL;
|
||||
tmp = (char **)malloc(sizeof(char *) * (tab_len(cmd->big_cmd->env) + 2));
|
||||
if(!tmp)
|
||||
if (!tmp)
|
||||
printf("no tmp\n");
|
||||
while (cmd->big_cmd->env[i])
|
||||
{
|
||||
tmp[i] = ft_strdup(cmd->big_cmd->env[i]);
|
||||
// printf("ici\n");
|
||||
// printf("%s\n", "let me in");
|
||||
i++;
|
||||
}
|
||||
// printf("i: %d %s\n",i,tmp[i]);
|
||||
// printf("%s\n", "brrrrrrr");
|
||||
tmp[i] = ft_strdup(variable);
|
||||
tmp[i + 1] = NULL;
|
||||
// printf("debut %p\n", tmp[2]);
|
||||
// printf("1--------------------\n");
|
||||
free_double(cmd->big_cmd->env);
|
||||
// printf("1--------------------\n");
|
||||
cmd->big_cmd->env = (char **)malloc(sizeof(char *) * (tab_len(tmp) + 1));
|
||||
if (!cmd->big_cmd->env)
|
||||
printf("no env\n");
|
||||
@ -70,27 +61,11 @@ void register_env(t_s_cmd *cmd, char *variable)
|
||||
while (tmp[i])
|
||||
{
|
||||
cmd->big_cmd->env[i] = ft_strdup(tmp[i]);
|
||||
// if (tmp[size])
|
||||
// free(tmp[size]);
|
||||
// printf("tmp----%s\n", tmp[size]);
|
||||
// printf("envy---%s\n", cmd->big_cmd->env[size]);
|
||||
i++;
|
||||
}
|
||||
cmd->big_cmd->env[i] = NULL;
|
||||
// printf("2--------------------\n");
|
||||
if (tmp)
|
||||
free_double(tmp);
|
||||
// printf("2--------------------\n");
|
||||
// int i = 0;
|
||||
// while (tmp[i])
|
||||
// {
|
||||
// printf("nano");
|
||||
// free(tmp[i]);
|
||||
// i++;
|
||||
// }
|
||||
// if(tmp)
|
||||
// free(tmp);
|
||||
// join_variable(cmd, variable, size, tmp);
|
||||
}
|
||||
|
||||
void ft_env(t_s_cmd *cmd, char **env)
|
||||
@ -110,16 +85,6 @@ void ft_env(t_s_cmd *cmd, char **env)
|
||||
cmd->big_cmd->env[i] = NULL;
|
||||
}
|
||||
|
||||
// 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);
|
||||
// }
|
||||
|
||||
void init_s_cmd(t_s_cmd *cmd, char **env)
|
||||
{
|
||||
ft_env(cmd, env);
|
||||
@ -127,7 +92,7 @@ void init_s_cmd(t_s_cmd *cmd, char **env)
|
||||
|
||||
int tab_len(char **tab)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (tab[i])
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/11 18:26:29 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/09 04:59:24 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:18:52 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -35,7 +35,6 @@ void unset_variable(t_s_cmd *cmd, int i)
|
||||
tmp[b] = NULL;
|
||||
free_double(cmd->big_cmd->env);
|
||||
a = 0;
|
||||
// cmd->big_cmd->env = malloc(sizeof(char *) * (tab_len(tmp) + 1));
|
||||
if (!cmd->big_cmd->env)
|
||||
printf("no env\n");
|
||||
cmd->big_cmd->env = ft_dup_double(tmp);
|
||||
@ -56,7 +55,6 @@ int find_variable(char *variable, t_s_cmd *cmd)
|
||||
ft_putstr_fd(variable, 2);
|
||||
ft_putstr_fd("': not a valid identifier\n", 2);
|
||||
return (check_return(cmd, 2));
|
||||
|
||||
}
|
||||
if (i == tab_len(cmd->big_cmd->env))
|
||||
return (check_return(cmd, 2));
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/16 15:04:12 by sadjigui #+# #+# */
|
||||
/* Updated: 2022/04/19 12:18:18 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:20:42 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -22,10 +22,9 @@ int find_len(char *input, int i, char c)
|
||||
return (j);
|
||||
}
|
||||
|
||||
|
||||
int find_it(char **str, char *s)
|
||||
int find_it(char **str, char *s)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
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))))
|
||||
@ -35,7 +34,7 @@ int find_it(char **str, char *s)
|
||||
return (i);
|
||||
}
|
||||
|
||||
int cd_error(t_s_cmd *cmd, char *str, int i)
|
||||
int cd_error(t_s_cmd *cmd, char *str, int i)
|
||||
{
|
||||
ft_putstr_fd(str, 2);
|
||||
ft_putstr_fd("\n", 2);
|
||||
@ -55,12 +54,11 @@ int size_path(char **str)
|
||||
return (j);
|
||||
}
|
||||
|
||||
int check_return(t_s_cmd *cmd, int var)
|
||||
int check_return(t_s_cmd *cmd, int var)
|
||||
{
|
||||
if (cmd->child)
|
||||
{
|
||||
cmd->big_cmd->err_var = var;
|
||||
|
||||
return (var);
|
||||
}
|
||||
else
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/09 23:58:21 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/19 12:03:24 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:00:38 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
int is_in_quote(char *str, int index)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
int open;
|
||||
|
||||
open = 0;
|
||||
@ -42,7 +42,7 @@ int is_in_quote(char *str, int index)
|
||||
|
||||
int is_quote_good(char *str)
|
||||
{
|
||||
int simple_quote;
|
||||
int simple_quote;
|
||||
int double_quote;
|
||||
int open;
|
||||
int i;
|
||||
@ -78,8 +78,8 @@ int is_quote_good(char *str)
|
||||
|
||||
char *del_char(char *str, int *index)
|
||||
{
|
||||
char *swap;
|
||||
char *swap2;
|
||||
char *swap;
|
||||
char *swap2;
|
||||
|
||||
swap = 0;
|
||||
swap = ft_strdup(str + *index + 1);
|
||||
@ -116,7 +116,7 @@ char *get_var(t_cmd *cmd, char *var_name)
|
||||
|
||||
char *change_var(t_cmd *big_cmd, char *cmd, int *index)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
char *swap;
|
||||
char *swap2;
|
||||
char *ret;
|
||||
@ -143,8 +143,8 @@ char *change_var(t_cmd *big_cmd, char *cmd, int *index)
|
||||
|
||||
char *set_var(t_cmd *big_cmd, char *cmd)
|
||||
{
|
||||
int i;
|
||||
char *del;
|
||||
int i;
|
||||
char *del;
|
||||
|
||||
i = 0;
|
||||
while (cmd[i])
|
||||
@ -183,16 +183,15 @@ char *set_var(t_cmd *big_cmd, char *cmd)
|
||||
return (cmd);
|
||||
}
|
||||
|
||||
int parse_quote(t_cmd *cmd)
|
||||
int parse_quote(t_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int i;
|
||||
int j;
|
||||
char *swap;
|
||||
|
||||
i = 0;
|
||||
while (cmd->s_cmds[i])
|
||||
{
|
||||
|
||||
j = -1;
|
||||
while (cmd->s_cmds[i]->args[++j])
|
||||
{
|
||||
|
||||
@ -6,22 +6,21 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/04/10 19:50:50 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/19 12:03:45 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 12:58:16 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../../includes/minishell.h"
|
||||
|
||||
int next_quote(const char *s, int i)
|
||||
int next_quote(const char *s, int i)
|
||||
{
|
||||
int simple_quote;
|
||||
int double_quote;
|
||||
int simple_quote;
|
||||
int double_quote;
|
||||
|
||||
simple_quote = 0;
|
||||
double_quote = 0;
|
||||
if (s[i] == '"' || s[i] == '\'')
|
||||
{
|
||||
|
||||
if (s[i] == '"')
|
||||
double_quote = 1;
|
||||
else if (s[i] == '\'')
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/09 15:18:58 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/19 12:04:35 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:07:33 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -37,7 +37,7 @@ char *cut_str(char *str, int start, int end)
|
||||
|
||||
char *get_word(char *str, int start)
|
||||
{
|
||||
char *new;
|
||||
char *new;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
@ -56,7 +56,7 @@ char *get_word(char *str, int start)
|
||||
char *set_input(char *line, t_s_cmd *cmd, int index)
|
||||
{
|
||||
int i;
|
||||
int word_index;
|
||||
int word_index;
|
||||
|
||||
word_index = 0;
|
||||
i = index;
|
||||
@ -84,10 +84,10 @@ char *set_input(char *line, t_s_cmd *cmd, int index)
|
||||
return (line);
|
||||
}
|
||||
|
||||
char *set_output(char *line, t_s_cmd *cmd, int index)
|
||||
char *set_output(char *line, t_s_cmd *cmd, int index)
|
||||
{
|
||||
int i;
|
||||
int word_index;
|
||||
int word_index;
|
||||
|
||||
word_index = 0;
|
||||
i = index;
|
||||
@ -107,7 +107,7 @@ char *set_output(char *line, t_s_cmd *cmd, int index)
|
||||
|
||||
char *ft_input(char *line, t_s_cmd *cmd, int index)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
char next;
|
||||
|
||||
i = index;
|
||||
@ -129,7 +129,7 @@ char *ft_input(char *line, t_s_cmd *cmd, int index)
|
||||
|
||||
char *ft_output(char *line, t_s_cmd *cmd, int index)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
char next;
|
||||
|
||||
i = index;
|
||||
@ -149,7 +149,7 @@ char *ft_output(char *line, t_s_cmd *cmd, int index)
|
||||
|
||||
int set_file(char *file)
|
||||
{
|
||||
int fd;
|
||||
int fd;
|
||||
|
||||
fd = open(file, O_TRUNC | O_CREAT, 0644);
|
||||
if (fd == -1)
|
||||
@ -166,7 +166,7 @@ int set_file(char *file)
|
||||
|
||||
char **add_line(char **tab, char *line)
|
||||
{
|
||||
int size;
|
||||
int size;
|
||||
char **ret;
|
||||
int i;
|
||||
|
||||
@ -175,7 +175,7 @@ char **add_line(char **tab, char *line)
|
||||
ret = 0;
|
||||
if (tab)
|
||||
size = double_size(tab);
|
||||
ret = ft_calloc(size + 2, sizeof(char*));
|
||||
ret = ft_calloc(size + 2, sizeof(char *));
|
||||
if (!ret)
|
||||
return (0);
|
||||
while (tab && tab[i])
|
||||
@ -187,7 +187,7 @@ char **add_line(char **tab, char *line)
|
||||
ret[i + 1] = 0;
|
||||
if (tab)
|
||||
free_double(tab);
|
||||
return(ret);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
char *set_heredoc(int index, char **in)
|
||||
@ -217,9 +217,9 @@ char *set_heredoc(int index, char **in)
|
||||
|
||||
void sig_heredoc(int num)
|
||||
{
|
||||
num = 0;
|
||||
struct sigaction base;
|
||||
struct sigaction base;
|
||||
|
||||
(void)num;
|
||||
memset(&base, 0, sizeof(base));
|
||||
base.sa_handler = &crtl_c;
|
||||
base.sa_flags = 0;
|
||||
@ -233,13 +233,13 @@ void sig_heredoc(int num)
|
||||
|
||||
int wait_prompt(t_s_cmd *cmd, int index)
|
||||
{
|
||||
char *input;
|
||||
int i;
|
||||
char **history;
|
||||
char *in;
|
||||
char *dup;
|
||||
char *del;
|
||||
struct sigaction test;
|
||||
char *input;
|
||||
int i;
|
||||
char **history;
|
||||
char *in;
|
||||
char *dup;
|
||||
char *del;
|
||||
struct sigaction test;
|
||||
|
||||
memset(&test, 0, sizeof(test));
|
||||
test.sa_handler = &sig_heredoc;
|
||||
@ -289,12 +289,12 @@ int wait_prompt(t_s_cmd *cmd, int index)
|
||||
|
||||
char *set_redirection(t_s_cmd *cmd, char *line, int index)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i= 0;
|
||||
i = 0;
|
||||
while (line[i])
|
||||
{
|
||||
if(line[i] == '<')
|
||||
if (line[i] == '<')
|
||||
{
|
||||
if (!is_in_quote(line, i))
|
||||
{
|
||||
@ -312,7 +312,7 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
else if(line[i] == '>')
|
||||
else if (line[i] == '>')
|
||||
{
|
||||
if (!is_in_quote(line, i))
|
||||
{
|
||||
@ -327,5 +327,5 @@ char *set_redirection(t_s_cmd *cmd, char *line, int index)
|
||||
else if (line[i] && line[i] != '<' && line[i] != '>')
|
||||
i++;
|
||||
}
|
||||
return(line);
|
||||
return (line);
|
||||
}
|
||||
@ -6,7 +6,7 @@
|
||||
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/03/11 16:35:37 by apommier #+# #+# */
|
||||
/* Updated: 2022/04/09 19:16:39 by apommier ### ########.fr */
|
||||
/* Updated: 2022/04/19 13:07:55 by apommier ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@ -14,7 +14,7 @@
|
||||
|
||||
int double_size(char **tab)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
if (tab == 0)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user