modified: src/db.c
modified: src/db.h modified: src/test.c modified: src/ui.cbugfixMaster
parent
08145cd4a2
commit
9b3238978b
67
src/db.c
67
src/db.c
|
@ -10,12 +10,12 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#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 task csv file.
|
write a complete linkedlist to a task csv file.
|
||||||
|
@ -25,24 +25,22 @@ void write_linkedlist_to_csv(llist* head, const char* filename) {
|
||||||
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{
|
|
||||||
|
} else {
|
||||||
// write the file header
|
// write the file header
|
||||||
fprintf(file, "TaskName, Created, Deadline, Priority, Spare\n");
|
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) {
|
||||||
|
task = current->data;
|
||||||
|
|
||||||
// Write the task data to the CSV file
|
// Write the task data to the CSV file
|
||||||
fprintf(file, "%s, %lu, %lu, %d, %lu\n",
|
fprintf(file, "%s, %lu, %lu, %d, %lu\n", task->name, task->created,
|
||||||
task->name,
|
task->deadline, task->priority, task->spare);
|
||||||
task->created,
|
|
||||||
task->deadline,
|
|
||||||
task->priority,
|
|
||||||
task->spare,
|
|
||||||
|
|
||||||
|
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
|
@ -54,17 +52,18 @@ void write_linkedlist_to_csv(llist* head, const char* filename) {
|
||||||
read a task 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) {
|
||||||
|
llist *list = NULL; // list to return
|
||||||
// Open file with read permision
|
// Open file with read permision
|
||||||
FILE *file = fopen(filename, "r");
|
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
|
||||||
|
@ -72,31 +71,28 @@ void write_csv_to_llist(const char* filename) {
|
||||||
|
|
||||||
// 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, ",");
|
||||||
|
|
||||||
|
|
||||||
// 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 taskdeadline_date =
|
||||||
|
strtoul(taskdeadline_dateSTR, NULL, 10);
|
||||||
unsigned long int taskspare = strtoul(taskspareSTR, NULL, 10);
|
unsigned long int taskspare = strtoul(taskspareSTR, NULL, 10);
|
||||||
int priority = atoi(prioritySTR);
|
int priority = atoi(taskprioritySTR);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// create Task
|
// create Task
|
||||||
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
|
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date,
|
||||||
|
priority, taskspare);
|
||||||
|
|
||||||
|
|
||||||
// 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(task, cmpTaskN);
|
list = llistNew(task, cmpTaskN);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
// Append the task to the linked list
|
// Append the task to the linked list
|
||||||
llistAppend(list, task);
|
llistAppend(list, task);
|
||||||
}
|
}
|
||||||
|
@ -104,8 +100,5 @@ void write_csv_to_llist(const char* filename) {
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
}
|
||||||
|
return list; // null on error
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
src/db.h
4
src/db.h
|
@ -5,5 +5,5 @@
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void write_linkedlist_to_csv(llist* head, const char* filename)
|
extern void write_linkedlist_to_csv(llist *head, const char *filename);
|
||||||
extern void write_csv_to_llist(const char* filename)
|
extern void write_csv_to_llist(const char *filename);
|
||||||
|
|
|
@ -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);
|
||||||
|
|
||||||
|
|
8
src/ui.c
8
src/ui.c
|
@ -5,7 +5,7 @@
|
||||||
/* Created by Juergen Buechel, 13.12.2024/
|
/* Created by Juergen Buechel, 13.12.2024/
|
||||||
*/
|
*/
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
// #include "db.h"
|
#include "db.h"
|
||||||
#include "llist.h"
|
#include "llist.h"
|
||||||
#include "planner.h" // for subject and event structs
|
#include "planner.h" // for subject and event structs
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
@ -31,9 +31,8 @@ int main(void) {
|
||||||
if (scanf("%d", &choice) != 1) {
|
if (scanf("%d", &choice) != 1) {
|
||||||
printf("Falsche Eingabe\n");
|
printf("Falsche Eingabe\n");
|
||||||
};
|
};
|
||||||
choice = 0;
|
// choice = 0;
|
||||||
|
|
||||||
while ((choice < 1 || choice > 5)) {
|
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1: {
|
case 1: {
|
||||||
printf(" Geben sie das gewünschte Fach ein: \n");
|
printf(" Geben sie das gewünschte Fach ein: \n");
|
||||||
|
@ -63,7 +62,7 @@ int main(void) {
|
||||||
case 2:
|
case 2:
|
||||||
printf(
|
printf(
|
||||||
"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("%c", &taskspare);
|
scanf("%d", &taskspare);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -123,7 +122,6 @@ int main(void) {
|
||||||
// case 4: iCAl();break;
|
// case 4: iCAl();break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} while (choice != 5);
|
} while (choice != 5);
|
||||||
{
|
{
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
|
Loading…
Reference in New Issue