diff --git a/src/db.c b/src/db.c index f117455..92ced72 100644 --- a/src/db.c +++ b/src/db.c @@ -12,9 +12,10 @@ #include "planner.h" #include -// serialize struct test -const char format[] = "{%s = {%lu, %lu, %d}\n"; // -int serialize(Subject *s) { - printf(format, s->name, s->created, s->deadline, s->priority); +// serialize struct test format +const char format[] = "{%s = {%lu, %lu, %d, %lu}\n"; + +int serialize(Task *s) { + printf(format, s->name, s->created, s->deadline, s->priority, s->spare); return 0; } diff --git a/src/db.h b/src/db.h index 01cea33..ce91910 100644 --- a/src/db.h +++ b/src/db.h @@ -2,6 +2,6 @@ #define DB #include "planner.h" -int serialize(Subject *s); +int serialize(Task *s); #endif diff --git a/src/planner.c b/src/planner.c index 5583fd8..2d704ca 100644 --- a/src/planner.c +++ b/src/planner.c @@ -7,4 +7,29 @@ */ #include "planner.h" // for subject and event structs -#include "config.h" +// #include "config.h" +#include + +Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp) { + Event *r = (Event *)malloc(sizeof(Event)); + if (r != NULL) { + r->task = t; + r->plannedEndTime = s; + r->plannedEndTime = e; + r->spare = sp; + } + return r; +} + +Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp) { + Task *r = (Task *)malloc(sizeof(Task)); + if (r != NULL) { + r->created = c; + r->deadline = d; + r->priority = p; + r->spare = sp; + r->name = n; + } + + return r; +} diff --git a/src/planner.h b/src/planner.h index 3b2c37d..e12af76 100644 --- a/src/planner.h +++ b/src/planner.h @@ -1,22 +1,51 @@ #ifndef PLANNER #define PLANNER +#include #include -typedef struct Subject { +/* + * task subject struct used to track different tasks + * create new task with taskNew(name, time_t created, time_t deadline, int + * priority, uint64_t spare) + * + * should be freed by user + * + * used to interface with human and store data + */ +typedef struct Task { char *name; time_t created; time_t deadline; int priority; - unsigned long long spare; -} Subject; + uint64_t spare; +} Task; +/* + * allocates and returns Task (free after use) + * returns NULL on failure + */ +Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp); + +/* + * Event struct contains task and planned time frame + * + * used to create timetable + * + * eventNew(task, start, end, spare) + * + */ typedef struct Event { - Subject subject; + Task *task; time_t plannedStartTime; time_t plannedEndTime; - unsigned long long spare; + uint64_t spare; // spare var } Event; +/* + * allocates and returns Event (free after use) + * returns NULL on failure + */ +Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp); -int genPlan(Subject *head); +int genPlan(Task *head); #endif // !PLANNER diff --git a/src/test.c b/src/test.c index 0427e6c..030824d 100644 --- a/src/test.c +++ b/src/test.c @@ -4,17 +4,15 @@ #include "planner.h" // for subject and event structs #include "ui.h" #include +#include int main() { time_t now = time(NULL); - Subject t1 = {.name = "LinAlg", - .created = now, - .deadline = now + days(5), - .priority = 3}; + Task *t1 = newTask("LinAlg", now, now + days(5), 3, 0); - Subject t2 = { + Task t2 = { .name = "Phys", .created = now, .deadline = now + days(2), .priority = 7}; // create plan @@ -22,8 +20,9 @@ int main() { // printf("%s\n", ctime(&now)); - serialize(&t1); + serialize(t1); serialize(&t2); + free(t1); return 0; }