Compare commits
5 Commits
d225e6aa41
...
37b6e1ce2c
Author | SHA1 | Date | |
---|---|---|---|
37b6e1ce2c | |||
3ead0c07b2 | |||
c4fc332419 | |||
ad344b03ac | |||
7809fb64ab |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
icscli
|
||||
.gitconfig
|
||||
*.o
|
||||
*.out
|
||||
tags
|
||||
|
@ -12,7 +12,7 @@ EXECUTABLE = "icscli"
|
||||
|
||||
# linking
|
||||
$(EXECUTABLE): $(OBJ_FILES)
|
||||
gcc $(CFLAGS) $(OBJ_FILES) -o $(EXECUTABLE) $(LDFLAGS)
|
||||
$(CC) $(CFLAGS) $(OBJ_FILES) -o $(EXECUTABLE) $(LDFLAGS)
|
||||
|
||||
main.o: main.c
|
||||
$(CC) $(CFLAGS) -c $<
|
||||
|
36
src/main.c
36
src/main.c
@ -2,16 +2,7 @@
|
||||
#include "parse_ics.h"
|
||||
#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,35 +10,16 @@ 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;
|
||||
|
||||
static char current_date[] = "xxxxxxxxTxxxxxx";
|
||||
get_date(current_date);
|
||||
printf ("Current date and time: ");
|
||||
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));
|
||||
}
|
||||
// initialize linked list
|
||||
struct event *head = NULL;
|
||||
|
||||
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,32 @@ void unfolding_string(char *folded_string, char *unfolded_string) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* this function takes the head of an empty initialized event list
|
||||
* and the path to the ics file
|
||||
* it will "fill" the list
|
||||
*/
|
||||
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));
|
||||
}
|
||||
|
||||
close(myfd);
|
||||
}
|
||||
|
@ -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);
|
||||
|
10
unit-tests/Makefile
Normal file
10
unit-tests/Makefile
Normal file
@ -0,0 +1,10 @@
|
||||
CC = gcc
|
||||
CFLAGS = -Wall -g -O0
|
||||
|
||||
test_parse_ics:
|
||||
$(CC) $(CFLAGS) test_parse_ics.c ../src/parse_ics.c ../src/string_handling.c ../src/list_handling.c ../src/date_time_handling.c ../src/read_until_string.c ../src/read_until_nl.c -o test_parse_ics.out
|
||||
./test_parse_ics.out
|
||||
|
||||
.PHONY:clean
|
||||
clean:
|
||||
-rm -vf *.out
|
12
unit-tests/test_parse_ics.c
Normal file
12
unit-tests/test_parse_ics.c
Normal file
@ -0,0 +1,12 @@
|
||||
#include "../src/list_handling.h"
|
||||
#include "../src/parse_ics.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
// initialize empty list
|
||||
struct event *head = NULL;
|
||||
|
||||
parse_ics_file("../tests/calendar.ics", &head);
|
||||
|
||||
print_list(head);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user