aboutsummaryrefslogtreecommitdiff
path: root/split_token
blob: 7aa502075ae1af4061e4c10df2136b43d6571148 (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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
diff --git a/include/eval.h b/include/eval.h
index 88142cd..88b6578 100644
--- a/include/eval.h
+++ b/include/eval.h
@@ -6,7 +6,7 @@
 /*   By: charles <charles@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2020/04/01 17:05:30 by charles           #+#    #+#             */
-/*   Updated: 2020/07/15 17:03:05 by charles          ###   ########.fr       */
+/*   Updated: 2020/07/20 13:22:26 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -58,6 +58,7 @@ int				eval(int fds[2], t_env env, t_path path, t_ast *ast);
 
 int				fork_wrap(int fds[2], void *passed, int (*wrapped)(void *param));
 int				eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast);
+t_ftlst         *split_token(t_ftlst **lst, enum e_token_tag);
 
 /*
 ** redir.c
diff --git a/include/lexer.h b/include/lexer.h
index ab2a448..f40db56 100644
--- a/include/lexer.h
+++ b/include/lexer.h
@@ -6,7 +6,7 @@
 /*   By: nahaddac <nahaddac@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2020/06/19 10:51:26 by nahaddac          #+#    #+#             */
-/*   Updated: 2020/07/16 07:10:58 by nahaddac         ###   ########.fr       */
+/*   Updated: 2020/07/20 11:07:13 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
diff --git a/libft b/libft
index 450e36f..0fc1e47 160000
--- a/libft
+++ b/libft
@@ -1 +1 @@
-Subproject commit 450e36f8ddf974e503731288c8d8bb8c62e67e47
+Subproject commit 0fc1e473e3bae0e1df32228ff72b9ab654fd2ac3
diff --git a/minishell_test b/minishell_test
index 520742c..a90b8ed 160000
--- a/minishell_test
+++ b/minishell_test
@@ -1 +1 @@
-Subproject commit 520742c77fc3d52301c54b7d678948f9c7c69ac6
+Subproject commit a90b8ed1561e1edd05e2689e566727acedf4ff68
diff --git a/src/eval/cmd.c b/src/eval/cmd.c
index 87c9bbf..adb4d1c 100644
--- a/src/eval/cmd.c
+++ b/src/eval/cmd.c
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   cmd.c                                              :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
+/*   By: charles <charles@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2020/06/14 10:41:31 by charles           #+#    #+#             */
-/*   Updated: 2020/07/19 19:00:54 by charles          ###   ########.fr       */
+/*   Updated: 2020/07/20 14:17:32 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -14,6 +14,7 @@
 
 pid_t	g_child_pid = -1;
 int		g_last_status_code = 0;
+void token_debug(void *v);
 
 /*
 ** \brief          Wrap a function in a fork
@@ -91,6 +92,8 @@ int			eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast)
 {
 	t_fork_param_cmd	param;
 	char				**argv;
+	char 				*id;
+	t_ftlst 			*tmp;
 
 	if (!redir_extract(ast->redirs, env, fds))
 	{
@@ -105,7 +108,14 @@ int			eval_cmd(int fds[2], t_env env, t_path path, t_ast *ast)
 		&& ((t_token*)ast->cmd_argv->data)->tag & TAG_IS_STR
 		&& utils_start_with_valid_identifier(((t_token*)ast->cmd_argv->data)->content))
 	{
-		if (env_export_full(param.env_local, ((t_token*)ast->cmd_argv->data)->content) == NULL)
+		id = ((t_token*)ast->cmd_argv->data)->content;
+		*ft_strchr(id, '=') = '\0';
+		((t_token*)ast->cmd_argv->data)->content = ft_strchr(id, '\0') + 1;
+		tmp = split_token(&ast->cmd_argv, TAG_STICK);
+		ft_lstiter(tmp, token_debug);
+		printf("%s\n", ((t_token *)ast->cmd_argv->data)->content);
+
+		if (env_export(param.env_local,id, ((t_token*)ast->cmd_argv->data)->content) == NULL)
 			return (-1);
 		ft_lstpop_front(&ast->cmd_argv, (void (*)(void*))token_destroy);
 	}
diff --git a/src/main.c b/src/main.c
index 85df51f..e1b956a 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/07/19 20:22:37 by charles          ###   ########.fr       */
+/*   Updated: 2020/07/20 11:21:23 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -32,10 +32,10 @@ void ast_print(int level, t_ast *ast);
 ** pipeline
 ** cmd variable preprocess
 ** PATH with no permission, link and other file system fun stuff
-** escape lexer
+** escape lexer ------- ok
 ** escape split preprocessing (escaped spaces)
 ** signal on whole line instead of single command
-** parsing error
+** parsing error ------ ok
 ** env local to current minishell process
 ** BETTER ERROR HANDLING IS BECOMING URGENT (spagetti code everywhere)
 */
@@ -67,12 +67,12 @@ int main(int argc, char **argv, char **envp)
 	path = path_update(NULL, env_search(env, "PATH"));
 
 	char *env_exec_path;
-	if ((env_exec_path = ft_htget(path, "env")) == NULL)
-	{
-		errorf("env: command not found\n");
-		return (127);
-	}
-	env_export(env, "_", env_exec_path);
+	// if ((env_exec_path = ft_htget(path, "env")) == NULL)
+	// {
+	// 	errorf("env: command not found\n");
+	// 	return (127);
+	// }
+	// env_export(env, "_", env_exec_path);
 
 	g_last_status_code = 0;
 	signal(SIGINT, signal_sigint);
@@ -104,7 +104,7 @@ int main(int argc, char **argv, char **envp)
 		if (parser_out == NULL || parser_out->syntax_error)
 			return (1);
 
-		 //ast_print(0, parser_out->ast);
+		 ast_print(0, parser_out->ast);
 
 		/* printf("===cmd_argv===\n"); */
 		/* ft_lstiter(parser_out->ast->cmd_argv, token_debug); */
diff --git a/src/parse/parse.c b/src/parse/parse.c
index 89102bc..29b3ccb 100644
--- a/src/parse/parse.c
+++ b/src/parse/parse.c
@@ -6,7 +6,7 @@
 /*   By: nahaddac <nahaddac@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2020/06/17 18:09:04 by nahaddac          #+#    #+#             */
-/*   Updated: 2020/07/19 19:25:29 by charles          ###   ########.fr       */
+/*   Updated: 2020/07/20 10:26:14 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
@@ -47,6 +47,13 @@ t_ret					*parse_redir(t_ftlst *input, t_ftlst **redirs)
 
 	push_token(redirs, input->data);
 	input = input->next;
+	if (input == NULL)
+	{
+		errorf("syntax error near unexpected token `newline'\n", NULL);
+		tmp = ret_wrap_ast(NULL, NULL);
+		tmp->syntax_error = true;
+		return tmp;
+	}
 	tag = ((t_token *)input->data)->tag;
 	while(input != NULL
 			&& input->next != NULL
@@ -91,7 +98,7 @@ t_ret                   *parse_cmd(t_ftlst *input)
 		else if (tag & TAG_IS_REDIR)
 		{
 			tmp = parse_redir(input, &ast->redirs);
-			if (tmp->syntax_error || tmp == NULL)
+			if (tmp == NULL || tmp->syntax_error)
 				return tmp;
 			input = tmp->rest;
 		}
diff --git a/src/parse/parse_error.c b/src/parse/parse_error.c
index 42d46ea..84b06b2 100644
--- a/src/parse/parse_error.c
+++ b/src/parse/parse_error.c
@@ -6,90 +6,8 @@
 /*   By: nahaddac <nahaddac@student.42.fr>          +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2020/06/18 15:09:48 by nahaddac          #+#    #+#             */
-/*   Updated: 2020/07/17 11:24:23 by nahaddac         ###   ########.fr       */
+/*   Updated: 2020/07/20 10:46:26 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */
 
 #include "parser.h"
-
-// t_token                 *error_syntax_parent(t_ftlst *in)
-// {
-//     t_token             *tk;
-//     t_ftlst             *first;
-//
-//     first = in;
-//     while(in != NULL)
-//     {
-//         tk = in->data;
-//         if (tk->tag & TAG_PARENT_OPEN || tk->tag & TAG_PARENT_CLOSE)
-//             printf("%s\n", "coucouc");
-//         in = in->next;
-//     }
-//     return first;
-// }
-
-// int                     out_error_first(t_token *tk)
-// {
-//     int                 i;
-//
-//     i = 0;
-//     if(tk->tag & TAG_IS_SEP)
-//             return(1);
-//     if (tk->tag & TAG_IS_REDIR)
-//     {
-//         while(tk->content[i])
-//             i++;
-//         if (tk->tag & TAG_REDIR_APPEND && i <= 2)
-//             return (0);
-//         else
-//             return(1);
-//     }
-//     return(0);
-// }
-//
-// t_token                 *error_syntax_simple(t_ftlst *in)
-// {
-//     t_token             *tk;
-//     size_t              i;
-//     /* t_ftlst             *first; */
-//
-//     tk = in->data;
-//     /* first = in; */
-//     if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR))
-//     {
-//         if (out_error_first(tk))
-//         {
-//             i = ft_strlen(tk->content);
-//             if (i >= 2)
-//                 tk->content[2] = '\0';
-//             tk->content =
-//             ft_strjoin3("minishell:  syntax error near unexpected token `",
-//                         tk->content, "'");
-//             return(tk);
-//         }
-//     }
-//     while(in != NULL)
-//     {
-//         i = 0;
-//         tk = in->data;
-//         if(tk->tag & TAG_IS_SEP || (tk->tag & TAG_IS_REDIR))
-//         {
-//             if (((t_token *)in->next->data)->tag &
-//             ((t_token*)in->next->data)->tag & TAG_IS_SEP ||
-//             (((t_token*)in->next->data)->tag & TAG_IS_REDIR))
-//             {
-//                 tk = in->next->data;
-//                 i = ft_strlen(tk->content);
-//                 if (i >= 3)
-//                     tk->content[2] = '\0';
-//                 tk->content =
-//                 ft_strjoin3("minishell:  syntax error near unexpected token `",
-//                             tk->content, "'");
-//                 printf("%s\n",tk->content );
-//                 return(tk);
-//             }
-//         }
-//         in = in->next;
-//     }
-//     return 0;
-// }
diff --git a/src/preprocess.c b/src/preprocess.c
index 2a884df..a834624 100644
--- a/src/preprocess.c
+++ b/src/preprocess.c
@@ -3,10 +3,10 @@
 /*                                                        :::      ::::::::   */
 /*   preprocess.c                                       :+:      :+:    :+:   */
 /*                                                    +:+ +:+         +:+     */
-/*   By: charles <charles.cabergs@gmail.com>        +#+  +:+       +#+        */
+/*   By: charles <charles@student.42.fr>            +#+  +:+       +#+        */
 /*                                                +#+#+#+#+#+   +#+           */
 /*   Created: 2020/04/03 08:58:49 by charles           #+#    #+#             */
-/*   Updated: 2020/07/19 19:01:53 by charles          ###   ########.fr       */
+/*   Updated: 2020/07/20 14:12:41 by nahaddac         ###   ########.fr       */
 /*                                                                            */
 /* ************************************************************************** */