Skip to content

Commit

Permalink
norminette completed
Browse files Browse the repository at this point in the history
  • Loading branch information
Thais Malheiros Assumpcao committed Oct 11, 2024
1 parent e4113f9 commit 26307f7
Show file tree
Hide file tree
Showing 18 changed files with 207 additions and 174 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ SRC_FILES += ./04_tree_execution/26.manage_pipe.c
SRC_FILES += ./04_tree_execution/manage_pipe_utils.c
SRC_FILES += ./04_tree_execution/27.manage_redirects.c
SRC_FILES += ./04_tree_execution/manage_redirects_utils.c
SRC_FILES += ./04_tree_execution/manage_redirects_utils_2.c
SRC_FILES += ./04_tree_execution/28.manage_subshell.c
SRC_FILES += ./04_tree_execution/29.manage_single_cmd.c
SRC_FILES += ./05_expansions/30.expansion_manager.c
Expand All @@ -90,7 +91,7 @@ SRC_FILES += ./05_expansions/32.expansion_quotes.c
SRC_FILES += ./05_expansions/33.expansion_tilde.c
SRC_FILES += ./05_expansions/34.expansion_env_var.c
SRC_FILES += ./05_expansions/35.expansion_env_var_utils.c
SRC_FILES += ./05_expansions/expansion_env_var_utils_2.c
SRC_FILES += ./05_expansions/expansion_env_key_rules.c
SRC_FILES += ./05_expansions/36.expansion_question.c
SRC_FILES += ./05_expansions/expansion_parent_dir.c
SRC_FILES += ./06_builtins/37.builtin_detectors.c
Expand Down
6 changes: 4 additions & 2 deletions headers/builtins.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* builtins.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/16 14:57:00 by umeneses #+# #+# */
/* Updated: 2024/10/10 17:30:23 by umeneses ### ########.fr */
/* Updated: 2024/10/11 03:03:25 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -198,4 +198,6 @@ void clear_all_to_exit_smoothly(void);
*/
bool arg_option_holder(bool update, bool call_status);

void update_oldpwd(int alterable, char *str);

#endif
6 changes: 4 additions & 2 deletions headers/execution.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* execution.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/05 13:56:37 by tmalheir #+# #+# */
/* Updated: 2024/10/07 22:27:23 by umeneses ### ########.fr */
/* Updated: 2024/10/11 03:14:31 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -124,6 +124,8 @@ void decrement_flag_and_close_fds(int *flag, int *std_fd);

char *redir_quote_detector(char *lexeme, int *flag);

bool check_pathname(char *pathname);

/*PRINTING FUNCTIONS (TO DELETE)*/

void ft_tree_printer(t_tree *root);
Expand Down
9 changes: 6 additions & 3 deletions headers/expansion.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* expansion.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/28 13:55:02 by umeneses #+# #+# */
/* Updated: 2024/10/07 14:42:19 by umeneses ### ########.fr */
/* Updated: 2024/10/11 04:17:22 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -37,7 +37,8 @@ bool expansion_tilde_detector(char *lexeme);
char *expansion_tilde_to_home(char *lexeme);

bool expansion_dollar_sign_detector(t_token_list *cmd);
char *expansion_env_var_runner(char *lexeme, int type);
char *expansion_env_var_manager(char *lexeme, int type);
char *expansion_env_var_runner(char **arr_lex, char *lexeme, int idx);
bool expansion_env_var_detector(char *lexeme);
bool env_var_key_rules_at_start(char c);
bool env_var_key_rules_at_middle(char c);
Expand All @@ -55,4 +56,6 @@ char *double_quote_remover(char *lex);
bool expansion_question_mark_detector(char *lexeme);
char *expansion_question_mark(char *lexeme);

char *process_single_quotes(char *lexeme, int type);

#endif
7 changes: 1 addition & 6 deletions src/02.signals.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmalheir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/13 09:47:06 by umeneses #+# #+# */
/* Updated: 2024/10/10 22:11:26 by tmalheir ### ########.fr */
/* Updated: 2024/10/11 03:55:54 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -56,11 +56,6 @@ void interrupt_signal_runner(int sig)
token_list_holder(NULL, false, true);
is_heredoc_running(false, false);
close(STDIN_FILENO);
// Abrir o dup do stdin original aqui
/****teste
* << a cat (Finaliza com CTRL + C)
* << a cat (Finaliza com CTRL + C de novo)
*/
close(STDERR_FILENO);
}
ft_putstr_fd("\n", STDOUT_FILENO);
Expand Down
6 changes: 3 additions & 3 deletions src/02_parser/heredoc_expansions.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* heredoc_expansions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/09 20:54:18 by umeneses #+# #+# */
/* Updated: 2024/10/10 23:10:07 by umeneses ### ########.fr */
/* Updated: 2024/10/11 03:59:40 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,7 +49,7 @@ int dollarsign_for_heredoc_runner(char *input, int idx, size_t start, int fd)
while (input[idx] && !is_blank(input[idx]))
idx++;
end = (size_t)idx;
var = expansion_env_var_runner((ft_substr(input, start,
var = expansion_env_var_manager((ft_substr(input, start,
(end - start))), 0);
idx = 0;
while (var[idx])
Expand Down
9 changes: 3 additions & 6 deletions src/04_tree_execution/27.manage_redirects.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* 27.manage_redirects.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: umeneses <umeneses@student.42.fr> +#+ +:+ +#+ */
/* By: tmalheir <tmalheir@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/04 10:20:13 by tmalheir #+# #+# */
/* Updated: 2024/10/11 01:24:31 by umeneses ### ########.fr */
/* Updated: 2024/10/11 03:13:58 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -73,11 +73,8 @@ static int open_redir_file(t_tree *tree, int *fd)
type = tree->type;
pathname = ft_strdup(tree->right->command->lexeme);
pathname = redir_quote_detector(pathname, &flag);
if (!pathname)
{
ft_putendl_fd("Ambiguous Redirect", STDERR_FILENO);
if (!check_pathname(pathname))
return (exit_status_holder(EXIT_FAILURE, true));
}
if (type == REDIR_IN || type == REDIR_HDOC)
*fd = open(pathname, O_RDONLY);
else if (type == REDIR_OUT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expansion_env_var_utils_2.c :+: :+: :+: */
/* manage_redirects_utils_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmalheir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 15:41:03 by tmalheir #+# #+# */
/* Updated: 2024/10/04 15:42:09 by tmalheir ### ########.fr */
/* Created: 2024/10/11 03:10:47 by tmalheir #+# #+# */
/* Updated: 2024/10/11 03:15:18 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

char *merging_array_lexeme(char **arr_lex)
bool check_pathname(char *pathname)
{
char *merged_lex;
char *tmp;
int idx;

idx = 0;
merged_lex = NULL;
tmp = NULL;
if (arr_lex && arr_lex[idx])
{
merged_lex = ft_strdup(arr_lex[idx]);
idx++;
}
while (arr_lex[idx])
if (!pathname)
{
tmp = ft_strjoin(merged_lex, arr_lex[idx]);
free(merged_lex);
merged_lex = tmp;
idx++;
ft_putendl_fd("Ambiguous Redirect", STDERR_FILENO);
return (false);
}
return (merged_lex);
return (true);
}
4 changes: 2 additions & 2 deletions src/05_expansions/30.expansion_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: tmalheir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/26 18:31:10 by umeneses #+# #+# */
/* Updated: 2024/10/10 20:21:26 by tmalheir ### ########.fr */
/* Updated: 2024/10/11 03:59:40 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -61,7 +61,7 @@ void expansion_manager(t_token_list *cmd)
if (expansion_question_mark_detector(tmp->lexeme))
tmp->lexeme = expansion_question_mark(tmp->lexeme);
if (expansion_dollar_sign_detector(tmp))
tmp->lexeme = expansion_env_var_runner(tmp->lexeme,
tmp->lexeme = expansion_env_var_manager(tmp->lexeme,
tmp->type);
}
}
Expand Down
78 changes: 33 additions & 45 deletions src/05_expansions/34.expansion_env_var.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,64 @@
/* By: tmalheir <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/27 12:39:23 by umeneses #+# #+# */
/* Updated: 2024/10/10 21:21:13 by tmalheir ### ########.fr */
/* Updated: 2024/10/11 04:30:45 by tmalheir ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

char *expansion_env_var_runner(char *lexeme, int type)
char *expansion_env_var_manager(char *lexeme, int type)
{
char **arr_lex;
char *merged_lex;
int c;
int idx;

c = 0;
idx = 0;
merged_lex = NULL;
arr_lex = NULL;
while (lexeme[c])
while (lexeme[idx])
{
if (lexeme[c] == '$' && type == SINGLE_QUOTES)
if (lexeme[idx] == '$' && type == SINGLE_QUOTES)
return (lexeme);
else if (lexeme[c] == '$' && type != SINGLE_QUOTES
&& lexeme[c + 1] && (lexeme[c + 1] != '?'))
else if (lexeme[idx] == '$' && lexeme[idx + 1]
&& (lexeme[idx + 1] != '?'))
{
arr_lex = ft_split(lexeme + c, '$');
char j = lexeme[c];
lexeme[c] = 0;
char *copy = ft_strdup(lexeme);
lexeme[c] = j;
arr_lex = expand_var_from_array(arr_lex);
if (arr_lex)
merged_lex = merging_array_lexeme(arr_lex);
if (copy && merged_lex)
{
char *tmp = ft_strdup(merged_lex);
free (merged_lex);
merged_lex = ft_strjoin(copy, tmp);
free(tmp);
}
free(copy);
merged_lex = expansion_env_var_runner(arr_lex, lexeme, idx);
break ;
}
c++;
idx++;
}
free_array(arr_lex);
free(lexeme);
return (merged_lex);
}

char **array_lex_env_key_rules_manager(char **arr_lex, int arr_len)
char *expansion_env_var_runner(char **arr_lex, char *lexeme, int idx)
{
size_t idx;
size_t pos;
char **new_arr;
char j;
char *copy;
char *merged_lex;
char *tmp;

idx = -1;
new_arr = (char **)ft_calloc(2, sizeof(char *) * arr_len);
while (arr_lex[++idx])
merged_lex = NULL;
tmp = NULL;
arr_lex = ft_split(lexeme + idx, '$');
j = lexeme[idx];
lexeme[idx] = 0;
copy = ft_strdup(lexeme);
lexeme[idx] = j;
arr_lex = expand_var_from_array(arr_lex);
if (arr_lex)
merged_lex = merging_array_lexeme(arr_lex);
if (copy && merged_lex)
{
pos = 0;
if (env_var_key_rules_at_start(arr_lex[idx][pos]))
pos++;
while (env_var_key_rules_at_middle(arr_lex[idx][pos]))
pos++;
if (pos > 0 && arr_lex[idx][pos]
&& !env_var_key_rules_at_middle(arr_lex[idx][pos]))
new_arr = apply_rules_on_lex(new_arr, arr_lex[idx], pos);
else
new_arr = send_approved_var(new_arr, arr_lex[idx]);
tmp = ft_strdup(merged_lex);
free (merged_lex);
merged_lex = ft_strjoin(copy, tmp);
free(tmp);
}
new_arr = free_runner_for_env_rules_manager(arr_lex, new_arr);
return (new_arr);
free(copy);
free_array(arr_lex);
return (merged_lex);
}

static void process_entry(char **arr_lex, size_t idx, bool *not_found)
Expand Down
Loading

0 comments on commit 26307f7

Please sign in to comment.