syntax
This commit is contained in:
29
srcs/main.c
29
srcs/main.c
@@ -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]);
|
||||
|
||||
@@ -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
41
srcs/parsing/syntax.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user