-
Notifications
You must be signed in to change notification settings - Fork 0
/
objectives.cpp
117 lines (106 loc) · 2.93 KB
/
objectives.cpp
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
113
114
115
116
117
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "calendar.hpp"
#include "calendarUtil.hpp"
#include "help.hpp"
#include "io.hpp"
#include "objectives.hpp"
#include "periodUtil.hpp"
#include "task.hpp"
#include "taskUtil.hpp"
#include "util.hpp"
using namespace std;
Task* rootTask;
Calendar *calendar;
int lastMenu;
int curMenu;
Task* curTask;
void freeAll() {
freeTask(rootTask);
delete calendar;
}
bool generalCommands(string commandName) {
if (commandName == "goto") {
if (validArgs(1)) {
Task *nextTask = searchTask();
if (nextTask != nullptr) {
curTask = nextTask;
curMenu = TASK_MENU;
return true;
}
}
} else if (commandName == "cal") {
if (validArgs(0)) {
lastMenu = curMenu;
curMenu = CALENDAR_MENU;
return true;
}
} else if (commandName == "week") {
if (getNComms() == 1) printWeekSummary(false);
else if (getNComms() == 2 && getToken(1) == "all") printWeekSummary(true);
else cout << "Opção inválida\n\n";
} else if (commandName == "tree") {
if (getNComms() == 1 || getNComms() == 2) {
printTaskTree();
} else {
printf("Número inválido de argumentos.\n\n");
}
} else if (commandName == "aps") {
if (getNComms() == 1 || getNComms() == 2) {
printAllPeriods();
} else {
printf("Número inválido de argumentos.\n\n");
}
} else if (commandName == "help") {
if (validArgs(0)) printHelp(curMenu);
} else if (commandName == "save") {
if (validArgs(0)) saveAll();
} else if (commandName == "exit") {
if (validArgs(0)) {
freeAll();
printf("Exiting...\n\n");
exit(EXIT_SUCCESS);
}
} else {
notAvailable(commandName);
}
return false;
};
int main(int argc, char **argv) {
calendar = createCalendar();
printTitle("Objetivos", PROGRAM_LEVEL);
printf("Digite 'ajuda' para uma lista de comandos.\n\n");
rootTask = createTask("Objetivos", "OBJS");
system("mkdir -p data");
system("mkdir -p plans");
// if (argc > 1) loadAllOld();
// else loadAll();
loadAll();
curMenu = TASK_MENU;
curTask = rootTask;
while (curMenu != -1) {
switch (curMenu) {
case TASK_MENU:
taskMenu(curTask);
break;
case SUBTASKS_MENU:
subtasksMenu(curTask);
break;
case TODOS_MENU:
todosMenu(curTask);
break;
case PERIODS_MENU:
periodsMenu(curTask);
break;
case CALENDAR_MENU:
calendarMenu();
break;
default:
curMenu = -1;
}
}
freeAll();
return EXIT_SUCCESS;
}