cleenup
This commit is contained in:
6
Makefile
6
Makefile
@@ -36,7 +36,7 @@ $(NAME): $(LIBFT) $(OBJS)
|
||||
|
||||
# test part
|
||||
|
||||
TEST_SRCDIR = tests
|
||||
TEST_SRCDIR = test
|
||||
TEST_OBJDIR = .TEST_objs
|
||||
TEST_SRCS = $(shell find $(TEST_SRCDIR) -name "*.c")
|
||||
TEST_OBJS = $(patsubst $(TEST_SRCDIR)/%.c, $(TEST_OBJDIR)/%.o, $(TEST_SRCS))
|
||||
@@ -46,8 +46,8 @@ $(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
|
||||
|
||||
tests: $(LIBFT) $(TEST_OBJS)
|
||||
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK)
|
||||
parser: $(LIBFT) $(TEST_OBJS)
|
||||
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o parser $(LINK)
|
||||
@echo "$(CYAN)Test build completed: test$(RESET)"
|
||||
|
||||
# test part end
|
||||
|
||||
@@ -47,10 +47,11 @@ void setup_cmd(t_ast_n *node, char *cmd, char *args)
|
||||
node->args = ft_split(args, " ");
|
||||
}
|
||||
|
||||
t_ast_n *return_hardcode_ast(char **envp)
|
||||
t_ast_n *get_ast(char **envp, t_node *lst)
|
||||
{
|
||||
t_ast_n *head;
|
||||
|
||||
(void)lst;
|
||||
// head
|
||||
head = created_ast_n(_AND, NULL, NULL);
|
||||
head->env = init_env(envp);
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
/*# include "../../includes/env.h"*/
|
||||
# include "../../lib/libft/libft.h"
|
||||
# include "../tokenizer/tokenizer.h"
|
||||
|
||||
typedef enum e_state
|
||||
{
|
||||
@@ -54,7 +55,7 @@ typedef struct s_ast_n
|
||||
char **env;
|
||||
} t_ast_n;
|
||||
|
||||
t_ast_n *return_hardcode_ast(char **envp);
|
||||
t_ast_n *get_ast(char **envp, t_node *lst);
|
||||
|
||||
// env TMP
|
||||
char **init_env(char **envp);
|
||||
@@ -13,11 +13,13 @@
|
||||
#ifndef PARSING_H
|
||||
# define PARSING_H
|
||||
|
||||
# define DEBUG 1
|
||||
|
||||
# include "tokenizer/tokenizer.h"
|
||||
# include "ast/ast.h"
|
||||
# include "drawio/drawio.h"
|
||||
|
||||
// drawio
|
||||
# include "drawio/drawio.h"
|
||||
|
||||
// tmp_env
|
||||
char **init_env(char **envp);
|
||||
@@ -11,7 +11,6 @@
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
/*#include "../includes/env.h"*/
|
||||
|
||||
void truncate_comment(char *str)
|
||||
{
|
||||
@@ -37,37 +36,34 @@ void truncate_comment(char *str)
|
||||
}
|
||||
}
|
||||
|
||||
/*static t_data *init_data(char **envp)*/
|
||||
/*{*/
|
||||
/* t_data *data;*/
|
||||
/**/
|
||||
/* data = malloc (sizeof(t_data));*/
|
||||
/* data->env = init_env(envp);*/
|
||||
/* return (data);*/
|
||||
/*}*/
|
||||
|
||||
int main(int ac, char **av, char **envp)
|
||||
{
|
||||
t_node *lst;
|
||||
t_ast_n *ast;
|
||||
int dio;
|
||||
/*t_data data;*/
|
||||
|
||||
if (ac != 3)
|
||||
{
|
||||
ft_error("./test drawio_file command_str\n");
|
||||
return (1);
|
||||
}
|
||||
/*data = init_data(envp);*/
|
||||
truncate_comment(av[1]);
|
||||
lst = tokenize(av[2]);
|
||||
if (!lst)
|
||||
return (1);
|
||||
if (DEBUG)
|
||||
{
|
||||
dio = drawio_init(av[1]);
|
||||
gen_dio_linked_list(lst, dio);
|
||||
/*debug_linked_list(lst, "ff");*/
|
||||
ast = return_hardcode_ast(envp);
|
||||
}
|
||||
ast = get_ast(envp, lst);
|
||||
if (!ast)
|
||||
return (1);
|
||||
if (DEBUG)
|
||||
{
|
||||
gen_dio_ast(ast, dio);
|
||||
drawio_end_file(dio);
|
||||
ft_debug(" draw.io file generated !\n");
|
||||
}
|
||||
free_linked_list(lst);
|
||||
}
|
||||
@@ -81,65 +81,3 @@ int merge_with_next_node(t_node *node)
|
||||
node->next = tmp_next;
|
||||
return (1);
|
||||
}
|
||||
|
||||
// have to be deleted after
|
||||
void debug_linked_list(t_node *head, char *msg)
|
||||
{
|
||||
t_node *current;
|
||||
char *token;
|
||||
char *pres;
|
||||
|
||||
current = head;
|
||||
printf("----------------------------------------------------------{%s} \n",
|
||||
msg);
|
||||
while (current != NULL)
|
||||
{
|
||||
// set val for base token
|
||||
if (current->token == OPERATOR)
|
||||
token = ft_strdup("OPERATOR");
|
||||
else if (current->token == WORD)
|
||||
token = ft_strdup(" WORD");
|
||||
else if (current->token == UNSET)
|
||||
token = ft_strdup(" UNSET");
|
||||
else
|
||||
token = ft_strdup(" ???");
|
||||
|
||||
// set vals for pressision token
|
||||
if (current->pressision == COMMAND)
|
||||
pres = ft_strdup("COMMAND ");
|
||||
else if (current->pressision == UNDEFINED)
|
||||
pres = ft_strdup("UNDEF ");
|
||||
else if (current->pressision == AND)
|
||||
pres = ft_strdup("AND ");
|
||||
else if (current->pressision == OR)
|
||||
pres = ft_strdup("OR ");
|
||||
else if (current->pressision == PIPE)
|
||||
pres = ft_strdup("PIPE ");
|
||||
else if (current->pressision == SUBSH_S)
|
||||
pres = ft_strdup("SUBSH_S ");
|
||||
else if (current->pressision == SUBSH_E)
|
||||
pres = ft_strdup("SUBSH_E ");
|
||||
else if (current->pressision == RED_L)
|
||||
pres = ft_strdup("RED_L ");
|
||||
else if (current->pressision == RED_R)
|
||||
pres = ft_strdup("RED_R ");
|
||||
else if (current->pressision == HEREDOC)
|
||||
pres = ft_strdup("HEREDOC ");
|
||||
else if (current->pressision == D_RED_R)
|
||||
pres = ft_strdup("D_RED_R ");
|
||||
else if (current->pressision == PARAMETER)
|
||||
pres = ft_strdup("PARAMETER");
|
||||
else if (current->pressision == RED_FILE)
|
||||
pres = ft_strdup("RED_FILE ");
|
||||
else if (current->pressision == LIM)
|
||||
pres = ft_strdup("LIM ");
|
||||
else
|
||||
pres = ft_strdup("??? ");
|
||||
|
||||
printf("| Node - TOKEN: %s.%s -> val: |%s|\n", token, pres, current->val);
|
||||
free(token);
|
||||
free(pres);
|
||||
current = current->next;
|
||||
}
|
||||
printf("----------------------------------------------------------\n\n");
|
||||
}
|
||||
@@ -13,7 +13,7 @@
|
||||
#ifndef TOKENIZER_H
|
||||
# define TOKENIZER_H
|
||||
|
||||
# include "../includes/minishell.h"
|
||||
# include "../../lib/libft/libft.h"
|
||||
|
||||
typedef enum e_token
|
||||
{
|
||||
Reference in New Issue
Block a user