2023-08-22 00:12:30 +02:00
|
|
|
#include "cli_arg_parsing.h"
|
2023-08-15 16:31:07 +02:00
|
|
|
#include "date_time_handling.h"
|
|
|
|
#include "list_handling.h"
|
|
|
|
#include "cut_string.h"
|
|
|
|
#include "move_lines.h"
|
|
|
|
#include "read_until_nl.h"
|
|
|
|
#include "read_until_string.h"
|
|
|
|
#include "seek_string_a.h"
|
|
|
|
#include "remove_whitespace.h"
|
|
|
|
#include <stdio.h>
|
2023-08-15 21:17:24 +02:00
|
|
|
#include <stdlib.h>
|
2023-08-15 16:31:07 +02:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.h>
|
|
|
|
|
2023-08-22 00:12:30 +02:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
char *ics_path = "";
|
|
|
|
get_cli_args(argc, argv, &ics_path);
|
2023-08-15 16:31:07 +02:00
|
|
|
|
|
|
|
char my_line[4096] = "";
|
|
|
|
|
2023-08-22 00:12:30 +02:00
|
|
|
int myfd = open(ics_path, O_RDONLY);
|
2023-08-15 16:31:07 +02:00
|
|
|
if (myfd == -1) {
|
|
|
|
perror ("Error opening file");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// initialize linked list
|
|
|
|
struct event *head = NULL;
|
|
|
|
|
|
|
|
static char current_date[] = "xxxxxxxxTxxxxxx";
|
|
|
|
get_date(current_date);
|
2023-08-23 20:03:26 +02:00
|
|
|
printf ("Current date and time: ");
|
|
|
|
pretty_print_date_time(current_date);
|
2023-08-24 01:55:50 +02:00
|
|
|
printf ("\n\n");
|
2023-08-15 16:31:07 +02:00
|
|
|
|
2023-08-24 01:55:50 +02:00
|
|
|
char start_date[256] = "";
|
|
|
|
char end_date[256] = "";
|
2023-08-15 16:31:07 +02:00
|
|
|
char summary[256] = "";
|
|
|
|
|
|
|
|
while(read_until_nl(myfd, my_line)) {
|
|
|
|
if (strncmp(my_line, "BEGIN:VEVENT", 12) == 0) {
|
|
|
|
memset(my_line, '\0', sizeof(my_line));
|
2023-08-24 01:55:50 +02:00
|
|
|
// put DTSTART into variable
|
2023-08-15 16:31:07 +02:00
|
|
|
seek_string_a(myfd, "DTSTART");
|
|
|
|
read_until_string(myfd, my_line, "DTEND");
|
|
|
|
remove_whitespace(my_line);
|
|
|
|
cut_string(my_line, ':', 1);
|
2023-08-24 01:55:50 +02:00
|
|
|
strcpy(start_date, my_line);
|
2023-08-15 16:31:07 +02:00
|
|
|
|
|
|
|
memset(my_line, '\0', sizeof(my_line));
|
|
|
|
|
2023-08-24 01:55:50 +02:00
|
|
|
// put DTEND into variable
|
|
|
|
read_until_string(myfd, my_line, "SEQUENCE");
|
|
|
|
remove_whitespace(my_line);
|
|
|
|
cut_string(my_line, ':', 1);
|
|
|
|
strcpy(end_date, my_line);
|
|
|
|
|
|
|
|
memset(my_line, '\0', sizeof(my_line));
|
|
|
|
|
|
|
|
// put summary into variable
|
2023-08-15 16:31:07 +02:00
|
|
|
seek_string_a(myfd, "SUMMARY:");
|
|
|
|
read_until_string(myfd, my_line, "TRANSP:");
|
|
|
|
remove_nl_and_cr(my_line);
|
|
|
|
strcpy(summary, my_line);
|
|
|
|
memset(my_line, '\0', sizeof(my_line));
|
|
|
|
|
2023-08-24 01:55:50 +02:00
|
|
|
sorted_insert(&head, start_date, end_date, summary);
|
|
|
|
memset(start_date, '\0', sizeof(start_date));
|
|
|
|
memset(end_date, '\0', sizeof(end_date));
|
2023-08-15 16:31:07 +02:00
|
|
|
memset(summary, '\0', sizeof(summary));
|
|
|
|
}
|
|
|
|
memset(my_line, '\0', sizeof(my_line));
|
|
|
|
}
|
|
|
|
|
|
|
|
print_upcoming(head, current_date);
|
|
|
|
|
|
|
|
free_list(head);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|