modified: src/db.c

modified:   src/db.h
	modified:   src/planner.c
	modified:   src/planner.h
	modified:   src/test.c
sql
simon 2024-12-11 01:08:31 +01:00
parent b7fab77c62
commit 33cd1e87e3
5 changed files with 72 additions and 18 deletions

View File

@ -12,9 +12,10 @@
#include "planner.h" #include "planner.h"
#include <stdio.h> #include <stdio.h>
// serialize struct test // serialize struct test format
const char format[] = "{%s = {%lu, %lu, %d}\n"; // const char format[] = "{%s = {%lu, %lu, %d, %lu}\n";
int serialize(Subject *s) {
printf(format, s->name, s->created, s->deadline, s->priority); int serialize(Task *s) {
printf(format, s->name, s->created, s->deadline, s->priority, s->spare);
return 0; return 0;
} }

View File

@ -2,6 +2,6 @@
#define DB #define DB
#include "planner.h" #include "planner.h"
int serialize(Subject *s); int serialize(Task *s);
#endif #endif

View File

@ -7,4 +7,29 @@
*/ */
#include "planner.h" // for subject and event structs #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;
}

View File

@ -1,22 +1,51 @@
#ifndef PLANNER #ifndef PLANNER
#define PLANNER #define PLANNER
#include <stdint.h>
#include <time.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; char *name;
time_t created; time_t created;
time_t deadline; time_t deadline;
int priority; int priority;
unsigned long long spare; uint64_t spare;
} Subject; } 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 { typedef struct Event {
Subject subject; Task *task;
time_t plannedStartTime; time_t plannedStartTime;
time_t plannedEndTime; time_t plannedEndTime;
unsigned long long spare; uint64_t spare; // spare var
} Event; } 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 #endif // !PLANNER

View File

@ -4,17 +4,15 @@
#include "planner.h" // for subject and event structs #include "planner.h" // for subject and event structs
#include "ui.h" #include "ui.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
int main() { int main() {
time_t now = time(NULL); time_t now = time(NULL);
Subject t1 = {.name = "LinAlg", Task *t1 = newTask("LinAlg", now, now + days(5), 3, 0);
.created = now,
.deadline = now + days(5),
.priority = 3};
Subject t2 = { Task t2 = {
.name = "Phys", .created = now, .deadline = now + days(2), .priority = 7}; .name = "Phys", .created = now, .deadline = now + days(2), .priority = 7};
// create plan // create plan
@ -22,8 +20,9 @@ int main() {
// //
printf("%s\n", ctime(&now)); printf("%s\n", ctime(&now));
serialize(&t1); serialize(t1);
serialize(&t2); serialize(&t2);
free(t1);
return 0; return 0;
} }