Merge pull request 'unfolding-function' (#4) from unfolding-function into master
Reviewed-on: bjoernf/ics_analyzer#4
This commit is contained in:
commit
c786ccf659
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
icscli
|
||||
.gitconfig
|
||||
*.o
|
||||
tags
|
||||
|
@ -52,7 +52,7 @@ void print_upcoming(struct event *head, char current_start_date[], int show_all_
|
||||
if (strcmp(head->start_date, current_start_date) >= 0) {
|
||||
pretty_print_date_time(head->start_date);
|
||||
print_end_date(head->end_date, head->start_date);
|
||||
printf("\n%s\n", head->summary);
|
||||
printf("\nSUMMARY: %s\n", head->summary);
|
||||
|
||||
if (!show_all_events) {
|
||||
i++;
|
||||
|
@ -19,6 +19,7 @@ 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) {
|
||||
@ -39,7 +40,8 @@ int main(int argc, char **argv) {
|
||||
if (strncmp(my_event, "BEGIN:VEVENT", 12) == 0) {
|
||||
memset(my_event, '\0', sizeof(my_event));
|
||||
read_until_string(myfd, my_event, "END:VEVENT");
|
||||
parse_event(my_event, &head);
|
||||
unfolding_string(my_event, unfolded_event);
|
||||
parse_event(unfolded_event, &head);
|
||||
}
|
||||
memset(my_event, '\0', sizeof(my_event));
|
||||
}
|
||||
|
@ -4,14 +4,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void parse_event(char event_string[], struct event **head) {
|
||||
char *start_date = strstr(event_string, "\r\nDTSTART;");
|
||||
char *end_date = strstr(event_string, "\r\nDTEND;");
|
||||
char *sequence = strstr(event_string, "\r\nSEQUENCE:");
|
||||
char *summary = strstr(event_string, "\r\nSUMMARY");
|
||||
char *location = strstr(event_string, "\r\nLOCATION:");
|
||||
char *transp = strstr(event_string, "\r\nTRANSP:");
|
||||
char *start_date = strstr(event_string, "\nDTSTART");
|
||||
char *end_date = strstr(event_string, "\nDTEND");
|
||||
char *summary = strstr(event_string, "\nSUMMARY");
|
||||
summary = strchr(summary, ':') + 1;
|
||||
|
||||
char *start_date_str = malloc(256);
|
||||
char *end_date_str = malloc(256);
|
||||
@ -23,23 +23,14 @@ void parse_event(char event_string[], struct event **head) {
|
||||
|
||||
assert(start_date != NULL);
|
||||
assert(end_date != NULL);
|
||||
assert(sequence != NULL);
|
||||
assert(summary != NULL);
|
||||
assert(transp != NULL);
|
||||
|
||||
strncpy(start_date_str, start_date, end_date - start_date);
|
||||
strncpy(start_date_str, start_date,
|
||||
strchr(start_date + 1, '\n') - start_date);
|
||||
|
||||
strncpy(end_date_str, end_date, sequence - end_date);
|
||||
strncpy(end_date_str, end_date, strchr(end_date + 1, '\n') - end_date);
|
||||
|
||||
if (location != NULL) {
|
||||
strncpy(summary_str,\
|
||||
summary + strlen("\r\nSUMMARY:"),\
|
||||
location - summary - strlen("\r\nSUMMARY:"));
|
||||
} else {
|
||||
strncpy(summary_str,\
|
||||
summary + strlen("\r\nSUMMARY:"),\
|
||||
transp - summary - strlen("\r\nSUMMARY:"));
|
||||
}
|
||||
strncpy(summary_str, summary, strchr(summary + 1, '\n') - summary);
|
||||
|
||||
// parse dates
|
||||
remove_whitespace(start_date_str);
|
||||
@ -47,7 +38,7 @@ void parse_event(char event_string[], struct event **head) {
|
||||
|
||||
remove_whitespace(end_date_str);
|
||||
cut_string(end_date_str, ':', 1);
|
||||
|
||||
|
||||
sorted_insert(head, start_date_str, end_date_str, summary_str);
|
||||
|
||||
free(start_date_str);
|
||||
@ -55,3 +46,24 @@ void parse_event(char event_string[], struct event **head) {
|
||||
free(summary_str);
|
||||
}
|
||||
|
||||
// the unfolded string has a space
|
||||
// as a separator between what where previously separate lines
|
||||
void unfolding_string(char *folded_string, char *unfolded_string) {
|
||||
int j = 0;
|
||||
for (int i = 0; i < strlen(folded_string); i++) {
|
||||
if (folded_string[i] == '\r' && folded_string[i + 1] == '\n'
|
||||
&& isblank(folded_string[i + 2])) {
|
||||
i += 3;
|
||||
while (isblank(folded_string[i])) {
|
||||
i++;
|
||||
}
|
||||
unfolded_string[j] = ' ';
|
||||
j++;
|
||||
unfolded_string[j] = folded_string[i];
|
||||
j++;
|
||||
} else {
|
||||
unfolded_string[j] = folded_string[i];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
void parse_event(char event_string[], struct event **head);
|
||||
void unfolding_string(char* folded_string, char* unfolded_string);
|
||||
|
27
tests/folded_with_spaces.ics
Normal file
27
tests/folded_with_spaces.ics
Normal file
@ -0,0 +1,27 @@
|
||||
BEGIN:VCALENDAR
|
||||
VERSION:2.0
|
||||
PRODID:-//www.example.com//iCal 4.0.3//EN
|
||||
METHOD:PUBLISH
|
||||
CALSCALE:GREGORIAN
|
||||
BEGIN:VEVENT
|
||||
CREATED:20240102T105004
|
||||
UID:ical-19709628-example-com
|
||||
DTSTART;VALUE=DATE:20250622T000000
|
||||
DTEND;VALUE=DATE:20250711T000000
|
||||
TRANSP:TRANSPARENT
|
||||
SUMMARY:vacation
|
||||
(approved)
|
||||
(again)
|
||||
DESCRIPTION:vacation\n\n
|
||||
status: approved\n
|
||||
workdays: 13,0\n\n
|
||||
entered by: John Doe\n
|
||||
entry date: Tue, 2024-01-02, 10:09 AM\n
|
||||
approved on: -\n\n\n\n
|
||||
Powered by example.com\n
|
||||
DTSTAMP:20240102T105004
|
||||
CATEGORIES:example.com
|
||||
X-MICROSOFT-CDO-BUSYSTATUS:OOF
|
||||
SEQUENCE:8
|
||||
END:VEVENT
|
||||
END:VCALENDAR
|
@ -9,7 +9,9 @@ UID:ical-19709628-example-com
|
||||
DTSTART;VALUE=DATE:20250622T000000
|
||||
DTEND;VALUE=DATE:20250711T000000
|
||||
TRANSP:TRANSPARENT
|
||||
SUMMARY:vacation (approved)
|
||||
SUMMARY:vacation
|
||||
(approved)
|
||||
(again)
|
||||
DESCRIPTION:vacation\n\n
|
||||
status: approved\n
|
||||
workdays: 13,0\n\n
|
||||
|
Loading…
x
Reference in New Issue
Block a user