modified: Makefile

modified:   src/planner.c
	modified:   src/test.c
plannerSim
simon 2024-12-14 20:26:12 +01:00
parent ba1322ac0d
commit b2aca861b7
3 changed files with 44 additions and 14 deletions

View File

@ -5,6 +5,7 @@ CFLAGS=-Wall -Wextra -g
#files
UIF=src/ui.c src/ui.h #UI files
UISF=src/uis.c src/uis.h #UI files
PLF=src/planner.c src/planner.h #planner files
DBF=src/db.c src/db.h #db files
CALF=src/iCal.c src/iCal.h
@ -13,8 +14,8 @@ CONFIG=src/config.h #config file
#targets
debug: test ui planner db iCal config llist
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
debug: test planner db iCal config llist uis
gcc test.o planner.o db.o iCal.o llist.o uis.o -o debugOut
config: $(CONFIG)
llist: $(LLST)
@ -24,6 +25,8 @@ test: src/test.c
iCal: $(CALF)
gcc -c $(CFLAGS) $(CALF)
ui: $(UIF)
uis: $(UISF)
gcc -c $(CFLAGS) $(UISF)
gcc -c $(CFLAGS) $(UIF)
planner: $(PLF)
gcc -c $(CFLAGS) $(PLF)
@ -32,10 +35,10 @@ db: $(DBF)
edit:
nvim $(PLF) Makefile $(LLST) src/test.c
nvim $(PLF) Makefile $(LLST) src/test.c src/uis.c
clean:
rm -rf *.o debugOut src/*.gch
rm -rf *.o debugOut src/*.gch *.ics *.csv

View File

@ -32,6 +32,7 @@ void llistPrintT(llist *head) {
}
}
int exportiCal(llist *ev_ll);
int taskLlToFile(llist *tll);
// print Event to stdout
void printEvent(Event *s) {
char st[26];
@ -242,7 +243,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
events_ll = events_ll->next;
tmp->next = NULL;
llistFreeE(tmp);
// llistPrintE(events_ll);
llistPrintE(events_ll);
// update prioriteis in original llist
for (int i = 0; i < lLen; i++) {
@ -256,6 +257,7 @@ llist *genPlan(llist *head, time_t timeAvail) {
planLog("END GEN PLAN", 0);
exportiCal(events_ll);
taskLlToFile(head);
// llistFreeT(head);
// send updated tasks to db for storage
@ -325,14 +327,17 @@ int exportiCal(llist *events_ll) {
llist *ev_ll = events_ll;
llistPrintE(ev_ll);
printf("%s", iCalHeader);
time_t now = time(NULL);
struct tm *lc = localtime(&now);
struct tm lc;
localtime_r(&now, &lc);
// gen filename & open for write
char nameBuf[32];
strftime(nameBuf, 32 - 12, "%F", lc);
strftime(nameBuf, 32 - 12, "%F", &lc);
strcat(nameBuf, "dayplan.ics");
FILE *fp = fopen(nameBuf, "w");
if (fp == NULL) {
@ -347,14 +352,19 @@ int exportiCal(llist *events_ll) {
while (ev_ll != NULL) {
// gen iCal compatible time str
Event *current = ev_ll->data;
struct tm *startlc = localtime(&current->plannedStartTime);
struct tm *endlc = localtime(&current->plannedEndTime);
struct tm startlc;
struct tm endlc;
localtime_r(&current->plannedStartTime, &startlc);
localtime_r(&current->plannedEndTime, &endlc);
char timeStartBuf[17];
char timeEndBuf[17];
char timeStamp[17];
strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", lc);
strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", startlc);
strftime(timeEndBuf, 17, "%Y%m%dT%k%M%SZ", endlc);
strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", &lc);
printf("%s\n", timeStamp);
strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", &startlc);
printf("%s\n", timeStartBuf);
strftime(timeEndBuf, 17, "%Y%m%dT%k%M%SZ", &endlc);
printf("%s\n", timeEndBuf);
fprintf(fp, iCalEvent, current->task->name, count, timeStamp, timeStartBuf,
timeEndBuf, current->task->name);
@ -369,3 +379,21 @@ int exportiCal(llist *events_ll) {
return 0;
}
const char *taskFileFormat = "%s,%lu,%lu,%d,%lu\n";
int taskLlToFile(llist *tll) {
// open file
FILE *fp = fopen("db.csv", "w");
if (fp == NULL)
return -1;
llist *c = tll;
while (c != NULL) {
Task *ct = (Task *)c->data;
fprintf(fp, taskFileFormat, ct->name, ct->created, ct->deadline,
ct->priority, ct->spare);
c = c->next;
}
fclose(fp);
return 0;
}

View File

@ -9,7 +9,7 @@
#include <stdlib.h>
#include <time.h>
int main() {
int test() {
time_t now = time(NULL);
@ -18,7 +18,6 @@ int main() {
Task *t1 = newTask("LinAlg", now, now + days(5), 3, 0);
assert(t1 != NULL);
// Stack Allocated vars only for local use!
Task *t2 = newTask("Phys", now, now + days(2), 7, 0);
assert(t2 != NULL);
Task *t3 = newTask("Analysis", now, now + days(10), 5, 0);