-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstring_node2string.c
More file actions
34 lines (32 loc) · 1.1 KB
/
string_node2string.c
File metadata and controls
34 lines (32 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "minishell.h"
#include "utils.h"
/*
* Convert AST string node to string.
*/
char *string_node2string(t_parse_node_string *string_node,
bool add_quotes)
{
char *result;
result = ft_strdup("");
check_malloc_has_succeeded("string_node2string", result);
while (string_node)
{
if (add_quotes && string_node->type == TOKTYPE_NON_EXPANDABLE)
result = strjoin_and_free_first(result, "\'");
else if (add_quotes && string_node->type == TOKTYPE_EXPANDABLE_QUOTED)
result = strjoin_and_free_first(result, "\"");
check_malloc_has_succeeded("string_node2string", result);
result = strjoin_and_free_first(result, string_node->text);
check_malloc_has_succeeded("string_node2string", result);
if (add_quotes && string_node->type == TOKTYPE_NON_EXPANDABLE)
result = strjoin_and_free_first(result, "\'");
else if (add_quotes && string_node->type == TOKTYPE_EXPANDABLE_QUOTED)
result = strjoin_and_free_first(result, "\"");
check_malloc_has_succeeded("string_node2string", result);
if (string_node->next)
string_node = string_node->next->content.string;
else
break ;
}
return (result);
}