-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLec_Shell.c
More file actions
113 lines (95 loc) · 2.77 KB
/
Copy pathLec_Shell.c
File metadata and controls
113 lines (95 loc) · 2.77 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
void Error(char* msg) {
perror(msg);
exit(1);
}
int main(int argc ,char* argv[]) {
//////////////////////// Initializing ///////////////
char buff[100];
char *scan,*id,*code,*name,*day,*hour_s,*hour_f;
int fd,ids,rbytes;
memset(buff, 0, sizeof(buff));
////////////////// lecturer funcs /////////////////////
while(1==1){
printf("LecShell> ");
fflush(stdout);
rbytes = read(STDIN_FILENO, buff, 100);
if(rbytes == -1){
Error("ERROR: failed to read");
}
buff[strlen(buff)-1] = '\0'; // remove newline character
scan=strtok(buff," ");
if(rbytes == -1){
Error("failed to read\n");
}
if (strcmp(scan,"SetCourses")==0){
code=strtok(NULL," ");
name=strtok(NULL," ");
day=strtok(NULL," ");
hour_s=strtok(NULL," ");
hour_f=strtok(NULL," ");
if(code== NULL || name == NULL || day == NULL || hour_s==NULL || hour_f==NULL){
printf("missing parameters!\n");
continue;
}
if ( ( ids = fork() ) == 0 ){
execl("/home/braude/SetCourses","SetCourses",code,name,day,hour_s,hour_f,NULL);
Error("failed execv SetCourses\n");
}
wait();
}
else if (strcmp(scan,"GetSchedule")==0){
id=strtok(NULL," ");
if ( ( ids = fork() ) == 0 ){
execl("/home/braude/GetSchedule","GetSchedule",id,NULL);
Error("failed execv GetSchedule\n");
}
wait();
}
else if (strcmp(scan,"DeleteStudent")==0){
id=strtok(NULL," ");
if ( ( ids = fork() ) == 0 ){
execl("/home/braude/DeleteStudent","DeleteStudent",id,NULL);
Error("failed execv DeleteStudent\n");
}
wait();
}
else if (strcmp(scan,"Freeze")==0){
id=strtok(NULL," ");
if ( ( ids = fork() ) == 0 ){
execl("/home/braude/Freeze","Freeze",id,NULL);
Error("failed execv Freeze\n");
}
wait();
}
else if (strcmp(scan,"Approve")==0){
id=strtok(NULL," ");
if ( ( ids = fork() ) == 0 ){
execl("/home/braude/Approve","Approve",id,NULL);
Error("failed execv Approve\n");
}
wait();
}
else if (strcmp(scan,"ShowCourses")==0){
if ( ( ids = fork() ) == 0 ) {
execl("/home/braude/ShowCourses","ShowCourses",NULL);
Error("failed execl ShowCourses\n");
}
wait();
}
else if (strcmp(scan,"LogOut")==0){
execl("/home/braude/LogOut",NULL);
Error("failed execv LogOut\n");
}
else
printf("Not Supported\n");
memset(buff, 0, sizeof(buff));
}
return 0;
}