From 541466e3a77d6bbaad251d13e2c129d94e687dcc Mon Sep 17 00:00:00 2001 From: Guyzmo Date: Wed, 18 Jan 2017 15:49:13 +0100 Subject: [PATCH] Improving the API naming and typing Signed-off-by: Guyzmo --- mutt_notmuch.c | 37 +++++++++++++++++++------------------ mutt_notmuch.h | 4 +++- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/mutt_notmuch.c b/mutt_notmuch.c index e09e37065..c69ce1272 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -234,7 +235,7 @@ static void url_free_tags(struct uri_tag *tags) * Extract the database filename (optional) and any search parameters (tags). * The tags will be saved in a linked list (#uri_tag). */ -static int url_parse_query(char *url, char **filename, struct uri_tag **tags) +static int url_parse_query(const char *url, char **filename, struct uri_tag **tags) { char *p = strstr(url, "://"); /* remote unsupported */ char *e; @@ -441,7 +442,7 @@ static int string_to_query_type(const char *str) * nm_query_window_timebase * */ -static int query_window_check_timebase(char *timebase) +static bool query_window_check_timebase(const char *timebase) { if ((strcmp(timebase, "hour") == 0) || (strcmp(timebase, "day") == 0) || @@ -506,7 +507,7 @@ static void query_window_reset(void) * If there's no search registered in `nm_query_window_current_search` or this is * a new search, it will reset the window and do the search. */ -static int windowed_query_from_query(const char *query, char *buf, size_t bufsz) +static bool windowed_query_from_query(const char *query, char *buf, size_t bufsz) { dprint(2, (debugfile, "nm: windowed_query_from_query (%s)\n", query)); @@ -517,7 +518,7 @@ static int windowed_query_from_query(const char *query, char *buf, size_t bufsz) if (NotmuchQueryWindowDuration <= 0) { query_window_reset(); - return 0; + return false; } // if the query has changed, reset the window position @@ -530,7 +531,7 @@ static int windowed_query_from_query(const char *query, char *buf, size_t bufsz) { mutt_message (_("Invalid nm_query_window_timebase value (valid values are: hour, day, week, month or year).")); dprint(2, (debugfile, "Invalid nm_query_window_timebase value\n")); - return 0; + return false; } if (end == 0) @@ -542,7 +543,7 @@ static int windowed_query_from_query(const char *query, char *buf, size_t bufsz) dprint(2, (debugfile, "nm: windowed_query_from_query (%s) -> %s\n", query, buf)); - return 1; + return true; } /** @@ -1774,9 +1775,9 @@ char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz) * It's aimed to be used by buffy when parsing the virtual_mailboxes to make the * parsed user written search strings comparable to the internally generated ones. */ -int nm_normalize_uri(char *new_url, char* url, size_t new_url_sz) +bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz) { - dprint(2, (debugfile, "nm_normalize_uri (%s)\n", url)); + dprint(2, (debugfile, "nm_normalize_uri (%s)\n", orig_uri)); char buf[LONG_STRING]; CONTEXT tmp_ctx; @@ -1786,20 +1787,20 @@ int nm_normalize_uri(char *new_url, char* url, size_t new_url_sz) tmp_ctx.data = &tmp_ctxdata; tmp_ctxdata.db_query = NULL; - if (url_parse_query(url, &tmp_ctxdata.db_filename, &tmp_ctxdata.query_items)) + if (url_parse_query(orig_uri, &tmp_ctxdata.db_filename, &tmp_ctxdata.query_items)) { - mutt_error(_("failed to parse #1 notmuch uri: %s"), url); + mutt_error(_("failed to parse notmuch uri: %s"), orig_uri); dprint(2, (debugfile, "nm_normalize_uri () -> error #1\n")); - return 0; + return false; } dprint(2, (debugfile, "nm_normalize_uri #1 () -> db_query: %s\n", tmp_ctxdata.db_query)); if (get_query_string(&tmp_ctxdata, false) == NULL) { - mutt_error(_("failed to parse #2 notmuch uri: %s"), url); + mutt_error(_("failed to parse notmuch uri: %s"), orig_uri); dprint(2, (debugfile, "nm_normalize_uri () -> error #2\n")); - return 0; + return false; } dprint(2, (debugfile, "nm_normalize_uri #2 () -> db_query: %s\n", tmp_ctxdata.db_query)); @@ -1808,15 +1809,15 @@ int nm_normalize_uri(char *new_url, char* url, size_t new_url_sz) if (nm_uri_from_query(&tmp_ctx, buf, sizeof(buf)) == NULL) { - mutt_error(_("failed to parse #3 notmuch uri: %s"), url); + mutt_error(_("failed to parse notmuch uri: %s"), orig_uri); dprint(2, (debugfile, "nm_normalize_uri () -> error #3\n")); - return 0; + return true; } - strncpy(new_url, buf, new_url_sz); + strncpy(new_uri, buf, new_uri_sz); - dprint(2, (debugfile, "nm_normalize_uri #3 (%s) -> %s\n", url, new_url)); - return 1; + dprint(2, (debugfile, "nm_normalize_uri #3 (%s) -> %s\n", orig_uri, new_uri)); + return true; } /** diff --git a/mutt_notmuch.h b/mutt_notmuch.h index 8b08aeef0..b46087792 100644 --- a/mutt_notmuch.h +++ b/mutt_notmuch.h @@ -19,11 +19,13 @@ #ifndef _MUTT_NOTMUCH_H #define _MUTT_NOTMUCH_H +#include + int nm_read_entire_thread(CONTEXT *ctx, HEADER *h); char *nm_header_get_folder(HEADER *h); int nm_update_filename(CONTEXT *ctx, const char *old, const char *new, HEADER *h); -int nm_normalize_uri(char *new_url, char *url, size_t new_url_sz); +bool nm_normalize_uri(char *new_uri, const char *orig_uri, size_t new_uri_sz); char *nm_uri_from_query(CONTEXT *ctx, char *buf, size_t bufsz); int nm_modify_message_tags(CONTEXT *ctx, HEADER *hdr, char *buf); -- 2.40.0