Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions includes/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* parsing.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcomin <mcomin@student.42.fr> +#+ +:+ +#+ */
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/30 07:27:45 by mcomin #+# #+# */
/* Updated: 2026/03/24 04:43:26 by mcomin ### ########.fr */
/* Updated: 2026/03/24 06:02:34 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

Expand All @@ -22,6 +22,7 @@ char *supp_quotes(char *str);
int count_quotes_closed(char *str);
int is_in_quotes(char const *s, size_t pos);
char **ft_split_quotes(char const *s, char c);
char **ft_split_space(char const *s);
t_data *load_data(t_data *data, char *input);
int count_pipe(char *input);
char *is_path(char *prefix_cmd_name, char **tab_paths, t_cmd *cmd);
Expand Down
2 changes: 1 addition & 1 deletion src/parse/check.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/* ::: :::::::: */
/* check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcomin <mcomin@student.42.fr> +#+ +:+ +#+ */
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/10 02:59:44 by mcomin #+# #+# */
/* Updated: 2026/03/24 05:34:50 by mcomin ### ########.fr */
Expand Down
41 changes: 29 additions & 12 deletions src/parse/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* error.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcomin <mcomin@student.42.fr> +#+ +:+ +#+ */
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/04 01:46:10 by mcomin #+# #+# */
/* Updated: 2026/03/24 05:23:16 by mcomin ### ########.fr */
/* Updated: 2026/03/24 06:28:48 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -49,7 +49,7 @@ int check_quotes(char *input)
i++;
}
if (quotes)
return (1);
return (i - 1);
return (0);
}

Expand All @@ -61,7 +61,7 @@ int check_pipes(char *input)
while (ft_isspace(input[i]))
i++;
if (input[i] == '|')
return (1);
return (-1);
i = 0;
while (input[i])
{
Expand All @@ -71,7 +71,7 @@ int check_pipes(char *input)
while (input[i] && ft_isspace(input[i]))
i++;
if (input[i] == '|' || !input[i])
return (1);
return (i);
}
else
i++;
Expand All @@ -92,12 +92,12 @@ int check_redirections(char *input)
{
i += check_count_redir(input + i);
if (i == -1)
return (1);
return (-1);
while (input[i] && ft_isspace(input[i]))
i++;
if (!input[i] || (input[i] == '>' || input[i] == '<')
|| input[i] == '|')
return (1);
return (i);
}
else
i++;
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion src/parse/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
95 changes: 95 additions & 0 deletions src/parse/split_space.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split_quotes.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/02/05 07:37:34 by mcomin #+# #+# */
/* Updated: 2026/02/17 08:30:21 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

#include "parsing.h"

static char **wordsmalloc(char const *s)
{
char **str;
size_t i;
size_t words;
int in_word;

i = 0;
words = 0;
in_word = 0;
while (s[i])
{
if (!in_word && !ft_isspace(s[i]))
{
words++;
in_word = 1;
}
else if (in_word && ft_isspace(s[i]) && !is_in_quotes(s, i))
in_word = 0;
i++;
}
str = ft_calloc(words + 1, sizeof(char *));
if (!str)
return (NULL);
return (str);
}

static void fill(char const *s, char **str)
{
size_t beg;
size_t end;
size_t i;

end = 0;
i = 0;
while (s[end])
{
while (ft_isspace(s[end]) && !is_in_quotes(s, end))
end++;
beg = end;
while (s[end] != '\0')
{
if (ft_isspace(s[end]) && !is_in_quotes(s, end))
break ;
end++;
}
if (end > 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);
}
2 changes: 1 addition & 1 deletion src/parse/wildcards.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: apuyane <apuyane@student.42angouleme.fr +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/03/15 21:41:58 by apuyane #+# #+# */
/* Updated: 2026/03/21 03:34:44 by apuyane ### ########.fr */
/* Updated: 2026/03/24 05:47:49 by apuyane ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down
Loading