Skip to content

Commit

Permalink
expand is implemented with caubry part
Browse files Browse the repository at this point in the history
  • Loading branch information
ychibani42 committed Oct 14, 2022
1 parent 25f40cf commit 4c14ee1
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 36 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2022/05/04 14:03:48 by ychibani #+# #+# #
# Updated: 2022/10/13 16:12:05 by ychibani ### ########.fr #
# Updated: 2022/10/14 14:45:21 by ychibani ### ########.fr #
# #
# **************************************************************************** #

Expand Down
6 changes: 3 additions & 3 deletions includes/minishell_fonctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/02 20:42:53 by ychibani #+# #+# */
/* Updated: 2022/10/13 17:10:44 by ychibani ### ########.fr */
/* Updated: 2022/10/14 14:32:15 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -232,9 +232,9 @@ int __error_after_expand(t_lexer **seq);
int sequence_launcher(t_user_input *ui, t_program_data *data);
char *get_testing_wd(char *start_wd, int *offset);
int find_key(char *testing_wd, char *env_str,
t_program_data *data, int j);
t_program_data *data);
char *handle_quotes_in_env(char *str);
int get_value(char *testing_wd, char *env_str,
int get_value(char *testing_wd,
char **expanded_wd, char *key_value);
int __heredoc_expansion(char **token, t_program_data *data);
void update_token(char **token, char **new_token);
Expand Down
4 changes: 2 additions & 2 deletions srcs/executor/builtin/env/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* env.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: caubry <caubry@student.42.fr> +#+ +:+ +#+ */
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/27 10:36:36 by caubry #+# #+# */
/* Updated: 2022/10/11 11:46:40 by caubry ### ########.fr */
/* Updated: 2022/10/13 18:42:35 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
23 changes: 8 additions & 15 deletions srcs/expander/expander.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/29 11:15:31 by ychibani #+# #+# */
/* Updated: 2022/10/11 17:20:31 by ychibani ### ########.fr */
/* Updated: 2022/10/14 18:39:22 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -48,29 +48,22 @@ int treat_final_rv(char **wd, int *offset, t_program_data *data)
int parameter_expand(char *str, char **expanded_wd,
t_program_data *data, int *offset)
{
int j;
char *env_str;
char *testing_wd;
t_env *env;

if (str[0] == '?')
return (treat_final_rv(expanded_wd, offset, data));
testing_wd = get_testing_wd(str, offset);
if (!testing_wd)
return (MALLOC_ERROR);
j = 0;
while (data->envp[j])
env = *(data->ui->test_env);
while (env)
{
if (data->envp[j][1][0] == '1' || data->envp[j][1][0] == '0')
{
env_str = get_key(data->envp[j][0]);
if (!env_str)
return (free(testing_wd), 0);
if (find_key(testing_wd, env_str, data, j))
return (get_value(testing_wd, env_str, expanded_wd,
(__strchr(data->envp[j][0], '=') + 1)));
free(env_str);
}
j++;
env_str = env->name;
if (find_key(testing_wd, env_str, data))
return (get_value(testing_wd, expanded_wd, env->value));
env = env->next;
}
return (free(testing_wd), 1);
}
11 changes: 4 additions & 7 deletions srcs/expander/expander2.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/02 16:08:42 by ychibani #+# #+# */
/* Updated: 2022/10/03 13:32:59 by ychibani ### ########.fr */
/* Updated: 2022/10/14 18:30:33 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -27,10 +27,9 @@ char *get_testing_wd(char *start_wd, int *offset)
return (testing_wd);
}

int find_key(char *testing_wd, char *env_str, t_program_data *data, int j)
int find_key(char *testing_wd, char *env_str, t_program_data *data)
{
if (!strcmp(testing_wd, env_str) && data->envp[j][1][0] == '1' &&
__strchr(data->envp[j][0], '='))
if (!strcmp(testing_wd, env_str) && data->ui->test_env)
return (1);
return (0);
}
Expand Down Expand Up @@ -58,13 +57,11 @@ char *handle_quotes_in_env(char *str)
return (tmp);
}

int get_value(char *testing_wd, char *env_str,
char **expanded_wd, char *key_value)
int get_value(char *testing_wd, char **expanded_wd, char *key_value)
{
char *final_str;

free(testing_wd);
free(env_str);
final_str = handle_quotes_in_env(key_value);
if (!final_str)
return (MALLOC_ERROR);
Expand Down
6 changes: 3 additions & 3 deletions srcs/expander/expander3.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/11 13:54:48 by ychibani #+# #+# */
/* Updated: 2022/10/11 17:23:10 by ychibani ### ########.fr */
/* Updated: 2022/10/14 18:44:26 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -60,8 +60,8 @@ int __usual_expansion(char **token, t_program_data *data)
expanded_wd = __strdup("");
while (str[++i])
{
if ((str[i] == '$' && is_valid_char(str[i + 1])
&& !dollars_status(str, &str[i])) || is_an_exception(str, i))
if ((str[i] == '$' && !dollars_status(str, &str[i]) && str[i + 1] != '$')
&& (is_valid_char(str[i + 1]) || is_an_exception(str, i)))
{
if (parameter_expand(str + i + 1,
&expanded_wd, data, &i) == MALLOC_ERROR)
Expand Down
2 changes: 1 addition & 1 deletion srcs/init/init_structs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/16 15:33:33 by ychibani #+# #+# */
/* Updated: 2022/10/11 14:11:40 by ychibani ### ########.fr */
/* Updated: 2022/10/14 13:45:29 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
3 changes: 1 addition & 2 deletions srcs/parser/parsing.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/12 19:43:21 by ychibani #+# #+# */
/* Updated: 2022/10/13 18:20:36 by ychibani ### ########.fr */
/* Updated: 2022/10/14 18:45:37 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -47,6 +47,5 @@ int treat_usr_inputs(char *arg, t_program_data *data, t_user_input *user_input)
return (__lexer_clear(&user_input->lexer), -1);
if (!sequence_launcher(user_input, data))
return (__lexer_clear(&user_input->lexer), -1);
// ft_pipex(user_input);
return (_SUCCESS_);
}
5 changes: 3 additions & 2 deletions srcs/parser/sequence_launcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: ychibani <ychibani@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/06 11:24:27 by ychibani #+# #+# */
/* Updated: 2022/10/13 17:22:56 by ychibani ### ########.fr */
/* Updated: 2022/10/14 18:45:40 by ychibani ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -17,7 +17,7 @@ int sequence_launcher(t_user_input *ui, t_program_data *data)
t_lexer **seq;

seq = &ui->lexer;
data->env = ui->env;
data->ui = ui;
if (__expand_var(*seq, data) == MALLOC_ERROR)
return (0);
if (!__error_catcher(seq, data))
Expand All @@ -26,5 +26,6 @@ int sequence_launcher(t_user_input *ui, t_program_data *data)
return (0);
if (!lexer_remove_quote(*seq))
return (0);
ft_pipex(ui);
return (1);
}

0 comments on commit 4c14ee1

Please sign in to comment.