This commit is contained in:
Nathan Lebrun
2025-01-31 18:57:58 +01:00
parent 3fd862f171
commit 1c643b7119
9 changed files with 224 additions and 104 deletions

View File

@@ -35,6 +35,7 @@ typedef struct s_elems
// internal
char *replace_ampercent(char *src);
char *replace_left_red(char *src);
t_dio_node get_cmd_txt(t_ast_n *node);
int print_ast(t_ast_n *node, t_elems *e, int fd);

View File

@@ -36,11 +36,11 @@ const char *translate_redir(t_redir redir)
const char *out;
if (redir == _RED_L)
out = "redir : < &#10;";
out = "redir : RED_L&#10;";
else if (redir == _RED_R)
out = "redir : > &#10;";
out = "redir : RED_R&#10;";
else if (redir == _RED_DR)
out = "redir : >> &#10;";
out = "redir : _RED_DR &#10;";
else
out = "Not redirected &#10;";
return (out);
@@ -49,12 +49,16 @@ const char *translate_redir(t_redir redir)
t_dio_node get_cmd_txt(t_ast_n *node)
{
t_dio_node txt;
char *args;
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.cmd = ft_sprintf("%s%s", NL, node->cmd);
txt.cmd = replace_left_red(txt.cmd);
args = ft_tabstr(node->args);
txt.args = ft_sprintf("%s%s%s", NL, args, NL);
free(args);
txt.redir = translate_redir(node->redir);
txt.inf = ft_sprintf("Infile : %s%s", node->infile, NL);
txt.outf = ft_sprintf("Outfile : %s", node->outfile);

View File

@@ -39,6 +39,7 @@ void gen_dio_linked_list(t_node *head, int fd)
{
rect.text = ft_sprintf("%s", current->val);
rect.text = replace_ampercent(rect.text);
rect.text = replace_left_red(rect.text);
arrow.id_dst = drawio_create_elem(fd, &rect);
drawio_create_elem(fd, &arrow);
arrow.id_src = arrow.id_dst;

View File

@@ -12,7 +12,7 @@
#include "drawio.h"
static int get_amp_count(char *str)
static int get_char_count(char *str, char c)
{
int i;
int count;
@@ -21,7 +21,7 @@ static int get_amp_count(char *str)
count = 0;
while (str[i])
{
if (str[i] == '&')
if (str[i] == c)
count++;
i++;
}
@@ -37,7 +37,7 @@ char *replace_ampercent(char *src)
i = -1;
j = 0;
amp_count = get_amp_count(src);
amp_count = get_char_count(src, '&');
out = malloc(ft_strlen(src) + amp_count * 4 + 1);
while (src[++i])
{
@@ -54,5 +54,39 @@ char *replace_ampercent(char *src)
out[j++] = src[i];
}
out[j] = 0;
free(src);
return (out);
}
char *replace_left_red(char *src)
{
int i;
int j;
int redl_count;
char *out;
i = -1;
j = 0;
redl_count = get_char_count(src, '<');
out = malloc(ft_strlen(src) + redl_count * 7 + 1);
while (src[++i])
{
if (src[i] == '<')
{
out[j] = '&';
out[j + 1] = 'a';
out[j + 2] = 'm';
out[j + 3] = 'p';
out[j + 4] = ';';
out[j + 5] = 'l';
out[j + 6] = 't';
out[j + 7] = ';';
j += 8;
}
else
out[j++] = src[i];
}
out[j] = 0;
free(src);
return (out);
}