aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/env.c4
-rw-r--r--src/eval/cmd.c23
-rw-r--r--src/eval/variable.c42
-rw-r--r--src/lexer/tok_lst.c20
-rw-r--r--src/main.c5
5 files changed, 87 insertions, 7 deletions
diff --git a/src/env.c b/src/env.c
index a80797f..1766a50 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/08/19 10:23:55 by charles ### ########.fr */
+/* Updated: 2020/09/09 16:56:39 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -105,7 +105,7 @@ char *env_search_first_match(t_env env, const char *haystack)
while (ft_isalnum(haystack[len]) || haystack[len] == '_')
len++;
if (haystack[0] == '?')
- return (ft_itoa(g_last_status_code)); // FIXME leak
+ return (ft_itoa(g_last_status_code)); // FIXME leak (static buffer)
if (len == 0)
return (NULL);
i = -1;
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index ccb4cc2..5130a45 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -6,7 +6,7 @@
/* By: charles <charles@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/14 10:41:31 by charles #+# #+# */
-/* Updated: 2020/08/28 16:54:48 by charles ### ########.fr */
+/* Updated: 2020/09/09 17:40:54 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -94,9 +94,30 @@ int eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast)
char **argv;
if (!redir_extract(&ast->redirs, env, fds))
+ {
+ ast->redirs = NULL;
return (-1);
+ }
+ ast->redirs = NULL;
if ((param.env_local = env_from_array((char*[]){NULL})) == NULL)
return (-1);
+ variable_extract(&ast->cmd_argv, env, param.env_local);
+
+ /* char **strs = preprocess(&start, env); */
+ /* */
+ /* if (env_export(env_local, id, strs[0]) == NULL) */
+ /* return (-1); */
+ /* if (ast->cmd_argv == NULL) // FIXME special env not passed to child processes */
+ /* { */
+ /* ft_vecpop(param.env_local, NULL); */
+ /* if (ft_vecswallow_at(env, env->size - 1, param.env_local) == NULL) */
+ /* { */
+ /* ft_vecdestroy(param.env_local, free); */
+ /* return (-1); */
+ /* } */
+ /* g_last_status_code = 0; */
+ /* return (0); */
+ /* } */
if ((argv = preprocess(&ast->cmd_argv, env)) == NULL)
{
diff --git a/src/eval/variable.c b/src/eval/variable.c
new file mode 100644
index 0000000..2b6d7cf
--- /dev/null
+++ b/src/eval/variable.c
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* variable.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/09/09 17:12:14 by charles #+# #+# */
+/* Updated: 2020/09/09 18:22:43 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "eval.h"
+
+bool variable_extract(t_tok_lst **argv, t_env env, t_env env_local)
+{
+ char *key;
+ t_tok_lst *value_tokens;
+ char **strs;
+
+ if (*argv == NULL || !((*argv)->tag & TAG_STR)
+ || !utils_start_with_valid_identifier((*argv)->content))
+ return (true);
+
+ key = (*argv)->content;
+ (*argv)->content = ft_strchr(key, '=');
+ *(*argv)->content = '\0';
+ (*argv)->content++;
+ (*argv)->content = ft_strdup((*argv)->content);
+
+ /* printf("|%s| |%s|\n", key, (*argv)->content); */
+ /* if (*(*argv)->content == '\0') */
+ /* { */
+ /* ft_lstpop_front((t_ftlst**)argv, NULL); */
+ /* return (true); */
+ /* } */
+ value_tokens = tok_lst_take_sticked(argv);
+ strs = preprocess(&value_tokens, env);
+ if (env_export(env_local, key, strs[0]) == NULL)
+ return (false);
+ return (variable_extract(argv, env, env_local));
+}
diff --git a/src/lexer/tok_lst.c b/src/lexer/tok_lst.c
index a746794..83f50bf 100644
--- a/src/lexer/tok_lst.c
+++ b/src/lexer/tok_lst.c
@@ -6,7 +6,7 @@
/* By: charles <me@cacharle.xyz> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/08/27 09:32:58 by charles #+# #+# */
-/* Updated: 2020/08/27 20:54:35 by charles ### ########.fr */
+/* Updated: 2020/09/09 18:10:26 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -70,3 +70,21 @@ t_tok_lst *tok_lst_uncons(t_tok_lst **tokens)
poped->next = NULL;
return (poped);
}
+
+t_tok_lst *tok_lst_take_sticked(t_tok_lst **tokens)
+{
+ t_tok_lst *start;
+ t_tok_lst *curr;
+
+ if (*tokens == NULL)
+ return (NULL);
+ start = *tokens;
+ curr = *tokens;
+ while (curr->tag & TAG_STICK && curr->tag & TAG_IS_STR)
+ curr = curr->next;
+ /* if (curr->tag & TAG_IS_STR) */
+ /* curr = curr->next; */
+ *tokens = curr->next;
+ curr->next = NULL;
+ return (start);
+}
diff --git a/src/main.c b/src/main.c
index 6a0d36a..17dee77 100644
--- a/src/main.c
+++ b/src/main.c
@@ -6,7 +6,7 @@
/* By: cacharle <cacharle@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/02/28 11:45:44 by cacharle #+# #+# */
-/* Updated: 2020/09/09 14:20:41 by charles ### ########.fr */
+/* Updated: 2020/09/09 16:19:00 by charles ### ########.fr */
/* */
/* ************************************************************************** */
@@ -31,7 +31,6 @@ void tok_lst_debug(t_tok_lst *tokens);
** $?
** concurrent pipeline
** cmd variable preprocess
-** PATH with no permission, link and other file system fun stuff
** signal on whole line instead of single command
** env local to current minishell process
*/
@@ -115,7 +114,7 @@ int main(int argc, char **argv, char **envp)
char *line;
print_prompt();
- while ((ret = ft_getline(STDOUT_FILENO, &line)) == FTGL_OK)
+ while ((ret = ft_getline(STDIN_FILENO, &line)) == FTGL_OK)
{
if (*line == '\0')
{