modified: src/db.c
modified: src/db.h modified: src/iCal.c modified: src/llist.c modified: src/planner.c modified: src/planner.h modified: src/test.csql
parent
8e233caf99
commit
f559d2a8bf
12
src/db.c
12
src/db.c
|
@ -1,9 +1,9 @@
|
||||||
/*
|
/*
|
||||||
* INPUT: query for previous state
|
* INPUT: query for previous state
|
||||||
* linked list of subjects to store
|
* linked list of tasks to store
|
||||||
*
|
*
|
||||||
* OUTPUT:
|
* OUTPUT:
|
||||||
* linked list of subjects from file
|
* linked list of tasks from file
|
||||||
* OK
|
* OK
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
@ -11,11 +11,3 @@
|
||||||
|
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
// 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;
|
|
||||||
}
|
|
||||||
|
|
1
src/db.h
1
src/db.h
|
@ -2,6 +2,5 @@
|
||||||
#define DB
|
#define DB
|
||||||
|
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
int serialize(Task *s);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,4 +4,4 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "planner.h" // for subject and event structs
|
#include "planner.h" // for task and event structs
|
||||||
|
|
|
@ -18,8 +18,8 @@ llist *llistNew(void *data, int (*cmpFN)(void *a, void *b)) {
|
||||||
|
|
||||||
/*return last node of linked list;
|
/*return last node of linked list;
|
||||||
*/
|
*/
|
||||||
llist *llistTail(llist *l) {
|
llist *llistTail(llist *head) {
|
||||||
llist *tail = l;
|
llist *tail = head;
|
||||||
while (tail->next != NULL) {
|
while (tail->next != NULL) {
|
||||||
tail = tail->next;
|
tail = tail->next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
#include "planner.h" // for subject and event structs
|
#include "planner.h" // for subject and event structs
|
||||||
// #include "config.h"
|
// #include "config.h"
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -21,6 +22,13 @@ Event *newEvent(Task *t, time_t s, time_t e, uint64_t sp) {
|
||||||
}
|
}
|
||||||
return r;
|
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 *newTask(char *n, time_t c, time_t d, int p, uint64_t sp) {
|
||||||
Task *r = (Task *)malloc(sizeof(Task));
|
Task *r = (Task *)malloc(sizeof(Task));
|
||||||
|
@ -35,6 +43,13 @@ Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp) {
|
||||||
return r;
|
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
|
// for llist
|
||||||
int cmpTask(void *a, void *b) {
|
int cmpTask(void *a, void *b) {
|
||||||
Task *aa = (Task *)a;
|
Task *aa = (Task *)a;
|
||||||
|
|
|
@ -31,12 +31,21 @@ Task *newTask(char *n, time_t c, time_t d, int p, uint64_t sp);
|
||||||
*/
|
*/
|
||||||
int cmpTask(void *a, void *b);
|
int cmpTask(void *a, void *b);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* prints human readable str of Task to stdout
|
||||||
|
*/
|
||||||
|
void printTask(Task *s);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Event struct contains task and planned time frame
|
* Event struct contains task and planned time frame
|
||||||
*
|
*
|
||||||
* used to create timetable
|
* used to create timetable
|
||||||
*
|
*
|
||||||
* eventNew(task, start, end, spare)
|
* eventNew(task, start, end, spare)
|
||||||
|
* task: pointer to task (Alloced with newTask)
|
||||||
|
* plannedStartTime: time_t
|
||||||
|
* plannedEndTime: time_t
|
||||||
|
* uint64_t spare var
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
typedef struct Event {
|
typedef struct Event {
|
||||||
|
|
16
src/test.c
16
src/test.c
|
@ -11,8 +11,11 @@ int main() {
|
||||||
|
|
||||||
time_t now = time(NULL);
|
time_t now = time(NULL);
|
||||||
|
|
||||||
|
// create new task named LinAlg with priority 3, created now with deadline in
|
||||||
|
// 5 days sp is currently unused spare var
|
||||||
Task *t1 = newTask("LinAlg", now, now + days(5), 3, 0);
|
Task *t1 = newTask("LinAlg", now, now + days(5), 3, 0);
|
||||||
|
|
||||||
|
// Stack Allocated vars only for local use!
|
||||||
Task t2 = {
|
Task t2 = {
|
||||||
.name = "Phys", .created = now, .deadline = now + days(2), .priority = 7};
|
.name = "Phys", .created = now, .deadline = now + days(2), .priority = 7};
|
||||||
|
|
||||||
|
@ -23,17 +26,20 @@ int main() {
|
||||||
llistAppend(list1, &t2);
|
llistAppend(list1, &t2);
|
||||||
|
|
||||||
// print test tasks
|
// print test tasks
|
||||||
serialize(t1);
|
printTask(t1);
|
||||||
serialize(&t2);
|
printTask(&t2);
|
||||||
|
|
||||||
// find in list & modify
|
// find in list & modify
|
||||||
Task search = {.name = "Phys"};
|
Task search = {.name = "Phys"}; // key to look for. cmpTask only compares
|
||||||
|
// names using strcmp(a.name, b.name)
|
||||||
llist *found = llistGet(list1, &search);
|
llist *found = llistGet(list1, &search);
|
||||||
if (found != NULL) {
|
if (found != NULL) {
|
||||||
((Task *)found->data)->deadline = time(NULL) + days(10);
|
((Task *)found->data)->deadline = time(NULL) + days(10);
|
||||||
serialize(found->data);
|
printTask(found->data);
|
||||||
|
} else {
|
||||||
|
printf("%s not in List!\n", search.name);
|
||||||
}
|
}
|
||||||
serialize(&t2);
|
printTask(&t2);
|
||||||
free(t1);
|
free(t1);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue