-
Notifications
You must be signed in to change notification settings - Fork 2
Feat/add env variable #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
23d9a04
ajustements sur le parser et le main
b04ace6
creation du header pour l'environnement + ecriture test unitaire pour…
a7e2cf1
debut set_variable
40b0a4a
debut d'implem pur ajuter une variable a l'env
b6539ae
test set_variable a renommer en test_create_variable
44a9200
tests
e1a9b5a
remove global variable + test add_variable
e809165
ecriture set_variable_form_keyvalue
211e01a
test static env
e6bd3c1
test env static
51b5bc2
integration modifications sans compilation
5fd0566
tests compilent mais erreur
5aa4e62
tests compilent mais erreur
05b4196
pFDbuiopVAD
e13d41b
fonctions manipulation environnement tests OK
838a1ee
correction petit bug sur le main
76c1243
correction const dans set_variable.c
6b28738
tests get_variable value + key = OK
1e00c1d
premier jet de build env dans minishell
8d8c40e
modification free sur variable keyvalue, SECU a faire
ee63b59
for merging
8a1ebe9
suppression d'oublis dans les headers
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule libft
updated
from 910aff to dd43fd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| ignore_libreadline_leaks | ||
| Memcheck:Leak | ||
| ... | ||
| obj:*/libreadline.so.* | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.