4
4
#include "include/parser.h"
5
5
#include "include/sh_history.h"
6
6
#include "include/utils.h"
7
-
7
+ #include "include/pipeline.h"
8
8
9
9
10
10
11
11
12
12
/*
13
- SAVING SESSION HISTORY TO THE FILE
14
- LOADING HISTORY FROM THE FILE BY A GIVEN ID
13
+ PIPES HANDLING
14
+ UNKNOWN COMMANDS HANDLING WITH EXECVP
15
+ WRITE CURSOR MOVEMENT MACROSES
16
+ STREAM REDIRECTION HANDLING
17
+ FIX EXIT, I THINK THE REASON IS OTHER PROCESSES CREATED IN HANDLERS
15
18
*/
16
19
17
20
18
21
19
-
20
-
21
-
22
-
23
-
24
22
int main (int argc , char * * argv )
25
23
{
26
24
set_session_id ();
@@ -32,12 +30,12 @@ int main(int argc, char** argv)
32
30
33
31
input_t * input = NULL ;
34
32
command_t * cmd = NULL ;
35
- his_entry_t * entry_to_retrieve = NULL ;
33
+ pipe_cmds_t * pipeline_commands = NULL ;
36
34
37
35
int free_prompt_base = 0 , free_hist_filename = 0 ;
38
36
int cursor_pos_in_command = 0 , non_canon_curr ;
39
37
unsigned previous_watched_command_len ;
40
- char * esc_seq = (char * )sh_malloc (ESC_SEQUENCE_MAX_LEN );
38
+ char * esc_seq = (char * )sh_malloc (ESC_SEQUENCE_MAX_LEN ), * ptr ;
41
39
42
40
while (TRUE)
43
41
{
@@ -156,23 +154,39 @@ int main(int argc, char** argv)
156
154
if (!input -> size ) { printf ("\n" ); continue ; }
157
155
158
156
putchar (non_canon_curr );
157
+ input_buffer_push (input , '\0' );
159
158
160
159
// check if the prompt basename has been changed. If so, we should free memory that
161
160
// has been allocated for a new basename to avoid memory leaks
162
161
if (!strcmp (prompt_basename , DEFAULT_PROMPT_BASENAME )) free_prompt_base = 1 ;
163
162
if (!strcmp (hist_file_name , DEFAULT_HIST_FILENAME )) free_hist_filename = 1 ;
164
- if (!strcmp (input -> buffer , "exit" )) { input_free (input ); break ; }
165
-
166
- input_buffer_push (input , '\0' );
167
- cmd = command_parse_new (input -> buffer );
168
- if (cmd ) {
169
- shell_history_prepend (history , cmd );
170
- int status = command_handle (cmd );
163
+ if (!strcmp (input -> buffer , "exit" )) { break ; }
164
+
165
+ cmd = command_parse_new (input -> buffer , FALSE);
166
+ shell_history_prepend (history , cmd );
167
+
168
+ // if the whole command is valid then it is splitted by pipes
169
+ // and joined in a chain of subcommands
170
+ if (cmd -> is_valid ) {
171
+ char * buffer = strdup (input -> buffer );
172
+ pipeline_commands = pipeline_commands_new ();
173
+ do {
174
+ cmd = command_parse_new (buffer , TRUE);
175
+
176
+ ptr = strchr (buffer , VERTICAL_BAR_SYMBOL );
177
+ if (ptr ) buffer = ptr + 1 ;
178
+ else buffer += strlen (buffer );
179
+
180
+ if (cmd -> is_valid ) {
181
+ pipeline_commands_push (pipeline_commands , cmd );
182
+ }
183
+ } while (* buffer );
184
+ int status = pipeline_commands_handle (pipeline_commands );
185
+ pipeline_commands_free (pipeline_commands );
171
186
}
172
-
173
187
input_free (input );
174
188
}
175
- command_free ( cmd );
189
+
176
190
shell_history_free (history );
177
191
178
192
if (free_prompt_base ) free (prompt_basename );
0 commit comments