This commit is contained in:
gazhonsepaskwa
2025-02-07 12:35:13 +01:00
parent 4d63a10900
commit 4c678f767d
6 changed files with 76 additions and 13 deletions

View File

@@ -62,5 +62,6 @@ int is_sticked(char *val);
int trim_nodes(t_node *head);
void debug_linked_list(t_node *head, char *msg);
int find_quote_node(t_node *head, char q);
int syntax_error(t_node *head);
#endif

View File

@@ -45,6 +45,7 @@ char *ft_strjoin(const char *s1, const char *s2);
char *ft_strtrim(const char *s1, const char *set);
char *ft_strmapi(char const *s, char (*f)(unsigned int, char));
void ft_striteri(char *s, void (*f)(unsigned int, char *));
int is_only_space(char *str);
void *ft_memset(void *b, int c, size_t len);
void *ft_memcpy(void *dst, const void *src, size_t n);

View File

@@ -21,6 +21,17 @@ static int ft_isspace(char c)
return (0);
}
int is_only_space(char *str)
{
int i;
i = -1;
while (str[++i])
if (!ft_isspace(str[i]))
return (0);
return (1);
}
static int ft_signer(char c, int *i)
{
int sign;

View File

@@ -18,36 +18,41 @@ static char *powerline(void)
char *tilt;
char *input;
char *prompt;
char *line;
pwd = getcwd(NULL, 0);
tilt = " ";
if (ft_strncmp(pwd, "/home/", 6) == 0)
{
pwd = pwd + 6;
pwd += 6;
while (*pwd && (*pwd) != '/')
pwd = pwd + 1;
pwd ++;
tilt = " ~";
}
else
tilt = " ";
// printf("%s----------------------------------------------
// ----------------------------------%s", POW5, RESET);
prompt = ft_sprintf("\n%s  MMOAT %s%s%s%s%s %s%s%s ",
POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
line = ft_sprintf("%s----------------------------------------------\
----------------------------------%s", POW5, RESET);
prompt = ft_sprintf("%s\n%s  MMOAT %s%s%s%s%s %s%s%s ",
line, POW1, POW2, POW3, POW4, tilt, pwd, RESET, POW5, RESET);
input = readline(prompt);
if (ft_strlen(input) > 0)
add_history(input);
free(prompt);
free(line);
return (input);
}
static void interpret_cmd(char **input, t_msh *msh)
{
msh->head = parser(*input, msh);
if (!msh->head)
{
ft_free(input);
return ;
}
msh->ex_code = execute_command(msh->head);
free_ast(msh->head);
msh->head = NULL;
free(*input);
*input = NULL;
ft_free(input);
}
int main(int ac, char **av, char **envp)
@@ -60,12 +65,14 @@ int main(int ac, char **av, char **envp)
if (!msh)
return (1);
if (ac == 1)
{
while (1)
{
while (!msh->input || !msh->input[0])
while (!msh->input || !msh->input[0] || is_only_space(msh->input))
msh->input = powerline();
interpret_cmd(&msh->input, msh);
}
}
else
{
msh->input = ft_strdup(av[1]);

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test.c :+: :+: :+: */
/* parser.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/15 08:23:41 by nalebrun #+# #+# */
/* Updated: 2025/02/03 11:49:21 by nalebrun ### ########.fr */
/* Updated: 2025/02/07 12:08:40 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
@@ -46,6 +46,8 @@ t_ast_n *parser(char *input, t_msh *msh)
lst = tokenize(input);
if (!lst)
return (NULL);
if (syntax_error(lst))
return (NULL);
if (DEBUG)
{
dio = drawio_init("ast.xml");

41
srcs/parsing/syntax.c Normal file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* syntax.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/02/07 12:08:53 by nalebrun #+# #+# */
/* Updated: 2025/02/07 12:08:53 by nalebrun ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/parser/parsing.h"
int only_operator(t_node *head)
{
if (!head->next && head->token == OPERATOR)
return (1);
return (0);
}
int syntax_err_mess(char *token)
{
ft_fprintf(2, "minishell : syntax error near unexpected token `%s'\n", token);
return (1);
}
int syntax_error(t_node *head)
{
// t_node *cpy;
if (only_operator(head))
return(syntax_err_mess(head->val));
// cpy = node;
// while (cpy)
// {
// cpy = cpy->next;
// }
return (0);
}