]> granicus.if.org Git - neomutt/commitdiff
browser.c: Convert other browser local variables to Buffer
authorKevin McCarthy <kevin@8t8.us>
Tue, 12 Mar 2019 05:56:51 +0000 (13:56 +0800)
committerRichard Russon <rich@flatcap.org>
Tue, 9 Apr 2019 13:04:55 +0000 (14:04 +0100)
Co-authored-by: Richard Russon <rich@flatcap.org>
browser.c
muttlib.c
muttlib.h

index e7d4d5fe94a699070b5f7fee194c3addeaf03935..629e8e06f8dbc17502f6adb61e9293ef37897319 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -334,14 +334,17 @@ static void browser_sort(struct BrowserState *state)
 static bool link_is_dir(const char *folder, const char *path)
 {
   struct stat st;
-  char fullpath[PATH_MAX];
+  bool retval = false;
 
-  mutt_path_concat(fullpath, folder, path, sizeof(fullpath));
+  struct Buffer *fullpath = mutt_buffer_pool_get();
+  mutt_buffer_concat_path(fullpath, folder, path);
 
-  if (stat(fullpath, &st) == 0)
-    return S_ISDIR(st.st_mode);
+  if (stat(mutt_b2s(fullpath), &st) == 0)
+    retval = S_ISDIR(st.st_mode);
 
-  return false;
+  mutt_buffer_pool_release(&fullpath);
+
+  return retval;
 }
 
 /**
@@ -684,6 +687,8 @@ static void init_state(struct BrowserState *state, struct Menu *menu)
 static int examine_directory(struct Menu *menu, struct BrowserState *state,
                              const char *d, const char *prefix)
 {
+  int rc = -1;
+  struct Buffer *buf = mutt_buffer_pool_get();
 #ifdef USE_NNTP
   if (OptNews)
   {
@@ -712,7 +717,6 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
     struct stat s;
     DIR *dp = NULL;
     struct dirent *de = NULL;
-    char buf[PATH_MAX + 128];
 
     while (stat(d, &s) == -1)
     {
@@ -728,13 +732,13 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
         }
       }
       mutt_perror(d);
-      return -1;
+      goto ed_out;
     }
 
     if (!S_ISDIR(s.st_mode))
     {
       mutt_error(_("%s is not a directory"), d);
-      return -1;
+      goto ed_out;
     }
 
     mutt_mailbox_check(Context->mailbox, 0);
@@ -743,7 +747,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
     if (!dp)
     {
       mutt_perror(d);
-      return -1;
+      goto ed_out;
     }
 
     init_state(state, menu);
@@ -763,8 +767,8 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
         continue;
       }
 
-      mutt_path_concat(buf, d, de->d_name, sizeof(buf));
-      if (lstat(buf, &s) == -1)
+      mutt_buffer_concat_path(buf, d, de->d_name);
+      if (lstat(mutt_b2s(buf), &s) == -1)
         continue;
 
       /* No size for directories or symlinks */
@@ -776,7 +780,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
       struct MailboxNode *np = NULL;
       STAILQ_FOREACH(np, &AllMailboxes, entries)
       {
-        if (mutt_str_strcmp(buf, np->mailbox->path) != 0)
+        if (mutt_str_strcmp(mutt_b2s(buf), np->mailbox->path) != 0)
           break;
       }
 
@@ -791,7 +795,10 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
     closedir(dp);
   }
   browser_sort(state);
-  return 0;
+  rc = 0;
+ed_out:
+  mutt_buffer_pool_release(&buf);
+  return rc;
 }
 
 /**
@@ -804,6 +811,7 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
 static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
 {
   struct stat s;
+  struct Buffer *md = NULL;
 
 #ifdef USE_NNTP
   if (OptNews)
@@ -828,6 +836,7 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
 
     if (STAILQ_EMPTY(&AllMailboxes))
       return -1;
+    md = mutt_buffer_pool_get();
     mutt_mailbox_check(Context ? Context->mailbox : NULL, 0);
 
     struct MailboxNode *np = NULL;
@@ -868,13 +877,12 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
       if (np->mailbox->magic == MUTT_MAILDIR)
       {
         struct stat st2;
-        char md[PATH_MAX];
 
-        snprintf(md, sizeof(md), "%s/new", np->mailbox->path);
-        if (stat(md, &s) < 0)
+        mutt_buffer_printf(md, "%s/new", np->mailbox->path);
+        if (stat(mutt_b2s(md), &s) < 0)
           s.st_mtime = 0;
-        snprintf(md, sizeof(md), "%s/cur", np->mailbox->path);
-        if (stat(md, &st2) < 0)
+        mutt_buffer_printf(md, "%s/cur", np->mailbox->path);
+        if (stat(mutt_b2s(md), &st2) < 0)
           st2.st_mtime = 0;
         if (st2.st_mtime > s.st_mtime)
           s.st_mtime = st2.st_mtime;
@@ -884,6 +892,8 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
     }
   }
   browser_sort(state);
+
+  mutt_buffer_pool_release(&md);
   return 0;
 }
 
@@ -998,12 +1008,13 @@ static void init_menu(struct BrowserState *state, struct Menu *menu,
     }
     else
     {
-      char path[PATH_MAX];
+      struct Buffer *path = mutt_buffer_pool_get();
       menu->is_mailbox_list = false;
-      mutt_str_strfcpy(path, mutt_b2s(LastDir), sizeof(path));
-      mutt_pretty_mailbox(path, sizeof(path));
-      snprintf(title, titlelen, _("Directory [%s], File mask: %s"), path,
-               NONULL(C_Mask ? C_Mask->pattern : NULL));
+      mutt_buffer_strcpy(path, mutt_b2s(LastDir));
+      mutt_buffer_pretty_mailbox(path);
+      snprintf(title, titlelen, _("Directory [%s], File mask: %s"),
+               mutt_b2s(path), NONULL(C_Mask ? C_Mask->pattern : NULL));
+      mutt_buffer_pool_release(&path);
     }
   }
 
@@ -1503,10 +1514,9 @@ void mutt_select_file(char *file, size_t filelen, SelectFileFlags flags,
               struct FolderFile ff = state.entry[i];
               if (ff.tagged)
               {
-                char full[PATH_MAX];
-                mutt_path_concat(full, mutt_b2s(LastDir), ff.name, sizeof(full));
-                mutt_expand_path(full, sizeof(full));
-                tfiles[j++] = mutt_str_strdup(full);
+                mutt_buffer_concat_path(tmp, mutt_b2s(LastDir), ff.name);
+                mutt_buffer_expand_path(tmp);
+                tfiles[j++] = mutt_str_strdup(mutt_b2s(tmp));
               }
             }
             *files = tfiles;
index 62715fd6c22a1184de5dd41aae67460cd3be2802..b687d1f872d7bf7ab17d0c2cc529c90b41ca59db 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -709,6 +709,19 @@ void mutt_pretty_mailbox(char *buf, size_t buflen)
   }
 }
 
+/**
+ * mutt_buffer_pretty_mailbox - Shorten a mailbox path using '~' or '='
+ * @param s Buffer containing Mailbox name
+ */
+void mutt_buffer_pretty_mailbox(struct Buffer *s)
+{
+  /* This reduces the size of the Buffer, so we can pass it through.
+   * We adjust the size just to make sure s->data is not NULL though */
+  mutt_buffer_increase_size(s, PATH_MAX);
+  mutt_pretty_mailbox(s->data, s->dsize);
+  mutt_buffer_fix_dptr(s);
+}
+
 /**
  * mutt_check_overwrite - Ask the user if overwriting is necessary
  * @param[in]  attname   Attachment name
index d8456d561d3716a07faba4688ec74fac0f1d0d16..5681439ca5e2012b71d47abde47de78c9d5363eb 100644 (file)
--- a/muttlib.h
+++ b/muttlib.h
@@ -47,6 +47,7 @@ void        mutt_buffer_adv_mktemp (struct Buffer *buf);
 void        mutt_buffer_mktemp_full(struct Buffer *buf, const char *prefix, const char *suffix, const char *src, int line);
 void        mutt_buffer_expand_path(struct Buffer *buf);
 void        mutt_buffer_expand_path_regex(struct Buffer *buf, bool regex);
+void        mutt_buffer_pretty_mailbox(struct Buffer *s);
 int         mutt_check_overwrite(const char *attname, const char *path, char *fname, size_t flen, enum SaveAttach *opt, char **directory);
 void        mutt_encode_path(char *dest, size_t dlen, const char *src);
 void        mutt_expando_format(char *buf, size_t buflen, size_t col, int cols, const char *src, format_t *callback, unsigned long data, MuttFormatFlags flags);