drawio generator
This commit is contained in:
2
Makefile
2
Makefile
@@ -46,7 +46,7 @@ $(TEST_OBJDIR)/%.o: $(TEST_SRCDIR)/%.c
|
|||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
|
@$(CC) $(WFLAGS) -MMD -MP -I$(INCDIR) -c $< -g3 -ggdb -o $@ $(LINK)
|
||||||
|
|
||||||
test: $(LIBFT) $(TEST_OBJS)
|
tests: $(LIBFT) $(TEST_OBJS)
|
||||||
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK)
|
@$(CC) $(WFLAGS) $(TEST_OBJS) $(LIBFT) -o test $(LINK)
|
||||||
@echo "$(CYAN)Test build completed: test$(RESET)"
|
@echo "$(CYAN)Test build completed: test$(RESET)"
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
<mxfile host="app.diagrams.net" modified="2025-01-24T12:00:00Z" agent="C-Shell-AST" version="15.8.7" type="device">
|
|
||||||
<diagram id="AST" name="AST-Diagram">
|
|
||||||
<mxGraphModel>
|
|
||||||
<root>
|
|
||||||
<mxCell id="0"/>
|
|
||||||
<mxCell id="1" parent="0"/>
|
|
||||||
<mxCell id="104" value="SEQUENCE" style="shape=rectangle;whiteSpace=wrap;html=1;"
|
|
||||||
vertex="1" parent="1">
|
|
||||||
<mxGeometry x="160.00" y="0.00" width="120.00" height="60.00" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="103" value="PIPE" style="shape=rectangle;whiteSpace=wrap;html=1;"
|
|
||||||
vertex="1" parent="1">
|
|
||||||
<mxGeometry x="80.00" y="160.00" width="120.00" height="60.00" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="100" value="COMMAND\nls -l " style="shape=rectangle;whiteSpace=wrap;html=1;"
|
|
||||||
vertex="1" parent="1">
|
|
||||||
<mxGeometry x="0.00" y="320.00" width="120.00" height="60.00" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="101" value="COMMAND\ngrep .c " style="shape=rectangle;whiteSpace=wrap;html=1;"
|
|
||||||
vertex="1" parent="1">
|
|
||||||
<mxGeometry x="160.00" y="320.00" width="120.00" height="60.00" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="102" value="COMMAND\necho done " style="shape=rectangle;whiteSpace=wrap;html=1;"
|
|
||||||
vertex="1" parent="1">
|
|
||||||
<mxGeometry x="320.00" y="160.00" width="120.00" height="60.00" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="edge_104_103" edge="1" parent="1" source="104" target="103">
|
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="edge_104_102" edge="1" parent="1" source="104" target="102">
|
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="edge_103_100" edge="1" parent="1" source="103" target="100">
|
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
<mxCell id="edge_103_101" edge="1" parent="1" source="103" target="101">
|
|
||||||
<mxGeometry relative="1" as="geometry"/>
|
|
||||||
</mxCell>
|
|
||||||
</root>
|
|
||||||
</mxGraphModel>
|
|
||||||
</diagram>
|
|
||||||
</mxfile>
|
|
||||||
@@ -19,10 +19,12 @@
|
|||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
# include <stdarg.h>
|
# include <stdarg.h>
|
||||||
|
# include <fcntl.h>
|
||||||
# include <errno.h>
|
# include <errno.h>
|
||||||
|
|
||||||
# include "colors.h"
|
# include "colors.h"
|
||||||
# include "general.h"
|
# include "general.h"
|
||||||
|
# include "srcs/drawio/drawio.h"
|
||||||
|
|
||||||
int ft_isalpha(int c);
|
int ft_isalpha(int c);
|
||||||
int ft_isdigit(int c);
|
int ft_isdigit(int c);
|
||||||
@@ -80,6 +82,7 @@ void ft_error(char *e);
|
|||||||
|
|
||||||
int ft_printf(const char *fstr, ...);
|
int ft_printf(const char *fstr, ...);
|
||||||
int ft_fprintf(int fd, const char *str, ...);
|
int ft_fprintf(int fd, const char *str, ...);
|
||||||
|
char *ft_sprintf(const char *str, ...);
|
||||||
int ft_debug(const char *fstr, ...);
|
int ft_debug(const char *fstr, ...);
|
||||||
|
|
||||||
char *get_next_line(int fd);
|
char *get_next_line(int fd);
|
||||||
|
|||||||
42
lib/libft/srcs/drawio/drawio.h
Normal file
42
lib/libft/srcs/drawio/drawio.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* drawio.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/24 09:34:41 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/24 09:34:41 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef DRAWIO_H
|
||||||
|
# define DRAWIO_H
|
||||||
|
|
||||||
|
#include "../../libft.h"
|
||||||
|
|
||||||
|
typedef enum e_dio_elemtype
|
||||||
|
{
|
||||||
|
RECT,
|
||||||
|
ARROW,
|
||||||
|
} t_dio_elemtype;
|
||||||
|
|
||||||
|
typedef struct s_dio_elem
|
||||||
|
{
|
||||||
|
t_dio_elemtype type;
|
||||||
|
char *text;
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
int id_src;
|
||||||
|
int id_dst;
|
||||||
|
int rounded;
|
||||||
|
|
||||||
|
} t_dio_elem;
|
||||||
|
|
||||||
|
int drawio_init(char *file_path);
|
||||||
|
int drawio_create_elem(int fd, t_dio_elem *elem);
|
||||||
|
void drawio_end_file(int fd);
|
||||||
|
|
||||||
|
#endif
|
||||||
19
lib/libft/srcs/drawio/header/dio_private.h
Normal file
19
lib/libft/srcs/drawio/header/dio_private.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* dio_private.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/24 11:06:54 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/24 11:06:54 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef DIO_PRIVATE
|
||||||
|
# define DIO_PRIVATE
|
||||||
|
|
||||||
|
int draw_rect(int fd, int id, t_dio_elem *elem);
|
||||||
|
int draw_arrow(int fd, int id, t_dio_elem *elem);
|
||||||
|
|
||||||
|
#endif
|
||||||
38
lib/libft/srcs/drawio/srcs/create_elem.c
Normal file
38
lib/libft/srcs/drawio/srcs/create_elem.c
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* create_elem.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/24 10:06:11 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/24 10:06:11 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../drawio.h"
|
||||||
|
#include "../header/dio_private.h"
|
||||||
|
|
||||||
|
int draw_rect(int fd, int id, t_dio_elem *elem)
|
||||||
|
{
|
||||||
|
ft_fprintf(fd, "<mxCell id=\"%d\" ", id);
|
||||||
|
ft_fprintf(fd, "value=\"%s\" ", elem->text);
|
||||||
|
ft_fprintf(fd, "style=\"rounded=%d;whiteSpace=wrap;html=1;\" ", elem->rounded);
|
||||||
|
ft_fprintf(fd, "vertex=\"1\" parent=\"1\"> \n");
|
||||||
|
ft_fprintf(fd, "<mxGeometry x=\"%d\" y=\"%d\" ", elem->x, elem->y);
|
||||||
|
ft_fprintf(fd, "width=\"%d\" height=\"%d\" ", elem->w, elem->h);
|
||||||
|
ft_fprintf(fd, "as=\"geometry\"/>\n");
|
||||||
|
ft_fprintf(fd, "</mxCell>\n");
|
||||||
|
return (id);
|
||||||
|
}
|
||||||
|
|
||||||
|
int draw_arrow(int fd, int id, t_dio_elem *elem)
|
||||||
|
{
|
||||||
|
if (!elem->id_src || !elem->id_dst)
|
||||||
|
return (0);
|
||||||
|
ft_fprintf(fd, "<mxCell id=\"%d\" ", id);
|
||||||
|
ft_fprintf(fd, "edge=\"1\" parent=\"1\" ");
|
||||||
|
ft_fprintf(fd, "source=\"%d\" target=\"%d\">\n", elem->id_src, elem->id_dst);
|
||||||
|
ft_fprintf(fd, "<mxGeometry relative=\"1\" as=\"geometry\"/>\n</mxCell>\n");
|
||||||
|
return (id);
|
||||||
|
}
|
||||||
50
lib/libft/srcs/drawio/srcs/drawio.c
Normal file
50
lib/libft/srcs/drawio/srcs/drawio.c
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* drawio.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/24 08:47:41 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/24 08:47:41 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "../drawio.h"
|
||||||
|
#include "../header/dio_private.h"
|
||||||
|
|
||||||
|
int drawio_init(char *file_path)
|
||||||
|
{
|
||||||
|
int fd;
|
||||||
|
|
||||||
|
fd = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||||
|
|
||||||
|
ft_fprintf(fd, "<mxfile host=\"app.diagrams.net\" ");
|
||||||
|
ft_fprintf(fd, "modified=\"2025-01-24T12:00:00Z\" ");
|
||||||
|
ft_fprintf(fd, "agent=\"c_generator\" version=\"15.8.7\" ");
|
||||||
|
ft_fprintf(fd, "type=\"device\">\n");
|
||||||
|
ft_fprintf(fd, "<diagram id=\"GEN\" name=\"GEN-Diagram\">\n");
|
||||||
|
ft_fprintf(fd, "<mxGraphModel>\n");
|
||||||
|
ft_fprintf(fd, "<root>\n");
|
||||||
|
ft_fprintf(fd, "<mxCell id=\"0\"/>\n");
|
||||||
|
ft_fprintf(fd, "<mxCell id=\"1\" parent=\"0\"/>\n");
|
||||||
|
return(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawio_end_file(int fd)
|
||||||
|
{
|
||||||
|
ft_fprintf(fd, "</root>\n</mxGraphModel>\n</diagram>\n</mxfile>");
|
||||||
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
int drawio_create_elem(int fd, t_dio_elem *elem)
|
||||||
|
{
|
||||||
|
static int id = 1;
|
||||||
|
|
||||||
|
id ++;
|
||||||
|
if (elem->type == ARROW)
|
||||||
|
return (draw_arrow(fd, id, elem));
|
||||||
|
if (elem->type == RECT || elem->type)
|
||||||
|
return (draw_rect(fd, id, elem));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
@@ -21,12 +21,15 @@ static int is_spec(char c)
|
|||||||
|
|
||||||
static char *add_arg(char c, char *str, va_list args)
|
static char *add_arg(char c, char *str, va_list args)
|
||||||
{
|
{
|
||||||
|
char *out;
|
||||||
|
|
||||||
if (c == 'c')
|
if (c == 'c')
|
||||||
return (ft_strfjoinc(str, va_arg(args, int)));
|
out = ft_strfjoinc(str, va_arg(args, int));
|
||||||
else if (c == 's')
|
else if (c == 's')
|
||||||
return (ft_strfjoin(str, va_arg(args, char *)));
|
out = ft_strfjoin(str, va_arg(args, char *));
|
||||||
else if (c == 'd')
|
else if (c == 'd')
|
||||||
return (ft_strfjoind(str, ft_itoa(va_arg(args, int))));
|
out = ft_strfjoind(str, ft_itoa(va_arg(args, int)));
|
||||||
|
return (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *build_str(const char *str, va_list args)
|
static char *build_str(const char *str, va_list args)
|
||||||
@@ -13,10 +13,7 @@
|
|||||||
#ifndef FT_SPRINTF_H
|
#ifndef FT_SPRINTF_H
|
||||||
# define FT_SPRINTF_H
|
# define FT_SPRINTF_H
|
||||||
|
|
||||||
# include <stdlib.h>
|
# include "../../libft.h"
|
||||||
# include <stdarg.h>
|
|
||||||
# include <stdio.h>
|
|
||||||
# include "../lib/libft/libft.h"
|
|
||||||
|
|
||||||
char *ft_strfjoin(char *s1, char *s2);
|
char *ft_strfjoin(char *s1, char *s2);
|
||||||
char *ft_strfjoinc(char *s1, char c);
|
char *ft_strfjoinc(char *s1, char c);
|
||||||
20
tests/ast/ast.c
Normal file
20
tests/ast/ast.c
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ast.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/24 08:22:16 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/24 08:22:16 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "ast.h"
|
||||||
|
|
||||||
|
/*void ast(t_node *token_lst)*/
|
||||||
|
/*{*/
|
||||||
|
/* t_node *head = token_lst;*/
|
||||||
|
/**/
|
||||||
|
/**/
|
||||||
|
/*}*/
|
||||||
19
tests/ast/ast.h
Normal file
19
tests/ast/ast.h
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* ast.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: nalebrun <nalebrun@student.s19.be> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2025/01/24 08:23:27 by nalebrun #+# #+# */
|
||||||
|
/* Updated: 2025/01/24 08:23:27 by nalebrun ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef AST_H
|
||||||
|
# define AST_H
|
||||||
|
|
||||||
|
#include "../../includes/minishell.h"
|
||||||
|
#include "../tokenizer/tokenizer.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -37,6 +37,36 @@ void truncate_comment(char *str)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
/*static t_data *init_data(char **envp)*/
|
/*static t_data *init_data(char **envp)*/
|
||||||
/*{*/
|
/*{*/
|
||||||
/* t_data *data;*/
|
/* t_data *data;*/
|
||||||
@@ -52,13 +82,21 @@ int main(int ac, char **av, char **envp)
|
|||||||
|
|
||||||
(void)ac;
|
(void)ac;
|
||||||
(void)envp;
|
(void)envp;
|
||||||
|
|
||||||
|
if (ac != 3)
|
||||||
|
{
|
||||||
|
ft_error("./test drawio_file command_str\n");
|
||||||
|
return (1);
|
||||||
|
}
|
||||||
|
|
||||||
/*t_data data;*/
|
/*t_data data;*/
|
||||||
|
|
||||||
/*data = init_data(envp);*/
|
/*data = init_data(envp);*/
|
||||||
truncate_comment(av[1]);
|
truncate_comment(av[1]);
|
||||||
lst = tokenize(av[1]);
|
lst = tokenize(av[2]);
|
||||||
if (!lst)
|
if (!lst)
|
||||||
return (1);
|
return (1);
|
||||||
debug_linked_list(lst, "Tokenized");
|
debug_linked_list(lst, "Tokenized");
|
||||||
|
gen_dio_linked_list(lst, av[1]);
|
||||||
free_linked_list(lst);
|
free_linked_list(lst);
|
||||||
}
|
}
|
||||||
@@ -111,16 +111,12 @@ t_node *tokenize(char *str)
|
|||||||
head = tokenize_base(str);
|
head = tokenize_base(str);
|
||||||
if (!head)
|
if (!head)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
debug_linked_list(head, "Base_cut");
|
|
||||||
if (!trim_nodes(head))
|
if (!trim_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
debug_linked_list(head, "Trimed");
|
|
||||||
if (!unstick_nodes(head))
|
if (!unstick_nodes(head))
|
||||||
return (NULL);
|
return (NULL);
|
||||||
debug_linked_list(head, "Nodes Unsticked");
|
|
||||||
stick_quote_node(head, 39);
|
stick_quote_node(head, 39);
|
||||||
stick_quote_node(head, '"');
|
stick_quote_node(head, '"');
|
||||||
debug_linked_list(head, "Quote Sticked");
|
|
||||||
set_token(head);
|
set_token(head);
|
||||||
return (head);
|
return (head);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user