From 7539f8c8804849294e100c5442e0397f4f4d2c40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 1 Oct 2019 23:39:00 +0200 Subject: Disabled bunch of old stuff, new stuff kinda builds. --- src/calendar.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index e634b166..2cd25f13 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -8,11 +8,12 @@ /* basename */ #include +#include #include "parse.h" #include "err.h" -int read_vcalendar(vcomponent* cal, char* path) { +int read_vcalendar(SCM cal, char* path) { struct stat statbuf; if (stat (path, &statbuf) != 0) { @@ -38,12 +39,12 @@ int read_vcalendar(vcomponent* cal, char* path) { return 0; } -int handle_file(vcomponent* cal, char* path) { +int handle_file(SCM cal, char* path) { INFO("Parsing a single file"); /* NAME is the `fancy' name of the calendar. */ - vcomponent_push_val(cal, "NAME", basename(path)); - vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file"); + // vcomponent_push_val(cal, "NAME", basename(path)); + // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file"); char* resolved_path = realpath(path, NULL); open_ics (resolved_path, cal); free (resolved_path); @@ -52,7 +53,7 @@ int handle_file(vcomponent* cal, char* path) { } -int handle_dir(vcomponent* cal, char* path) { +int handle_dir(SCM cal, char* path) { INFO("Parsing a directory"); DIR* dir = opendir(path); @@ -66,8 +67,8 @@ int handle_dir(vcomponent* cal, char* path) { /* NAME is the `fancy' name of the calendar. */ - vcomponent_push_val(cal, "NAME", basename(path)); - vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "vdir"); + // vcomponent_push_val(cal, "NAME", basename(path)); + // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "vdir"); struct dirent* d; while ((d = readdir(dir)) != NULL) { @@ -90,7 +91,8 @@ int handle_dir(vcomponent* cal, char* path) { info_buf[read - 1] = '\0'; fclose(f); - vcomponent_push_val(cal, "COLOR", info_buf); + // TODO + // vcomponent_push_val(cal, "COLOR", info_buf); } else if (strcmp (d->d_name, "displayname") == 0) { f = fopen(resolved_path, "r"); read = getline(&info_buf, &size, f); @@ -104,7 +106,8 @@ int handle_dir(vcomponent* cal, char* path) { * This works since *currently* values are returned in * reverse order */ - vcomponent_push_val(cal, "NAME", info_buf); + // TODO + // vcomponent_push_val(cal, "NAME", info_buf); } else { open_ics (resolved_path, cal); } @@ -149,7 +152,7 @@ int check_ext (const char* path, const char* ext) { return has_ext && strcmp(buf, ext) == 0; } -int open_ics (char* resolved_path, vcomponent* cal) { +int open_ics (char* resolved_path, SCM cal) { if (! check_ext(resolved_path, "ics") ) return 2; FILE* f = fopen(resolved_path, "r"); -- cgit v1.2.3 From e13f6bb201dff690208b9cc951b5c098b0d63356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 3 Oct 2019 00:46:01 +0200 Subject: Slowly going through and fixing everything. --- src/calendar.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index 2cd25f13..a90dfe44 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -10,6 +10,8 @@ #include #include +#include "struct.h" + #include "parse.h" #include "err.h" @@ -45,6 +47,9 @@ int handle_file(SCM cal, char* path) { /* NAME is the `fancy' name of the calendar. */ // vcomponent_push_val(cal, "NAME", basename(path)); // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file"); + SCM line = scm_make_vline(); + scm_struct_set_x(line, vline_value, scm_from_utf8_string("file")); + scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); char* resolved_path = realpath(path, NULL); open_ics (resolved_path, cal); free (resolved_path); @@ -68,7 +73,9 @@ int handle_dir(SCM cal, char* path) { /* NAME is the `fancy' name of the calendar. */ // vcomponent_push_val(cal, "NAME", basename(path)); - // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "vdir"); + SCM line = scm_make_vline(); + scm_struct_set_x(line, vline_value, scm_from_utf8_string("vdir")); + scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); struct dirent* d; while ((d = readdir(dir)) != NULL) { -- cgit v1.2.3 From 60d51e5700a55bc3ae17e34f9f3da1d4653a3026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Thu, 3 Oct 2019 23:56:59 +0200 Subject: Everything seems to parse now. --- src/calendar.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index a90dfe44..7d8d598e 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -47,8 +47,7 @@ int handle_file(SCM cal, char* path) { /* NAME is the `fancy' name of the calendar. */ // vcomponent_push_val(cal, "NAME", basename(path)); // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file"); - SCM line = scm_make_vline(); - scm_struct_set_x(line, vline_value, scm_from_utf8_string("file")); + SCM line = scm_make_vline(scm_from_utf8_string("file")); scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); char* resolved_path = realpath(path, NULL); open_ics (resolved_path, cal); @@ -73,8 +72,7 @@ int handle_dir(SCM cal, char* path) { /* NAME is the `fancy' name of the calendar. */ // vcomponent_push_val(cal, "NAME", basename(path)); - SCM line = scm_make_vline(); - scm_struct_set_x(line, vline_value, scm_from_utf8_string("vdir")); + SCM line = scm_make_vline(scm_from_utf8_string("vdir")); scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); struct dirent* d; -- cgit v1.2.3 From 100ac33c561d59057425ddfeb26c4bd7b054db57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 4 Oct 2019 00:08:45 +0200 Subject: Reintroduce color and name parsing. --- src/calendar.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index 7d8d598e..bafc13c3 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -96,8 +96,8 @@ int handle_dir(SCM cal, char* path) { info_buf[read - 1] = '\0'; fclose(f); - // TODO - // vcomponent_push_val(cal, "COLOR", info_buf); + scm_add_line_x(cal, scm_from_utf8_string("COLOR"), + scm_make_vline(scm_from_utf8_stringn(info_buf, read))); } else if (strcmp (d->d_name, "displayname") == 0) { f = fopen(resolved_path, "r"); read = getline(&info_buf, &size, f); @@ -111,8 +111,8 @@ int handle_dir(SCM cal, char* path) { * This works since *currently* values are returned in * reverse order */ - // TODO - // vcomponent_push_val(cal, "NAME", info_buf); + scm_add_line_x(cal, scm_from_utf8_string("NAME"), + scm_make_vline(scm_from_utf8_stringn(info_buf, read))); } else { open_ics (resolved_path, cal); } -- cgit v1.2.3 From 533b1994a73b6ae5003ad73109a600c0d05b4a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Fri, 4 Oct 2019 00:15:19 +0200 Subject: Actually fix NAME. --- src/calendar.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index bafc13c3..f3a9b254 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -72,6 +72,8 @@ int handle_dir(SCM cal, char* path) { /* NAME is the `fancy' name of the calendar. */ // vcomponent_push_val(cal, "NAME", basename(path)); + scm_add_line_x(cal, scm_from_utf8_string("NAME"), + scm_make_vline(scm_from_utf8_stringn(basename(path), strlen(basename(path))))); SCM line = scm_make_vline(scm_from_utf8_string("vdir")); scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); -- cgit v1.2.3 From 71e7b5fc4f28bcccd5fd9e27617b0ca2d13fc179 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 6 Oct 2019 13:35:14 +0200 Subject: Remove old C code. --- src/calendar.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index f3a9b254..1362ee2e 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -11,7 +11,6 @@ #include #include "struct.h" - #include "parse.h" #include "err.h" @@ -46,7 +45,6 @@ int handle_file(SCM cal, char* path) { /* NAME is the `fancy' name of the calendar. */ // vcomponent_push_val(cal, "NAME", basename(path)); - // vcomponent_push_val(cal, "X-HNH-SOURCETYPE", "file"); SCM line = scm_make_vline(scm_from_utf8_string("file")); scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); char* resolved_path = realpath(path, NULL); -- cgit v1.2.3 From fd7c76fc987dcaa928139ac4991ea02e61a2a1d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 8 Oct 2019 21:57:23 +0200 Subject: Remove tailing null from parsed color files. --- src/calendar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c index 1362ee2e..28891330 100644 --- a/src/calendar.c +++ b/src/calendar.c @@ -92,12 +92,14 @@ int handle_dir(SCM cal, char* path) { if (strcmp (d->d_name, "color") == 0) { f = fopen(resolved_path, "r"); read = getline(&info_buf, &size, f); + // TODO this isn't actually needed since we trim the + // string into an SCM string directly here. if (info_buf[read - 1] == '\n') info_buf[read - 1] = '\0'; fclose(f); scm_add_line_x(cal, scm_from_utf8_string("COLOR"), - scm_make_vline(scm_from_utf8_stringn(info_buf, read))); + scm_make_vline(scm_from_utf8_stringn(info_buf, read - 1))); } else if (strcmp (d->d_name, "displayname") == 0) { f = fopen(resolved_path, "r"); read = getline(&info_buf, &size, f); -- cgit v1.2.3 From 3a1d3898c3d42d43645b79586f0b26ab4f8ff331 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 2 Nov 2019 22:29:47 +0100 Subject: Remove ALL c code. --- src/calendar.c | 173 --------------------------------------------------------- 1 file changed, 173 deletions(-) delete mode 100644 src/calendar.c (limited to 'src/calendar.c') diff --git a/src/calendar.c b/src/calendar.c deleted file mode 100644 index 28891330..00000000 --- a/src/calendar.c +++ /dev/null @@ -1,173 +0,0 @@ -#include "calendar.h" - -#include -#include -#include -#include -#include - -/* basename */ -#include -#include - -#include "struct.h" -#include "parse.h" -#include "err.h" - -int read_vcalendar(SCM cal, char* path) { - - struct stat statbuf; - if (stat (path, &statbuf) != 0) { - fprintf(stderr, - "Error stating file or directory, errno = %i\npath = [%s]\n", - errno, path); - } - - int type = statbuf.st_mode & 0777000; - int chmod = statbuf.st_mode & 0777; - INFO_F("file has mode 0%o, with chmod = 0%o", type, chmod); - - switch (type) { - case S_IFREG: handle_file(cal, path); break; - case S_IFDIR: handle_dir (cal, path); break; - case S_IFLNK: - ERR("Found symlink, can't be bothered to check it further."); - break; - - default: ; - } - - return 0; -} - -int handle_file(SCM cal, char* path) { - INFO("Parsing a single file"); - - /* NAME is the `fancy' name of the calendar. */ - // vcomponent_push_val(cal, "NAME", basename(path)); - SCM line = scm_make_vline(scm_from_utf8_string("file")); - scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); - char* resolved_path = realpath(path, NULL); - open_ics (resolved_path, cal); - free (resolved_path); - - return 0; -} - - -int handle_dir(SCM cal, char* path) { - INFO("Parsing a directory"); - DIR* dir = opendir(path); - - /* Buffer for holding search path and filename */ - char buf[PATH_MAX] = { [0 ... PATH_MAX - 1] = '\0' }; - strcpy(buf, path); - int path_len = strlen(path) + 1; - - /* Slash to guarantee we have at least one */ - buf[path_len - 1] = '/'; - - - /* NAME is the `fancy' name of the calendar. */ - // vcomponent_push_val(cal, "NAME", basename(path)); - scm_add_line_x(cal, scm_from_utf8_string("NAME"), - scm_make_vline(scm_from_utf8_stringn(basename(path), strlen(basename(path))))); - SCM line = scm_make_vline(scm_from_utf8_string("vdir")); - scm_add_line_x(cal, scm_from_utf8_string("X-HNH-SOURCETYPE"), line); - - struct dirent* d; - while ((d = readdir(dir)) != NULL) { - /* Check that it's a regular file */ - if (d->d_type != DT_REG) continue; - - /* Append filename with currentt searchpath */ - strcat(buf, d->d_name); - char* resolved_path = realpath(buf, NULL); - /* Remove file part from combined path */ - buf[path_len] = '\0'; - - FILE* f; - size_t read, size = 0x100; - char* info_buf = malloc(size); - if (strcmp (d->d_name, "color") == 0) { - f = fopen(resolved_path, "r"); - read = getline(&info_buf, &size, f); - // TODO this isn't actually needed since we trim the - // string into an SCM string directly here. - if (info_buf[read - 1] == '\n') - info_buf[read - 1] = '\0'; - - fclose(f); - scm_add_line_x(cal, scm_from_utf8_string("COLOR"), - scm_make_vline(scm_from_utf8_stringn(info_buf, read - 1))); - } else if (strcmp (d->d_name, "displayname") == 0) { - f = fopen(resolved_path, "r"); - read = getline(&info_buf, &size, f); - if (info_buf[read - 1] == '\n') - info_buf[read - 1] = '\0'; - - fclose(f); - - /* This adds the new list to the set of names, keeping the - * filename name. - * This works since *currently* values are returned in - * reverse order - */ - scm_add_line_x(cal, scm_from_utf8_string("NAME"), - scm_make_vline(scm_from_utf8_stringn(info_buf, read))); - } else { - open_ics (resolved_path, cal); - } - - free (resolved_path); - } - - closedir(dir); - return 0; -} - -int get_extension(const char* filename, char* ext, ssize_t max_len) { - - if (filename == NULL) { - ext[0] = '\0'; - return 0; - } - - int ext_idx = -1; - ext[0] = '\0'; - for (int i = 0; filename[i] != '\0'; i++) { - if (filename[i] == '.') ext_idx = i + 1; - if (filename[i] == '/') ext_idx = -1; - } - - if (ext_idx == -1) return 0; - - int ext_len = 0; - for (int i = 0; i < max_len; i++, ext_len++) { - char c = filename[i + ext_idx]; - if (c == '\0') break; - ext[i] = c; - } - ext[ext_len] = '\0'; - return ext_len; -} - -int check_ext (const char* path, const char* ext) { - char buf[10]; - int has_ext = get_extension(path, buf, 9); - - return has_ext && strcmp(buf, ext) == 0; -} - -int open_ics (char* resolved_path, SCM cal) { - if (! check_ext(resolved_path, "ics") ) return 2; - - FILE* f = fopen(resolved_path, "r"); - - if (f == NULL) return 1; - - parse_file(resolved_path, f, cal); - fclose(f); - - return 0; -} -- cgit v1.2.3