Compare commits
2 Commits
5ebd852864
...
b027a12354
Author | SHA1 | Date |
---|---|---|
Jan Wild | b027a12354 | |
Jan Wild | e32c7d8951 |
|
@ -0,0 +1,2 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="External" external.linked.project.id="StudyPlanner" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="Makefile" type="CPP_MODULE" version="4" />
|
|
@ -18,7 +18,16 @@
|
||||||
<inspection_tool class="PyArgumentEqualDefaultInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyArgumentEqualDefaultInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="PyAugmentAssignmentInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyAugmentAssignmentInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="PyClassicStyleClassInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyClassicStyleClassInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyCompatibilityInspection" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ourVersions">
|
||||||
|
<value>
|
||||||
|
<list size="2">
|
||||||
|
<item index="0" class="java.lang.String" itemvalue="2.7" />
|
||||||
|
<item index="1" class="java.lang.String" itemvalue="3.13" />
|
||||||
|
</list>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
<inspection_tool class="PyMandatoryEncodingInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyMandatoryEncodingInspection" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="PyMissingOrEmptyDocstringInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyMissingOrEmptyDocstringInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
<inspection_tool class="PyMissingTypeHintsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
<inspection_tool class="PyMissingTypeHintsInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
|
||||||
|
|
|
@ -1,10 +1,19 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
|
<component name="CMakePythonSetting">
|
||||||
|
<option name="pythonIntegrationState" value="YES" />
|
||||||
|
</component>
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="MakefileSettings">
|
<component name="MakefileSettings">
|
||||||
<option name="linkedExternalProjectsSettings">
|
<option name="linkedExternalProjectsSettings">
|
||||||
<MakefileProjectSettings>
|
<MakefileProjectSettings>
|
||||||
|
<option name="buildTarget" value="debug" />
|
||||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||||
|
<option name="modules">
|
||||||
|
<set>
|
||||||
|
<option value="$PROJECT_DIR$" />
|
||||||
|
</set>
|
||||||
|
</option>
|
||||||
<option name="version" value="2" />
|
<option name="version" value="2" />
|
||||||
</MakefileProjectSettings>
|
</MakefileProjectSettings>
|
||||||
</option>
|
</option>
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/StudyPlanner.iml" filepath="$PROJECT_DIR$/.idea/StudyPlanner.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
68
src/db.c
68
src/db.c
|
@ -13,57 +13,57 @@
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <string.h>
|
||||||
#include "planner.h"
|
#include "planner.h"
|
||||||
#include "list.h"
|
#include "llist.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
write a complete linkedlist to a task 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 permission
|
||||||
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 become an error
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("Could not open file %s\n", filename);
|
perror("Could not open file\n");
|
||||||
}
|
}
|
||||||
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;
|
||||||
while (current != NULL) {
|
while (current != NULL) {
|
||||||
|
|
||||||
// Write the task data to the CSV file
|
// Write the task data to the CSV file
|
||||||
|
Task *task = (Task *) (current->data);
|
||||||
fprintf(file, "%s, %lu, %lu, %d, %lu\n",
|
fprintf(file, "%s, %lu, %lu, %d, %lu\n",
|
||||||
task->name,
|
task->name,
|
||||||
task->created,
|
task->created,
|
||||||
task->deadline,
|
task->deadline,
|
||||||
task->priority,
|
task->priority,
|
||||||
task->spare,
|
task->spare);
|
||||||
|
|
||||||
|
|
||||||
current = current->next;
|
current = current->next;
|
||||||
}
|
}
|
||||||
fclose(file); // Close the file
|
fclose(file); // Close the file
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
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) {
|
||||||
//Open file with read permision
|
//initialize list
|
||||||
FILE* file = fopen(filename, "r");
|
llist *list = NULL;
|
||||||
|
//Open file with read permission
|
||||||
|
FILE *file = fopen(filename, "r");
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
perror("Could not open file %s\n", filename);
|
perror("Could not open file\n");
|
||||||
}
|
}
|
||||||
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++;
|
||||||
|
@ -71,41 +71,33 @@ void write_csv_to_llist(const char* filename) {
|
||||||
line[strcspn(line, "\n")] = '\0';
|
line[strcspn(line, "\n")] = '\0';
|
||||||
|
|
||||||
// column slice
|
// column slice
|
||||||
char *taskname = strtok(line, ",");
|
char *task_name = strtok(line, ",");
|
||||||
char *tsakcreation_dateSTR = strtok(NULL, ",");
|
char *task_creation_dateSTR = strtok(NULL, ",");
|
||||||
char *tsakdeadline_dateSTR = strtok(NULL, ",");
|
char *task_deadline_dateSTR = strtok(NULL, ",");
|
||||||
char *tsakprioritySTR = strtok(NULL, ",");
|
char *task_prioritySTR = strtok(NULL, ",");
|
||||||
char *tsakspareSTR = strtok(NULL, ",");
|
char *task_spareSTR = 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 task_creation_date = strtoul(task_creation_dateSTR,NULL, 10);
|
||||||
unsigned long int taskdeadline_date = strtoul(taskdeadline_dateSTR,NULL,10);
|
unsigned long int task_deadline_date = strtoul(task_deadline_dateSTR,NULL, 10);
|
||||||
unsigned long int taskspare = strtoul(taskspareSTR,NULL,10);
|
unsigned long int task_spare = strtoul(task_spareSTR,NULL, 10);
|
||||||
int priority = atoi(prioritySTR);
|
int task_priority = (int) strtol(task_prioritySTR, NULL, 10);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//create Task
|
//create Task
|
||||||
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
|
Task *task = newTask(task_name, task_creation_date, task_deadline_date, task_priority, task_spare);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
}
|
return list;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue