-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrepeat.c
63 lines (55 loc) · 1.61 KB
/
repeat.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
#include "main.h"
// This function is for the repeat functionality
void repeat (long long int totalArgsInEachCommand, char *listofArgs[]) {
// Return if no. of args < 3
if (totalArgsInEachCommand < 3) {
printf(stderr, "Too less arguments\n");
return;
}
ll repeatTimes = atoi(listOfArgs[1]);
char *args[totalArgsInEachCommand - 2];
int k=0;
for (int i = 2; i < totalArgsInEachCommand; i++) {
int len = strlen(listOfArgs[i]);
args[k] = (char *)malloc((len + 2) * sizeof(char));
strcpy(args[k], listOfArgs[i]);
k++;
}
if (strcmp(args[0], "echo") == 0) {
for (int i = 0; i < repeatTimes; i++) {
echo(totalArgsInEachCommand - 2, args);
}
return;
}
else if (strcmp(args[0], "cd") == 0) {
for (int i = 0; i < repeatTimes; i++) {
cd(totalArgsInEachCommand - 2, args[1]);
}
return;
}
else if (strcmp(args[0], "pwd") == 0) {
for (int i = 0; i < repeatTimes; i++) {
pwd(totalArgsInEachCommand - 2, args);
}
return;
}
else if (strcmp(args[0], "ls") == 0) {
for (int i = 0; i < repeatTimes; i++) {
ls(totalArgsInEachCommand - 2, args);
}
return;
}
else if(strcmp(args[0], "pinfo") == 0) {
for (int i = 0; i < repeatTimes; i++) {
pinfo(totalArgsInEachCommand - 2, args);
}
return;
}
else {
for (int i = 0; i < repeatTimes; i++) {
foregroundProcess(totalArgsInEachCommand - 2, args);
}
return;
}
return;
}