2024-12-15 12:40:05 +01:00

151 lines
4.2 KiB
C

/*
* command line interface for user input
*
*/
/* 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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
char taskname[256]; // taskName Buffer
int taskcreation_date = 0;
int taskdeadline_date = 0;
int taskpriority = 0;
int taskspare = 0;
llist *list = NULL;
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- Kalenderlink ausgeben\n");
printf(" -5- Planer beenden\n");
printf(" Wähle die gewünschte Option aus\n");
if (scanf("%d", &choice) != 1) {
printf("Falsche Eingabe\n");
};
// choice = 0;
switch (choice) {
case 1:
printf(" Geben sie das gewünschte Fach ein: \n");
time_t now = time(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 (list == NULL) {
list = llistNew(newT, cmpTaskN);
} else {
llistAppend(list, 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 (list != NULL) {
genPlan(list, taskspare);
} else {
printf("list is empty!");
return -1;
}
break;
case 3:
if (list == NULL) {
printf("Die Liste ist leer");
} else {
llistPrintT(list);
// 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
// }
}
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:
printf(
"Geben Sie die zur verfuegung stehende Zeit für die Fächer an: \n");
scanf("%d", &taskspare);
break;
case 5:
// 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
// }
// }
break;
// case 4: iCAl();break;
}
} while (choice != 5);
return EXIT_SUCCESS;
}