ast
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -36,11 +36,11 @@ const char *translate_redir(t_redir redir)
|
||||
const char *out;
|
||||
|
||||
if (redir == _RED_L)
|
||||
out = "redir : < ";
|
||||
out = "redir : RED_L ";
|
||||
else if (redir == _RED_R)
|
||||
out = "redir : > ";
|
||||
out = "redir : RED_R ";
|
||||
else if (redir == _RED_DR)
|
||||
out = "redir : >> ";
|
||||
out = "redir : _RED_DR ";
|
||||
else
|
||||
out = "Not redirected ";
|
||||
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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user