changes in ui.c

ui.c
Jürgen Büchel 2024-12-14 21:22:45 +01:00
parent 3ec9275695
commit 51bd481de1
1 changed files with 65 additions and 106 deletions

171
src/ui.c
View File

@ -8,103 +8,36 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "ui.h" #include "ui.h"
#include <assert.h>
#include "planner.h" #include "planner.h"
#include "iCal.h"
#include "db.h" #include "db.h"
#include "llist.h"
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 main(void)
{ {
char taskname;
int taskcreation_date;
int taskdeadline_date;
int taskpriority;
int taskspare;
Task *task = newTask(taskname, taskcreation_date, taskdeadline_date, taskpriority, taskspare);
{
// Insert task into the linked list
if (list == NULL) {
// If the list is empty, initialize it with the first task
list = llistNew(task, cmpTaskN);
}
else {
// Append the task to the linked list
llistAppend(list, task);
}
}
int time;
int choice = 0, i = 0; int choice = 0, i = 0;
do do
{ {
@ -113,25 +46,51 @@ int main(void)
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- Planer beenden\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");};
choice = 0; choice = 0;
dump_buffer(stdin);
switch (choice) while(( choice < 1 || choice > 5)){
{ switch (choice)
case 1: newTask();break; {
case 2: newTime();break; case 1:
case 3: if( firsttask == NULL){ {
printf("Die Liste ist leer"); printf(" Geben sie das gewünschte Fach ein: \n");
} scanf("%c",taskname);
else{
tasklisting(); printf(" Wie viel Zeit bleibt ihnen:\n")
}break; scanf("%c", taskdeadline_date);
case 4: iCAl();break;
} printf(" Gib die Priorität des Faches an: \n");
}while (choice !=5); scanf("%c", &taskpriority);
return EXIT_SUCCESS;
printf(" Wie viel Zeit habe Sie für dieses Fach: \n");
scanf("%c", taskspare);
}
case 2:
printf("Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n");
scanf("%c", &taskspare);
case 3: if( task == NULL){
printf("Die Liste ist leer");
}
else{
while (task != NULL)
{
printf("Faecher %d: \n", llistAppend(task));
}
}break;
// case 4: iCAl();break;
}
}while (choice !=5);
return EXIT_SUCCESS;
}
} }