2024-12-09 19:27:50 +01:00
|
|
|
/*
|
2024-12-10 22:06:49 +01:00
|
|
|
* INPUT: linked list of subjects
|
|
|
|
* OUTPUT: ll of events to iCal
|
|
|
|
* ll of updated subjects to db for next day
|
|
|
|
* return events_ll to caller(ui)??
|
2024-12-09 19:27:50 +01:00
|
|
|
*
|
|
|
|
*/
|
2024-12-10 22:06:49 +01:00
|
|
|
|
|
|
|
#include "planner.h" // for subject and event structs
|
2024-12-11 01:08:31 +01:00
|
|
|
// #include "config.h"
|
2024-12-11 13:03:28 +01:00
|
|
|
#include <stdio.h>
|
2024-12-11 01:08:31 +01:00
|
|
|
#include <stdlib.h>
|
2024-12-11 03:09:54 +01:00
|
|
|
#include <string.h>
|
2024-12-11 01:08:31 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-12-11 13:03:28 +01:00
|
|
|
// pretty print Event
|
|
|
|
const char eventFormat[] =
|
|
|
|
"Event { %s = {\n start={%lu},\n end={%lu},\n spare={%lu}\n}\n";
|
|
|
|
void printEvent(Event *s) {
|
|
|
|
printf(eventFormat, s->task->name, s->plannedStartTime, s->plannedEndTime,
|
|
|
|
s->spare);
|
|
|
|
}
|
2024-12-11 01:08:31 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2024-12-11 03:09:54 +01:00
|
|
|
|
2024-12-11 13:03:28 +01:00
|
|
|
// pretty print task
|
|
|
|
const char taskFormat[] = "Task { %s = {\n created={%lu},\n deadline={%lu},\n "
|
|
|
|
"priority={%d},\n spare={%lu}\n}\n";
|
|
|
|
void printTask(Task *s) {
|
|
|
|
printf(taskFormat, s->name, s->created, s->deadline, s->priority, s->spare);
|
|
|
|
}
|
|
|
|
|
2024-12-11 03:09:54 +01:00
|
|
|
// for llist
|
2024-12-11 11:27:00 +01:00
|
|
|
int cmpTask(void *a, void *b) {
|
|
|
|
Task *aa = (Task *)a;
|
|
|
|
Task *bb = (Task *)b;
|
|
|
|
return strcmp(aa->name, bb->name);
|
|
|
|
}
|
|
|
|
int cmpEvent(void *a, void *b) {
|
|
|
|
Event *aa = (Event *)a;
|
|
|
|
Event *bb = (Event *)b;
|
|
|
|
return cmpTask(aa->task, bb->task);
|
|
|
|
}
|