modified: src/llist.c
modified: src/planner.c modified: src/planner.h modified: src/test.c new file: test.c
This commit is contained in:
1 parent
f559d2a8bf
commit
a504f3cb03
5 files changed
+40
-8
No files matched your search
+25
-7
@@ -7,11 +7,18 @@
|
||||
*/
|
||||
|
||||
#include "planner.h" // for subject and event structs
|
||||
// #include "config.h"
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
const char taskFormat[] =
|
||||
"Task { %.64s = {\n created={%lu},\n deadline={%lu},\n "
|
||||
"priority={%d},\n spare={%lu}\n}\n";
|
||||
|
||||
const char eventFormat[] =
|
||||
"Event { %s = {\n start={%lu},\n end={%lu},\n spare={%lu}\n}\n";
|
||||
|
||||
Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp) {
|
||||
Event *r = (Event *)malloc(sizeof(Event));
|
||||
if (r != NULL) {
|
||||
@@ -22,14 +29,16 @@ Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp) {
|
||||
}
|
||||
return r;
|
||||
}
|
||||
// pretty print Event
|
||||
const char eventFormat[] =
|
||||
"Event { %s = {\n start={%lu},\n end={%lu},\n spare={%lu}\n}\n";
|
||||
|
||||
// print Event to stdout
|
||||
void printEvent(Event *s) {
|
||||
printf(eventFormat, s->task->name, s->plannedStartTime, s->plannedEndTime,
|
||||
s->spare);
|
||||
}
|
||||
|
||||
/*
|
||||
* creat new task with name n created c deadline d priority p spare sp
|
||||
*/
|
||||
Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp) {
|
||||
Task *r = (Task *)malloc(sizeof(Task));
|
||||
if (r != NULL) {
|
||||
@@ -43,13 +52,22 @@ Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp) {
|
||||
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);
|
||||
}
|
||||
|
||||
// return string representation of task
|
||||
// NULL on failure
|
||||
// free string after use
|
||||
char *taskToStr(Task *t) {
|
||||
char *r = malloc(sizeof(char) * strlen(taskFormat) + 0x200);
|
||||
if (r != NULL) {
|
||||
sprintf(r, taskFormat, t->name, t->created, t->deadline, t->priority,
|
||||
t->spare);
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
// for llist
|
||||
int cmpTask(void *a, void *b) {
|
||||
Task *aa = (Task *)a;
|
||||
|
||||
Reference in new issue
Block a user