aboutsummaryrefslogtreecommitdiff
path: root/src/preprocess.c
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-04-03 15:13:08 +0200
committerCharles <sircharlesaze@gmail.com>2020-04-03 15:13:08 +0200
commitc0e2ee28eedc1a9a886f9729a994d77738e2eb58 (patch)
treef099ec9b9effe0db078a521c9405c5765b68fd8f /src/preprocess.c
parente5393671a265e1c301c6c303f21f938c4cf9ca75 (diff)
downloadminishell-c0e2ee28eedc1a9a886f9729a994d77738e2eb58.tar.gz
minishell-c0e2ee28eedc1a9a886f9729a994d77738e2eb58.tar.bz2
minishell-c0e2ee28eedc1a9a886f9729a994d77738e2eb58.zip
Refactoring env, connecting pipes, preprocess draft
Diffstat (limited to 'src/preprocess.c')
-rw-r--r--src/preprocess.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/preprocess.c b/src/preprocess.c
new file mode 100644
index 0000000..30d2aa3
--- /dev/null
+++ b/src/preprocess.c
@@ -0,0 +1,74 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* preprocess.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/03 08:58:49 by charles #+# #+# */
+/* Updated: 2020/04/03 14:48:57 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "minishell.h"
+
+char *ms_glob(char *pattern)
+{
+ (void)pattern;
+ return (NULL);
+}
+
+/* void iterpolate_iter_f(char **curr) */
+/* { */
+/* if (*curr != '$') */
+/* return (i + 1); */
+/* } */
+
+
+char *preprocess(char *input, t_env env)
+{
+ int i;
+ t_ftdstr *input_dstr;
+ char *glob_str;
+ /* char *tmp; */
+
+ glob_str = NULL;
+ if ((input_dstr = ft_dstrnew(input)) == NULL)
+ return (NULL);
+ i = 0;
+ while (input_dstr->str[i] != '\0')
+ {
+ if (input_dstr->str[i] == '*')
+ {
+ free(glob_str);
+ /* if ((glob_str = ms_glob()) = NULL) */
+ /* { */
+ /* ft_dstrdestroy(input_str); */
+ /* return (NULL); */
+ /* } */
+ if (ft_dstrinsert(input_dstr, glob_str, 0) == NULL)
+ {
+ free(glob_str);
+ ft_dstrdestroy(input_dstr);
+ return (NULL);
+ }
+ i += strlen(glob_str);
+ }
+ /* else if (input_dstr->str[i] == '$') */
+ /* { */
+ /* if ((tmp = env_match_first(env, input_dstr->str + i + 1)) == NULL) */
+ /* tmp = ""; */
+ /* if (ft_dstrreplace(input_dstr, tmp, i, i + ft_strlen(tmp)) == NULL) */
+ /* { */
+ /* free(glob_str); */
+ /* ft_dstrdestroy(input_dstr); */
+ /* return (NULL); */
+ /* } */
+ /* i += ft_strlen(tmp); */
+ /* } */
+ /* else */
+ i++;
+ }
+ printf("%d %d %s\n", input_dstr->length, input_dstr->capacity, input_dstr->str);
+ return (ft_dstrunwrap(input_dstr));
+}