-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsash.c
49 lines (41 loc) · 1.15 KB
/
sash.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
#include "header.h"
char* home = NULL;
struct process *processes = NULL;
int plen = 0;
char* fg_name = NULL;
int main() {
char* delims = ";\n";
size_t len = MAXLEN;
char* line = (char *) malloc(sizeof(char) * len);
size_t homesize = MAXLEN;
home = (char *) malloc(sizeof(char)*homesize);
fg_name = (char *) malloc(sizeof(char)*MAXLEN);
fg_name = "main";
processes = (struct process*) malloc(sizeof(struct process)*MAXLEN);
setup();
if (getcwd(home, homesize) == NULL) {
printf("Error Number: %d\n", errno);
perror("getcwd home: ");
return -1;
}
initPrev();
while(1) {
prompt();
errno = 0;
if (!fgets(line, len, stdin)) {
printf("Error Number: %d\n", errno);
perror("read main: ");
return -1;
} else {
char* save_pointer;
char* args = strtok_r(removeSpace(line), delims, &save_pointer);
while (args!= NULL) {
pipeRun(args);
args = strtok_r(NULL, delims, &save_pointer);
}
}
}
free(line);
free(home);
free(processes);
}