agendafs
A filesystem for your calendar.
git clone git://mccd.space/agendafscommit ddbd94ee1fb30c687f9dd0f034ff095ead25b6e0
parent 19390f855dfb4c23b532ac03e1e4d163d0873760
Author: Marc Coquand <marc@coquand.email>
Date: Sun, 1 Jun 2025 18:48:11 +0100
fmt
Diffstat:
| M | main.c | | | 109 | ++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------- |
1 file changed, 69 insertions(+), 40 deletions(-)
diff --git a/main.c b/main.c
@@ -42,7 +42,8 @@ struct hashmap *entries_original_key = NULL;
static pthread_mutex_t entries_mutex = PTHREAD_MUTEX_INITIALIZER;
-void free_journal_entry(void *val)
+void
+free_journal_entry(void *val)
{
journal_entry *entry = (journal_entry *)val;
if (!entry)
@@ -55,7 +56,8 @@ void free_journal_entry(void *val)
free(entry);
}
-static time_t parse_datetime(const char *datetime)
+static time_t
+parse_datetime(const char *datetime)
{
struct tm tm = {0};
int ret =
@@ -72,7 +74,8 @@ static time_t parse_datetime(const char *datetime)
}
// Folds are [\r]\n followed by ' ' or '\t'
-static int skip_fold(const char *p)
+static int
+skip_fold(const char *p)
{
// '\r\n' + ' ' OR '\t'
if (*p == '\r' && p[1] == '\n' && (p[2] == ' ' || p[2] == '\t'))
@@ -89,7 +92,8 @@ static int skip_fold(const char *p)
// Once extracted it will also need to be escaped.
// Field name should be without colon, I.E.
// "DESCRIPTION"
-char *extract_ical_field(const char *ical, const char *field_name)
+char *
+extract_ical_field(const char *ical, const char *field_name)
{
size_t field_len = strlen(field_name);
const char *start = strstr(ical, field_name);
@@ -122,8 +126,9 @@ char *extract_ical_field(const char *ical, const char *field_name)
return final;
}
-static int compile_regexes(regex_t *regex_dtstamp, regex_t *regex_lastmod,
- regex_t *regex_fuse_file)
+static int
+compile_regexes(regex_t *regex_dtstamp, regex_t *regex_lastmod,
+ regex_t *regex_fuse_file)
{
if (regcomp(regex_dtstamp, "DTSTAMP:([0-9T]+Z)", REG_EXTENDED) != 0)
return -1;
@@ -138,7 +143,8 @@ static int compile_regexes(regex_t *regex_dtstamp, regex_t *regex_lastmod,
}
// Extracts the matched text from regexp
-static char *extract_match(const char *content, regmatch_t match)
+static char *
+extract_match(const char *content, regmatch_t match)
{
size_t len = match.rm_eo - match.rm_so;
char *m_str = calloc(len + 1, sizeof(char));
@@ -149,7 +155,8 @@ static char *extract_match(const char *content, regmatch_t match)
// RFC 5545 specifies how human-readable text is escaped
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.11
-static void unescape_text(char *desc)
+static void
+unescape_text(char *desc)
{
char *src = desc;
char *dst = desc;
@@ -191,7 +198,8 @@ done:
// RFC 5545 specifies how human-readable text is escaped
// https://datatracker.ietf.org/doc/html/rfc5545#section-3.3.11
-static char *escape_text(const char *src)
+static char *
+escape_text(const char *src)
{
size_t len = strlen(src);
// Safe amount
@@ -242,7 +250,8 @@ static char *escape_text(const char *src)
return realloc(escaped, actual_len);
}
-static journal_entry *get_entry_from_fuse_path(const char *path)
+static journal_entry *
+get_entry_from_fuse_path(const char *path)
{
if (!path || path[0] != '/') {
LOG("invalid path '%s'\n", path ? path : "NULL");
@@ -262,7 +271,8 @@ static journal_entry *get_entry_from_fuse_path(const char *path)
return entry;
}
-static int parse_ics_file(const char *file_path, journal_entry *entry)
+static int
+parse_ics_file(const char *file_path, journal_entry *entry)
{
FILE *file = fopen(file_path, "r");
if (!file) {
@@ -355,7 +365,8 @@ static int parse_ics_file(const char *file_path, journal_entry *entry)
}
// Dynamically create a time string using format
-char *time_string(time_t time_val, const char *format)
+char *
+time_string(time_t time_val, const char *format)
{
struct tm tm_info;
if (!localtime_r(&time_val, &tm_info)) {
@@ -371,7 +382,8 @@ char *time_string(time_t time_val, const char *format)
// Uses created_at as filename.
// However, in case of collission, set the add 1,2 et.c.
-char *get_unique_filename(time_t created_at, struct hashmap *entries_map)
+char *
+get_unique_filename(time_t created_at, struct hashmap *entries_map)
{
char *filename_time_str = time_string(created_at, date_title_fmt);
if (!filename_time_str) {
@@ -408,7 +420,8 @@ char *get_unique_filename(time_t created_at, struct hashmap *entries_map)
// entries_original_key
// entries_fuse_key
// Should only be run once
-static void load_journal_entries()
+static void
+load_journal_entries()
{
pthread_mutex_lock(&entries_mutex);
@@ -488,20 +501,22 @@ static void load_journal_entries()
pthread_mutex_unlock(&entries_mutex);
}
-int write_entry_content(char *buf, size_t max_len, journal_entry *entry)
+int
+write_entry_content(char *buf, size_t max_len, journal_entry *entry)
{
int size = snprintf(buf, max_len, "%s\n---\n%s", entry->summary,
entry->description);
return size;
}
-int get_entry_content_size(journal_entry *entry)
+int
+get_entry_content_size(journal_entry *entry)
{
return write_entry_content(NULL, 0, entry);
}
-int journal_getattr(const char *path, struct stat *stbuf,
- struct fuse_file_info *fi)
+int
+journal_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *fi)
{
pthread_mutex_lock(&entries_mutex);
@@ -540,9 +555,10 @@ unlock_and_return:
return ret_code;
}
-static int journal_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
- off_t offset, struct fuse_file_info *fi,
- enum fuse_readdir_flags flags)
+static int
+journal_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
+ off_t offset, struct fuse_file_info *fi,
+ enum fuse_readdir_flags flags)
{
pthread_mutex_lock(&entries_mutex);
@@ -563,7 +579,8 @@ static int journal_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
return 0;
}
-static int journal_open(const char *path, struct fuse_file_info *fi)
+static int
+journal_open(const char *path, struct fuse_file_info *fi)
{
pthread_mutex_lock(&entries_mutex);
LOG("Opening journal for %s", path);
@@ -573,8 +590,9 @@ static int journal_open(const char *path, struct fuse_file_info *fi)
return ret;
}
-static int journal_read(const char *path, char *buf, size_t size, off_t offset,
- struct fuse_file_info *fi)
+static int
+journal_read(const char *path, char *buf, size_t size, off_t offset,
+ struct fuse_file_info *fi)
{
int ret_code = 0;
pthread_mutex_lock(&entries_mutex);
@@ -615,7 +633,8 @@ unlock_and_return:
return ret_code;
}
-char *journal_entry_to_ical(const journal_entry *entry)
+char *
+journal_entry_to_ical(const journal_entry *entry)
{
char *escaped_summary = escape_text(entry->summary);
char *escaped_description = escape_text(entry->description);
@@ -655,7 +674,8 @@ char *journal_entry_to_ical(const journal_entry *entry)
return ical;
}
-int parse_entry_content(journal_entry *entry, const char *buf, size_t size)
+int
+parse_entry_content(journal_entry *entry, const char *buf, size_t size)
{
char *copy = strndup(buf, size);
@@ -690,7 +710,8 @@ int parse_entry_content(journal_entry *entry, const char *buf, size_t size)
return 0;
}
-int write_entry_to_ical_file(const journal_entry *entry, const char *filepath)
+int
+write_entry_to_ical_file(const journal_entry *entry, const char *filepath)
{
char *ical_str = journal_entry_to_ical(entry);
@@ -709,7 +730,8 @@ int write_entry_to_ical_file(const journal_entry *entry, const char *filepath)
}
// Full filepath of original ics file
-char *get_original_filepath(const journal_entry *entry)
+char *
+get_original_filepath(const journal_entry *entry)
{
size_t needed =
snprintf(NULL, 0, "%s/%s", ICS_DIR, entry->filename_original);
@@ -719,8 +741,9 @@ char *get_original_filepath(const journal_entry *entry)
return filepath;
}
-static int journal_write(const char *path, const char *buf, size_t size,
- off_t offset, struct fuse_file_info *fi)
+static int
+journal_write(const char *path, const char *buf, size_t size, off_t offset,
+ struct fuse_file_info *fi)
{
pthread_mutex_lock(&entries_mutex);
journal_entry *entry = get_entry_from_fuse_path(path);
@@ -745,7 +768,8 @@ static int journal_write(const char *path, const char *buf, size_t size,
return size;
}
-journal_entry *copy_journal_entry(const journal_entry *src)
+journal_entry *
+copy_journal_entry(const journal_entry *src)
{
journal_entry *copy = calloc(1, sizeof(journal_entry));
@@ -761,7 +785,8 @@ journal_entry *copy_journal_entry(const journal_entry *src)
return copy;
}
-time_t timestamp_from_filename(const char *filename)
+time_t
+timestamp_from_filename(const char *filename)
{
regmatch_t matches[4];
@@ -804,8 +829,8 @@ time_t timestamp_from_filename(const char *filename)
return timestamp;
}
-static int do_journal_entry_rename(time_t new_created_at, const char *old,
- const char *new)
+static int
+do_journal_entry_rename(time_t new_created_at, const char *old, const char *new)
{
const char *old_basename = strrchr(old, '/');
old_basename = old_basename + 1;
@@ -844,7 +869,8 @@ static int do_journal_entry_rename(time_t new_created_at, const char *old,
return 0;
}
-static int journal_rename(const char *old, const char *new, unsigned int flags)
+static int
+journal_rename(const char *old, const char *new, unsigned int flags)
{
pthread_mutex_lock(&entries_mutex);
LOG("Renaming %s -> %s", old, new);
@@ -864,7 +890,8 @@ static int journal_rename(const char *old, const char *new, unsigned int flags)
return res;
}
-void update_fuse_entry_from_original(const char *filename)
+void
+update_fuse_entry_from_original(const char *filename)
{
pthread_mutex_lock(&entries_mutex);
const char *base_name = strrchr(filename, '/');
@@ -910,7 +937,8 @@ void update_fuse_entry_from_original(const char *filename)
pthread_mutex_unlock(&entries_mutex);
}
-void *watch_ics_dir(void *arg)
+void *
+watch_ics_dir(void *arg)
{
int fd = inotify_init1(IN_NONBLOCK);
if (fd < 0) {
@@ -967,8 +995,8 @@ void *watch_ics_dir(void *arg)
return NULL;
}
-int journal_create(const char *file_name, mode_t mode,
- struct fuse_file_info *info)
+int
+journal_create(const char *file_name, mode_t mode, struct fuse_file_info *info)
{
return -EIO;
}
@@ -981,7 +1009,8 @@ static const struct fuse_operations journal_oper = {.getattr = journal_getattr,
.create = journal_create,
.rename = journal_rename};
-int main(int argc, char *argv[])
+int
+main(int argc, char *argv[])
{
pthread_t watcher_thread;