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/preprocess.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/preprocess/preprocess.c') diff --git a/src/preprocess/preprocess.c b/src/preprocess/preprocess.c index 3852b8b..7bc50d5 100644 --- a/src/preprocess/preprocess.c +++ b/src/preprocess/preprocess.c @@ -6,7 +6,7 @@ /* By: charles +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/03 08:58:49 by charles #+# #+# */ -/* Updated: 2020/10/10 10:32:53 by cacharle ### ########.fr */ +/* Updated: 2020/10/10 10:56:41 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,12 @@ #include "lexer.h" #include "minishell.h" +/* +** \brief Concatenate sticked string tokens +** \param tokens List of tokens to concatenate +** \return The resulting list of tokens +*/ + t_tok_lst *st_stick_tokens(t_tok_lst *tokens) { t_tok_lst *curr; @@ -36,6 +42,13 @@ t_tok_lst *st_stick_tokens(t_tok_lst *tokens) return (tokens); } +/* +** \brief Convert a list of tokens to a NULL terminated string array +** \param tokens A pointer to a list of tokens to convert +** \return The string array of arguments +** \note tokens is destroyed +*/ + char **st_tokens_to_argv(t_tok_lst **tokens) { char **ret; @@ -56,6 +69,15 @@ char **st_tokens_to_argv(t_tok_lst **tokens) return (ret); } +/* +** \brief Try to escape the first character of a string +** \param str String to escape +** \param tag Tag of the current token +** (different characters are escaped in different type of strings) +** \return true if the first there was a character to escape, +** false otherwise +*/ + bool escape(char *str, enum e_tok tag) { if (str[0] == '\\' && @@ -68,6 +90,14 @@ bool escape(char *str, enum e_tok tag) return (false); } +/* +** \brief Preprocess (escaping and interpolation) +** tokens an convert then to an argv +** \param tokens List of token to preprocess +** \param env Environment +** \return The arguments on success, NULL on allocation error +*/ + char **preprocess(t_tok_lst **tokens, t_env env) { t_tok_lst *curr; -- cgit