aboutsummaryrefslogtreecommitdiff
path: root/src/preprocess/filename.c
blob: 0470554bede622a35b1ff7091790c4d0c3ed9c60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   filename.c                                         :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <me@cacharle.xyz>                 +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/10/09 15:29:04 by cacharle          #+#    #+#             */
/*   Updated: 2020/10/09 15:30:03 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "eval.h"
#include "lexer.h"
#include "minishell.h"

int	preprocess_filename(t_tok_lst **tokens, t_env env, char **filename)
{
	char	**strs;

	if ((strs = preprocess(tokens, env)) == NULL || strs[0] == NULL)
	{
		free(strs);
		return (EVAL_FATAL);
	}
	if (strs[1] != NULL)
	{
		errorf("%s: ambiguous redidrect\n", strs[1]);
		ft_split_destroy(strs);
		return (1);
	}
	*filename = strs[0];
	free(strs);
	return (*filename == NULL ? EVAL_FATAL : 0);
}