-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thais Malheiros Assumpcao
committed
Oct 11, 2024
1 parent
e4113f9
commit 26307f7
Showing
18 changed files
with
207 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 8 additions & 22 deletions
30
...05_expansions/expansion_env_var_utils_2.c → ...tree_execution/manage_redirects_utils_2.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -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); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
Oops, something went wrong.