Skip to content

Commit c488058

Browse files
authored
Merge pull request #27 from cuajarsaki/fix_smallerror
norm and unnesserary group file
2 parents 11d3aa2 + 1fcc07c commit c488058

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ SRC = $(SRC_DIR)/$(CMD_DIR)/shell_cd.c \
2222
$(SRC_DIR)/parser/parser_ast.c \
2323
$(SRC_DIR)/parser/parser_cmd.c \
2424
$(SRC_DIR)/parser/parser_env.c \
25-
$(SRC_DIR)/parser/parser_group.c \
2625
$(SRC_DIR)/parser/parser_redir.c \
2726
$(SRC_DIR)/parser/parser_token_utils.c \
2827
$(SRC_DIR)/parser/parser_token.c \

src/parser/parser.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jidler <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/04 16:00:00 by jidler #+# #+# */
9-
/* Updated: 2025/03/04 16:10:23 by jidler ### ########.fr */
9+
/* Updated: 2025/03/04 19:24:30 by jidler ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -19,6 +19,9 @@
1919
# include <ctype.h>
2020
# include <stdio.h>
2121

22+
23+
24+
2225
/* ************************************************************************** */
2326
/* UTILITY FUNCTIONS */
2427
/* ************************************************************************** */

src/parser/parser_ast.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/* By: jidler <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* Created: 2025/03/04 16:09:23 by jidler #+# #+# */
9-
/* Updated: 2025/03/04 16:10:44 by jidler ### ########.fr */
9+
/* Updated: 2025/03/04 19:08:10 by jidler ### ########.fr */
1010
/* */
1111
/* ************************************************************************** */
1212

@@ -17,6 +17,7 @@ t_ast *get_ast(const char *input, t_env *env_list, int *exit_status)
1717
t_ast *ast;
1818
t_list *command_group;
1919
int curr_pos;
20+
void *cmd_grp;
2021

2122
ast = (t_ast *)malloc(sizeof(t_ast));
2223
if (!ast)
@@ -26,7 +27,9 @@ t_ast *get_ast(const char *input, t_env *env_list, int *exit_status)
2627
while (input[curr_pos])
2728
{
2829
ft_skip_spaces(input, &curr_pos);
29-
command_group = ft_lstnew((void *)get_command_group(input, &curr_pos, env_list, exit_status));
30+
cmd_grp = (void *)get_command_group(input,
31+
&curr_pos, env_list, exit_status);
32+
command_group = ft_lstnew(cmd_grp);
3033
if (!command_group)
3134
{
3235
free(ast);
@@ -35,4 +38,4 @@ t_ast *get_ast(const char *input, t_env *env_list, int *exit_status)
3538
ft_lstadd_back(&ast->command_groups, command_group);
3639
}
3740
return (ast);
38-
}
41+
}

src/parser/parser_cmd.c

+20-21
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,28 @@
66
/* By: jidler <[email protected]> +#+ +:+ +#+ */
77
/* +#+#+#+#+#+ +#+ */
88
/* 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 */
1010
/* */
1111
/* ************************************************************************** */
1212

1313
#include "parser.h"
1414

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)
1617
{
1718
t_cmd *cmd;
1819
t_list *new_node;
20+
t_token *token_struct;
21+
char *final_token;
1922

2023
cmd = (t_cmd *)malloc(sizeof(t_cmd));
2124
if (!cmd)
2225
return (NULL);
2326
cmd->tokens = NULL;
2427
cmd->redirs = NULL;
25-
2628
while (input[*curr_pos] && input[*curr_pos] != '|')
2729
{
2830
ft_skip_spaces(input, curr_pos);
29-
3031
if (input[*curr_pos] == '>' || input[*curr_pos] == '<')
3132
{
3233
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
3637
}
3738
else
3839
{
39-
t_token *token_struct = get_token(input, curr_pos);
40+
token_struct = get_token(input, curr_pos);
4041
if (token_struct)
4142
{
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);
4547
free(token_struct->value);
4648
free(token_struct);
47-
4849
new_node = ft_lstnew((void *)final_token);
4950
if (!new_node)
5051
{
@@ -58,35 +59,33 @@ t_cmd *get_cmd(const char *input, int *curr_pos, t_env *env_list, int *exit_stat
5859
return (cmd);
5960
}
6061

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)
6264
{
6365
t_command_group *command_group;
64-
t_list *cmd;
66+
t_list *cmd;
6567

6668
command_group = (t_command_group *)malloc(sizeof(t_command_group));
6769
if (!command_group)
6870
return (NULL);
6971
command_group->cmds = NULL;
70-
7172
while (input[*curr_pos])
7273
{
7374
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));
7777
if (!cmd)
7878
{
79-
ft_lstclear(&command_group->cmds, (void (*)(void *))free_cmd);
79+
ft_lstclear(&command_group->cmds,
80+
(void (*)(void *))free_cmd);
8081
return (NULL);
8182
}
8283
ft_lstadd_back(&command_group->cmds, cmd);
83-
84-
// Handle pipes within the same command table
8584
if (input[*curr_pos] == '|' && input[*curr_pos + 1] != '|')
8685
{
87-
(*curr_pos)++; // Skip the `|`
88-
continue; // Stay inside the same `t_command_group`
86+
(*curr_pos)++;
87+
continue;
8988
}
9089
}
9190
return (command_group);
92-
}
91+
}

0 commit comments

Comments
 (0)