more constness.
[apps/madmutt.git] / complete.c
index b84d0b1..f451e1a 100644 (file)
@@ -21,6 +21,7 @@
 #endif
 
 #include "lib/str.h"
+#include "lib/debug.h"
 
 #include <dirent.h>
 #include <string.h>
@@ -47,7 +48,7 @@ int mutt_complete (char *s, size_t slen)
   char imap_path[LONG_STRING];
 #endif
 
-  dprint (2, (debugfile, "mutt_complete: completing %s\n", s));
+  debug_print (2, ("completing %s\n", s));
 
 #ifdef USE_NNTP
   if (option (OPTNEWS)) {
@@ -59,7 +60,7 @@ int mutt_complete (char *s, size_t slen)
      * special case to handle when there is no filepart yet.
      * find the first subscribed newsgroup
      */
-    if ((len = safe_strlen (filepart)) == 0) {
+    if ((len = str_len (filepart)) == 0) {
       for (; l; l = l->next) {
         NNTP_DATA *data = (NNTP_DATA *) l->data;
 
@@ -76,7 +77,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) {
+          str_ncmp (data->group, filepart, len) == 0) {
         if (init) {
           for (i = 0; filepart[i] && data->group[i]; i++) {
             if (filepart[i] != data->group[i]) {
@@ -102,17 +103,13 @@ 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, q, s + 1, sizeof (imap_path));
   }
   else
     strfcpy (imap_path, s, sizeof (imap_path));
 
-  if (mx_is_imap (imap_path))
+  if (mx_get_magic (imap_path) == M_IMAP)
     return imap_complete (s, slen, imap_path);
 #endif
 
@@ -167,9 +164,7 @@ int mutt_complete (char *s, size_t slen)
   }
 
   if (dirp == NULL) {
-    dprint (1,
-            (debugfile, "mutt_complete(): %s: %s (errno %d).\n", exp_dirpart,
-             strerror (errno), errno));
+    debug_print (1, ("%s: %s (errno %d).\n", exp_dirpart, strerror (errno), errno));
     return (-1);
   }
 
@@ -177,10 +172,10 @@ 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 = safe_strlen (filepart)) == 0) {
+  if ((len = str_len (filepart)) == 0) {
     while ((de = readdir (dirp)) != NULL) {
-      if (safe_strcmp (".", de->d_name) != 0
-          && safe_strcmp ("..", de->d_name) != 0) {
+      if (str_cmp (".", de->d_name) != 0
+          && str_cmp ("..", de->d_name) != 0) {
         strfcpy (filepart, de->d_name, sizeof (filepart));
         init++;
         break;
@@ -189,7 +184,7 @@ int mutt_complete (char *s, size_t slen)
   }
 
   while ((de = readdir (dirp)) != NULL) {
-    if (safe_strncmp (de->d_name, filepart, len) == 0) {
+    if (str_ncmp (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]) {
@@ -208,14 +203,14 @@ int mutt_complete (char *s, size_t slen)
         /* check to see if it is a directory */
         if (dirpart[0]) {
           strfcpy (buf, exp_dirpart, sizeof (buf));
-          strfcpy (buf + safe_strlen (buf), "/", sizeof (buf) - safe_strlen (buf));
+          strfcpy (buf + str_len (buf), "/", sizeof (buf) - str_len (buf));
         }
         else
           buf[0] = 0;
-        strfcpy (buf + safe_strlen (buf), filepart, sizeof (buf) - safe_strlen (buf));
+        strfcpy (buf + str_len (buf), filepart, sizeof (buf) - str_len (buf));
         if (stat (buf, &st) != -1 && (st.st_mode & S_IFDIR))
-          strfcpy (filepart + safe_strlen (filepart), "/",
-                   sizeof (filepart) - safe_strlen (filepart));
+          strfcpy (filepart + str_len (filepart), "/",
+                   sizeof (filepart) - str_len (filepart));
         init = 1;
       }
     }
@@ -224,10 +219,10 @@ int mutt_complete (char *s, size_t slen)
 
   if (dirpart[0]) {
     strfcpy (s, dirpart, slen);
-    if (safe_strcmp ("/", dirpart) != 0 && dirpart[0] != '='
+    if (str_cmp ("/", dirpart) != 0 && dirpart[0] != '='
         && dirpart[0] != '+')
-      strfcpy (s + safe_strlen (s), "/", slen - safe_strlen (s));
-    strfcpy (s + safe_strlen (s), filepart, slen - safe_strlen (s));
+      strfcpy (s + str_len (s), "/", slen - str_len (s));
+    strfcpy (s + str_len (s), filepart, slen - str_len (s));
   }
   else
     strfcpy (s, filepart, slen);