aboutsummaryrefslogtreecommitdiff
path: root/src/preprocess.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/preprocess.c')
-rw-r--r--src/preprocess.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/preprocess.c b/src/preprocess.c
index badf3cf..1c59e28 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -6,13 +6,14 @@
/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/04/03 08:58:49 by charles #+# #+# */
-/* Updated: 2020/06/14 10:33:17 by charles ### ########.fr */
+/* Updated: 2020/06/15 10:47:24 by charles ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
#include "ms_glob.h"
#include "lexer.h"
+#include "eval.h"
static bool st_escapable(char c, enum e_token_tag tag)
{
@@ -113,11 +114,19 @@ static void st_iter_func_unwrap_token(void **addr)
*(char**)addr = content;
}
-char **preprocess(t_ftvec *argv, t_env env)
+// need to free argv on error
+char **preprocess(t_ftlst **tokens, t_env env)
{
size_t i;
t_token *token;
+ t_ftvec *argv;
+ if ((argv = ft_vecfrom_lst(*tokens)) == NULL)
+ {
+ ft_lstdestroy(tokens, NULL);
+ return (NULL);
+ }
+ ft_lstdestroy(tokens, NULL);
i = -1;
while (++i < argv->size)
{
@@ -154,3 +163,24 @@ char **preprocess(t_ftvec *argv, t_env env)
ft_vecpush(argv, NULL);
return ((char**)ft_vecunwrap(argv));
}
+
+// need to free tokens
+char *preprocess_filename(t_ftlst **tokens, t_env env)
+{
+ char **strs;
+ char *ret;
+
+ if ((strs = preprocess(tokens, env)) == NULL
+ || strs[0] == NULL)
+ return (NULL);
+ if (strs[1] != NULL)
+ {
+ // save tokens
+ error_eval_put(ERROR_AMBIGUOUS_REDIR, strs[1]);
+ ft_split_destroy(strs);
+ return (NULL);
+ }
+ ret = strs[0];
+ free(strs);
+ return (ret);
+}