This repository has been archived on 2025-02-01. You can view files and clone it, but cannot push or open issues or pull requests.
ics_cli/src/main.c

77 lines
1.8 KiB
C
Raw Normal View History

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>
#include <stdlib.h>
2023-08-15 16:31:07 +02:00
#include <fcntl.h>
#include <string.h>
#include <limits.h>
int main() {
//const char ICS_PATH[] = "tests/calendar.ics";
char *ICS_PATH;
char *HOME = getenv("HOME");
if (HOME != NULL) {
ICS_PATH = strcat(HOME, "/.local/share/evolution/calendar/system/calendar.ics");
} else {
printf ("Environment variable HOME is not set.\n");
return 1;
}
2023-08-15 16:31:07 +02:00
char my_line[4096] = "";
int myfd = open(ICS_PATH, O_RDONLY);
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);
printf ("Current date and time: %s\n\n", current_date);
char date[256] = "";
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));
// go to DTSTART, but dont write to a variable
seek_string_a(myfd, "DTSTART");
read_until_string(myfd, my_line, "DTEND");
remove_whitespace(my_line);
cut_string(my_line, ':', 1);
strcpy(date, my_line);
memset(my_line, '\0', sizeof(my_line));
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));
sorted_insert(&head, date, summary);
memset(date, '\0', sizeof(date));
memset(summary, '\0', sizeof(summary));
}
memset(my_line, '\0', sizeof(my_line));
}
//print_list(head);
print_upcoming(head, current_date);
free_list(head);
return 0;
}