aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.DS_Storebin6148 -> 0 bytes
-rw-r--r--src/env.c16
-rw-r--r--src/eval/eval.c5
-rw-r--r--src/lexer/.DS_Storebin6148 -> 0 bytes
-rw-r--r--src/lexer/lexer.c37
-rw-r--r--src/lexer/lexer_count_nb_element.c31
-rw-r--r--src/lexer/lexer_len_element_and_mall.c58
-rw-r--r--src/lexer/lexer_utils.c10
-rw-r--r--src/lexer/main.c29
-rw-r--r--src/lexer/token.c35
-rw-r--r--src/main.c57
-rw-r--r--src/ms_glob.c (renamed from src/glob.c)19
-rw-r--r--src/parse/lexer.c26
-rw-r--r--src/parse/parse.c18
-rw-r--r--src/preprocess.c141
-rw-r--r--src/utils.c4
16 files changed, 388 insertions, 98 deletions
diff --git a/src/.DS_Store b/src/.DS_Store
deleted file mode 100644
index 68abd32..0000000
--- a/src/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/src/env.c b/src/env.c
index 41aca6d..2557e35 100644
--- a/src/env.c
+++ b/src/env.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 09:21:24 by cacharle #+# #+# */
-/* Updated: 2020/04/05 14:42:38 by charles ### ########.fr */
+/* Updated: 2020/06/12 10:51:10 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -67,19 +67,25 @@ char *env_search(t_env env, char *key)
char *env_search_first_match(t_env env, const char *haystack)
{
- int len;
+ size_t len;
size_t i;
+ size_t key_len;
if (ft_isdigit(*haystack))
return (NULL);
len = 0;
while (ft_isalnum(haystack[len]) || haystack[len] == '_')
len++;
- while (i < env->size)
+ if (len == 0)
+ return (NULL);
+ i = -1;
+ while (++i < env->size - 1)
{
+ key_len = ft_strchr(env->data[i], '=') - (char*)env->data[i];
+ if (len != key_len)
+ continue ;
if (ft_strncmp((char*)env->data[i], haystack, len) == 0)
- return (ft_strchr((char*)env->data[i], '=') + 1);
- i++;
+ return (ft_strchr(env->data[i], '=') + 1);
}
return (NULL);
}
diff --git a/src/eval/eval.c b/src/eval/eval.c
index 0270024..c4df1c9 100644
--- a/src/eval/eval.c
+++ b/src/eval/eval.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/01 17:05:21 by charles #+# #+# */
-/* Updated: 2020/05/04 12:00:38 by charles ### ########.fr */
+/* Updated: 2020/05/15 00:12:51 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -89,7 +89,7 @@ static int eval_cmd(int fd_in, int fd_out, t_eval_state *state, t_cmd *cmd)
if (cmd->in != NULL && (fd_in = open(cmd->in, O_RDONLY)) == -1)
return (-1);
if (cmd->out != NULL && (fd_out = open(cmd->out,
- (cmd->is_append ? O_APPEND : O_RDONLY) | O_CREAT)) == -1)
+ (cmd->is_append ? O_APPEND : O_WRONLY) | O_CREAT)) == -1)
return (-1);
param.argv = cmd->argv;
param.envp = (char**)state->env->data;
@@ -102,6 +102,7 @@ static int eval_cmd(int fd_in, int fd_out, t_eval_state *state, t_cmd *cmd)
** \param line Line to evaluate
** \return Last Executed command status or -1 on error
*/
+
static int eval_line(void *param)
{
int status;
diff --git a/src/lexer/.DS_Store b/src/lexer/.DS_Store
deleted file mode 100644
index fcaf8ef..0000000
--- a/src/lexer/.DS_Store
+++ /dev/null
Binary files differ
diff --git a/src/lexer/lexer.c b/src/lexer/lexer.c
index 185ff83..92cd34a 100644
--- a/src/lexer/lexer.c
+++ b/src/lexer/lexer.c
@@ -1,4 +1,3 @@
-
#include "lexer.h"
int len_is_not_sep(char *input)
@@ -76,16 +75,16 @@ t_token *lexer_lst_token_str(char *input, int i, int j)
if (!(lst_token = malloc(sizeof(t_token) * 1)))
return (NULL);
- lst_token->token = 0;
- lst_token->value = NULL;
- if (!(lst_token->value = malloc(sizeof(char) * j + 1)))
+ lst_token->tag = 0;
+ lst_token->content = NULL;
+ if (!(lst_token->content = malloc(sizeof(char) * j + 1)))
return(0);
- if (!(ft_strlcpy(lst_token->value, &input[i], j + 1)))
+ if (!(ft_strlcpy(lst_token->content, &input[i], j + 1)))
{
free(lst_token);
return(0);
}
- //printf("%s-\n", lst_token->value);
+ //printf("%s-\n", lst_token->content);
return (lst_token);
}
@@ -93,11 +92,11 @@ enum e_token_tag token_verif_stick(t_token *lst_token)
{
int i;
- i = ft_strlen(lst_token->value);
+ i = ft_strlen(lst_token->content);
- if (lst_token->value[i - 1] == ' ')
- return(lst_token->token);
- return(lst_token->token | LTAG_STICK);
+ if (lst_token->content[i - 1] == ' ')
+ return(lst_token->tag);
+ return(lst_token->tag | LTAG_STICK);
}
enum e_token_tag token_str_or_cote(t_token *lst_token)
@@ -105,21 +104,21 @@ enum e_token_tag token_str_or_cote(t_token *lst_token)
int i;
i = 0;
- while(lst_token->value[i] != '\0')
+ while(lst_token->content[i] != '\0')
{
- if(lst_token->value[i] == '\'')
+ if(lst_token->content[i] == '\'')
{
- lst_token->token = LTAG_STR_SINGLE;
+ lst_token->tag = LTAG_STR_SINGLE;
return(token_verif_stick(lst_token));
}
- if(lst_token->value[i] == '"')
+ if(lst_token->content[i] == '"')
{
- lst_token->token = LTAG_STR_DOUBLE;
+ lst_token->tag = LTAG_STR_DOUBLE;
return(token_verif_stick(lst_token));
}
else
{
- lst_token->token = LTAG_STR;
+ lst_token->tag = LTAG_STR;
return(token_verif_stick(lst_token));
}
i++;
@@ -131,12 +130,12 @@ t_token *push_token_enum_and_trim(t_token *lst_token)
{
enum e_token_tag tk;
- tk = ret_token(lst_token->value, 0);
+ tk = ret_token(lst_token->content, 0);
if (tk == 0)
{
- lst_token->token = token_str_or_cote(lst_token);
+ lst_token->tag = token_str_or_cote(lst_token);
}
- printf("%s-, %d\n",lst_token->value, (int)lst_token->token);
+ /* printf("%s-, %d\n",lst_token->content, (int)lst_token->tag); */
return (lst_token);
}
diff --git a/src/lexer/lexer_count_nb_element.c b/src/lexer/lexer_count_nb_element.c
new file mode 100644
index 0000000..1455d5e
--- /dev/null
+++ b/src/lexer/lexer_count_nb_element.c
@@ -0,0 +1,31 @@
+
+#include "lexer.h"
+
+int lexer_count_nb_element(char *input)
+{
+ int i;
+ int j;
+
+ i = 0;
+ j = 1;
+ while(input[i] != '\0')
+ {
+ if (lexer_sep(input[i]) || input[i] == '"' || input[i] == '\'')
+ {
+ if (input[i] == '"' || input[i] == '\'')
+ {
+ i = lexer_verif_entre_cote(input,i);
+ j++;
+ }
+ if (lexer_sep(input[i]))
+ {
+ while (lexer_sep(input[i]) || input[i] == ' ')
+ ++i;
+ j++;
+ }
+ j++;
+ }
+ i++;
+ }
+ return (j);
+}
diff --git a/src/lexer/lexer_len_element_and_mall.c b/src/lexer/lexer_len_element_and_mall.c
new file mode 100644
index 0000000..e0e1132
--- /dev/null
+++ b/src/lexer/lexer_len_element_and_mall.c
@@ -0,0 +1,58 @@
+
+#include "lexer.h"
+
+int lexer_count_len_element(char *input, int i)
+{
+ int j = -1;
+ if (input[i] == '"' || input[i] == '\'')
+ {
+ return(j = lexer_verif_entre_cote(input,i));
+ }
+ else if (lexer_sep(input[i]) || input[i] == ' ')
+ {
+ while(lexer_sep(input[i]) || input[i] == ' ')
+ {
+ if(input[j] == '\0')
+ return(j);
+ ++i;
+ ++j;
+ }
+ }
+ else
+ {
+ while (!lexer_sep(input[i]) && input[i] != ' ')
+ {
+ if(input[j] == '\0')
+ return(j);
+ ++i;
+ ++j;
+ }
+ }
+ ++j;
+ return(j);
+}
+
+char **lexer_malloc_len_elem(char *input, int i, char **out)
+{
+ int j = 0;
+ int k = 0;
+ int temp = 0;
+
+ (void)i;
+ j += lexer_count_len_element(&input[j], 0);
+ k = j;
+ out[temp] = malloc(sizeof(char) * k);
+ ft_strlcpy(out[temp], input, k + 1);
+ while (input[j] != '\0')
+ {
+ temp++;
+ j += lexer_count_len_element(&input[j], 0);
+ k -= j;
+ if (k < 0)
+ k *= -1;
+ out[temp] = malloc(sizeof(char) * j - k + 1);
+ ft_strlcpy(out[temp], &input[j - k], k + 1);
+ k = j;
+ }
+ return(out);
+}
diff --git a/src/lexer/lexer_utils.c b/src/lexer/lexer_utils.c
index 72d8288..986db50 100644
--- a/src/lexer/lexer_utils.c
+++ b/src/lexer/lexer_utils.c
@@ -1,8 +1,5 @@
-
#include "lexer.h"
-
-
enum e_token_tag ret_token_sep_redir_append(char *input, int i)
{
if (input[i + 1] == '>')
@@ -33,8 +30,7 @@ enum e_token_tag ret_token(char *input, int i)
}
-
-int lexer_sep(char input)
+int lexer_sep(char input)
{
char *sep;
int i;
@@ -50,7 +46,7 @@ int lexer_sep(char input)
return (0);
}
-int lexe_space(char *input)
+int lexe_space(char *input)
{
int i;
@@ -75,7 +71,7 @@ static int lex_verif_simple_cote(char *input, int i)
return(i + 1);
}
-int lexer_verif_entre_cote(char *input, int i)
+int lexer_verif_entre_cote(char *input, int i)
{
if(input[i] == '\'')
return(lex_verif_simple_cote(input, i));
diff --git a/src/lexer/main.c b/src/lexer/main.c
deleted file mode 100644
index 753969d..0000000
--- a/src/lexer/main.c
+++ /dev/null
@@ -1,29 +0,0 @@
-
-#include "lexer.h"
-
-/*int main(int argc, char **argv)
-{
- char *input;
-
- if (!(input = malloc(sizeof(char) * ft_strlen(argv[1]) + 1)))
- return(0);
- ft_strlcpy(input, argv[1], ft_strlen(argv[1]) + 1);
-
- lexer(input);
- free(input);
- exit(0);
- return (0);
-}*/
-/*
-#include <stdio.h>
-int main(int argc, char **argv, char **envp)
-{
- printf("ARGV:\n");
- for (int i = 0; i < argc; i++)
- printf("[%d] %s\n", i, argv[i]);
- printf("\nENV:\n");
- for (int i = 0; envp[i] != NULL && i < 10; i++)
- printf("[%d] %s\n", i, envp[i]);
- return 0;
-}
-*/
diff --git a/src/lexer/token.c b/src/lexer/token.c
new file mode 100644
index 0000000..6c6a184
--- /dev/null
+++ b/src/lexer/token.c
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* token.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/06/09 13:38:08 by charles #+# #+# */
+/* Updated: 2020/06/09 17:55:23 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "lexer.h"
+
+t_token *token_new(enum e_token_tag tag, char *content)
+{
+ t_token *token;
+
+ if (content == NULL
+ || (token = (t_token*)malloc(sizeof(t_token))) == NULL)
+ return (NULL);
+ if ((token->content = ft_strdup(content)) == NULL)
+ {
+ free(token);
+ return (NULL);
+ }
+ token->tag = tag;
+ return token;
+}
+
+void token_destroy(t_token *token)
+{
+ free(token->content);
+ free(token);
+}
diff --git a/src/main.c b/src/main.c
index d9302ad..5dac612 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/04/05 12:15:57 by charles ### ########.fr */
+/* Updated: 2020/06/13 11:56:27 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -19,6 +19,7 @@
#include "ast.h"
#include "eval.h"
#include "ms_glob.h"
+#include "lexer.h"
/*
** \brief Program entrypoint
@@ -88,9 +89,57 @@ int main(int argc, char **argv, char **envp)
/* free(line); */
/* ft_htdestroy(path, free); */
/* ms_glob("src#<{(|"); */
- char *j = ms_glob("*/*.c");
- printf("%s\n", j);
- free(j);
+
+ /* char *j = ms_glob("|)}>#*.c"); */
+ /* printf("%s\n", j); */
+ /* free(j); */
+
+ t_ftvec *v = ft_vecnew(32);
+ ft_vecpush(v, token_new(LTAG_STR, "$TERM$LFS$TERM$TERM."));
+ ft_vecpush(v, token_new(LTAG_STR, "$$LFS$TERM$TERM."));
+ ft_vecpush(v, token_new(LTAG_STR, "*/*.c$TERM"));
+ ft_vecpush(v, token_new(LTAG_STR, "src/*.c include/*.h"));
+ ft_vecpush(v, token_new(LTAG_STR, "$A$B"));
+
+ ft_vecpush(v, token_new(LTAG_STR, "\\$TERM"));
+ ft_vecpush(v, token_new(LTAG_STR, "$TER\\M"));
+ ft_vecpush(v, token_new(LTAG_STR, "\\\\"));
+ ft_vecpush(v, token_new(LTAG_STR_SINGLE, "''''$TEST\\TEST"));
+ ft_vecpush(v, token_new(LTAG_STR_DOUBLE, ",$TEST,$B,"));
+
+ ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
+ ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
+ ft_vecpush(v, token_new(LTAG_STR_DOUBLE , "$TEST"));
+ ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
+ ft_vecpush(v, token_new(LTAG_STR_SINGLE, "$TEST"));
+
+ char **as = preprocess(v, env);
+ char **tmp = as;
+
+ while (*as != NULL)
+ puts(*as++);
+
+ ft_split_destroy(tmp);
ft_vecdestroy(env, free);
return (0);
}
+
+
+/////////////////////////////////////////////////////////////////////////////////////////
+// lexer main
+/////////////////////////////////////////////////////////////////////////////////////////
+
+#include "lexer.h"
+
+/* int main(void) */
+/* { */
+/* char **out; */
+/* int i = -1; */
+/* */
+/* out = lexer("\"echo\" \"* login_x\"<<AUTHORS; echo && ; salut;\"echo\"\"* login_x\""); */
+/* //out = lexer("echo * login_x << AUTHORS&&cd Desktop"); */
+/* while(out[++i]) */
+/* printf("%s\n", out[i]);; */
+/* exit(0); */
+/* return (0); */
+/* } */
diff --git a/src/glob.c b/src/ms_glob.c
index d1d1bdf..39c537c 100644
--- a/src/glob.c
+++ b/src/ms_glob.c
@@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
-/* glob.c :+: :+: :+: */
+/* ms_glob.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/05 11:44:07 by charles #+# #+# */
-/* Updated: 2020/04/05 13:21:25 by charles ### ########.fr */
+/* Updated: 2020/06/12 11:51:41 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -148,7 +148,7 @@ char *ms_glob(char *pattern)
return (NULL);
ft_vecsort(matches, ft_compar_str);
if (ft_vecpush(matches, NULL) == NULL ||
- (join = ft_strsjoin((char**)matches->data, "\n")) == NULL)
+ (join = ft_strsjoin((char**)matches->data, " ")) == NULL)
{
ft_vecdestroy(matches, free);
return (NULL);
@@ -161,3 +161,16 @@ char *ms_glob(char *pattern)
}
return (join);
}
+
+/*
+** \brief Wrapper around `ms_glob` which free `pattern` for convinience
+*/
+
+char *ms_globf(char *pattern)
+{
+ char *ret;
+
+ ret = ms_glob(pattern);
+ free(pattern);
+ return (ret);
+}
diff --git a/src/parse/lexer.c b/src/parse/lexer.c
new file mode 100644
index 0000000..2aa8a6f
--- /dev/null
+++ b/src/parse/lexer.c
@@ -0,0 +1,26 @@
+/*
+** \file lexer.c
+** \brief Lexer
+*/
+
+#include "minishell.h"
+
+/* static char **lex_len(char *input) */
+/* { */
+/* int i; */
+/* */
+/* i = 0; */
+/* while(input[i] != '\0') */
+/* { */
+/* lex_comp_cmd(input); */
+/* i++; */
+/* } */
+/* } */
+
+/* char **lexer(char *input) */
+/* { */
+/* if (!input) */
+/* return (NULL); */
+/* lex_len(input); */
+/* return (NULL); */
+/* } */
diff --git a/src/parse/parse.c b/src/parse/parse.c
new file mode 100644
index 0000000..a0da5d9
--- /dev/null
+++ b/src/parse/parse.c
@@ -0,0 +1,18 @@
+/*
+** \file parse.c
+** \brief Parser
+*/
+
+#include "parse.h"
+
+t_ast *parse(char **input)
+{
+ /* int i = 0; */
+
+ (void)input;
+ /* while (input[i] != '\0') */
+ /* { */
+ /* */
+ /* } */
+ return NULL;
+}
diff --git a/src/preprocess.c b/src/preprocess.c
index c30bb70..1034068 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -6,64 +6,151 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/03 08:58:49 by charles #+# #+# */
-/* Updated: 2020/04/05 15:04:06 by charles ### ########.fr */
+/* Updated: 2020/06/12 11:57:17 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "ms_glob.h"
+#include "lexer.h"
-static char *iterpolate(char *str, t_env env)
+static bool st_escapable(char c, enum e_token_tag tag)
+{
+ if (tag & LTAG_STR)
+ return (true);
+ if ((tag & LTAG_STR_DOUBLE) && (c == '\\' || c == '"' || c == '$'))
+ return (true);
+ return (false);
+}
+
+static char *st_iterpolate_env(char *str, enum e_token_tag tag, t_env env)
{
size_t i;
t_ftdstr *dstr;
char *match;
- if ((dstr = ft_dstrnew(str)) == NULL)
+ if ((dstr = ft_dstrwrap(str)) == NULL)
return (NULL);
- free(str);
- i = 0;
- while (i < dstr->length)
- {
- if (dstr->str[i] == '$')
+ i = -1;
+ while (++i < dstr->length)
+ if (dstr->str[i] == '\\' && st_escapable(dstr->str[i + 1], tag))
+ ft_dstrerase(dstr, i, 1);
+ else if (dstr->str[i] == '$')
{
if ((match = env_search_first_match(env, dstr->str + i + 1)) == NULL)
+ {
ft_dstrerase(dstr, i, utils_var_end(dstr->str + i + 1));
+ i--;
+ }
else
{
if (ft_dstrsubstitute(dstr, match, i, utils_var_end(dstr->str + i + 1)) == NULL)
+ {
+ ft_dstrdestroy(dstr);
return (NULL);
+ }
+ i += ft_strlen(match) - 1;
}
}
+ return (ft_dstrunwrap(dstr));
+}
+
+static char *st_iterpolate_globs(char *str)
+{
+ char **strs;
+ int i;
+
+ if ((strs = ft_splitf(str, ' ')) == NULL)
+ return (NULL);
+ i = 0;
+ while (strs[i] != NULL)
+ {
+ if (ft_strchr(strs[i], '*') != NULL
+ && (strs[i] = ms_globf(strs[i])) == NULL)
+ {
+ ft_split_destroy(strs);
+ return (NULL);
+ }
i++;
}
- return (ft_dstrunwrap(dstr));
+ return (ft_strsjoinf(strs, " "));
}
-static char *preprocess_arg(char *arg, t_env env)
+static int st_splat_arg(t_ftvec *argv, int i)
{
- if (*arg == '\'')
- return (ft_strsubf(arg, 1, ft_strlen(arg) - 1));
- if (*arg == '"')
+ t_token *splated;
+ char **strs;
+ int j;
+
+ if ((splated = ft_vectake(argv, i)) == NULL
+ || (strs = ft_split(splated->content, ' ')) == NULL)
{
- if (ft_strchr(arg, '$') != NULL)
- arg = iterpolate(arg, env);
- return (ft_strsubf(arg, 1, ft_strlen(arg) - 1));
+ token_destroy(splated);
+ return (-1);
}
- if (ft_strchr(arg, '$') != NULL)
- return (iterpolate(arg, env));
- if (ft_strchr(arg, '*') != NULL)
- return (ms_glob(arg));
- return (arg);
+ j = 0;
+ while (strs[j] != NULL)
+ {
+ if (ft_vecinsert_safe(argv, i + j, token_new(LTAG_STR, strs[j])) == NULL)
+ {
+ token_destroy(splated);
+ ft_split_destroy(strs);
+ return (-1);
+ }
+ j++;
+ }
+ token_destroy(splated);
+ ft_split_destroy(strs);
+ return (i + j - 1);
+}
+
+static void st_iter_func_unwrap_token(void **addr)
+{
+ char *content;
+
+ content = (*(t_token**)addr)->content;
+ free(*(t_token**)addr);
+ *(char**)addr = content;
}
-char **preprocess_argv(char **argv, t_env env)
+char **preprocess(t_ftvec *argv, t_env env)
{
- int i;
+ size_t i;
+ t_token *token;
i = -1;
- while (argv[++i] != NULL)
- if ((argv[i] = preprocess_arg(argv[i], env)) == NULL)
- return (NULL);
- return (argv);
+ while (++i < argv->size)
+ {
+ token = argv->data[i];
+ if (token->tag & LTAG_STR_SINGLE)
+ continue ;
+ token->content = st_iterpolate_env(token->content, token->tag, env);
+ if (token->tag & LTAG_STR)
+ {
+ if (ft_strchr(token->content, '*') != NULL)
+ token->content = st_iterpolate_globs(token->content);
+ if ((i = st_splat_arg(argv, i)) == (size_t)-1)
+ return (NULL);
+ }
+ }
+
+ t_token *next;
+ i = -1;
+ while (++i < argv->size - 1)
+ {
+ token = argv->data[i];
+ while (token->tag & LTAG_STICK && i + 1 < argv->size)
+ {
+ next = argv->data[i + 1];
+ token->content = ft_strjoinf_fst(token->content, next->content);
+ if (token->content == NULL)
+ return (NULL);
+ token->tag &= next->tag;
+ ft_vecremove(argv, i + 1, (void (*)(void*))token_destroy);
+ }
+ }
+
+ ft_veciter_addr(argv, st_iter_func_unwrap_token);
+ ft_vecpush(argv, NULL);
+ return ((char**)ft_vecunwrap(argv));
}
diff --git a/src/utils.c b/src/utils.c
index dd89457..3449c25 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -6,7 +6,7 @@
/* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:56:31 by cacharle #+# #+# */
-/* Updated: 2020/04/05 14:51:52 by charles ### ########.fr */
+/* Updated: 2020/06/09 15:49:39 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -59,5 +59,5 @@ size_t utils_var_end(char *name)
i = 0;
while (ft_isalnum(name[i]) || name[i] == '_')
i++;
- return (i);
+ return (i + 1);
}