diff --git a/src/iCal.c b/src/iCal.c index 4cf5d7e..fa99ddb 100644 --- a/src/iCal.c +++ b/src/iCal.c @@ -1,7 +1,13 @@ -const char *iCalHeader = "BEGIN:VCALENDAR\r\n" //definition of commands for final iCal file - "VERSION:2.0\r\n" - "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"; +#include "llist.h" +#include "planner.h" +#include +#include + +const char *iCalHeader = + "BEGIN:VCALENDAR\r\n" // definition of commands for final iCal file + "VERSION:2.0\r\n" + "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"; const char *iCalEvent = "BEGIN:VEVENT\r\n" "UID:%s%d\r\n" "DTSTAMP:%s\r\n" @@ -57,16 +63,16 @@ conflicts.[13] */ -//exportical function: generates ical file from llist +// exportical function: generates ical file from llist int exportiCal(llist *events_ll) { - llist *ev_ll = events_ll; //input from llist + llist *ev_ll = events_ll; // input from llist llistPrintE(ev_ll); printf("%s", iCalHeader); - time_t now = time(NULL); //current time is captured an formatted + time_t now = time(NULL); // current time is captured an formatted struct tm lc; localtime_r(&now, &lc); @@ -76,7 +82,7 @@ int exportiCal(llist *events_ll) { strcat(nameBuf, "dayplan.ics"); FILE *fp = fopen(nameBuf, "w"); if (fp == NULL) { - planLog("fopen failed!!", 1); + printf("fopen failed!!"); return 1; } // write iCal header to file @@ -94,7 +100,8 @@ int exportiCal(llist *events_ll) { char timeStartBuf[17]; char timeEndBuf[17]; char timeStamp[17]; - strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", &lc); //strftime to match ical format + strftime(timeStamp, 17, "%Y%m%dT%k%M%SZ", + &lc); // strftime to match ical format printf("%s\n", timeStamp); strftime(timeStartBuf, 17, "%Y%m%dT%k%M%SZ", &startlc); printf("%s\n", timeStartBuf); @@ -115,16 +122,17 @@ int exportiCal(llist *events_ll) { return 0; } -//export data from llist to csv file +// export data from llist to csv file 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; //if file cannot be opend, return -1 + if (fp == NULL) + return -1; // if file cannot be opend, return -1 llist *c = tll; while (c != NULL) { - Task *ct = (Task *)c->data; //loop to go through tasks(name, created time, deadline, priority, etc.) + Task *ct = (Task *)c->data; // loop to go through tasks(name, created time, + // deadline, priority, etc.) fprintf(fp, taskFileFormat, ct->name, ct->created, ct->deadline, ct->priority, ct->spare); c = c->next; diff --git a/src/iCal.h b/src/iCal.h index e69de29..3ecc718 100644 --- a/src/iCal.h +++ b/src/iCal.h @@ -0,0 +1,7 @@ +#ifndef iCAL +#define iCAL + +#include "llist.h" +int exportiCal(llist *events_ll); + +#endif diff --git a/src/planner.c b/src/planner.c index 7a3b30b..92385f5 100644 --- a/src/planner.c +++ b/src/planner.c @@ -275,71 +275,72 @@ llist *genPlan(llist *head, time_t timeAvail) { return events_ll; } - -const char *iCalHeader = "BEGIN:VCALENDAR\r\n" - "VERSION:2.0\r\n" - "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"; -const char *iCalEvent = "BEGIN:VEVENT\r\n" - "UID:%s%d\r\n" - "DTSTAMP:%s\r\n" - "DTSTART:%s\r\n" - "DTEND:%s\r\n" - "SUMMARY:%s\r\n" - "END:VEVENT\r\n"; - -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_r(&now, &lc); - - // gen filename & open for write - char nameBuf[32]; - strftime(nameBuf, 32 - 12, "%F", &lc); - strcat(nameBuf, "dayplan.ics"); - FILE *fp = fopen(nameBuf, "w"); - if (fp == NULL) { - planLog("fopen failed!!", 1); - return 1; - } - // write iCal header to file - fprintf(fp, "%s", iCalHeader); - - // for every event in events_ll create VEVENT str and write to fp - int count = 0; - while (ev_ll != NULL) { - // gen iCal compatible time str - Event *current = ev_ll->data; - struct tm startlc; - struct tm endlc; - localtime_r(¤t->plannedStartTime, &startlc); - localtime_r(¤t->plannedEndTime, &endlc); - char timeStartBuf[17]; - char timeEndBuf[17]; - char timeStamp[17]; - 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); - ev_ll = ev_ll->next; - count += 1; - } - - // after all events are written end cal with - // END:VCALENDAR - fprintf(fp, "END:VCALENDAR\r\n"); - fclose(fp); - - return 0; -} +// +// const char *iCalHeader = "BEGIN:VCALENDAR\r\n" +// "VERSION:2.0\r\n" +// "PRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\n"; +// const char *iCalEvent = "BEGIN:VEVENT\r\n" +// "UID:%s%d\r\n" +// "DTSTAMP:%s\r\n" +// "DTSTART:%s\r\n" +// "DTEND:%s\r\n" +// "SUMMARY:%s\r\n" +// "END:VEVENT\r\n"; +// +// 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_r(&now, &lc); +// +// // gen filename & open for write +// char nameBuf[32]; +// strftime(nameBuf, 32 - 12, "%F", &lc); +// strcat(nameBuf, "dayplan.ics"); +// FILE *fp = fopen(nameBuf, "w"); +// if (fp == NULL) { +// planLog("fopen failed!!", 1); +// return 1; +// } +// // write iCal header to file +// fprintf(fp, "%s", iCalHeader); +// +// // for every event in events_ll create VEVENT str and write to fp +// int count = 0; +// while (ev_ll != NULL) { +// // gen iCal compatible time str +// Event *current = ev_ll->data; +// struct tm startlc; +// struct tm endlc; +// localtime_r(¤t->plannedStartTime, &startlc); +// localtime_r(¤t->plannedEndTime, &endlc); +// char timeStartBuf[17]; +// char timeEndBuf[17]; +// char timeStamp[17]; +// 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); +// ev_ll = ev_ll->next; +// count += 1; +// } +// +// // after all events are written end cal with +// // END:VCALENDAR +// fprintf(fp, "END:VCALENDAR\r\n"); +// fclose(fp); +// +// return 0; +// } diff --git a/src/planner.h b/src/planner.h index 33dbd0f..74e17f3 100644 --- a/src/planner.h +++ b/src/planner.h @@ -84,6 +84,6 @@ int cmpEvent(const void *a, const void *b); */ llist *genPlan(llist *head, time_t timeAvail); -int exportiCal(llist *head); +// int exportiCal(llist *head); #endif // !PLANNER diff --git a/src/ui.c b/src/ui.c index fef67eb..c0fec41 100644 --- a/src/ui.c +++ b/src/ui.c @@ -7,6 +7,7 @@ #define _GNU_SOURCE #include "ui.h" #include "db.h" +#include "iCal.h" #include "llist.h" #include "planner.h" // for subject and event structs #include @@ -19,8 +20,6 @@ #define localtime_r(T, Tm) (_localtime64_s(Tm, T) ? NULL : Tm) #endif - - const char *dbName = "db.csv"; int main(void) {