Skip to content

Commit

Permalink
refactor: fix norm issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
facetint committed Apr 1, 2024
1 parent 1f8052c commit 7693dd9
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 29 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ SOURCES = src/execute/execute_utils.c src/builtin/cd.c src/builtin/exit.c src/bu
src/parser/parser.c src/parser/parser_state.c src/parser/parser_utils.c src/execute/heredoc.c \
src/expander/expander.c src/splitter.c src/lexer/syntax_analyzer.c src/signal.c $(MEMORY_ALLOCATOR_SOURCES) \
src/redirections/redirections.c src/env/global_env.c src/utils/unsafe_utils.c src/utils/char_classification.c src/utils/string_utils.c \
src/utils/quote_classification.c
src/utils/quote_classification.c src/expander/expander_2.c

MINISHELL_SOURCES = src/main.c $(SOURCES)
MINISHELL_OBJECTS = $(MINISHELL_SOURCES:.c=.o)
Expand Down
7 changes: 5 additions & 2 deletions includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* minishell.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hamza <hamza@student.42.fr> +#+ +:+ +#+ */
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/31 09:14:38 by hamza #+# #+# */
/* Updated: 2024/04/01 07:31:02 by hamza ### ########.fr */
/* Updated: 2024/04/01 17:49:31 by facetint ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -185,4 +185,7 @@ char *ft_unsafe_strdup(const char *str);
void export_env(char *format);
void handle_file_redirections(t_command *cur);

void expand_token(t_token *token, t_token **head,
t_token **token_ptr, t_token **prev_ptr);

#endif
7 changes: 4 additions & 3 deletions includes/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
/* ::: :::::::: */
/* utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hamza <hamza@student.42.fr> +#+ +:+ +#+ */
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/31 09:28:02 by hamza #+# #+# */
/* Updated: 2024/04/01 08:58:09 by hamza ### ########.fr */
/* Updated: 2024/04/01 17:49:02 by facetint ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef UTILS_H
# define UTILS_H

typedef struct s_token t_token;
typedef struct s_token t_token;

char *get_cur_folder_name(void);
char *ft_str_arr_join(char **str_list, unsigned int str_count);
Expand All @@ -28,5 +28,6 @@ char **ft_unsafe_strarrdup(char **arr);
int is_full_of_spaces(const char *str);
t_token *skip_delimiters(t_token *token);
void print_error(char *cmd, char *error);
void remove_token(t_token **prev_ptr, t_token **head, t_token *token);

#endif
4 changes: 2 additions & 2 deletions memory-allocator/allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: facetint <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/16 15:13:21 by hamza #+# #+# */
/* Updated: 2024/03/30 17:46:06 by facetint ### ########.fr */
/* Updated: 2024/04/01 17:49:52 by facetint ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -65,7 +65,7 @@ int append_memory_block(void *ptr)
*/
int remove_memory_block(void *ptr)
{
t_memory_block *cur;
t_memory_block *cur;
t_memory_block *prev;

if (!ptr)
Expand Down
22 changes: 3 additions & 19 deletions src/expander/expander.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* expander.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hamza <hamza@student.42.fr> +#+ +:+ +#+ */
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/03 13:17:39 by facetint #+# #+# */
/* Updated: 2024/04/01 08:00:15 by hamza ### ########.fr */
/* Updated: 2024/04/01 17:46:58 by facetint ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -85,23 +85,7 @@ void expand(t_token **head)
while (token)
{
if (token->type == UNQUOTED_WORD || token->type == DOUBLE_QUOTED_WORD)
{
if (is_nameless_variable(token))
token->value = ft_strdup("");
else
{
expand_string(&token->value);
if (is_full_of_spaces(token->value))
{
if (prev_ptr == NULL)
*head = token->next;
else
(*prev_ptr)->next = token->next;
}
else if (token->type == UNQUOTED_WORD)
internal_field_split(token_ptr);
}
}
expand_token(token, head, token_ptr, prev_ptr);
prev_ptr = token_ptr;
token_ptr = &token->next;
token = token->next;
Expand Down
30 changes: 30 additions & 0 deletions src/expander/expander_2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* expander_2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: facetint <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/01 17:50:47 by facetint #+# #+# */
/* Updated: 2024/04/01 17:50:59 by facetint ### ########.fr */
/* */
/* ************************************************************************** */

#include "../../includes/minishell.h"
#include "../../includes/utils.h"
#include "../../libft/libft.h"

void expand_token(t_token *token, t_token **head,
t_token **token_ptr, t_token **prev_ptr)
{
if (is_nameless_variable(token))
token->value = ft_strdup("");
else
{
expand_string(&token->value);
if (is_full_of_spaces(token->value))
remove_token(prev_ptr, head, token);
else if (token->type == UNQUOTED_WORD)
internal_field_split(token_ptr);
}
}
12 changes: 10 additions & 2 deletions src/lexer/syntax_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
/* ::: :::::::: */
/* syntax_analyzer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hamza <hamza@student.42.fr> +#+ +:+ +#+ */
/* By: facetint <facetint@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/03 13:18:35 by facetint #+# #+# */
/* Updated: 2024/04/01 08:35:41 by hamza ### ########.fr */
/* Updated: 2024/04/01 17:50:37 by facetint ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -84,3 +84,11 @@ int validate_pipes(t_token *token)
}
return (1);
}

void remove_token(t_token **prev_ptr, t_token **head, t_token *token)
{
if (prev_ptr == NULL)
*head = token->next;
else
(*prev_ptr)->next = token->next;
}

0 comments on commit 7693dd9

Please sign in to comment.