add more encoding arrays
[apps/madmutt.git] / complete.c
index 2c0f14e..bd2bb05 100644 (file)
@@ -20,7 +20,8 @@
 #include "nntp.h"
 #endif
 
-#include "lib/str.h"
+#include <lib-lib/str.h>
+#include <lib-lib/file.h>
 #include "lib/debug.h"
 
 #include <dirent.h>
@@ -54,18 +55,18 @@ int mutt_complete (char *s, size_t slen)
   if (option (OPTNEWS)) {
     LIST *l = CurrentNewsSrv->list;
 
-    strfcpy (filepart, s, sizeof (filepart));
+    m_strcpy(filepart, sizeof(filepart), s);
 
     /*
      * special case to handle when there is no filepart yet.
      * find the first subscribed newsgroup
      */
-    if ((len = mutt_strlen (filepart)) == 0) {
+    if ((len = m_strlen(filepart)) == 0) {
       for (; l; l = l->next) {
         NNTP_DATA *data = (NNTP_DATA *) l->data;
 
         if (data && data->subscribed) {
-          strfcpy (filepart, data->group, sizeof (filepart));
+          m_strcpy(filepart, sizeof(filepart), data->group);
           init++;
           l = l->next;
           break;
@@ -77,7 +78,7 @@ int mutt_complete (char *s, size_t slen)
       NNTP_DATA *data = (NNTP_DATA *) l->data;
 
       if (data && data->subscribed &&
-          safe_strncmp (data->group, filepart, len) == 0) {
+          m_strncmp(data->group, filepart, len) == 0) {
         if (init) {
           for (i = 0; filepart[i] && data->group[i]; i++) {
             if (filepart[i] != data->group[i]) {
@@ -88,7 +89,7 @@ int mutt_complete (char *s, size_t slen)
           filepart[i] = 0;
         }
         else {
-          strfcpy (filepart, data->group, sizeof (filepart));
+          m_strcpy(filepart, sizeof(filepart), data->group);
           init = 1;
         }
       }
@@ -103,15 +104,11 @@ int mutt_complete (char *s, size_t slen)
 #ifdef USE_IMAP
   /* we can use '/' as a delimiter, imap_complete rewrites it */
   if (*s == '=' || *s == '+' || *s == '!') {
-    if (*s == '!')
-      p = NONULL (Spoolfile);
-    else
-      p = NONULL (Maildir);
-
-    mutt_concat_path (imap_path, p, s + 1, sizeof (imap_path));
+      const char *q = NONULL(*s == '!' ? Spoolfile : Maildir);
+      mutt_concat_path(imap_path, sizeof(imap_path), q, s + 1);
   }
   else
-    strfcpy (imap_path, s, sizeof (imap_path));
+    m_strcpy(imap_path, sizeof(imap_path), s);
 
   if (mx_get_magic (imap_path) == M_IMAP)
     return imap_complete (s, slen, imap_path);
@@ -121,40 +118,40 @@ int mutt_complete (char *s, size_t slen)
     dirpart[0] = *s;
     dirpart[1] = 0;
     if (*s == '!')
-      strfcpy (exp_dirpart, NONULL (Spoolfile), sizeof (exp_dirpart));
+      m_strcpy(exp_dirpart, sizeof(exp_dirpart), NONULL(Spoolfile));
     else
-      strfcpy (exp_dirpart, NONULL (Maildir), sizeof (exp_dirpart));
+      m_strcpy(exp_dirpart, sizeof(exp_dirpart), NONULL(Maildir));
     if ((p = strrchr (s, '/'))) {
       char buf[_POSIX_PATH_MAX];
 
       *p++ = 0;
-      mutt_concat_path (buf, exp_dirpart, s + 1, sizeof (buf));
-      strfcpy (exp_dirpart, buf, sizeof (exp_dirpart));
+      mutt_concat_path(buf, sizeof(buf), exp_dirpart, s + 1);
+      m_strcpy(exp_dirpart, sizeof(exp_dirpart), buf);
       snprintf (buf, sizeof (buf), "%s%s/", dirpart, s + 1);
-      strfcpy (dirpart, buf, sizeof (dirpart));
-      strfcpy (filepart, p, sizeof (filepart));
+      m_strcpy(dirpart, sizeof(dirpart), buf);
+      m_strcpy(filepart, sizeof(filepart), p);
     }
     else
-      strfcpy (filepart, s + 1, sizeof (filepart));
+      m_strcpy(filepart, sizeof(filepart), s + 1);
     dirp = opendir (exp_dirpart);
   }
   else {
     if ((p = strrchr (s, '/'))) {
       if (p == s) {             /* absolute path */
         p = s + 1;
-        strfcpy (dirpart, "/", sizeof (dirpart));
+        m_strcpy(dirpart, sizeof(dirpart), "/");
         exp_dirpart[0] = 0;
-        strfcpy (filepart, p, sizeof (filepart));
+        m_strcpy(filepart, sizeof(filepart), p);
         dirp = opendir (dirpart);
       }
       else {
         *p = 0;
         len = (size_t) (p - s);
-        strncpy (dirpart, s, len);
+        memcpy(dirpart, s, len);
         dirpart[len] = 0;
         p++;
-        strfcpy (filepart, p, sizeof (filepart));
-        strfcpy (exp_dirpart, dirpart, sizeof (exp_dirpart));
+        m_strcpy(filepart, sizeof(filepart), p);
+        m_strcpy(exp_dirpart, sizeof(exp_dirpart), dirpart);
         mutt_expand_path (exp_dirpart, sizeof (exp_dirpart));
         dirp = opendir (exp_dirpart);
       }
@@ -162,7 +159,7 @@ int mutt_complete (char *s, size_t slen)
     else {
       /* no directory name, so assume current directory. */
       dirpart[0] = 0;
-      strfcpy (filepart, s, sizeof (filepart));
+      m_strcpy(filepart, sizeof(filepart), s);
       dirp = opendir (".");
     }
   }
@@ -176,11 +173,11 @@ int mutt_complete (char *s, size_t slen)
    * special case to handle when there is no filepart yet.  find the first
    * file/directory which is not ``.'' or ``..''
    */
-  if ((len = mutt_strlen (filepart)) == 0) {
+  if ((len = m_strlen(filepart)) == 0) {
     while ((de = readdir (dirp)) != NULL) {
-      if (mutt_strcmp (".", de->d_name) != 0
-          && mutt_strcmp ("..", de->d_name) != 0) {
-        strfcpy (filepart, de->d_name, sizeof (filepart));
+      if (m_strcmp(".", de->d_name) != 0
+          && m_strcmp("..", de->d_name) != 0) {
+        m_strcpy(filepart, sizeof(filepart), de->d_name);
         init++;
         break;
       }
@@ -188,7 +185,7 @@ int mutt_complete (char *s, size_t slen)
   }
 
   while ((de = readdir (dirp)) != NULL) {
-    if (safe_strncmp (de->d_name, filepart, len) == 0) {
+    if (m_strncmp(de->d_name, filepart, len) == 0) {
       if (init) {
         for (i = 0; filepart[i] && de->d_name[i]; i++) {
           if (filepart[i] != de->d_name[i]) {
@@ -202,19 +199,19 @@ int mutt_complete (char *s, size_t slen)
         char buf[_POSIX_PATH_MAX];
         struct stat st;
 
-        strfcpy (filepart, de->d_name, sizeof (filepart));
+        m_strcpy(filepart, sizeof(filepart), de->d_name);
 
         /* check to see if it is a directory */
         if (dirpart[0]) {
-          strfcpy (buf, exp_dirpart, sizeof (buf));
-          strfcpy (buf + mutt_strlen (buf), "/", sizeof (buf) - mutt_strlen (buf));
+          m_strcpy(buf, sizeof(buf), exp_dirpart);
+          m_strcpy(buf + m_strlen(buf), sizeof(buf) - m_strlen(buf), "/");
         }
         else
           buf[0] = 0;
-        strfcpy (buf + mutt_strlen (buf), filepart, sizeof (buf) - mutt_strlen (buf));
+        m_strcpy(buf + m_strlen(buf), sizeof(buf) - m_strlen(buf), filepart);
         if (stat (buf, &st) != -1 && (st.st_mode & S_IFDIR))
-          strfcpy (filepart + mutt_strlen (filepart), "/",
-                   sizeof (filepart) - mutt_strlen (filepart));
+          m_strcpy(filepart + m_strlen(filepart),
+                   sizeof(filepart) - m_strlen(filepart), "/");
         init = 1;
       }
     }
@@ -222,14 +219,14 @@ int mutt_complete (char *s, size_t slen)
   closedir (dirp);
 
   if (dirpart[0]) {
-    strfcpy (s, dirpart, slen);
-    if (mutt_strcmp ("/", dirpart) != 0 && dirpart[0] != '='
+    m_strcpy(s, slen, dirpart);
+    if (m_strcmp("/", dirpart) != 0 && dirpart[0] != '='
         && dirpart[0] != '+')
-      strfcpy (s + mutt_strlen (s), "/", slen - mutt_strlen (s));
-    strfcpy (s + mutt_strlen (s), filepart, slen - mutt_strlen (s));
+      m_strcpy(s + m_strlen(s), slen - m_strlen(s), "/");
+    m_strcpy(s + m_strlen(s), slen - m_strlen(s), filepart);
   }
   else
-    strfcpy (s, filepart, slen);
+    m_strcpy(s, slen, filepart);
 
   return (init ? 0 : -1);
 }