cleenup
This commit is contained in:
69
test/drawio/drawio_ast_utils.c
Normal file
69
test/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);
|
||||
}
|
||||
Reference in New Issue
Block a user