Rocco Rutte:
[apps/madmutt.git] / curs_lib.c
index 4eab988..dc53a27 100644 (file)
 #include "pager.h"
 #include "mbyte.h"
 
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+#include "lib/debug.h"
+
 #include <termios.h>
 #include <sys/types.h>
 #include <fcntl.h>
@@ -139,7 +144,7 @@ int mutt_get_password (char *msg, char *buf, size_t buflen)
   CLEARLINE (LINES - 1);
   addstr (msg);
   set_option (OPTUNBUFFEREDINPUT);
-  rc = mutt_enter_string (buf, buflen, LINES - 1, mutt_strlen (msg), M_PASS);
+  rc = mutt_enter_string (buf, buflen, LINES - 1, safe_strlen (msg), M_PASS);
   unset_option (OPTUNBUFFEREDINPUT);
   CLEARLINE (LINES - 1);
   return (rc);
@@ -213,7 +218,7 @@ int mutt_yesorno (const char *msg, int def)
   answer_string = safe_malloc (COLS + 1);
   snprintf (answer_string, COLS + 1, " ([%s]/%s): ", def == M_YES ? yes : no,
             def == M_YES ? no : yes);
-  answer_string_len = mutt_strlen (answer_string);
+  answer_string_len = safe_strlen (answer_string);
   printw ("%.*s%s", COLS - answer_string_len, msg, answer_string);
   FREE (&answer_string);
 
@@ -233,7 +238,7 @@ int mutt_yesorno (const char *msg, int def)
 #else
     if (
 #endif
-         (tolower (ch.ch) == 'y')) {
+         (tolower (ch.ch) == *yes)) {
       def = M_YES;
       break;
     }
@@ -241,7 +246,7 @@ int mutt_yesorno (const char *msg, int def)
 #ifdef HAVE_LANGINFO_YESEXPR
               reno_ok ? (regexec (&reno, answer, 0, 0, 0) == 0) :
 #endif
-              (tolower (ch.ch) == 'n')) {
+              (tolower (ch.ch) == *no)) {
       def = M_NO;
       break;
     }
@@ -289,7 +294,7 @@ void mutt_curses_error (const char *fmt, ...)
   vsnprintf (Errorbuf, sizeof (Errorbuf), fmt, ap);
   va_end (ap);
 
-  dprint (1, (debugfile, "%s\n", Errorbuf));
+  debug_print (1, ("%s\n", Errorbuf));
   mutt_format_string (TmpErrorbuf, sizeof (TmpErrorbuf),
                       0, COLS - 2, 0, 0, Errorbuf, sizeof (Errorbuf), 0);
   snprintf (Errorbuf, sizeof (Errorbuf), "%s", TmpErrorbuf);    /* overkill */
@@ -357,13 +362,12 @@ void mutt_endwin (const char *msg)
   }
 }
 
-void mutt_perror (const char *s)
+void _mutt_perror (const char *s, const char* filename, int line)
 {
   char *p = strerror (errno);
 
-  dprint (1, (debugfile, "%s: %s (errno = %d)\n", s,
-              p ? p : "unknown error", errno));
-  mutt_error ("%s: %s (errno = %d)", s, p ? p : _("unknown error"), errno);
+  debug_print (1, ("%s: %s (errno = %d)\n", s, p ? p : "unknown error", errno));
+  mutt_error ("%s: %s (errno = %d) from %s:%i", s, p ? p : _("unknown error"), errno, filename, line);
 }
 
 int mutt_any_key_to_continue (const char *s)
@@ -399,7 +403,7 @@ int mutt_do_pager (const char *banner,
 {
   int rc;
 
-  if (!Pager || mutt_strcmp (Pager, "builtin") == 0)
+  if (!Pager || safe_strcmp (Pager, "builtin") == 0)
     rc = mutt_pager (banner, tempfile, do_color, info);
   else {
     char cmd[STRING];
@@ -444,7 +448,7 @@ int _mutt_enter_fname (const char *prompt, char *buf, size_t blen,
     *redraw = REDRAW_FULL;
   }
   else {
-    char *pc = safe_malloc (mutt_strlen (prompt) + 3);
+    char *pc = safe_malloc (safe_strlen (prompt) + 3);
 
     sprintf (pc, "%s: ", prompt);       /* __SPRINTF_CHECKED__ */
     mutt_ungetch (ch.op ? 0 : ch.ch, ch.op ? ch.op : 0);
@@ -524,7 +528,7 @@ int mutt_multi_choice (char *prompt, char *letters)
       }
       else if (ch.ch <= '9' && ch.ch > '0') {
         choice = ch.ch - '0';
-        if (choice <= mutt_strlen (letters))
+        if (choice <= safe_strlen (letters))
           break;
       }
     }
@@ -644,7 +648,7 @@ static void mutt_format_s_x (char *dest,
   }
 
   mutt_format_string (dest, destlen, min_width, max_width,
-                      right_justify, ' ', s, mutt_strlen (s), arboreal);
+                      right_justify, ' ', s, safe_strlen (s), arboreal);
 }
 
 void mutt_format_s (char *dest,
@@ -669,7 +673,7 @@ void mutt_paddstr (int n, const char *s)
   wchar_t wc;
   int w;
   size_t k;
-  size_t len = mutt_strlen (s);
+  size_t len = safe_strlen (s);
   mbstate_t mbstate;
 
   memset (&mbstate, 0, sizeof (mbstate));
@@ -693,7 +697,7 @@ void mutt_paddstr (int n, const char *s)
 }
 
 /*
- * mutt_strwidth is like mutt_strlen except that it returns the width
+ * mutt_strwidth is like safe_strlen except that it returns the width
  * refering to the number of characters cells.
  */
 
@@ -707,7 +711,7 @@ int mutt_strwidth (const char *s)
   if (!s)
     return 0;
 
-  n = mutt_strlen (s);
+  n = safe_strlen (s);
 
   memset (&mbstate, 0, sizeof (mbstate));
   for (w = 0; n && (k = mbrtowc (&wc, s, n, &mbstate)); s += k, n -= k) {