6
6
/* By: jidler <[email protected] > +#+ +:+ +#+ */
7
7
/* +#+#+#+#+#+ +#+ */
8
8
/* Created: 2025/03/04 16:09:28 by jidler #+# #+# */
9
- /* Updated: 2025/03/04 16:09:29 by jidler ### ########.fr */
9
+ /* Updated: 2025/03/04 19:25:32 by jidler ### ########.fr */
10
10
/* */
11
11
/* ************************************************************************** */
12
12
13
13
#include "parser.h"
14
14
15
- t_cmd * get_cmd (const char * input , int * curr_pos , t_env * env_list , int * exit_status )
15
+ t_cmd * get_cmd (const char * input , int * curr_pos ,
16
+ t_env * env_list , int * exit_status )
16
17
{
17
18
t_cmd * cmd ;
18
19
t_list * new_node ;
20
+ t_token * token_struct ;
21
+ char * final_token ;
19
22
20
23
cmd = (t_cmd * )malloc (sizeof (t_cmd ));
21
24
if (!cmd )
22
25
return (NULL );
23
26
cmd -> tokens = NULL ;
24
27
cmd -> redirs = NULL ;
25
-
26
28
while (input [* curr_pos ] && input [* curr_pos ] != '|' )
27
29
{
28
30
ft_skip_spaces (input , curr_pos );
29
-
30
31
if (input [* curr_pos ] == '>' || input [* curr_pos ] == '<' )
31
32
{
32
33
new_node = ft_lstnew ((void * )get_redir (input , curr_pos ));
@@ -36,15 +37,15 @@ t_cmd *get_cmd(const char *input, int *curr_pos, t_env *env_list, int *exit_stat
36
37
}
37
38
else
38
39
{
39
- t_token * token_struct = get_token (input , curr_pos );
40
+ token_struct = get_token (input , curr_pos );
40
41
if (token_struct )
41
42
{
42
- char * final_token = token_struct -> is_single_quoted ? ft_strdup (token_struct -> value ) :
43
- expand_env_token (token_struct -> value , env_list , exit_status );
44
-
43
+ final_token = token_struct -> is_single_quoted
44
+ ? ft_strdup (token_struct -> value )
45
+ : expand_env_token (token_struct -> value ,
46
+ env_list , exit_status );
45
47
free (token_struct -> value );
46
48
free (token_struct );
47
-
48
49
new_node = ft_lstnew ((void * )final_token );
49
50
if (!new_node )
50
51
{
@@ -58,35 +59,33 @@ t_cmd *get_cmd(const char *input, int *curr_pos, t_env *env_list, int *exit_stat
58
59
return (cmd );
59
60
}
60
61
61
- t_command_group * get_command_group (const char * input , int * curr_pos , t_env * env_list , int * exit_status )
62
+ t_command_group * get_command_group (const char * input , int * curr_pos ,
63
+ t_env * env_list , int * exit_status )
62
64
{
63
65
t_command_group * command_group ;
64
- t_list * cmd ;
66
+ t_list * cmd ;
65
67
66
68
command_group = (t_command_group * )malloc (sizeof (t_command_group ));
67
69
if (!command_group )
68
70
return (NULL );
69
71
command_group -> cmds = NULL ;
70
-
71
72
while (input [* curr_pos ])
72
73
{
73
74
ft_skip_spaces (input , curr_pos );
74
-
75
- // Parse commands inside this table
76
- cmd = ft_lstnew ((void * )get_cmd (input , curr_pos , env_list , exit_status ));
75
+ cmd = ft_lstnew ((void * )get_cmd (input , curr_pos ,
76
+ env_list , exit_status ));
77
77
if (!cmd )
78
78
{
79
- ft_lstclear (& command_group -> cmds , (void (* )(void * ))free_cmd );
79
+ ft_lstclear (& command_group -> cmds ,
80
+ (void (* )(void * ))free_cmd );
80
81
return (NULL );
81
82
}
82
83
ft_lstadd_back (& command_group -> cmds , cmd );
83
-
84
- // Handle pipes within the same command table
85
84
if (input [* curr_pos ] == '|' && input [* curr_pos + 1 ] != '|' )
86
85
{
87
- (* curr_pos )++ ; // Skip the `|`
88
- continue ; // Stay inside the same `t_command_group`
86
+ (* curr_pos )++ ;
87
+ continue ;
89
88
}
90
89
}
91
90
return (command_group );
92
- }
91
+ }
0 commit comments