Revert "we use glibc, and gconv. Don't need our own transcoding stuff, glibc does"
[apps/madmutt.git] / state.c
diff --git a/state.c b/state.c
index 4d4c19a..f21db7e 100644 (file)
--- a/state.c
+++ b/state.c
@@ -6,18 +6,13 @@
  * It's licensed under the GNU General Public License,
  * please see the file GPL in the top level source directory.
  */
-#if HAVE_CONFIG_H
-#include "config.h"
-#endif
 
-#include <stdlib.h>
-#include <stdio.h>
+#include <lib-lib/lib-lib.h>
 
-#include <lib-lib/debug.h>
+#include <lib-mime/rfc3676.h>
 
 #include "mutt.h"
 #include "state.h"
-#include "rfc3676.h"
 
 static void state_prefix_put (const char *d, ssize_t dlen, STATE * s)
 {
@@ -36,7 +31,7 @@ void mutt_convert_to_state (iconv_t cd, char *bufi, ssize_t * l, STATE * s)
   ssize_t ibl, obl;
 
   if (!bufi) {
-    if (cd != (iconv_t) (-1)) {
+    if (cd != MUTT_ICONV_ERROR) {
       ob = bufo, obl = sizeof (bufo);
       my_iconv(cd, 0, 0, &ob, &obl);
       if (ob != bufo)
@@ -47,7 +42,7 @@ void mutt_convert_to_state (iconv_t cd, char *bufi, ssize_t * l, STATE * s)
     return;
   }
 
-  if (cd == (iconv_t) (-1)) {
+  if (cd == MUTT_ICONV_ERROR) {
     state_prefix_put (bufi, *l, s);
     *l = 0;
     return;
@@ -74,12 +69,9 @@ void state_prefix_putc (char c, STATE * s)
     Quotebuf[i++] = c;
     Quotebuf[i] = '\0';
     if (i == sizeof (Quotebuf) - 1 || c == '\n') {
-      char buf[2 * SHORT_STRING];
+      char buf[2 * STRING];
       int j = 0, offset = 0;
       regmatch_t pmatch[1];
-#ifdef DEBUG
-      unsigned char save = '\0';
-#endif
 
       state_reset_prefix (s);
       while (regexec
@@ -95,21 +87,12 @@ void state_prefix_putc (char c, STATE * s)
         for (i = 0; i < offset; i++)
           if (Quotebuf[i] != ' ')
             j = i;
-        strncpy (buf, Quotebuf, j + 1);
-        strcpy (buf + j + 1, Quotebuf + j);
+        m_strncpy(buf, sizeof(buf), Quotebuf, j + 1);
+        m_strcpy(buf + j + 1, sizeof(buf) - j - 1, Quotebuf + j);
       }
       else
         snprintf (buf, sizeof (buf), "%s%s", NONULL (s->prefix), Quotebuf);
 
-#ifdef DEBUG
-      if (m_strlen(buf) >= 2) {
-        save = buf[m_strlen(buf) - 1];
-        buf[m_strlen(buf) - 1] = '\0';
-        debug_print (2, ("buf = '%s'\n", buf));
-        buf[m_strlen(buf)] = save;
-      }
-#endif
-
       state_puts (buf, s);
     }
   }
@@ -136,7 +119,7 @@ int state_printf (STATE * s, const char *fmt, ...)
 
 void state_mark_attach (STATE * s)
 {
-  if ((s->flags & M_DISPLAY) && !m_strcmp(Pager, "builtin"))
+  if (s->flags & M_DISPLAY)
     state_puts (AttachmentMarker, s);
 }