aboutsummaryrefslogtreecommitdiff
path: root/src/preprocess.c
blob: 30d2aa3d7ba6f9cdc8498ce2110491059a1a50af (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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));
}