implemented new function parse_ics_file

This commit is contained in:
2024-07-09 07:02:12 +02:00
parent d225e6aa41
commit 7809fb64ab
3 changed files with 31 additions and 29 deletions

View File

@ -1,11 +1,15 @@
#include "list_handling.h"
#include "parse_ics.h"
#include "read_until_nl.h"
#include "read_until_string.h"
#include "string_handling.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void parse_event(char event_string[], struct event **head) {
char *start_date = strstr(event_string, "\nDTSTART");
@ -67,3 +71,26 @@ void unfolding_string(char *folded_string, char *unfolded_string) {
}
}
}
void parse_ics_file(char *file_path, struct event **head) {
char my_event[8192] = "";
char unfolded_event[8192] = "";
int myfd = open(file_path, O_RDONLY);
if (myfd == -1) {
perror ("Error opening file");
exit(1);
}
while(read_until_nl(myfd, my_event)) {
if (strncmp(my_event, "BEGIN:VEVENT", 12) == 0) {
// include the BEGIN:EVENT to not loose the new line of first field
lseek(myfd, -1, SEEK_CUR);
memset(my_event, '\0', sizeof(my_event));
read_until_string(myfd, my_event, "END:VEVENT");
unfolding_string(my_event, unfolded_event);
parse_event(unfolded_event, head);
}
memset(my_event, '\0', sizeof(my_event));
}
}