Compare commits
No commits in common. "809239492dbe20f1d8513660be51e653850c93c2" and "b5dc110cd25c020f96f5d799f3ef72a7f29833fb" have entirely different histories.
809239492d
...
b5dc110cd2
4
src/db.h
4
src/db.h
|
@ -5,5 +5,5 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void write_linkedlist_to_csv(llist *head, const char *filename);
|
extern void write_linkedlist_to_csv(llist *head, const char *filename);
|
||||||
llist *write_csv_to_llist(const char *filename);
|
extern void write_csv_to_llist(const char *filename);
|
||||||
|
|
|
@ -269,71 +269,3 @@ llist *genPlan(llist *head, time_t timeAvail) {
|
||||||
|
|
||||||
return events_ll;
|
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;
|
|
||||||
}
|
|
||||||
|
|
|
@ -83,6 +83,4 @@ int cmpEvent(const void *a, const void *b);
|
||||||
*/
|
*/
|
||||||
llist *genPlan(llist *head, time_t timeAvail);
|
llist *genPlan(llist *head, time_t timeAvail);
|
||||||
|
|
||||||
int exportiCal(llist *head);
|
|
||||||
|
|
||||||
#endif // !PLANNER
|
#endif // !PLANNER
|
||||||
|
|
61
src/ui.c
61
src/ui.c
|
@ -13,8 +13,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
|
||||||
const char *dbName = "db.csv";
|
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
char taskname[256]; // taskName Buffer
|
char taskname[256]; // taskName Buffer
|
||||||
int taskcreation_date = 0;
|
int taskcreation_date = 0;
|
||||||
|
@ -22,16 +20,14 @@ int main(void) {
|
||||||
int taskpriority = 0;
|
int taskpriority = 0;
|
||||||
int taskspare = 0;
|
int taskspare = 0;
|
||||||
|
|
||||||
llist *listT = NULL;
|
llist *list = NULL;
|
||||||
llist *listE = NULL;
|
|
||||||
int choice = 0, i = 0;
|
int choice = 0, i = 0;
|
||||||
do {
|
do {
|
||||||
printf(" -1- Neues Fach eingeben\n");
|
printf(" -1- Neues Fach eingeben\n");
|
||||||
printf(" -2- Verfuegbare Zeit eingeben\n");
|
printf(" -2- Verfuegbare Zeit eingeben\n");
|
||||||
printf(" -3- Alle vorhandenen Faecher aufliesten\n");
|
printf(" -3- Alle vorhandenen Faecher aufliesten\n");
|
||||||
printf(" -4- Kalenderlink ausgeben\n");
|
printf(" -4- Kalenderlink ausgeben\n");
|
||||||
printf(" -5- Faecher Importieren\n");
|
printf(" -5- Planer beenden\n");
|
||||||
printf(" -6- Planer beenden\n");
|
|
||||||
printf(" Wähle die gewünschte Option aus\n");
|
printf(" Wähle die gewünschte Option aus\n");
|
||||||
if (scanf("%d", &choice) != 1) {
|
if (scanf("%d", &choice) != 1) {
|
||||||
printf("Falsche Eingabe\n");
|
printf("Falsche Eingabe\n");
|
||||||
|
@ -61,20 +57,20 @@ int main(void) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printf(" Wie viel Zeit habe Sie für dieses Fach: \n");
|
printf(" Wie viel Zeit habe Sie für dieses Fach: \n");
|
||||||
// if (scanf("%d", &taskspare) != 1) {
|
if (scanf("%d", &taskspare) != 1) {
|
||||||
// printf("Ungültige Eingabe.\n");
|
printf("Ungültige Eingabe.\n");
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// create deadline timestamp
|
// create deadline timestamp
|
||||||
lc.tm_yday += taskdeadline_date;
|
lc.tm_yday += taskdeadline_date;
|
||||||
time_t deadline = mktime(&lc);
|
time_t deadline = mktime(&lc);
|
||||||
Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
|
Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
|
||||||
if (listT == NULL) {
|
if (list == NULL) {
|
||||||
listT = llistNew(newT, cmpTaskN);
|
list = llistNew(newT, cmpTaskN);
|
||||||
} else {
|
} else {
|
||||||
llistAppend(listT, newT);
|
llistAppend(list, newT);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -83,9 +79,8 @@ int main(void) {
|
||||||
"Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n");
|
"Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n");
|
||||||
scanf("%d", &taskspare);
|
scanf("%d", &taskspare);
|
||||||
// if list exists use it to generate plan
|
// if list exists use it to generate plan
|
||||||
if (listT != NULL) {
|
if (list != NULL) {
|
||||||
listE = genPlan(listT, taskspare);
|
genPlan(list, taskspare);
|
||||||
write_linkedlist_to_csv(listT, dbName);
|
|
||||||
} else {
|
} else {
|
||||||
printf("list is empty!");
|
printf("list is empty!");
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -93,10 +88,10 @@ int main(void) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
if (listT == NULL) {
|
if (list == NULL) {
|
||||||
printf("Die Liste ist leer");
|
printf("Die Liste ist leer");
|
||||||
} else {
|
} else {
|
||||||
llistPrintT(listT);
|
llistPrintT(list);
|
||||||
// llist *iterator = list;
|
// llist *iterator = list;
|
||||||
// while (iterator != NULL) {
|
// while (iterator != NULL) {
|
||||||
// Task *currentTask = (Task *)(iterator->data); // Cast zu Task
|
// Task *currentTask = (Task *)(iterator->data); // Cast zu Task
|
||||||
|
@ -128,28 +123,13 @@ int main(void) {
|
||||||
// }
|
// }
|
||||||
// break;
|
// break;
|
||||||
case 4:
|
case 4:
|
||||||
if (listE == NULL || taskspare <= 0) {
|
printf(
|
||||||
printf("vor Export erst task list erstellen, dann verfuegbare zeit "
|
"Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n");
|
||||||
"eingeben!\n");
|
scanf("%d", &taskspare);
|
||||||
break;
|
|
||||||
}
|
|
||||||
exportiCal(listE);
|
|
||||||
// printf(
|
|
||||||
// "Geben Sie die zur verfuegung stehende Zeit für die Fächer an:
|
|
||||||
// \n");
|
|
||||||
// scanf("%d", &taskspare);
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 5:
|
case 5:
|
||||||
listT = write_csv_to_llist(dbName);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 6:
|
|
||||||
printf("Goodbye!\n");
|
|
||||||
if (listE != NULL)
|
|
||||||
llistFreeE(listE);
|
|
||||||
if (listT != NULL)
|
|
||||||
llistPrintT(listT);
|
|
||||||
// if (task == NULL) {//task?
|
// if (task == NULL) {//task?
|
||||||
// printf("Die Liste ist leer");
|
// printf("Die Liste ist leer");
|
||||||
// } else {
|
// } else {
|
||||||
|
@ -162,8 +142,9 @@ int main(void) {
|
||||||
// iterator = iterator->next; // Gehe zum nächsten Listenelement
|
// iterator = iterator->next; // Gehe zum nächsten Listenelement
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
return EXIT_SUCCESS;
|
break;
|
||||||
// case 4: iCAl();break;
|
// case 4: iCAl();break;
|
||||||
}
|
}
|
||||||
} while (choice < 6);
|
} while (choice != 5);
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue