-
Notifications
You must be signed in to change notification settings - Fork 0
/
ec.c
101 lines (86 loc) · 1.59 KB
/
ec.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
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
#include "headers.h"
char *command_array[1000];
char *temp[1000];
char **extract_command(char *input, int *cnt)
{
temp[0] = strtok(input, " \t\r\n\v\f");
(*cnt) = (*cnt) + 1;
long long int i = 0, j = 0;
while (temp[i] != NULL)
{
(*cnt) = (*cnt) + 1;
i++;
temp[i] = strtok(NULL, " \t\r\n\v\f");
}
int temp_cnt = *cnt;
(*cnt) = 0;
for (int i = 0; i < temp_cnt - 1; i++)
{
if (strstr(temp[i], "<") != NULL)
{
if (temp[i][0] == '<')
{
if (strlen(temp[i]) == 1)
{
i++;
continue;
}
else
{
continue;
}
}
else
{
command_array[j] = (char *)malloc(200 * sizeof(char));
strcpy(command_array[j], temp[i]);
command_array[j][strlen(temp[i]) - 1] = '\0';
i++;
j++;
(*cnt) = (*cnt) + 1;
}
}
else if (strstr(temp[i], ">") != NULL)
{
if (temp[i][0] == '>')
{
if (strlen(temp[i]) == 1)
{
i++;
continue;
}
else if (temp[i][1] == '>')
{
if (strlen(temp[i]) == 2)
{
i++;
continue;
}
else
continue;
}
}
else
{
command_array[j] = (char *)malloc(200 * sizeof(char));
strcpy(command_array[j], temp[i]);
command_array[j][strlen(temp[i]) - 1] = '\0';
if (command_array[j][strlen(temp[i]) - 2] == '>')
command_array[j][strlen(temp[i]) - 2] = '\0';
j++;
i++;
(*cnt) = (*cnt) + 1;
}
}
else
{
command_array[j] = (char *)malloc(200 * sizeof(char));
strcpy(command_array[j], temp[i]);
j++;
(*cnt) = (*cnt) + 1;
}
}
command_array[(*cnt)] = NULL;
(*cnt) = (*cnt) + 1;
return command_array;
}