forked from sruthi2498/MyShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper_to_parser.c
40 lines (30 loc) · 941 Bytes
/
helper_to_parser.c
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
#include "all_include.h"
//Initialize a global intermediate array to store arguments
int Init_parsed_args(){
parsed_arg=malloc(sizeof(char *) * MAX_NUMBER_OF_ARGUMENTS);
for(int i=0; i<MAX_NUMBER_OF_ARGUMENTS; i++){
parsed_arg[i] = malloc(sizeof(char) * MAX_LEN_OF_ARG);
}
count_arg = 0;
}
//Send the arguments in reverse order to actual SimpleComand
int Send_all_args(){
//printf("\nSending all args \n");
insertArgument(parsed_arg[count_arg-1]);
for(int i=0; i<count_arg-1; i++){
//printf("parsed_arg[i] : %s ", parsed_arg[i]);
insertArgument(parsed_arg[i]);
}
insertArgument(NULL);
return 1;
//for i = number of args to 0
//insertArgument(arg_list[i])
//Append NULL as last argument
}
//Insert each argument into intermediate array (in reverse order)
int Insert_parsed_arg(char *buf){
//printf("Inserting parsed arg %s\n", buf);
char *temp = strdup(buf);
parsed_arg[count_arg] = temp;
count_arg++;
}