unfolding doesnt work correctly
This commit is contained in:
parent
ce356065a7
commit
ecfae506c9
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
icscli
|
||||
.gitconfig
|
||||
*.o
|
||||
tags
|
||||
|
@ -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,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.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 *start_date = strstr(event_string, "\r\nDTSTART");
|
||||
char *end_date = strstr(event_string, "\r\nDTEND");
|
||||
char *summary = strstr(event_string, "\r\nSUMMARY");
|
||||
char *location = strstr(event_string, "\r\nLOCATION:");
|
||||
char *transp = strstr(event_string, "\r\nTRANSP:");
|
||||
|
||||
char *start_date_str = malloc(256);
|
||||
char *end_date_str = malloc(256);
|
||||
@ -23,23 +21,13 @@ 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, '\r') - start_date);
|
||||
|
||||
strncpy(end_date_str, end_date, sequence - end_date);
|
||||
strncpy(end_date_str, end_date, strchr(end_date, '\r') - 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, '\r') - summary);
|
||||
|
||||
// parse dates
|
||||
remove_whitespace(start_date_str);
|
||||
@ -55,3 +43,21 @@ void parse_event(char event_string[], struct event **head) {
|
||||
free(summary_str);
|
||||
}
|
||||
|
||||
// the unfolded string has a semicolon
|
||||
// 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') {
|
||||
while (isblank(folded_string[i+2])) {
|
||||
i++;
|
||||
if (! isblank(folded_string[i+2]))
|
||||
folded_string[i+1] = ';';
|
||||
}
|
||||
} 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user