]> granicus.if.org Git - neomutt/commitdiff
Move escape_path to the library
authorIan Zimmerman <itz@no-use.mooo.com>
Sat, 15 Dec 2018 22:45:26 +0000 (14:45 -0800)
committerRichard Russon <rich@flatcap.org>
Sun, 16 Dec 2018 14:04:23 +0000 (14:04 +0000)
Also, make its source argument const

compress.c
mutt/path.c
mutt/path.h

index 9e13bbc919028b256e86fe2502bfac453882d151..438a679d03685e0a8a4703c8372b00962e74accd 100644 (file)
@@ -251,47 +251,6 @@ static void free_compress_info(struct Mailbox *m)
   FREE(&m->compress_info);
 }
 
-/**
- * escape_path - Escapes single quotes in a path for a command string
- * @param src the path to escape
- * @retval ptr The escaped string
- */
-static char *escape_path(char *src)
-{
-  static char dest[HUGE_STRING];
-  char *destp = dest;
-  int destsize = 0;
-
-  if (!src)
-    return NULL;
-
-  while (*src && (destsize < sizeof(dest) - 1))
-  {
-    if (*src != '\'')
-    {
-      *destp++ = *src++;
-      destsize++;
-    }
-    else
-    {
-      /* convert ' into '\'' */
-      if (destsize + 4 < sizeof(dest))
-      {
-        *destp++ = *src++;
-        *destp++ = '\\';
-        *destp++ = '\'';
-        *destp++ = '\'';
-        destsize += 4;
-      }
-      else
-        break;
-    }
-  }
-  *destp = '\0';
-
-  return dest;
-}
-
 /**
  * compress_format_str - Expand the filenames in a command string - Implements ::format_t
  *
@@ -314,11 +273,11 @@ static const char *compress_format_str(char *buf, size_t buflen, size_t col, int
   {
     case 'f':
       /* Compressed file */
-      snprintf(buf, buflen, "%s", NONULL(escape_path(m->realpath)));
+      snprintf(buf, buflen, "%s", NONULL(mutt_path_escape(m->realpath)));
       break;
     case 't':
       /* Plaintext, temporary file */
-      snprintf(buf, buflen, "%s", NONULL(escape_path(m->path)));
+      snprintf(buf, buflen, "%s", NONULL(mutt_path_escape(m->path)));
       break;
   }
   return src;
index 9f9371fdda7c75b997d533c2a9888db6e7665442..e0d7e2c26ef9be65d46a9a85e9592c18b220bfc9 100644 (file)
@@ -526,3 +526,44 @@ bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder)
   memmove(buf + 1, buf + flen + 1, rlen + 1);
   return true;
 }
+
+/**
+ * mutt_escape_path - Escapes single quotes in a path for a command string
+ * @param src the path to escape
+ * @retval ptr The escaped string
+ */
+char *mutt_path_escape(const char *src)
+{
+  static char dest[HUGE_STRING];
+  char *destp = dest;
+  int destsize = 0;
+
+  if (!src)
+    return NULL;
+
+  while (*src && (destsize < sizeof(dest) - 1))
+  {
+    if (*src != '\'')
+    {
+      *destp++ = *src++;
+      destsize++;
+    }
+    else
+    {
+      /* convert ' into '\'' */
+      if (destsize + 4 < sizeof(dest))
+      {
+        *destp++ = *src++;
+        *destp++ = '\\';
+        *destp++ = '\'';
+        *destp++ = '\'';
+        destsize += 4;
+      }
+      else
+        break;
+    }
+  }
+  *destp = '\0';
+
+  return dest;
+}
index 36c7cf6f5e15b2017e1f86e1c9a08f7acb8d227a..3319a8695b3536a61a910e34ac4ea68f95c8ddc6 100644 (file)
@@ -32,6 +32,7 @@ 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);
 char *      mutt_path_concatn(char *dst, size_t dstlen, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
 char *      mutt_path_dirname(const char *path);
+char *      mutt_path_escape(const char *src);
 bool        mutt_path_parent(char *buf, size_t buflen);
 bool        mutt_path_pretty(char *buf, size_t buflen, const char *homedir);
 size_t      mutt_path_realpath(char *buf);