-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.c
50 lines (34 loc) · 921 Bytes
/
command.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
#include "command.h"
#include "headers.h"
void getCommands(char* command, char*** commands) {
char* str = NULL;
long unsigned size = 1024;
int len = getline(&str, &size, stdin);
if (len < 0) {
printf("\n");
exit(0);
}
strcpy(command, str);
str[len - 1] = '\0';
if (str[0] == '\0') return;
char* tempCommands[20];
tempCommands[0] = NULL;
char* token = strtok(str, ";");
for (ll i = 0; token != NULL; i++) {
tempCommands[i] = token;
tempCommands[i + 1] = NULL;
token = strtok(NULL, ";");
}
commands[0] = NULL;
for (int i = 0; tempCommands[i] != NULL; i++) {
commands[i + 1] = NULL;
commands[i] = malloc(20 * sizeof(char*));
commands[i][0] = NULL;
char* token = strtok(tempCommands[i], "|");
for (int j = 0; token != NULL; j++) {
commands[i][j + 1] = NULL;
commands[i][j] = token;
token = strtok(NULL, "|");
}
}
}