modified: src/db.c
modified: src/db.h modified: src/planner.c modified: src/planner.h modified: src/test.csql
parent
b7fab77c62
commit
33cd1e87e3
9
src/db.c
9
src/db.c
|
@ -12,9 +12,10 @@
|
|||
#include "planner.h"
|
||||
#include <stdio.h>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
2
src/db.h
2
src/db.h
|
@ -2,6 +2,6 @@
|
|||
#define DB
|
||||
|
||||
#include "planner.h"
|
||||
int serialize(Subject *s);
|
||||
int serialize(Task *s);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,4 +7,29 @@
|
|||
*/
|
||||
|
||||
#include "planner.h" // for subject and event structs
|
||||
#include "config.h"
|
||||
// #include "config.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -1,22 +1,51 @@
|
|||
#ifndef PLANNER
|
||||
#define PLANNER
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
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
|
||||
|
|
11
src/test.c
11
src/test.c
|
@ -4,17 +4,15 @@
|
|||
#include "planner.h" // for subject and event structs
|
||||
#include "ui.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue