base ast + coloriage
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
# include "colors.h"
|
||||
# include "general.h"
|
||||
# include "srcs/drawio/drawio.h"
|
||||
# include "srcs/drawio/lib_drawio.h"
|
||||
|
||||
int ft_isalpha(int c);
|
||||
int ft_isdigit(int c);
|
||||
|
||||
@@ -10,8 +10,8 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DRAWIO_H
|
||||
# define DRAWIO_H
|
||||
#ifndef LIB_DRAWIO_H
|
||||
# define LIB_DRAWIO_H
|
||||
|
||||
# include "../../libft.h"
|
||||
|
||||
@@ -30,6 +30,9 @@ t_ast_n *created_ast_n(t_state st, t_ast_n *prt, t_ast_n *he)
|
||||
node->redir = _NR;
|
||||
node->infile = NULL;
|
||||
node->outfile = NULL;
|
||||
node->left = NULL;
|
||||
node->right = NULL;
|
||||
node->pline = NULL;
|
||||
if (prt)
|
||||
node->shlvl = prt->shlvl;
|
||||
else
|
||||
|
||||
26
tests/drawio/drawio.h
Normal file
26
tests/drawio/drawio.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* drawio.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 14:20:35 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/27 14:20:35 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef DRAWIO_H
|
||||
# define DRAWIO_H
|
||||
|
||||
# include "../../lib/libft/libft.h"
|
||||
# include "../tokenizer/tokenizer.h"
|
||||
# include "../ast/ast.h"
|
||||
|
||||
// internal
|
||||
char* replace_ampercent(char *src);
|
||||
|
||||
// external
|
||||
void gen_dio_linked_list(t_node *head, int fd);
|
||||
void gen_dio_ast(t_ast_n *head, int fd);
|
||||
#endif
|
||||
83
tests/drawio/drawio_ast.c
Normal file
83
tests/drawio/drawio_ast.c
Normal file
@@ -0,0 +1,83 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* drawio_ast.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/27 17:15:39 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/27 17:15:39 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
|
||||
void set_ast_rect(t_dio_elem *rect)
|
||||
{
|
||||
rect->type = RECT;
|
||||
rect->rounded = 0;
|
||||
rect->x = 50;
|
||||
rect->y = 150;
|
||||
rect->w = 150;
|
||||
rect->h = 100;
|
||||
}
|
||||
|
||||
const char *translate_state(t_state state)
|
||||
{
|
||||
const char *out;
|
||||
|
||||
if (state == _AND)
|
||||
out = "CMD_AND";
|
||||
else if (state == _OR)
|
||||
out = "CMD_OR";
|
||||
else if (state == _PLINE)
|
||||
out = "CMD_PIPELINE";
|
||||
else if (state == _CMD)
|
||||
out = "SIMPLE_CMD";
|
||||
else
|
||||
out = "UNDEFINED";
|
||||
|
||||
return (out);
|
||||
|
||||
}
|
||||
|
||||
void print_ast(t_ast_n *node, t_dio_elem *rect, int fd)
|
||||
{
|
||||
int i;
|
||||
const char *state;
|
||||
|
||||
if (!node || !rect)
|
||||
return;
|
||||
|
||||
state = translate_state(node->state);
|
||||
rect->text = ft_sprintf("%s\ntest", state);
|
||||
drawio_create_elem(fd, rect);
|
||||
|
||||
if (node->state != _PLINE)
|
||||
{
|
||||
rect->y += rect->h + 50;
|
||||
print_ast(node->left, rect, fd);
|
||||
rect->x += rect->w + 50;
|
||||
print_ast(node->right, rect, fd);
|
||||
rect->y -= rect->h + 50;
|
||||
rect->x -= rect->w + 50;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = 0;
|
||||
rect->y += rect->h + 50;
|
||||
while (node->pline[i])
|
||||
{
|
||||
print_ast(node->pline[i++], rect, fd);
|
||||
rect->x += rect->w + 50;
|
||||
}
|
||||
}
|
||||
}
|
||||
void gen_dio_ast(t_ast_n *head, int fd)
|
||||
{
|
||||
t_dio_elem rect;
|
||||
|
||||
set_ast_rect(&rect);
|
||||
print_ast(head, &rect, fd);
|
||||
return ;
|
||||
}
|
||||
46
tests/drawio/drawio_linklist.c
Normal file
46
tests/drawio/drawio_linklist.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* drawio_linklist.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/24 14:41:02 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/27 17:16:53 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "drawio.h"
|
||||
|
||||
void set_ll_rect(t_dio_elem *rect)
|
||||
{
|
||||
rect->type = RECT;
|
||||
rect->rounded = 0;
|
||||
rect->x = 50;
|
||||
rect->y = 50;
|
||||
rect->w = 100;
|
||||
rect->h = 50;
|
||||
}
|
||||
|
||||
void gen_dio_linked_list(t_node *head, int fd)
|
||||
{
|
||||
t_dio_elem rect;
|
||||
t_dio_elem arrow;
|
||||
t_node *current;
|
||||
|
||||
current = head;
|
||||
set_ll_rect(&rect);
|
||||
arrow.id_src = 0;
|
||||
arrow.type = ARROW;
|
||||
while (current != NULL)
|
||||
{
|
||||
rect.text = ft_sprintf("%s", current->val);
|
||||
rect.text = replace_ampercent(rect.text);
|
||||
arrow.id_dst = drawio_create_elem(fd, &rect);
|
||||
drawio_create_elem(fd, &arrow);
|
||||
arrow.id_src = arrow.id_dst;
|
||||
rect.x += 150;
|
||||
free(rect.text);
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* drawio.c :+: :+: :+: */
|
||||
/* drawio_utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/01/24 14:41:02 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/24 14:41:02 by nalebrun ### ########.fr */
|
||||
/* Created: 2025/01/27 15:09:16 by nalebrun #+# #+# */
|
||||
/* Updated: 2025/01/27 15:09:16 by nalebrun ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "parsing.h"
|
||||
#include "tokenizer/tokenizer.h"
|
||||
#include "drawio.h"
|
||||
|
||||
int get_amp_count(char *str)
|
||||
static int get_amp_count(char *str)
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
@@ -58,33 +57,4 @@ char* replace_ampercent(char *src)
|
||||
return (out);
|
||||
}
|
||||
|
||||
void gen_dio_linked_list(t_node *head, char *fp)
|
||||
{
|
||||
int fd;
|
||||
t_dio_elem rect;
|
||||
t_dio_elem arrow;
|
||||
t_node *current;
|
||||
|
||||
current = head;
|
||||
fd = drawio_init(fp);
|
||||
rect.type = RECT;
|
||||
rect.rounded = 0;
|
||||
rect.x = 50;
|
||||
rect.y = 50;
|
||||
rect.w = 100;
|
||||
rect.h = 50;
|
||||
arrow.id_src = 0;
|
||||
arrow.type = ARROW;
|
||||
while (current != NULL)
|
||||
{
|
||||
rect.text = ft_sprintf("|||%s|||", current->val);
|
||||
rect.text = replace_ampercent(rect.text);
|
||||
arrow.id_dst = drawio_create_elem(fd, &rect);
|
||||
drawio_create_elem(fd, &arrow);
|
||||
arrow.id_src = arrow.id_dst;
|
||||
rect.x += 150;
|
||||
free(rect.text);
|
||||
current = current->next;
|
||||
}
|
||||
drawio_end_file(fd);
|
||||
}
|
||||
@@ -15,9 +15,9 @@
|
||||
|
||||
# include "tokenizer/tokenizer.h"
|
||||
# include "ast/ast.h"
|
||||
# include "drawio/drawio.h"
|
||||
|
||||
// drawio
|
||||
void gen_dio_linked_list(t_node *head, char *fp);
|
||||
|
||||
// tmp_env
|
||||
char **init_env(char **envp);
|
||||
|
||||
@@ -49,6 +49,8 @@ void truncate_comment(char *str)
|
||||
int main(int ac, char **av, char **envp)
|
||||
{
|
||||
t_node *lst;
|
||||
t_ast_n *ast;
|
||||
int dio;
|
||||
/*t_data data;*/
|
||||
|
||||
if (ac != 3)
|
||||
@@ -61,8 +63,11 @@ int main(int ac, char **av, char **envp)
|
||||
lst = tokenize(av[2]);
|
||||
if (!lst)
|
||||
return (1);
|
||||
gen_dio_linked_list(lst, av[1]);
|
||||
dio = drawio_init(av[1]);
|
||||
gen_dio_linked_list(lst, dio);
|
||||
/*debug_linked_list(lst, "ff");*/
|
||||
return_hardcode_ast(envp);
|
||||
ast = return_hardcode_ast(envp);
|
||||
gen_dio_ast(ast, dio);
|
||||
drawio_end_file(dio);
|
||||
free_linked_list(lst);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user