aboutsummaryrefslogtreecommitdiff
path: root/src/main.c
blob: 5dac61242d0f90f1f032f0943cdbe1a2abc75b70 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   main.c                                             :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/02/28 11:45:44 by cacharle          #+#    #+#             */
/*   Updated: 2020/06/13 11:56:27 by charles          ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

/*
** \file   main.c
** \brief  Minishell entrypoint
*/

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

/*
** \brief       Program entrypoint
** \param argc  Number of arguments in `argv`
** \param argv  Array of string, argument of the program
** \param envp  NULL terminated array of string representing the environment
** \return      0 if ok, 1 otherwise
*/

int main(int argc, char **argv, char **envp)
{
	(void)argc;
	(void)argv;
	/* (void)envp; */
	/* t_path	path; */
	t_env	env;
	/* char	*line; */
	/* int		ret; */

	env = env_from_array(envp);
	/* path = path_update(NULL, env_search(env, "PATH")); */
    /*  */
	/* t_ast *ast; */
	/* t_line line; */
	/* t_cmd cmd; */
	/* t_eval_state state; */
    /*  */
	/* cmd.argv = ft_split("ls -l", ' '); */
	/* cmd.in = NULL; */
	/* cmd.out = NULL; */
	/* cmd.is_append = false; */
    /*  */
	/* line.left = ast_new(TAG_CMD, &cmd); */
	/* line.right = NULL; */
	/* line.sep = SEP_END; */
	/* ast = ast_new(TAG_LINE, &line); */

	/* printf("%p\n", ast); */
	/* printf("%d\n", ast->tag); */
	/* printf("%p\n", ast->data.line.left); */
	/* printf("%p\n", ast->data.line.right); */
	/* printf("%d\n", ast->data.line.left->tag); */
	/* printf("%p\n", ast->data.line.left->data.cmd.argv); */
	/* printf("%s\n", ast->data.line.left->data.cmd.argv[0]); */
	/* printf("%s\n", ast->data.line.left->data.cmd.argv[1]); */

	/* state.pipe_in[0] = -1; */
	/* state.pipe_in[1] = -1; */
	/* state.pipe_out[0] = -1; */
	/* state.pipe_out[1] = -1; */
	/* state.path = path; */
	/* state.env = env; */
	/* t_io_frame frame; */
	/* io_frame_init(&frame); */
	/* printf("ret: %d %s\n", eval(&frame,&state, ast), strerror(errno)); */

	/* char buf[2048]; */
	/* printf("%s\n", getcwd(buf, 2048)); */
	/* builtin_env(NULL, state.env); */
	/* ast_destroy(ast); */
	/* while ((ret = ft_next_line(STDIN_FILENO, &line)) == 1) */
	/* { */
	/* 	if (eval(parse(line)) == -1) */
	/* 		continue ;  // and display error */
	/* 	free(line); */
	/* } */
	/* free(line); */
	/* ft_htdestroy(path, free); */
	/* ms_glob("src#<{(|"); */

	/* char *j = ms_glob("|)}>#*.c"); */
	/* printf("%s\n", j); */
	/* free(j); */

	t_ftvec *v = ft_vecnew(32);
	ft_vecpush(v, token_new(LTAG_STR, "$TERM$LFS$TERM$TERM."));
	ft_vecpush(v, token_new(LTAG_STR, "$$LFS$TERM$TERM."));
	ft_vecpush(v, token_new(LTAG_STR, "*/*.c$TERM"));
	ft_vecpush(v, token_new(LTAG_STR, "src/*.c include/*.h"));
	ft_vecpush(v, token_new(LTAG_STR, "$A$B"));

	ft_vecpush(v, token_new(LTAG_STR, "\\$TERM"));
	ft_vecpush(v, token_new(LTAG_STR, "$TER\\M"));
	ft_vecpush(v, token_new(LTAG_STR, "\\\\"));
	ft_vecpush(v, token_new(LTAG_STR_SINGLE, "''''$TEST\\TEST"));
	ft_vecpush(v, token_new(LTAG_STR_DOUBLE, ",$TEST,$B,"));

	ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
	ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
	ft_vecpush(v, token_new(LTAG_STR_DOUBLE , "$TEST"));
	ft_vecpush(v, token_new(LTAG_STR_DOUBLE | LTAG_STICK, "$TEST"));
	ft_vecpush(v, token_new(LTAG_STR_SINGLE, "$TEST"));

	char **as = preprocess(v, env);
	char **tmp = as;

	while (*as != NULL)
		puts(*as++);

	ft_split_destroy(tmp);
	ft_vecdestroy(env, free);
	return (0);
}


/////////////////////////////////////////////////////////////////////////////////////////
// lexer main
/////////////////////////////////////////////////////////////////////////////////////////

#include "lexer.h"

/* int         main(void) */
/* { */
/* 	char **out; */
/*     int i = -1; */
/*  */
/* 	out = lexer("\"echo\" \"* login_x\"<<AUTHORS; echo && ; salut;\"echo\"\"* login_x\""); */
/*     //out = lexer("echo       * login_x << AUTHORS&&cd Desktop"); */
/*     while(out[++i]) */
/*         printf("%s\n", out[i]);; */
/*     exit(0); */
/*     return (0); */
/* } */