implemented new function parse_ics_file
This commit is contained in:
parent
d225e6aa41
commit
7809fb64ab
28
src/main.c
28
src/main.c
@ -3,15 +3,8 @@
|
||||
#include "cli_arg_parsing.h"
|
||||
#include "date_time_handling.h"
|
||||
#include "string_handling.h"
|
||||
#include "read_until_nl.h"
|
||||
#include "read_until_string.h"
|
||||
#include "seek_string_a.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
char *ics_path = "";
|
||||
@ -19,15 +12,6 @@ int main(int argc, char **argv) {
|
||||
|
||||
get_cli_args(argc, argv, &ics_path, &show_all_events);
|
||||
|
||||
char my_event[8192] = "";
|
||||
char unfolded_event[8192] = "";
|
||||
|
||||
int myfd = open(ics_path, O_RDONLY);
|
||||
if (myfd == -1) {
|
||||
perror ("Error opening file");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// initialize linked list
|
||||
struct event *head = NULL;
|
||||
|
||||
@ -37,17 +21,7 @@ int main(int argc, char **argv) {
|
||||
pretty_print_date_time(current_date);
|
||||
printf ("\n\n");
|
||||
|
||||
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));
|
||||
}
|
||||
parse_ics_file(ics_path, &head);
|
||||
|
||||
print_upcoming(head, current_date, show_all_events);
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -2,3 +2,4 @@
|
||||
|
||||
void parse_event(char event_string[], struct event **head);
|
||||
void unfolding_string(char* folded_string, char* unfolded_string);
|
||||
void parse_ics_file(char *file_path, struct event **head);
|
||||
|
Loading…
Reference in New Issue
Block a user