-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathms_parsing_utils.c
More file actions
91 lines (81 loc) · 2.1 KB
/
Copy pathms_parsing_utils.c
File metadata and controls
91 lines (81 loc) · 2.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ms_parsing_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: nmeintje <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/12 16:21:20 by nmeintje #+# #+# */
/* Updated: 2025/02/14 10:06:44 by hutzig ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/ms.h"
t_tree_node *create_redirection(t_token **tokens, t_token *temp)
{
t_tree_node *node;
node = new_tree_node((*tokens)->type);
*tokens = (*tokens)->next->next;
node->left = parse_redirection(tokens);
node->right = create_file_node(temp->next);
free(temp->content);
free(temp);
return (node);
}
int argument_count(t_token *token)
{
int count;
count = 0;
while (token && token->type == WORD)
{
count++;
token = token->next;
}
return (count);
}
t_tree_node *new_tree_node(t_type type)
{
t_tree_node *node;
node = malloc(sizeof(t_tree_node));
if (!node)
return (NULL);
node->type = type;
node->value = NULL;
node->status = -1;
node->expand = -1;
node->fd[0] = -1;
node->fd[1] = -1;
node->left = NULL;
node->right = NULL;
return (node);
}
int has_space(const char *str)
{
while (*str)
{
if (*str == ' ')
return (1);
str++;
}
return (0);
}
char **split_expand(char **value, char *content, int *i)
{
char **split_words;
int j;
split_words = ft_split(content, ' ');
j = 0;
while (split_words[j])
{
value[*i] = ft_strdup(split_words[j]);
(*i)++;
j++;
}
if (split_words)
{
j = 0;
while (split_words[j])
free(split_words[j++]);
free(split_words);
}
return (value);
}