drawio done and at norm
This commit is contained in:
@@ -64,6 +64,7 @@ void ft_bzero(void *s, size_t n);
|
|||||||
|
|
||||||
char **ft_split(const char *s, char *set);
|
char **ft_split(const char *s, char *set);
|
||||||
char **ft_split_keep(const char *s, char *set);
|
char **ft_split_keep(const char *s, char *set);
|
||||||
|
char *ft_tabstr(char **tab);
|
||||||
int is_charset(char c, char *set);
|
int is_charset(char c, char *set);
|
||||||
void free_tab(char **tab);
|
void free_tab(char **tab);
|
||||||
char **free_all(char **tab, int count);
|
char **free_all(char **tab, int count);
|
||||||
|
|||||||
36
lib/libft/srcs/format/ft_tabstr.c
Normal file
36
lib/libft/srcs/format/ft_tabstr.c
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ft_tabstr.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/29 08:54:00 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/29 08:54:00 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../../libft.h"
|
||||||
|
|
||||||
|
char *ft_tabstr(char **tab)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int alloc_count;
|
||||||
|
char *out;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
|
i = -1;
|
||||||
|
alloc_count = 0;
|
||||||
|
while (tab[++i])
|
||||||
|
alloc_count += ft_strlen(tab[i]) + 1;
|
||||||
|
i = 0;
|
||||||
|
out = tab[0];
|
||||||
|
while (tab[++i])
|
||||||
|
{
|
||||||
|
tmp = out;
|
||||||
|
out = ft_sprintf("%s %s", out, tab[i]);
|
||||||
|
free(tmp);
|
||||||
|
}
|
||||||
|
out[alloc_count] = 0;
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
@@ -17,8 +17,26 @@
|
|||||||
# include "../tokenizer/tokenizer.h"
|
# include "../tokenizer/tokenizer.h"
|
||||||
# include "../ast/ast.h"
|
# include "../ast/ast.h"
|
||||||
|
|
||||||
|
typedef struct s_dio_node
|
||||||
|
{
|
||||||
|
const char *st;
|
||||||
|
const char *redir;
|
||||||
|
char *cmd;
|
||||||
|
char *args;
|
||||||
|
char *inf;
|
||||||
|
char *outf;
|
||||||
|
} t_dio_node;
|
||||||
|
|
||||||
|
typedef struct s_elems
|
||||||
|
{
|
||||||
|
t_dio_elem rect;
|
||||||
|
t_dio_elem arrow;
|
||||||
|
} t_elems;
|
||||||
|
|
||||||
// internal
|
// internal
|
||||||
char* replace_ampercent(char *src);
|
char *replace_ampercent(char *src);
|
||||||
|
t_dio_node get_cmd_txt(t_ast_n *node);
|
||||||
|
int print_ast(t_ast_n *node, t_elems *e, int fd);
|
||||||
|
|
||||||
// external
|
// external
|
||||||
void gen_dio_linked_list(t_node *head, int fd);
|
void gen_dio_linked_list(t_node *head, int fd);
|
||||||
|
|||||||
@@ -19,128 +19,17 @@ void set_ast_rect(t_dio_elem *rect)
|
|||||||
rect->x = 50;
|
rect->x = 50;
|
||||||
rect->y = 150;
|
rect->y = 150;
|
||||||
rect->w = 150;
|
rect->w = 150;
|
||||||
rect->h = 150;
|
rect->h = 120;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *translate_redir(t_redir redir)
|
|
||||||
{
|
|
||||||
const char *out;
|
|
||||||
|
|
||||||
if (redir == _RED_L)
|
|
||||||
out = "redir : < ";
|
|
||||||
else if (redir == _RED_R)
|
|
||||||
out = "redir : > ";
|
|
||||||
else if (redir == _RED_DR)
|
|
||||||
out = "redir : >> ";
|
|
||||||
else
|
|
||||||
out = "Not redirected ";
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_node_txt(t_ast_n *node)
|
|
||||||
{
|
|
||||||
const char *st;
|
|
||||||
char *out;
|
|
||||||
char *cmd;
|
|
||||||
char *args;
|
|
||||||
const char *redir;
|
|
||||||
char *inf;
|
|
||||||
char *outf;
|
|
||||||
|
|
||||||
st = translate_state(node->state);
|
|
||||||
if (node->state == _CMD)
|
|
||||||
{
|
|
||||||
cmd = ft_sprintf("%s%s%s", NL, node->cmd, NL);
|
|
||||||
args = ft_sprintf("future args", NL);
|
|
||||||
redir = translate_redir(node->redir);
|
|
||||||
inf = ft_sprintf("Infile : %s%s", node->infile, NL);
|
|
||||||
outf = ft_sprintf("Outfile : %s%s", node->outfile, NL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cmd = ft_calloc(1, 1);
|
|
||||||
args = ft_calloc(1, 1);
|
|
||||||
redir = "";
|
|
||||||
inf = ft_calloc(1, 1);
|
|
||||||
outf = ft_calloc(1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
out = ft_sprintf("%s%s%s%s%s%s%s", st, cmd, args, NL, redir, inf, outf);
|
|
||||||
free(cmd);
|
|
||||||
free(args);
|
|
||||||
free(inf);
|
|
||||||
free(outf);
|
|
||||||
return (out);
|
|
||||||
}
|
|
||||||
|
|
||||||
int print_ast(t_ast_n *node, t_dio_elem *rect, t_dio_elem *arrow, int fd)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
int node_id;
|
|
||||||
|
|
||||||
if (!node || !rect)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
rect->text = get_node_txt(node);
|
|
||||||
node_id = drawio_create_elem(fd, rect);
|
|
||||||
|
|
||||||
if (node->state != _PLINE)
|
|
||||||
{
|
|
||||||
rect->y += rect->h + 50;
|
|
||||||
arrow->id_dst = print_ast(node->left, rect, arrow, fd);
|
|
||||||
arrow->id_src = node_id;
|
|
||||||
drawio_create_elem(fd, arrow);
|
|
||||||
|
|
||||||
rect->x += rect->w + 50;
|
|
||||||
arrow->id_dst = print_ast(node->right, rect, arrow, fd);
|
|
||||||
arrow->id_src = node_id;
|
|
||||||
drawio_create_elem(fd, arrow);
|
|
||||||
|
|
||||||
rect->y -= rect->h + 50;
|
|
||||||
if (node->state == _CMD)
|
|
||||||
rect->x -= rect->w + 50;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
i = 0;
|
|
||||||
rect->y += rect->h + 50;
|
|
||||||
while (node->pline[i])
|
|
||||||
{
|
|
||||||
arrow->id_dst = print_ast(node->pline[i++], rect, arrow, fd);
|
|
||||||
arrow->id_src = node_id;
|
|
||||||
drawio_create_elem(fd, arrow);
|
|
||||||
rect->x += rect->w + 50;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return (node_id);
|
|
||||||
}
|
|
||||||
void gen_dio_ast(t_ast_n *head, int fd)
|
void gen_dio_ast(t_ast_n *head, int fd)
|
||||||
{
|
{
|
||||||
t_dio_elem rect;
|
t_elems e;
|
||||||
t_dio_elem arrow;
|
|
||||||
|
|
||||||
set_ast_rect(&rect);
|
set_ast_rect(&e.rect);
|
||||||
arrow.type = ARROW;
|
e.arrow.type = ARROW;
|
||||||
arrow.id_src = 0;
|
e.arrow.id_src = 0;
|
||||||
arrow.id_dst = 0;
|
e.arrow.id_dst = 0;
|
||||||
|
print_ast(head, &e, fd);
|
||||||
print_ast(head, &rect, &arrow, fd);
|
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|||||||
69
tests/drawio/drawio_ast_utils.c
Normal file
69
tests/drawio/drawio_ast_utils.c
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* drawio_ast_utils.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/29 09:21:09 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/29 09:21:09 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "drawio.h"
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *translate_redir(t_redir redir)
|
||||||
|
{
|
||||||
|
const char *out;
|
||||||
|
|
||||||
|
if (redir == _RED_L)
|
||||||
|
out = "redir : < ";
|
||||||
|
else if (redir == _RED_R)
|
||||||
|
out = "redir : > ";
|
||||||
|
else if (redir == _RED_DR)
|
||||||
|
out = "redir : >> ";
|
||||||
|
else
|
||||||
|
out = "Not redirected ";
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
|
|
||||||
|
t_dio_node get_cmd_txt(t_ast_n *node)
|
||||||
|
{
|
||||||
|
t_dio_node txt;
|
||||||
|
|
||||||
|
txt.st = translate_state(node->state);
|
||||||
|
if (node->state == _CMD)
|
||||||
|
{
|
||||||
|
txt.cmd = ft_sprintf("%s%s%s", NL, node->cmd, NL);
|
||||||
|
txt.args = ft_sprintf(ft_tabstr(node->args), NL);
|
||||||
|
txt.redir = translate_redir(node->redir);
|
||||||
|
txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL);
|
||||||
|
txt.outf = ft_sprintf("Outfile : %s", node->outfile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
txt.cmd = ft_calloc(1, 1);
|
||||||
|
txt.args = ft_calloc(1, 1);
|
||||||
|
txt.redir = "";
|
||||||
|
txt.inf = ft_calloc(1, 1);
|
||||||
|
txt.outf = ft_calloc(1, 1);
|
||||||
|
}
|
||||||
|
return (txt);
|
||||||
|
}
|
||||||
73
tests/drawio/drawio_print_ast.c
Normal file
73
tests/drawio/drawio_print_ast.c
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* drawio_print_ast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/29 09:54:31 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/29 09:54:31 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "drawio.h"
|
||||||
|
|
||||||
|
char *get_node_txt(t_ast_n *node)
|
||||||
|
{
|
||||||
|
t_dio_node txt;
|
||||||
|
char *out;
|
||||||
|
|
||||||
|
txt = get_cmd_txt(node);
|
||||||
|
out = ft_sprintf("%s%s%s%s%s%s%s", txt.st, txt.cmd, txt.args,
|
||||||
|
NL, txt.redir, txt.inf, txt.outf);
|
||||||
|
free(txt.cmd);
|
||||||
|
free(txt.args);
|
||||||
|
free(txt.inf);
|
||||||
|
free(txt.outf);
|
||||||
|
return (out);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_bin_part(t_ast_n *node, t_elems *e, int fd, int node_id)
|
||||||
|
{
|
||||||
|
e->rect.y += e->rect.h + 50;
|
||||||
|
e->arrow.id_dst = print_ast(node->left, e, fd);
|
||||||
|
e->arrow.id_src = node_id;
|
||||||
|
drawio_create_elem(fd, &e->arrow);
|
||||||
|
e->rect.x += e->rect.w + 50;
|
||||||
|
e->arrow.id_dst = print_ast(node->right, e, fd);
|
||||||
|
e->arrow.id_src = node_id;
|
||||||
|
drawio_create_elem(fd, &e->arrow);
|
||||||
|
e->rect.y -= e->rect.h + 50;
|
||||||
|
if (node->state == _CMD)
|
||||||
|
e->rect.x -= e->rect.w + 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_pline_part(t_ast_n *node, t_elems *e, int fd, int node_id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
e->rect.y += e->rect.h + 50;
|
||||||
|
while (node->pline[i])
|
||||||
|
{
|
||||||
|
e->arrow.id_dst = print_ast(node->pline[i++], e, fd);
|
||||||
|
e->arrow.id_src = node_id;
|
||||||
|
drawio_create_elem(fd, &e->arrow);
|
||||||
|
e->rect.x += e->rect.w + 50;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int print_ast(t_ast_n *node, t_elems *e, int fd)
|
||||||
|
{
|
||||||
|
int node_id;
|
||||||
|
|
||||||
|
if (!node)
|
||||||
|
return (-1);
|
||||||
|
e->rect.text = get_node_txt(node);
|
||||||
|
node_id = drawio_create_elem(fd, &e->rect);
|
||||||
|
if (node->state != _PLINE)
|
||||||
|
draw_bin_part(node, e, fd, node_id);
|
||||||
|
else
|
||||||
|
draw_pline_part(node, e, fd, node_id);
|
||||||
|
return (node_id);
|
||||||
|
}
|
||||||
@@ -56,5 +56,3 @@ char *replace_ampercent(char *src)
|
|||||||
out[j] = 0;
|
out[j] = 0;
|
||||||
return (out);
|
return (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user