aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/lexer.h1
-rw-r--r--include/ms_glob.h3
m---------libft0
-rw-r--r--src/lexer/token.c10
-rw-r--r--src/main.c10
-rw-r--r--src/ms_glob.c11
-rw-r--r--src/preprocess.c27
7 files changed, 40 insertions, 22 deletions
diff --git a/include/lexer.h b/include/lexer.h
index e20e0e7..9377807 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -16,6 +16,7 @@ typedef struct
} t_token;
t_token *token_new(enum e_token_tag tag, char *content);
+void token_destroy(t_token *token);
//////////////////////////////////////
char **lexer(char *input);
diff --git a/include/ms_glob.h b/include/ms_glob.h
index 774d3be..2eb16f1 100644
--- a/include/ms_glob.h
+++ b/include/ms_glob.h
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/05 11:45:11 by charles #+# #+# */
-/* Updated: 2020/04/05 13:05:10 by charles ### ########.fr */
+/* Updated: 2020/06/09 17:51:34 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -28,5 +28,6 @@ struct s_glob_param
t_ftvec *glob_matches(char *pattern);
char *ms_glob(char *pattern);
+char *ms_globf(char *pattern);
#endif
diff --git a/libft b/libft
-Subproject f1babc364b2507cb8999d3132941b056feac37c
+Subproject 6fe30c97aad7a4a3564e7037d64a43edcb9a216
diff --git a/src/lexer/token.c b/src/lexer/token.c
index bf534a4..6c6a184 100644
--- a/src/lexer/token.c
+++ b/src/lexer/token.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/09 13:38:08 by charles #+# #+# */
-/* Updated: 2020/06/09 13:39:27 by charles ### ########.fr */
+/* Updated: 2020/06/09 17:55:23 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -17,7 +17,7 @@ t_token *token_new(enum e_token_tag tag, char *content)
t_token *token;
if (content == NULL
- || (token = malloc(sizeof(t_token))) == NULL)
+ || (token = (t_token*)malloc(sizeof(t_token))) == NULL)
return (NULL);
if ((token->content = ft_strdup(content)) == NULL)
{
@@ -27,3 +27,9 @@ t_token *token_new(enum e_token_tag tag, char *content)
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 802d3d2..76c863d 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/06/09 16:53:45 by charles ### ########.fr */
+/* Updated: 2020/06/09 17:48:03 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -95,11 +95,11 @@ int main(int argc, char **argv, char **envp)
/* 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, "$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, "src/*.c include/*.h"));
+ ft_vecpush(v, token_new(LTAG_STR, "$A$B"));
char **as = preprocess_argv(v, env);
char **tmp = as;
diff --git a/src/ms_glob.c b/src/ms_glob.c
index 2ab62a3..a96c45f 100644
--- a/src/ms_glob.c
+++ b/src/ms_glob.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/05 11:44:07 by charles #+# #+# */
-/* Updated: 2020/06/09 16:20:22 by charles ### ########.fr */
+/* Updated: 2020/06/09 17:51:30 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -160,3 +160,12 @@ char *ms_glob(char *pattern)
}
return (join);
}
+
+char *ms_globf(char *pattern)
+{
+ char *ret;
+
+ ret = ms_glob(pattern);
+ free(pattern);
+ return (ret);
+}
diff --git a/src/preprocess.c b/src/preprocess.c
index 0d72a2c..c09ba71 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -6,7 +6,7 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/03 08:58:49 by charles #+# #+# */
-/* Updated: 2020/06/09 17:03:37 by charles ### ########.fr */
+/* Updated: 2020/06/09 17:56:20 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -14,18 +14,16 @@
#include "ms_glob.h"
#include "lexer.h"
-static char *iterpolate(char *str, t_env env)
+static char *iterpolate(char *str, 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)
- {
+ i = -1;
+ while (++i < dstr->length)
if (dstr->str[i] == '$')
{
if ((match = env_search_first_match(env, dstr->str + i + 1)) == NULL)
@@ -43,8 +41,6 @@ static char *iterpolate(char *str, t_env env)
i += ft_strlen(match) - 1;
}
}
- i++;
- }
return (ft_dstrunwrap(dstr));
}
@@ -53,13 +49,13 @@ static char *iterpolate_globs(char *str)
char **strs;
int i;
- if ((strs = ft_split(str, ' ')) == NULL)
+ if ((strs = ft_splitf(str, ' ')) == NULL)
return (NULL);
i = 0;
while (strs[i] != NULL)
{
if (ft_strchr(strs[i], '*') != NULL
- && (strs[i] = ms_glob(strs[i])) == NULL)
+ && (strs[i] = ms_globf(strs[i])) == NULL)
{
ft_split_destroy(strs);
return (NULL);
@@ -69,7 +65,7 @@ static char *iterpolate_globs(char *str)
return (ft_strsjoinf(strs, " "));
}
-static int splat_arg(t_ftvec *argv, int i)
+static int splat_arg(t_ftvec *argv, int i)
{
t_token *splated;
char **strs;
@@ -77,19 +73,24 @@ static int splat_arg(t_ftvec *argv, int i)
if ((splated = ft_vectake(argv, i)) == NULL
|| (strs = ft_split(splated->content, ' ')) == NULL)
+ {
+ token_destroy(splated);
return (-1);
+ }
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;
+ return (i + j - 1);
}
void iter_func_unwrap_token(void **addr)