StudyPlanner/src/planner.c

64 lines
1.5 KiB
C
Raw Normal View History

/*
* 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)??
*
*/
#include "planner.h" // for subject and event structs
// #include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.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;
}
// 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);
}
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;
}
// 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);
}
// for llist
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);
}