24 Commits
Author SHA1 Message Date
ketrptr 809239492d modified: src/planner.c
modified:   src/ui.c
2024-12-15 13:16:02 +01:00
ketrptr 5e3d89fb57 modified: src/planner.c 2024-12-15 12:54:59 +01:00
ketrptr 5d76c54213 modified: src/db.h
modified:   src/planner.h
2024-12-15 12:53:33 +01:00
ketrptr b5dc110cd2 modified: src/ui.c 2024-12-15 12:40:05 +01:00
ketrptr 9b3238978b modified: src/db.c
modified:   src/db.h
	modified:   src/test.c
	modified:   src/ui.c
2024-12-15 12:18:32 +01:00
buechejuerge 08145cd4a2 minor changes 2024-12-14 23:01:50 +01:00
simon f72c98de28 Merge branch 'master' of https://gitea.fhgr.ch/schurtisimon/StudyPlanner
merge
2024-12-14 22:58:02 +01:00
simon a302bfc4e8 modified: src/ui.c 2024-12-14 22:57:44 +01:00
buechejuerge d428589063 Merge remote-tracking branch 'origin/master' 2024-12-14 22:46:27 +01:00
buechejuerge 1fb016296b minor changes 2024-12-14 22:46:11 +01:00
simon dd88cd8b64 Merge branch 'master' of https://gitea.fhgr.ch/schurtisimon/StudyPlanner
modified:   src/ui.c
2024-12-14 22:44:45 +01:00
simon 24f0e9e7ec new file: src/iCal.c 2024-12-14 22:42:37 +01:00
simon 63ee77f5c4 deleted: src/iCal.c
modified:   src/ui.c
2024-12-14 22:40:29 +01:00
buechejuerge cf63dc4712 minor changes 2024-12-14 22:37:18 +01:00
buechejuerge bf14307a71 minor changes 2024-12-14 22:26:40 +01:00
buechejuerge b792eed3d2 changes 2024-12-14 22:23:02 +01:00
buechejuerge ad20db3995 changes 2024-12-14 22:20:10 +01:00
buechejuerge 81c62f892d changes 2024-12-14 22:14:56 +01:00
buechejuerge f6cea89dd2 changes 2024-12-14 22:14:17 +01:00
simon b308dc4c95 modified: src/ui.c 2024-12-14 21:44:35 +01:00
buechejuerge 834b3270b9 changes 2024-12-14 21:36:09 +01:00
buechejuerge 0ef20822fd changes 2024-12-14 21:31:32 +01:00
wildjan 06a81ad27e db.c von event auf task geändert 2024-12-14 20:21:52 +01:00
wildjan 9a9dddaad0 db.h aktualisiert 2024-12-14 16:45:03 +01:00
7 changed files with 272 additions and 208 deletions

No files matched your search

+50 -71
View File
@@ -10,46 +10,37 @@
* *
*/ */
#include "llist.h"
#include "planner.h"
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <time.h> #include <time.h>
#include "planner.h"
#include "list.h"
/* /*
write a complete linkedlist to a Event csv file. write a complete linkedlist to a task csv file.
*/ */
void write_linkedlist_to_csv(llist* head, const char* filename) { void write_linkedlist_to_csv(llist *head, const char *filename) {
//Open file with write permision // Open file with write permision
FILE* file = fopen(filename, "w"); FILE *file = fopen(filename, "w");
//if there is no file or a wrong file path you becom an error // if there is no file or a wrong file path you becom an error
if (file == NULL) { if (file == NULL) {
perror("Could not open file %s\n", filename); fprintf(stderr, "Could not open file %s\n", filename);
} exit(1);
else{
//write the file header } else {
fprintf(file, "TaskName, Created, Deadline, Priority, Spare, EventStartTime, EventEndTime, EventSpare\n"); // write the file header
fprintf(file, "TaskName, Created, Deadline, Priority, Spare\n");
// Iterate through the linked list and write the data to the CSV // Iterate through the linked list and write the data to the CSV
llist* current = head; llist *current = head;
Task *task;
while (current != NULL) { while (current != NULL) {
// Extract data from the current node task = current->data;
Event* event = (Event*)current->data; // Assumed that current->data holds an Event pointer
// Extract the associated task from the event // Write the task data to the CSV file
Task* task = event->task; fprintf(file, "%s, %lu, %lu, %d, %lu\n", task->name, task->created,
task->deadline, task->priority, task->spare);
// Write the task and event data to the CSV file
fprintf(file, "%s, %lu, %lu, %d, %lu, %lu, %lu, %lu\n",
task->name,
task->created,
task->deadline,
task->priority,
task->spare,
event->plannedStartTime,
event->plannedEndTime,
event->spare);
current = current->next; current = current->next;
} }
@@ -58,68 +49,56 @@ void write_linkedlist_to_csv(llist* head, const char* filename) {
} }
/* /*
read an event csv file and write the data in a linked list read a task csv file and write the data in a linked list
*/ */
void write_csv_to_llist(const char* filename) { llist *write_csv_to_llist(const char *filename) {
//Open file with read permision llist *list = NULL; // list to return
FILE* file = fopen(filename, "r"); // Open file with read permision
FILE *file = fopen(filename, "r");
if (file == NULL) { if (file == NULL) {
perror("Could not open file %s\n", filename); fprintf(stderr, "Could not open file %s\n", filename);
}
else{ } else {
char line[1024]; //Line Buffer char line[1024]; // Line Buffer
int count = 0; //task counter int count = 0; // task counter
llist *list = NULL fgets(line, sizeof(line), file); // read and ignore file head
fgets(line, sizeof(line), file); //read and ignore file head
while (fgets(line, sizeof(line), file)) { while (fgets(line, sizeof(line), file)) {
count++; count++;
//remove newline sign // remove newline sign
line[strcspn(line, "\n")] = '\0'; line[strcspn(line, "\n")] = '\0';
// column slice // column slice
char *taskname = strtok(line, ","); char *taskname = strtok(line, ",");
char *tsakcreation_dateSTR = strtok(NULL, ","); char *taskcreation_dateSTR = strtok(NULL, ",");
char *tsakdeadline_dateSTR = strtok(NULL, ","); char *taskdeadline_dateSTR = strtok(NULL, ",");
char *tsakprioritySTR = strtok(NULL, ","); char *taskprioritySTR = strtok(NULL, ",");
char *tsakspareSTR = strtok(NULL, ","); char *taskspareSTR = strtok(NULL, ",");
char *eventStartTimeSTR = strtok(NULL, ",");
char *eventEndTimeSTR = strtok(NULL, ",");
char *eventSpareSTR = strtok(NULL, ",");
// convert char in integer and date // convert char in integer and date
unsigned long int taskcreation_date = strtoul(taskcreation_dateSTR,NULL,10); unsigned long int taskcreation_date =
unsigned long int taskdeadline_date = strtoul(taskdeadline_dateSTR,NULL,10); strtoul(taskcreation_dateSTR, NULL, 10);
unsigned long int taskspare = strtoul(taskspareSTR,NULL,10); unsigned long int taskdeadline_date =
unsigned long int eventStartTime = strtoul(eventStartTimeSTR,NULL,10); strtoul(taskdeadline_dateSTR, NULL, 10);
unsigned long int eventEndTime = strtoul(eventEndTimeSTR,NULL,10); unsigned long int taskspare = strtoul(taskspareSTR, NULL, 10);
unsigned long int eventSpare = strtoul(eventSpareSTR,NULL,10); int priority = atoi(taskprioritySTR);
int priority = atoi(prioritySTR); // create Task
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date,
priority, taskspare);
//create Task
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
//create Event
Event *event = newEvent(task,eventStartTime, eventEndTime, eventSpare);
// Insert task into the linked list // Insert task into the linked list
if (list == NULL) { if (list == NULL) {
// If the list is empty, initialize it with the first task // If the list is empty, initialize it with the first task
list = llistNew(event, NULL); list = llistNew(task, cmpTaskN);
} } else {
else {
// Append the task to the linked list // Append the task to the linked list
llistAppend(list, event); llistAppend(list, task);
} }
} }
fclose(file); fclose(file);
} }
return list; // null on error
} }
+2
View File
@@ -5,3 +5,5 @@
#endif #endif
void write_linkedlist_to_csv(llist *head, const char *filename);
llist *write_csv_to_llist(const char *filename);
+68
View File
@@ -269,3 +269,71 @@ 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(&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);
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;
}
+2
View File
@@ -83,4 +83,6 @@ 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
+1 -1
View File
@@ -9,7 +9,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <time.h> #include <time.h>
int main() { int test() {
time_t now = time(NULL); time_t now = time(NULL);
+147 -136
View File
@@ -3,156 +3,167 @@
* *
*/ */
/* Created by Juergen Buechel, 13.12.2024/ /* Created by Juergen Buechel, 13.12.2024/
*/ */
#include "ui.h"
#include "db.h"
#include "llist.h"
#include "planner.h" // for subject and event structs #include "planner.h" // for subject and event structs
#include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "ui.h" #include <time.h>
#include "planner.h"
#include "iCal.h"
#include "db.h"
typedef struct task { const char *dbName = "db.csv";
char name;
int priority;
struct task *nextTask;
};
typedef struct task task_1; int main(void) {
typedef struct task* task_ptr; char taskname[256]; // taskName Buffer
task_ptr firsttask = NULL; int taskcreation_date = 0;
int taskdeadline_date = 0;
int taskpriority = 0;
int taskspare = 0;
typedef struct time { llist *listT = NULL;
int time; llist *listE = NULL;
struct time *nextTime;
};
typedef struct time time_1;
typedef struct time* time_ptr;
time_ptr firsttime = NULL;
void dump_buffer(FILE *fp){
int ch;
while((ch = fgetc(fp)) != EOF && ch != '\n');
}
void insertTask(task_ptr newtask)
{
task_ptr TaskPointer;
if (firsttask == NULL){
firsttask = newtask;
newtask->nextTask ;
}
else {
TaskPointer = firsttask;
while(TaskPointer->nextTask!=NULL)
{
TaskPointer = TaskPointer->nextTask;
}
TaskPointer->nextTask = newtask;
newtask ->nextTask;
}
}
void newTask (void)
{
task_ptr new = malloc(sizeof(task_1));
if (new == NULL){
printf("Die Liste ist leer?!\n");
}
printf(" Neues Fach eigeben: ");
if(scanf("%d", &newTask)!=1)
{
dump_buffer(stdin);
printf("Fehlerhafte eingabe\n");
free(new);
return;
}
dump_buffer (stdin);
insertTask(new);
}
void inserttime(time_ptr newtime)
{
time_ptr TimePointer;
if (firsttime == NULL){
firsttime = newtime;
newtime->nextTime =NULL;
}
else {
TimePointer = firsttime;
while(TimePointer->nextTime!=NULL)
{
TimePointer = TimePointer->nextTime;
}
TimePointer->nextTime = newtime;
newtime ->nextTime = NULL;
}
}
void newTime(void)
{
time_ptr newtime = malloc(sizeof(task_1));
if (newtime == NULL){
printf("Die Liste ist leer?!\n");
}
printf(" Neue Zeit eingeben: ");
if(scanf("%d",&newTime)!=1)
{
dump_buffer(stdin);
printf("Fehlerhafte eingabe\n");
free(newtime);
return;
}
dump_buffer (stdin);
inserttime(newtime);
}
void tasklisting(void){
task_ptr TaskPointer = firsttask;
printf("Erfasste Fächer:\n");
while(TaskPointer!=NULL)
printf("\t->%d\n", TaskPointer->name);
TaskPointer = TaskPointer->nextTask;
}
void getlink (void)
{
}
int main(void)
{
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- Planer beenden\n"); printf(" -5- Faecher Importieren\n");
if( scanf("%d", &choice) != 1){ printf(" -6- Planer beenden\n");
printf("Falsche Eingabe\n");}; printf(" Wähle die gewünschte Option aus\n");
choice = 0; if (scanf("%d", &choice) != 1) {
dump_buffer(stdin); printf("Falsche Eingabe\n");
};
// choice = 0;
switch (choice) switch (choice) {
{ case 1:
case 1: newTask();break; printf(" Geben sie das gewünschte Fach ein: \n");
case 2: newTime();break; time_t now = time(NULL);
case 3: if( firsttask == NULL){ struct tm lc;
localtime_r(&now, &lc);
if (fscanf(stdin, "%s", taskname) <= 0) {
printf("Ungültige Eingabe für den Namen.\n");
return -1;
}
printf(" Wie viel Zeit bleibt ihnen (tage bis deadline):\n");
if (scanf("%d", &taskdeadline_date) != 1) {
printf("Ungültige Eingabe.\n");
return -1;
}
printf(" Gib die Priorität des Faches an: \n");
if (scanf("%d", &taskpriority) != 1) {
printf("Ungültige Eingabe.\n");
return -1;
}
// printf(" Wie viel Zeit habe Sie für dieses Fach: \n");
// if (scanf("%d", &taskspare) != 1) {
// printf("Ungültige Eingabe.\n");
// return -1;
// }
// create deadline timestamp
lc.tm_yday += taskdeadline_date;
time_t deadline = mktime(&lc);
Task *newT = newTask(taskname, now, deadline, taskpriority, 0);
if (listT == NULL) {
listT = llistNew(newT, cmpTaskN);
} else {
llistAppend(listT, newT);
}
break;
case 2:
printf(
"Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n");
scanf("%d", &taskspare);
// if list exists use it to generate plan
if (listT != NULL) {
listE = genPlan(listT, taskspare);
write_linkedlist_to_csv(listT, dbName);
} else {
printf("list is empty!");
return -1;
}
break;
case 3:
if (listT == NULL) {
printf("Die Liste ist leer"); printf("Die Liste ist leer");
} else {
llistPrintT(listT);
// llist *iterator = list;
// while (iterator != NULL) {
// Task *currentTask = (Task *)(iterator->data); // Cast zu Task
// printf("Fach: %s, Deadline: %ld, Priorität: %d\n",
// currentTask->name, currentTask->deadline,
// currentTask->priority);
// iterator = iterator->next; // Gehe zum nächsten Listenelement
// }
} }
else{ break;
tasklisting(); // // case 4: iCAl();break;
}break; //
case 4: iCAl();break; // printf(" Wie viel Zeit bleibt ihnen:\n");
// if (scanf("%d", &taskdeadline_date) != 1) {
// printf("Ungültige Eingabe.\n");
// return -1;
// }
//
// printf(" Gib die Priorität des Faches an: \n");
// if (scanf("%d", &taskpriority) != 1) {
// printf("Ungültige Eingabe.\n");
// return -1;
// }
//
// printf(" Wie viel Zeit habe Sie für dieses Fach: \n");
// if (scanf("%d", &taskspare) != 1) {
// printf("Ungültige Eingabe.\n");
// return -1;
// }
// break;
case 4:
if (listE == NULL || taskspare <= 0) {
printf("vor Export erst task list erstellen, dann verfuegbare zeit "
"eingeben!\n");
break;
} }
}while (choice !=5); exportiCal(listE);
// printf(
// "Geben Sie die zur verfuegung stehende Zeit für die Fächer an:
// \n");
// scanf("%d", &taskspare);
break;
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?
// printf("Die Liste ist leer");
// } else {
// llist *iterator = list;
// while (iterator != NULL) {
// Task *currentTask = (Task *)(iterator->data); // Cast zu Task
// printf("Fach: %s, Deadline: %ld, Priorität: %d\n",
// currentTask->name, currentTask->deadline,
// currentTask->priority);
// iterator = iterator->next; // Gehe zum nächsten Listenelement
// }
// }
return EXIT_SUCCESS; return EXIT_SUCCESS;
// case 4: iCAl();break;
}
} while (choice < 6);
} }
+2
View File
@@ -2,4 +2,6 @@
#define UI #define UI
#endif // !UI #endif // !UI