-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparcer_01.c
71 lines (65 loc) · 2.35 KB
/
parcer_01.c
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parcer_01.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: prranges <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/12 16:31:02 by prranges #+# #+# */
/* Updated: 2021/11/12 16:31:05 by prranges ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
void create_cmd_lists(t_arg *args, char **sub_strs, \
int **start_end_i, int num_of_parts)
{
int s;
char **cmd;
s = -1;
cmd = malloc(sizeof(char **) * num_of_parts + 1);
if (!cmd)
my_exit(args, "malloc", 12, 0);
while (num_of_parts > ++s)
{
cmd[s] = ft_substr(sub_strs[0], start_end_i[0][s], \
start_end_i[1][s] - start_end_i[0][s]);
if (!cmd[s])
my_exit(args, "malloc", 12, 0);
cmd[s] = lexe(cmd[s], args, 0);
}
cmd[s] = NULL;
args->num = add_token(&args->tokens, cmd, args);
}
void parcer(char *str, t_arg *args)
{
char **sub_strs;
int num_of_parts;
int **start_end_i;
sub_strs = make_substrs_pipe_devided(str, args);
while (*sub_strs)
{
args->num++;
num_of_parts = find_number_of_parts(args, *sub_strs);
start_end_i = malloc(sizeof(int **));
start_end_i[0] = malloc(sizeof(int *) * num_of_parts);
start_end_i[1] = malloc(sizeof(int *) * num_of_parts);
if (!start_end_i || !start_end_i[0] || !start_end_i[1])
my_exit(args, "malloc", 12, 0);
find_parts_of_str(*sub_strs, start_end_i, args, args->num);
create_cmd_lists(args, sub_strs, start_end_i, num_of_parts);
free(start_end_i[0]);
free(start_end_i[1]);
free(start_end_i);
free(*sub_strs);
sub_strs++;
}
free (*sub_strs);
add_redirs_to_cmd(args->redir, args->tokens);
}
void set_quotes_flag(t_arg *args, char *str, int i)
{
if (str[i] == '\'' && (!(args->flag_dq % 2)))
args->flag_sq++;
if (str[i] == '\"' && (!(args->flag_sq % 2)))
args->flag_dq++;
}