-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplit.h
More file actions
98 lines (86 loc) · 2.46 KB
/
split.h
File metadata and controls
98 lines (86 loc) · 2.46 KB
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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char** splitcommand(char arg[]) {
char **commands = (char**)malloc(sizeof(char*)*100);
for(int i=0;i<100;i++) {
commands[i] = (char*)malloc(sizeof(char)*100);
}
char *splittoken = strtok(arg, ";");
int count = 0;
while(splittoken != NULL) {
strcpy(commands[count++], splittoken);
splittoken = strtok(NULL, ";");
}
return commands;
}
char** spliteachcommand(char arg[]) {
char **commandparts=(char**)malloc(sizeof(char*)*100);
for(int i=0;i<100;i++) {
commandparts[i] = (char*)malloc(sizeof(char)*100);
}
char *splittoken = strtok(arg, " ");
int count = 0;
while(splittoken != NULL) {
strcpy(commandparts[count++], splittoken);
splittoken = strtok(NULL, " ");
}
return commandparts;
}
char** splitpipes(char arg[]) {
char **commandpartspipe=(char**)malloc(sizeof(char*)*100);
for(int i=0;i<100;i++) {
commandpartspipe[i] = (char*)malloc(sizeof(char)*100);
}
char *splittoken = strtok(arg, "|");
int count = 0;
while(splittoken != NULL) {
strcpy(commandpartspipe[count++], splittoken);
splittoken = strtok(NULL, "|");
}
return commandpartspipe;
}
char** splitinred(char arg[]) {
char **inredcommands = (char**)malloc(sizeof(char*)*2);
inredcommands[0] = (char*)malloc(sizeof(char)*100);
inredcommands[1] = (char*)malloc(sizeof(char)*100);
char *splittoken = strtok(arg, "<");
int count = 0;
while(splittoken != NULL) {
strcpy(inredcommands[count++], splittoken);
splittoken = strtok(NULL, "<");
}
return inredcommands;
}
char** splitoutred(char arg[]) {
char **outredcommands = (char**)malloc(sizeof(char*)*2);
outredcommands[0] = (char*)malloc(sizeof(char)*100);
outredcommands[1] = (char*)malloc(sizeof(char)*100);
char *splittoken = strtok(arg, ">");
int count = 0;
while(splittoken != NULL) {
strcpy(outredcommands[count++], splittoken);
splittoken = strtok(NULL, ">");
}
return outredcommands;
}
void trim(char arg[]) {
int start, end, i = 0;
while(arg[i] == 32) {
i++;
}
start = i;
i = strlen(arg) - 1;
while(arg[i] == 32) {
i--;
}
end = i;
char retchar[1000];
strcpy(retchar, "");
for(int i=start;i<=end;i++) {
retchar[i-start] = arg[i];
}
retchar[end-start+1] = '\0';
strcpy(arg, retchar);
return;
}