1 Commits
Author SHA1 Message Date
buechejuerge d86bcbfcf2 new 2024-12-13 22:26:20 +01:00
5 changed files with 189 additions and 33407 deletions

No files matched your search

+4 -9
View File
@@ -13,18 +13,10 @@ CONFIG=src/config.h #config file
#targets
debug: db test ui planner iCal config llist
debug: test ui planner db iCal config llist
gcc test.o ui.o planner.o db.o iCal.o llist.o -o debugOut
config: $(CONFIG)
db: $(DBF)
curl -L https://sqlite.org/2024/sqlite-amalgamation-3470200.zip --output src/sqlite.zip
unzip src/sqlite.zip
mv sqlite-amalgamation-3470200/* src/
rm -rf sqlite-amalgamation-3470200
gcc -c $(CFLAGS) $(DBF)
llist: $(LLST)
gcc -c $(CFLAGS) $(LLST)
test: src/test.c
@@ -35,6 +27,9 @@ ui: $(UIF)
gcc -c $(CFLAGS) $(UIF)
planner: $(PLF)
gcc -c $(CFLAGS) $(PLF)
db: $(DBF)
gcc -c $(CFLAGS) $(DBF)
edit:
nvim $(PLF) Makefile $(LLST) src/test.c
+36 -36
View File
@@ -10,59 +10,59 @@
*/
/************************************************************
*Create a database and handel it
*Created by Jan on 13.12.2024.
*
************************************************************/
#include "planner.h"
#include <sqlite3.h>
*Create a database and handel it
*Created by Jan on 13.12.2024.
*
************************************************************/
#include <stdio.h>
#include <time.h>
#include "sqlite3.h"
#include "planner.h"
extern struct llist;
// Initialize a new Database if there no one.
void init_db(sqlite3 *db) {
const char *sql_LinkedList = "CREATE TABLE LinkedList ("
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"data TEXT;)";
const char *sql_LinkedList =
"CREATE TABLE LinkedList ("
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
"data TEXT;)";
// Checks the SQL answer and if it's not ok prints the error code
char *errmsg = NULL;
if (sqlite3_exec(db, sql_LinkedList, NULL, NULL, &errmsg) != SQLITE_OK) {
fprintf(stderr, "Error in creation Table: %s\n", errmsg);
sqlite3_free(errmsg);
}
// Checks the SQL answer and if it's not ok prints the error code
char *errmsg = NULL;
if (sqlite3_exec(db, sql_LinkedList, NULL, NULL, &errmsg) != SQLITE_OK) {
fprintf(stderr, "Error in creation Table: %s\n", errmsg);
sqlite3_free(errmsg);
}
}
// Save a single node of the linkedlist in the database
// node needs to be replaced with the correct name and pointer
void save_node_to_db(sqlite3 *db, Node *node) {
char *errmsg = NULL;
sqlite3_stmt *stmt;
const char *sql = "INSERT INTO LinkedList (id, data) VALUES (?, ?);";
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
fprintf(stderr, "Failed to prepare statement: %s\n", sqlite3_errmsg(db));
} else {
sqlite3_bind_int(stmt, 1, node->id); // ? -> node->id
sqlite3_bind_text(stmt, 2, node->data, -1,
SQLITE_STATIC); // ? -> node->data
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
char* errmsg = NULL;
sqlite3_stmt *stmt;
const char* sql = "INSERT INTO LinkedList (id, data) VALUES (?, ?);";
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
fprintf(stderr, "Failed to prepare statement: %s\n", sqlite3_errmsg(db));
} else {
printf("Node with ID %d saved.\n", node->id);
sqlite3_bind_int(stmt, 1, node->id); // ? -> node->id
sqlite3_bind_text(stmt, 2, node->data, -1, SQLITE_STATIC); // ? -> node->data
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "Execution failed: %s\n", sqlite3_errmsg(db));
} else {
printf("Node with ID %d saved.\n", node->id);
}
}
}
sqlite3_finalize(stmt);
sqlite3_finalize(stmt);
}
// save a whole linkedlist in the database
// node needs to be replaced with the correct name and pointer
void save_linked_list_to_db(sqlite3 *db, Node *head) {
Node *current = head;
while (current != NULL) {
save_node_to_db(db, current);
current = current->next;
}
}
void save_linked_list_to_db(sqlite3* db, Node* head) {
Node* current = head;
while (current != NULL) {
save_node_to_db(db, current);
current = current->next;
}
}
-33362
View File
File diff suppressed because it is too large. Load diff
+140
View File
@@ -3,3 +3,143 @@
*
*/
#include "planner.h" // for subject and event structs
#include <stdio.h>
#include <stdlib.h>
#include "ui.h"
typedef struct task_elements {
char name;
int priority;
struct task *nextTask;
};
typedef struct task task_1;
typedef struct task* task_ptr;
task_ptr firsttask = NULL;
typedef struct time_elements {
int time;
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 eigneben: ");
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;
}
int main(void)
{
int choice = 0, i = 0;
do
{
printf(" -1- Neues Fach eingeben\n");
printf(" -2- Verfuegbare Zeit eingeben\n");
printf(" -3- Alle vorhandenen Faecher aufliesten\n");
printf(" -4- Planer beenden\n");
if( scanf("%d", &choice) != 1){
printf("Falsche Eingabe\n");};
choice = 0;
dump_buffer(stdin);
switch (choice)
{
case 1: newTask();break;
case 2: newTime();break;
case 3: if( firsttask == NULL){
printf("Die Liste ist leer");
}
else{
tasklisting();
}break;
}
}while (choice != 4);
return EXIT_SUCCESS;
}
+9
View File
@@ -1,4 +1,13 @@
#ifndef UI
#define UI
typedef struct task_elements{
char name;
int priority;
};
typedef struct time{
int time;
};
#endif // !UI