-
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.
* start expander refactor * start new expander * Add expander_split ans expander_join * Add expander_file --------- Co-authored-by: Ofacy <[email protected]>
- Loading branch information
1 parent
3a95945
commit 929be33
Showing
16 changed files
with
425 additions
and
279 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* expander.h :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bwisniew <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/21 19:30:58 by bwisniew #+# #+# */ | ||
/* Updated: 2024/04/03 14:21:20 by bwisniew ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#ifndef EXPANDER_H | ||
# define EXPANDER_H | ||
|
||
# include "minishell.h" | ||
# include <stddef.h> | ||
|
||
typedef struct s_expand_size | ||
{ | ||
size_t exp_size; | ||
size_t str_size; | ||
int error; | ||
} t_expand_size; | ||
|
||
int tokens_expand(t_mshell *sh, size_t token_i); | ||
bool need_expand_str(t_token *token, size_t str_i); | ||
size_t expanded_len(t_mshell *sh, t_token *token); | ||
size_t skip_envname(char *str); | ||
size_t expander_split(t_mshell *sh, size_t token_i); | ||
int expander_unseparated(t_vector *lex, size_t i, size_t n); | ||
int token_expand(t_token *token, t_mshell *sh, size_t exp_len); | ||
size_t expander_skip_file(t_vector *lex, size_t i, size_t n); | ||
|
||
#endif |
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
Submodule libft
updated
4 files
+6 −3 | ft_convert_fd.c | |
+1 −2 | ft_dprintf.c | |
+3 −2 | ft_putnbr_base_fd.c | |
+1 −2 | ft_putstr_fd.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 |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
/* By: bwisniew <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/10 18:29:04 by lcottet #+# #+# */ | ||
/* Updated: 2024/03/20 14:32:07 by bwisniew ### ########.fr */ | ||
/* Updated: 2024/04/03 14:23:26 by bwisniew ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
|
@@ -48,7 +48,7 @@ int exec_set_output(t_execute *exec, t_mshell *sh, size_t i) | |
{ | ||
exec->has_redirect = true; | ||
close_fd(&exec->out); | ||
if (expend_file(sh, i)) | ||
if (expand_file(sh, i)) | ||
return (1); | ||
exec->out = open(((t_token *)sh->tokens.tab)[i + 1].txt, | ||
O_WRONLY | O_CREAT | O_TRUNC, 0644); | ||
|
@@ -63,7 +63,7 @@ int exec_set_output(t_execute *exec, t_mshell *sh, size_t i) | |
int exec_set_input(t_execute *exec, t_mshell *sh, size_t i) | ||
{ | ||
close_fd(&exec->in); | ||
if (expend_file(sh, i)) | ||
if (expand_file(sh, i)) | ||
return (1); | ||
exec->in = open(((t_token *)sh->tokens.tab)[i + 1].txt, O_RDONLY); | ||
if (exec->in == -1) | ||
|
@@ -78,7 +78,7 @@ int exec_set_append(t_execute *exec, t_mshell *sh, size_t i) | |
{ | ||
exec->has_redirect = true; | ||
close_fd(&exec->out); | ||
if (expend_file(sh, i)) | ||
if (expand_file(sh, i)) | ||
return (1); | ||
exec->out = open(((t_token *)sh->tokens.tab)[i + 1].txt, | ||
O_WRONLY | O_CREAT | O_APPEND, 0644); | ||
|
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,11 +6,12 @@ | |
/* By: bwisniew <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/10 20:41:37 by lcottet #+# #+# */ | ||
/* Updated: 2024/03/20 16:28:14 by bwisniew ### ########.fr */ | ||
/* Updated: 2024/04/03 18:26:48 by bwisniew ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
#include "expander.h" | ||
#include "libft.h" | ||
#include <readline/readline.h> | ||
#include <unistd.h> | ||
|
@@ -61,7 +62,7 @@ char *here_doc_getline(t_mshell *sh, size_t i, t_fd fd, int *err) | |
line.type = ((t_token *)sh->tokens.tab)[i].old_type; | ||
if (((t_token *)sh->tokens.tab)[i].old_type == UNQUOTED) | ||
{ | ||
if (get_expended_str(&line, sh) < 0) | ||
if (token_expand(&line, sh, expanded_len(sh, &line)) != 0) | ||
{ | ||
free_token(&line); | ||
return (NULL); | ||
|
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* expander.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bwisniew <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/03/21 19:13:27 by bwisniew #+# #+# */ | ||
/* Updated: 2024/04/03 18:11:59 by bwisniew ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "expander.h" | ||
#include <stdio.h> | ||
|
||
int expander(t_mshell *sh, size_t start, size_t end) | ||
{ | ||
size_t token_i; | ||
int ret; | ||
|
||
token_i = expander_skip_file(&sh->tokens, start, end); | ||
while (token_i < end) | ||
{ | ||
if (!is_special(((t_token *)sh->tokens.tab)[token_i].type)) | ||
{ | ||
ret = tokens_expand(sh, token_i); | ||
if (ret < 0) | ||
return (1); | ||
token_i += ret; | ||
end += ret - 1; | ||
} | ||
else | ||
token_i++; | ||
token_i = expander_skip_file(&sh->tokens, token_i, end); | ||
} | ||
return (expander_unseparated(&sh->tokens, start, token_i)); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* ************************************************************************** */ | ||
/* */ | ||
/* ::: :::::::: */ | ||
/* expander_file.c :+: :+: :+: */ | ||
/* +:+ +:+ +:+ */ | ||
/* By: bwisniew <[email protected]> +#+ +:+ +#+ */ | ||
/* +#+#+#+#+#+ +#+ */ | ||
/* Created: 2024/04/03 13:50:42 by bwisniew #+# #+# */ | ||
/* Updated: 2024/04/03 18:26:42 by bwisniew ### ########.fr */ | ||
/* */ | ||
/* ************************************************************************** */ | ||
|
||
#include "minishell.h" | ||
#include "expander.h" | ||
#include "libft.h" | ||
|
||
size_t expander_skip_file(t_vector *lex, size_t i, size_t n) | ||
{ | ||
if (i < n && is_type_arrow(((t_token *)lex->tab)[i].type)) | ||
{ | ||
((t_token *)lex->tab)[i + 1].is_file = true; | ||
i += 2; | ||
while (i < n && !((t_token *)lex->tab)[i - 1].is_separated | ||
&& !is_special(((t_token *)lex->tab)[i - 1].type)) | ||
{ | ||
((t_token *)lex->tab)[i].is_file = true; | ||
i++; | ||
} | ||
if (i < n) | ||
((t_token *)lex->tab)[i].is_file = true; | ||
} | ||
return (i); | ||
} | ||
|
||
size_t expand_ambi_file(t_token *token, t_mshell *sh) | ||
{ | ||
size_t txt_i; | ||
t_env *env_var; | ||
|
||
txt_i = 0; | ||
while (txt_i < token->txt_size) | ||
{ | ||
if (need_expand_str(token, txt_i)) | ||
{ | ||
env_var = env_get(sh, token->txt + txt_i + 1, false); | ||
if (env_var && token->type == UNQUOTED | ||
&& ft_strchr(env_var->value, ' ') != NULL) | ||
{ | ||
custom_error(env_var->key, "ambiguous redirect"); | ||
return (1); | ||
} | ||
txt_i += skip_envname(token->txt + txt_i + 1) + 1; | ||
} | ||
else | ||
txt_i++; | ||
} | ||
return (0); | ||
} | ||
|
||
int expand_file(t_mshell *sh, size_t token_i) | ||
{ | ||
size_t i_cp; | ||
|
||
i_cp = token_i; | ||
token_i++; | ||
while (token_i < sh->tokens.len | ||
&& ((t_token *)sh->tokens.tab)[token_i].is_file == 1) | ||
{ | ||
if (expand_ambi_file(&((t_token *)sh->tokens.tab)[token_i], sh) != 0) | ||
return (1); | ||
token_i++; | ||
} | ||
if (expander(sh, i_cp + 1, expander_skip_file(&sh->tokens, | ||
i_cp, sh->tokens.len) + 1) < 0) | ||
return (1); | ||
return (0); | ||
} |
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
Oops, something went wrong.