2023-08-15 16:31:07 +02:00
|
|
|
#include "list_handling.h"
|
2023-08-23 20:03:26 +02:00
|
|
|
#include "date_time_handling.h"
|
2023-08-15 16:31:07 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
void print_list(struct event *head) {
|
|
|
|
while (head != NULL) {
|
2023-08-24 01:10:53 +02:00
|
|
|
printf("%s\n", head->start_date);
|
2023-08-24 01:55:50 +02:00
|
|
|
printf("%s\n", head->end_date);
|
2023-08-15 16:31:07 +02:00
|
|
|
printf("%s\n", head->summary);
|
|
|
|
head = head->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-24 01:55:50 +02:00
|
|
|
void sorted_insert(struct event** head, char start_date[], char end_date[], char summary[]) {
|
2023-08-15 16:31:07 +02:00
|
|
|
struct event *new_node = malloc(sizeof(struct event));
|
2023-08-24 01:10:53 +02:00
|
|
|
strcpy((*new_node).start_date, start_date);
|
2023-08-24 01:55:50 +02:00
|
|
|
strcpy((*new_node).end_date, end_date);
|
2023-08-15 16:31:07 +02:00
|
|
|
strcpy((*new_node).summary, summary);
|
|
|
|
|
2023-08-24 01:10:53 +02:00
|
|
|
if (*head == NULL || strcmp((*head)->start_date, new_node->start_date) >= 0) {
|
2023-08-15 16:31:07 +02:00
|
|
|
new_node->next = *head;
|
|
|
|
*head = new_node;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Locate the node before the point of insertion
|
|
|
|
struct event* current = *head;
|
2023-08-24 01:55:50 +02:00
|
|
|
while (current->next!=NULL && strcmp(current->next->start_date, new_node->start_date) < 0)
|
|
|
|
current = current->next;
|
|
|
|
|
2023-08-15 16:31:07 +02:00
|
|
|
new_node->next = current->next;
|
|
|
|
current->next = new_node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void free_list(struct event *head)
|
|
|
|
{
|
|
|
|
struct event* tmp;
|
|
|
|
|
|
|
|
while (head != NULL)
|
|
|
|
{
|
|
|
|
tmp = head;
|
|
|
|
head = head->next;
|
|
|
|
free(tmp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-17 10:27:52 +02:00
|
|
|
void print_upcoming(struct event *head, char current_start_date[], int show_all_events) {
|
|
|
|
int i = 0;
|
2023-08-15 16:31:07 +02:00
|
|
|
while (head != NULL) {
|
2023-08-24 01:10:53 +02:00
|
|
|
if (strcmp(head->start_date, current_start_date) >= 0) {
|
|
|
|
pretty_print_date_time(head->start_date);
|
2023-09-10 11:37:32 +02:00
|
|
|
print_end_date(head->end_date, head->start_date);
|
2024-01-20 21:00:18 +01:00
|
|
|
printf("\nSUMMARY: %s\n", head->summary);
|
2023-09-17 10:27:52 +02:00
|
|
|
|
|
|
|
if (!show_all_events) {
|
|
|
|
i++;
|
|
|
|
if (i > 4)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-08-24 02:15:46 +02:00
|
|
|
if (head->next != NULL)
|
|
|
|
printf("\n");
|
2023-08-15 16:31:07 +02:00
|
|
|
}
|
2023-08-24 02:15:46 +02:00
|
|
|
|
|
|
|
head = head->next;
|
2023-08-15 16:31:07 +02:00
|
|
|
}
|
|
|
|
}
|