-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
98 lines (94 loc) · 2.71 KB
/
main.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
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 "Test.h"
#include "InputHandler.h"
#include <stdlib.h>
/**
* Checks for user input and goes to the switch statement for that input.
* Runs until x is entered
* @param graph the graph it uses to run on.
*/
void run(Graph *graph) {
char command;
char *line = malloc(MAX_LINE_LENGTH), *initialLine = line;
while (true) {
fgets(line, MAX_LINE_LENGTH, stdin);
if (strlen(line) == 0) continue;
command = line[0];
if (command == 'x') break;
line += 2;
removeNewline(line);
/**
* Switches between the different commands.
*/
switch(command) {
case 'c':
Graph_describeCourse(graph, line);
break;
case 'd':
Graph_describeDegree(graph, line);
break;
case 's':
Graph_describeCourseEffect(graph, line);
break;
case 'a':
Graph_addCourse(graph, line);
break;
case 'm':
Graph_describeDegreeReq(graph, line);
break;
case 'n':
Graph_describeNextDegreeReqs(graph, line);
break;
case 'q':
Graph_removeCourseDegree(graph, line);
break;
case 'r':
Graph_removeCourse(graph, line);
break;
case 'p':
command = line[0];
line += 2;
switch(command) {
case 'c':
Graph_printCourse(graph, line);
break;
case 'd':
Graph_printDepartment(graph, line);
break;
case 'g':
Graph_printDegree(graph, line);
break;
case 's':
Graph_printStudent(graph, line);
break;
default:
printf("Invalid Input. Please try again\n");
break;
}
break;
default:
printf("Invalid Input. Please try again\n");
}
line = initialLine;
}
free(initialLine);
}
/**
* Main function called from cli
* @param argc Number of args
* @param argv Each arg as string
* @return 0 if no error
*/
int main(int argc, char *argv[]) {
Graph *graph = malloc(sizeof(Graph));
Graph_init(graph);
if (argc > 1) {
for (int i = 1; i < argc; i++) {
readFile(graph, argv[i]);
}
}
run(graph);
testGraph(graph);
Graph_free(graph);
free(graph);
return 0;
}