From cccd4692fab390d0c4fbab3fcae7f4aa55ca9f1a Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 10 Oct 2020 11:43:05 +0200 Subject: Added comment to preprocess, redir, setup, signal, eval_cmd and utils --- src/preprocess/interpolation.c | 50 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/preprocess/interpolation.c') diff --git a/src/preprocess/interpolation.c b/src/preprocess/interpolation.c index c28d545..455cb90 100644 --- a/src/preprocess/interpolation.c +++ b/src/preprocess/interpolation.c @@ -6,7 +6,7 @@ /* By: cacharle +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/10/09 15:27:46 by cacharle #+# #+# */ -/* Updated: 2020/10/10 10:26:43 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 11:07:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,12 @@ #include "lexer.h" #include "minishell.h" +/* +** \brief Split a string into token +** \param str String to split +** \return The list of tokens or NULL on error +*/ + static t_tok_lst *st_field_split(char *str) { t_tok_lst *ret; @@ -45,6 +51,19 @@ static t_tok_lst *st_field_split(char *str) #define MATCH 1 #define AFTER 2 +/* +** \brief Search for a match in the environmnet +** initialize strs variable if found +** \param strs Strings to intialise +** strs[0] string before the match +** strs[1] interpolation match +** strs[2] string after the match +** \param env Environment +** \param str Current string to search in the environment +** \param i Current position in the str +** \return Return true on match, false otherwise +*/ + static bool st_make_strs(char *strs[3], t_env env, char *str, size_t i) { size_t var_len; @@ -62,6 +81,15 @@ static bool st_make_strs(char *strs[3], t_env env, char *str, size_t i) return (true); } +/* +** \brief Merge the fields tokens in the current token +** \param strs before/match/after strings +** \param curr Pointer to list where to merge the fields +** \param fields Fields to merge in curr +** \param len The current position in the string after the interpolation +** \return Returns len because of norm complience trick +*/ + static size_t st_merge_fields_in_curr( char *strs[3], t_tok_lst **curr, t_tok_lst *fields, size_t len) { @@ -80,6 +108,15 @@ static size_t st_merge_fields_in_curr( return (len); } +/* +** \brief Interpolate a non quoted string +** \param strs before/match/after strings +** \param curr Current token +** \param i Current position in string +** \param prev_tag Previous Token tag +** \return The position after the interpolation +*/ + static size_t st_interpolate_non_quoted( char *strs[3], t_tok_lst **curr, size_t i, enum e_tok prev_tag) { @@ -109,6 +146,17 @@ static size_t st_interpolate_non_quoted( return (i); } +/* +** \brief Interpolate the string in a token +** \param ptrs Norm complience trick +** ptrs[0] (char*) current string +** ptrs[1] (t_tok_lst**) current token +** \param i Current position in token +** \param prev_tag Tag of the previous token +** \param env Environment +** \return The position in the token after interpolation +*/ + size_t interpolate( void *ptrs[2], size_t i, enum e_tok prev_tag, t_env env) { -- cgit