Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"files.associations": {
"minishell.h": "c"
}
},
"cmake.sourceDirectory": "/home/tchobert/GitHub_perso/Minishell/Unity"
}
50 changes: 46 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ PATH_SRCS += srcs/history
PATH_SRCS += srcs/syntax_analysis
PATH_SRCS += srcs/lexical_analysis
PATH_SRCS += srcs/syntax_analysis
PATH_SRCS += srcs/environment_management
PATH_SRCS += srcs/environment_building

PATH_SRCS += srcs/functions_for_debug

SRCS += main.c
SRCS += exit_shell_routine.c
Expand All @@ -29,14 +33,12 @@ SRCS += add_history.c

# srcs/lexing

SRCS += lexical_analysis.c
SRCS += lexe_input.c
SRCS += tokenizer.c
SRCS += add_token_to_token_list.c
SRCS += create_token.c
SRCS += delete_token.c
SRCS += delete_token_list.c
# SRCS += print_token.c
# SRCS += print_token_list.c

SRCS += tokenize_operator.c
SRCS += tokenize_word.c
Expand All @@ -45,9 +47,32 @@ SRCS += lexer_utils.c

# srcs/parsing

SRCS += syntax_analysis.c
SRCS += parser.c

# srcs/environment_management

SRCS += get_environment.c
SRCS += set_variable.c
SRCS += set_variable_from_keyvalue.c
SRCS += create_variable.c
SRCS += update_variable.c
SRCS += add_variable_to_environment.c
SRCS += delete_variable.c
SRCS += delete_variables_list.c
SRCS += find_variable_from_key.c
SRCS += get_variable_key.c
SRCS += get_variable_value.c

# srcs/environment_building

SRCS += build_environment.c

# print_functions to use for debug and tests

# SRCS += print_env.c
# SRCS += print_token.c
# SRCS += print_token_list.c

vpath %.c $(PATH_SRCS)

### TETS SRCS ################################################################
Expand All @@ -60,6 +85,10 @@ TESTS_SRCS_DIR += ./tests/tests_syntax_analysis
TESTS_SRCS_DIR += ./tests/tests_lexical_analysis/BDD
TESTS_SRCS_DIR += ./tests/tests_lexical_analysis/unit_tests
TESTS_SRCS_DIR += ./tests/tests_syntax_analysis/BDD
TESTS_SRCS_DIR += ./tests/tests_environment_management
TESTS_SRCS_DIR += ./tests/tests_environment_management/unit_tests
TESTS_SRCS_DIR += ./tests/tests_environment_building
TESTS_SRCS_DIR += ./tests/tests_environment_building/unit_tests

TESTS_SRCS += tests_main.c

Expand Down Expand Up @@ -87,6 +116,19 @@ TESTS_SRCS += test_just_a_pipe.c
TESTS_SRCS += test_two_pipes.c
TESTS_SRCS += free_parser_test.c

# environment management

TESTS_SRCS += unit_tests_environment.c
TESTS_SRCS += test_create_variable.c
TESTS_SRCS += test_add_variable_to_variables_list.c
TESTS_SRCS += delete_variables_list_tests_version.c
TESTS_SRCS += test_get_variable_key.c
TESTS_SRCS += test_get_variable_value.c

# environemt building

TESTS_SRCS += unit_tests_environment_building.c

# Unity

UNITY_SRCS := Unity/src/unity.c
Expand Down
2 changes: 1 addition & 1 deletion Unity
Submodule Unity updated 106 files
70 changes: 70 additions & 0 deletions includes/environment.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* environment.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchobert <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/04 18:54:09 by tchobert #+# #+# */
/* Updated: 2025/01/04 18:58:35 by tchobert ### ########.fr */
/* */
/* ************************************************************************** */

#ifndef ENVIRONMENT_H
# define ENVIRONMENT_H

// INCLUDES

# include "minishell.h"

// DEFINES

# define EQUAL_OPERATOR '='
# define EXPORTABLE 1

// TYPEDEFS

typedef t_list * t_variable_list;

// ENUMS

typedef enum e_status
{
PROCESS_SUCCESS,
PROCESS_FAILURE
} t_status;

// STRUCTURES

typedef struct s_variable
{
char *key;
char *value;
bool is_exportable;
} t_variable;

// PROTOTYPES

t_variable_list *get_environment(void);
t_status build_environment(char **variables);
t_status set_variable_from_keyvalue(const char *keyvalue,
bool make_it_exportable);
t_status set_variable(const char *key, const char *value,
bool make_it_exportable);
t_variable *create_variable(const char *key, const char *value,
bool is_exportable);
t_status update_variable(t_variable *variable, const char *value,
const bool is_exportable);
t_variable *find_variable_from_key(const t_variable_list *environment,
char *key);
bool is_variable_key_equal(void *variable_as_content, void *key);
t_status add_variable_to_environment(t_variable_list *environment,
t_variable *variable);
void delete_variable(void *data);
void delete_variables_list(void);
char *get_variable_key(const char *keyvalue);
char *get_variable_value(const char *keyvalue);

void print_env(void);

#endif
14 changes: 10 additions & 4 deletions includes/minishell.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# include "user_interface.h"
# include "lexing.h"
# include "parsing.h"
# include "environment.h"

# include <stdio.h>
# include <stdlib.h>
Expand All @@ -30,17 +31,22 @@

// STRUCTURES

typedef struct s_minishell
typedef struct s_command_session
{
char *user_input_line;
t_token_list tokenized_user_input_line;
} t_minishell;
} t_command_session;

typedef struct s_minishell_context
{
t_command_session command_session;
} t_minishell_context;

// PROTOTYPES

int exit_shell_routine(void);
char *prompt_gets_user_input(void);
t_lexing_status lexical_analysis(t_minishell *minishell_data);
t_syntax_status syntaxic_analysis(t_token_list token_list);
t_lexing_status lexe_input(t_command_session *current_command);
t_syntax_status parse_input(t_token_list token_list);

#endif
8 changes: 0 additions & 8 deletions includes/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@

# include "minishell.h"

// DEFINES

# define POSSIBILITES_END -1

// ENUMS

typedef enum e_syntax_status
Expand All @@ -30,8 +26,4 @@ typedef enum e_syntax_status
INVALID_SYNTAX
} t_syntax_status;

// PROTOTYPES

t_syntax_status parser(t_token_list token_list);

#endif
13 changes: 12 additions & 1 deletion includes/tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,15 @@ void test_input_just_a_pipe(void);
void test_input_two_pipes(void);
void test_free(void);

#endif
// ENVIRONMENT MANAGEMENT

void unit_tests_environment_management(void);
void test_create_variable(void);
void test_add_variable_to_environment(void);
void delete_variables_list_tests_version(t_variable_list *variable_list);
void test_get_variable_key(void);
void test_get_variable_value(void);

// ENVIRONMENT BUILDING

#endif
2 changes: 1 addition & 1 deletion libft
Submodule libft updated from 910aff to dd43fd
6 changes: 6 additions & 0 deletions readline.supp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
ignore_libreadline_leaks
Memcheck:Leak
...
obj:*/libreadline.so.*
}
28 changes: 28 additions & 0 deletions srcs/environment_building/build_environment.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* build_environment.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchobert <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/09 16:26:17 by tchobert #+# #+# */
/* Updated: 2025/01/09 16:26:28 by tchobert ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

t_status build_environment(char **variables)
{
size_t i;

i = 0;
while (variables[i] != NULL)
{
if (set_variable_from_keyvalue(variables[i], EXPORTABLE)
== PROCESS_FAILURE)
return (PROCESS_FAILURE);
++i;
}
return (PROCESS_SUCCESS);
}
25 changes: 25 additions & 0 deletions srcs/environment_management/add_variable_to_environment.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* add_variable_to_variables_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchobert <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/06 21:48:23 by tchobert #+# #+# */
/* Updated: 2025/01/06 21:48:51 by tchobert ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

t_status add_variable_to_environment(t_variable_list *environment,
t_variable *variable)
{
t_variable_list new_node;

new_node = ft_lstnew(variable);
if (new_node == NULL)
return (PROCESS_FAILURE);
ft_lstadd_back(environment, new_node);
return (PROCESS_SUCCESS);
}
32 changes: 32 additions & 0 deletions srcs/environment_management/create_variable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* create_variable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchobert <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/06 21:46:37 by tchobert #+# #+# */
/* Updated: 2025/01/06 21:46:48 by tchobert ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

t_variable *create_variable(const char *key, const char *value,
bool is_exportable)
{
t_variable *new_variable;

new_variable = (t_variable *)ft_calloc(1, sizeof(t_variable));
if (new_variable == NULL)
return (NULL);
new_variable->key = ft_strdup(key);
if (new_variable->key == NULL
|| update_variable(new_variable, value, is_exportable)
== PROCESS_FAILURE)
{
delete_variable(new_variable);
return (NULL);
}
return (new_variable);
}
24 changes: 24 additions & 0 deletions srcs/environment_management/delete_variable.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* delete_variable.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tchobert <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/06 21:04:28 by tchobert #+# #+# */
/* Updated: 2025/01/06 21:05:22 by tchobert ### ########.fr */
/* */
/* ************************************************************************** */

#include "minishell.h"

void delete_variable(void *data)
{
t_variable *variable_to_delete;

variable_to_delete = (t_variable *)data;
free(variable_to_delete->key);
if (variable_to_delete->value != NULL)
free(variable_to_delete->value);
free(variable_to_delete);
}
Loading
Loading