agendafs

A filesystem for your calendar.

git clone git://mccd.space/agendafs
commit ff7848fd0df5b5722d978d0265bbc47178e7d23a
parent d0566a84d00d523038098fa603e60259f4fa3eee
Author: Marc Coquand <marc@coquand.email>
Date:   Sun, 15 Jun 2025 11:25:26 +0100

Refactor (2)

Diffstat:
Mjournal_entry.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mjournal_entry.h | 9+++++++++
Mmain.c | 54------------------------------------------------------
3 files changed, 63 insertions(+), 54 deletions(-)
diff --git a/journal_entry.c b/journal_entry.c
@@ -582,3 +582,57 @@ do_journal_entry_rename(const char *old, const char *new)
 	return 0;
 }
 
+//  uuid-caldavfs
+char *
+create_new_unique_ics_uid()
+{
+	uuid_t uuid;
+	char uuid_str[37]; // UUIDs are 36 characters + null terminator
+	uuid_generate(uuid);
+	uuid_unparse(uuid, uuid_str);
+	char *res = NULL;
+	if (asprintf(&res, "%s-caldavfs", uuid_str) == -1) {
+		return NULL;
+	}
+	return res;
+}
+
+icalcomponent *
+create_vjournal_entry(char *summary)
+{
+
+	icalcomponent *calendar = icalcomponent_new_vcalendar();
+
+	icalcomponent_add_property(calendar, icalproperty_new_version("2.0"));
+	icalcomponent_add_property(calendar,
+				   icalproperty_new_prodid("-//caldavfs//EN"));
+
+	// Step 2: Create a VJOURNAL entry
+	icalcomponent *journal = icalcomponent_new_vjournal();
+	char *id = create_new_unique_ics_uid();
+
+	icalcomponent_add_property(journal, icalproperty_new_uid(id));
+
+	icalcomponent_add_property(
+	    journal, icalproperty_new_dtstamp(icaltime_current_time_with_zone(
+			 icaltimezone_get_utc_timezone())));
+	icalcomponent_add_property(journal, icalproperty_new_summary(summary));
+	icalcomponent_add_property(journal, icalproperty_new_description(""));
+
+	icalcomponent_add_component(calendar, journal);
+
+	return calendar;
+}
+
+void
+remove_file_extension(char *path)
+{
+	char *last_dot = strrchr(path, '.');
+	char *last_slash = strrchr(path, '/');
+
+	// Only remove the extension if dot is after last slash
+	if (last_dot && (!last_slash || last_dot > last_slash)) {
+		*last_dot = '\0';
+	}
+}
+
diff --git a/journal_entry.h b/journal_entry.h
@@ -121,5 +121,14 @@ build_notes_hashmap();
 
 size_t
 load_caldavfs_environment();
+char *
+create_new_unique_ics_uid();
+
+icalcomponent *
+create_vjournal_entry(char *summary);
+
+void
+remove_file_extension(char *path);
 
 #endif // JOURNAL_ENTRY_H
+
diff --git a/main.c b/main.c
@@ -386,60 +386,6 @@ journal_rename(const char *old, const char *new, unsigned int flags)
 	return res;
 }
 
-//  uuid-caldavfs
-char *
-create_new_unique_ics_uid()
-{
-	uuid_t uuid;
-	char uuid_str[37]; // UUIDs are 36 characters + null terminator
-	uuid_generate(uuid);
-	uuid_unparse(uuid, uuid_str);
-	char *res = NULL;
-	if (asprintf(&res, "%s-caldavfs", uuid_str) == -1) {
-		return NULL;
-	}
-	return res;
-}
-
-icalcomponent *
-create_vjournal_entry(char *summary)
-{
-
-	icalcomponent *calendar = icalcomponent_new_vcalendar();
-
-	icalcomponent_add_property(calendar, icalproperty_new_version("2.0"));
-	icalcomponent_add_property(calendar,
-				   icalproperty_new_prodid("-//caldavfs//EN"));
-
-	// Step 2: Create a VJOURNAL entry
-	icalcomponent *journal = icalcomponent_new_vjournal();
-	char *id = create_new_unique_ics_uid();
-
-	icalcomponent_add_property(journal, icalproperty_new_uid(id));
-
-	icalcomponent_add_property(
-	    journal, icalproperty_new_dtstamp(icaltime_current_time_with_zone(
-			 icaltimezone_get_utc_timezone())));
-	icalcomponent_add_property(journal, icalproperty_new_summary(summary));
-	icalcomponent_add_property(journal, icalproperty_new_description(""));
-
-	icalcomponent_add_component(calendar, journal);
-
-	return calendar;
-}
-
-void
-remove_file_extension(char *path)
-{
-	char *last_dot = strrchr(path, '.');
-	char *last_slash = strrchr(path, '/');
-
-	// Only remove the extension if dot is after last slash
-	if (last_dot && (!last_slash || last_dot > last_slash)) {
-		*last_dot = '\0';
-	}
-}
-
 int
 journal_create(const char *filename, mode_t mode, struct fuse_file_info *info)
 {