diff --git a/Makefile b/Makefile index 257a9cd..8e41467 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ SRC_UTILS := envp_utils.c free_utils.c builtin_utils.c free_protected.c fd SRC_PARSE_DIR := $(SRC_DIR)/parse SRC_PARSE := init.c parse.c path.c error.c split_quotes.c expand.c expand_utils.c redir_file.c \ - redir.c check.c wildcards.c + redir.c check.c wildcards.c split_space.c SRC_EXEC_DIR := $(SRC_DIR)/exec SRC_EXEC := exec.c builtin.c ft_cd.c ft_unset.c ft_export.c forks.c ft_echo.c ft_export_utils.c mark.c diff --git a/includes/parsing.h b/includes/parsing.h index 5f0a80a..85b02fc 100644 --- a/includes/parsing.h +++ b/includes/parsing.h @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* parsing.h :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: mcomin +#+ +:+ +#+ */ +/* By: apuyane +#+ +:+ +#+ */ +/* By: apuyane +#+ +:+ +#+ */ +/* By: apuyane ' || input[i] == '<') || input[i] == '|') - return (1); + return (i); } else i++; @@ -107,11 +107,28 @@ int check_redirections(char *input) int check_syntax(char *input) { - if (check_quotes(input)) - return (1); - if (check_pipes(input)) - return (1); - if (check_redirections(input)) + int i; + int j; + int k; + int id; + + i = check_quotes(input); + j = check_pipes(input); + k = check_redirections(input); + if (i || j || k) + { + if (i > 0 || j > 0 || k > 0) + { + id = 2147483647; + if (i > 0 && i < id) + id = i; + if (j > 0 && j < id) + id = j; + if (k > 0 && k < id) + id = k; + ft_dprintf(2, "minishell: syntax error near `%c'\n", input[id]); + } return (1); + } return (0); } diff --git a/src/parse/init.c b/src/parse/init.c index 6556328..ccad50d 100755 --- a/src/parse/init.c +++ b/src/parse/init.c @@ -43,7 +43,7 @@ t_cmd new_cmd(char *token, t_data *data, int i) data->cmds[i].access = -1; return (data->cmds[i]); } - data->cmds[i].args = ft_split_quotes(token, ' '); + data->cmds[i].args = ft_split_space(token); cmd_is_pipe(data, i); handle_redir(data); data->cmds[i].function_name = ft_strdup(data->cmds[i].args[0]); diff --git a/src/parse/split_space.c b/src/parse/split_space.c new file mode 100755 index 0000000..5f05773 --- /dev/null +++ b/src/parse/split_space.c @@ -0,0 +1,95 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_quotes.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: apuyane beg) + { + str[i] = ft_substr(s, beg, end - beg); + if (!str[i]) + return ; + i++; + } + } +} + +char **ft_split_space(char const *s) +{ + size_t i; + char **str; + + i = 0; + if (!s) + return (NULL); + str = wordsmalloc(s); + if (!str) + return (NULL); + fill(s, str); + if (!str) + { + while (str[i]) + { + free_single(str[i]); + str[i] = NULL; + i++; + } + free_single(str); + str = NULL; + } + return (str); +} diff --git a/src/parse/wildcards.c b/src/parse/wildcards.c index 9a95b02..9ceae4c 100644 --- a/src/parse/wildcards.c +++ b/src/parse/wildcards.c @@ -6,7 +6,7 @@ /* By: apuyane