From: Richard Russon Date: Sat, 25 Aug 2018 10:47:07 +0000 (+0100) Subject: add mutt_path_abbr_folder X-Git-Tag: 2019-10-25~682^2~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89458dc7c1e3306e1319a7ba763baf72c869ee54;p=neomutt add mutt_path_abbr_folder --- diff --git a/mutt/path.c b/mutt/path.c index 343c1c46d..fac54781d 100644 --- a/mutt/path.c +++ b/mutt/path.c @@ -499,3 +499,38 @@ void mutt_path_get_parent(char *path, char *buf, size_t buflen) buf[1] = '\0'; } } + +/** + * mutt_path_abbr_folder - Create a folder abbreviation + * @param buf Path to modify + * @param buflen Length of buffer + * @param folder Base path for '=' substitution + * @retval true Path was abbreviated + * + * Abbreviate a path using '=' to represent the 'folder'. + * If the folder path is passed, it won't be abbreviated to just '=' + */ +bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder) +{ + if (!buf || !folder) + return false; + + size_t flen = mutt_str_strlen(folder); + if (flen < 2) + return false; + + if (folder[flen - 1] == '/') + flen--; + + if (mutt_str_strncmp(buf, folder, flen) != 0) + return false; + + if (buf[flen + 1] == '\0') // Don't abbreviate to '=/' + return false; + + size_t rlen = mutt_str_strlen(buf + flen + 1); + + buf[0] = '='; + memmove(buf + 1, buf + flen + 1, rlen + 1); + return true; +} diff --git a/mutt/path.h b/mutt/path.h index e762a015a..ae83bdb55 100644 --- a/mutt/path.h +++ b/mutt/path.h @@ -26,6 +26,7 @@ #include #include +bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder); const char *mutt_path_basename(const char *f); bool mutt_path_canon(char *buf, size_t buflen, const char *homedir); char * mutt_path_concat(char *d, const char *dir, const char *fname, size_t l);