commit 6e58b2dbc32390bfa0e7bf57a96f6846c0e030ab
parent 4da97e90728f15da456179f8a25c5979b54ca791
Author: Andreas Gruhler <agruhl@gmx.ch>
Date: Wed, 22 Sep 2021 23:12:37 +0200
read first VEVENT DESCRIPTION from ics file
Diffstat:
3 files changed, 37 insertions(+), 0 deletions(-)
diff --git a/src/diary.c b/src/diary.c
@@ -474,6 +474,8 @@ int main(int argc, char** argv) {
int ch, conf_ch;
int pad_pos = 0;
int syear = 0, smonth = 0, sday = 0;
+ char ics_input_filepath[256];
+ char* expanded_ics_input_filepath;
struct tm new_date;
int prev_width = COLS - ASIDE_WIDTH - CAL_WIDTH;
int prev_height = LINES - 1;
@@ -666,6 +668,19 @@ int main(int argc, char** argv) {
it.tm_mday++;
}
break;
+ // import from ics file
+ case 'i':
+ wclear(header);
+ curs_set(2);
+ mvwprintw(header, 0, 0, "Import from file: ");
+ if (wscanw(header, "%s", &ics_input_filepath) == 1) {
+ // fprintf(stderr, "ICS input file: %s\n", ics_input_filepath);
+ expanded_ics_input_filepath = expand_path(ics_input_filepath);
+ ics_import(expanded_ics_input_filepath);
+ free(expanded_ics_input_filepath);
+ }
+ curs_set(0);
+ break;
}
if (mv_valid) {
diff --git a/src/utils.c b/src/utils.c
@@ -319,6 +319,27 @@ void fpath(const char* dir, size_t dir_size, const struct tm* date, char** rpath
strcat(*rpath, dstr);
}
+/* Import journal entries from an ics file */
+void ics_import(const char* ics_input) {
+ FILE* pfile = fopen(ics_input, "r");
+
+ fseek(pfile, 0, SEEK_END);
+ long ics_bytes = ftell(pfile) + 1;
+ rewind(pfile);
+
+ char* ics = malloc(ics_bytes);
+ fread(ics, 1, ics_bytes, pfile);
+ fclose(pfile);
+
+ ics[ics_bytes] = 0;
+ // fprintf(stderr, "Import ICS file: %s\n", ics);
+
+
+ char* desc = extract_ical_field(ics, "DESCRIPTION", true);
+ fprintf(stderr, "Import DESCRIPTION: %s\n", desc);
+ free (desc);
+}
+
config CONFIG = {
.range = 1,
.weekday = 1,
diff --git a/src/utils.h b/src/utils.h
@@ -30,6 +30,7 @@ char* extract_ical_field(const char* ical, char* key, bool multline);
char* expand_path(const char* str);
char* strrstr(char *haystack, char *needle);
void fpath(const char* dir, size_t dir_size, const struct tm* date, char** rpath, size_t rpath_size);
+void ics_import(const char* ics_input);
typedef struct
{