Rocco Rutte:
[apps/madmutt.git] / browser.c
index 5cfd37e..3ed8a11 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -19,6 +19,8 @@
 #include "mapping.h"
 #include "sort.h"
 #include "browser.h"
 #include "mapping.h"
 #include "sort.h"
 #include "browser.h"
+#include "attach.h"
+
 #ifdef USE_IMAP
 #include "imap.h"
 #include "imap/mx_imap.h"
 #ifdef USE_IMAP
 #include "imap.h"
 #include "imap/mx_imap.h"
@@ -76,14 +78,14 @@ static void destroy_state (struct browser_state *state)
   int c;
 
   for (c = 0; c < state->entrylen; c++) {
   int c;
 
   for (c = 0; c < state->entrylen; c++) {
-    FREE (&((state->entry)[c].name));
-    FREE (&((state->entry)[c].desc));
-    FREE (&((state->entry)[c].st));
+    mem_free (&((state->entry)[c].name));
+    mem_free (&((state->entry)[c].desc));
+    mem_free (&((state->entry)[c].st));
   }
 #ifdef USE_IMAP
   }
 #ifdef USE_IMAP
-  FREE (&state->folder);
+  mem_free (&state->folder);
 #endif
 #endif
-  FREE (&state->entry);
+  mem_free (&state->entry);
 }
 
 static int browser_compare_subject (const void *a, const void *b)
 }
 
 static int browser_compare_subject (const void *a, const void *b)
@@ -91,7 +93,7 @@ static int browser_compare_subject (const void *a, const void *b)
   struct folder_file *pa = (struct folder_file *) a;
   struct folder_file *pb = (struct folder_file *) b;
 
   struct folder_file *pa = (struct folder_file *) a;
   struct folder_file *pb = (struct folder_file *) b;
 
-  int r = safe_strcoll (pa->name, pb->name);
+  int r = str_coll (pa->name, pb->name);
 
   return ((BrowserSort & SORT_REVERSE) ? -r : r);
 }
 
   return ((BrowserSort & SORT_REVERSE) ? -r : r);
 }
@@ -424,7 +426,7 @@ static void add_folder (MUTTMENU * m, struct browser_state *state,
 {
   if (state->entrylen == state->entrymax) {
     /* need to allocate more space */
 {
   if (state->entrylen == state->entrymax) {
     /* need to allocate more space */
-    safe_realloc (&state->entry,
+    mem_realloc (&state->entry,
                   sizeof (struct folder_file) * (state->entrymax += 256));
     memset (&state->entry[state->entrylen], 0,
             sizeof (struct folder_file) * 256);
                   sizeof (struct folder_file) * (state->entrymax += 256));
     memset (&state->entry[state->entrylen], 0,
             sizeof (struct folder_file) * 256);
@@ -437,13 +439,13 @@ static void add_folder (MUTTMENU * m, struct browser_state *state,
     (state->entry)[state->entrylen].mtime = s->st_mtime;
     (state->entry)[state->entrylen].size = s->st_size;
 
     (state->entry)[state->entrylen].mtime = s->st_mtime;
     (state->entry)[state->entrylen].size = s->st_size;
 
-    (state->entry)[state->entrylen].st = safe_malloc (sizeof (struct stat));
+    (state->entry)[state->entrylen].st = mem_malloc (sizeof (struct stat));
     memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat));
   }
 
   (state->entry)[state->entrylen].new = new;
     memcpy ((state->entry)[state->entrylen].st, s, sizeof (struct stat));
   }
 
   (state->entry)[state->entrylen].new = new;
-  (state->entry)[state->entrylen].name = safe_strdup (name);
-  (state->entry)[state->entrylen].desc = safe_strdup (name);
+  (state->entry)[state->entrylen].name = str_dup (name);
+  (state->entry)[state->entrylen].desc = str_dup (name);
 #ifdef USE_IMAP
   (state->entry)[state->entrylen].imap = 0;
 #endif
 #ifdef USE_IMAP
   (state->entry)[state->entrylen].imap = 0;
 #endif
@@ -459,7 +461,7 @@ static void init_state (struct browser_state *state, MUTTMENU * menu)
   state->entrylen = 0;
   state->entrymax = 256;
   state->entry =
   state->entrylen = 0;
   state->entrymax = 256;
   state->entry =
-    (struct folder_file *) safe_calloc (state->entrymax,
+    (struct folder_file *) mem_calloc (state->entrymax,
                                         sizeof (struct folder_file));
 #ifdef USE_IMAP
   state->imap_browse = 0;
                                         sizeof (struct folder_file));
 #ifdef USE_IMAP
   state->imap_browse = 0;
@@ -485,7 +487,7 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state,
       if (!(data = (NNTP_DATA *) tmp->data))
         continue;
       if (prefix && *prefix && strncmp (prefix, data->group,
       if (!(data = (NNTP_DATA *) tmp->data))
         continue;
       if (prefix && *prefix && strncmp (prefix, data->group,
-                                        mutt_strlen (prefix)) != 0)
+                                        str_len (prefix)) != 0)
         continue;
       if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not))
         continue;
         continue;
       if (!((regexec (Mask.rx, data->group, 0, NULL, 0) == 0) ^ Mask.not))
         continue;
@@ -530,11 +532,11 @@ static int examine_directory (MUTTMENU * menu, struct browser_state *state,
     init_state (state, menu);
 
     while ((de = readdir (dp)) != NULL) {
     init_state (state, menu);
 
     while ((de = readdir (dp)) != NULL) {
-      if (mutt_strcmp (de->d_name, ".") == 0)
+      if (str_cmp (de->d_name, ".") == 0)
         continue;               /* we don't need . */
 
       if (prefix && *prefix
         continue;               /* we don't need . */
 
       if (prefix && *prefix
-          && safe_strncmp (prefix, de->d_name, mutt_strlen (prefix)) != 0)
+          && str_ncmp (prefix, de->d_name, str_len (prefix)) != 0)
         continue;
       if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not))
         continue;
         continue;
       if (!((regexec (Mask.rx, de->d_name, 0, NULL, 0) == 0) ^ Mask.not))
         continue;
@@ -775,7 +777,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
     }
     else {
 #endif
     }
     else {
 #endif
-      for (i = mutt_strlen (f) - 1; i > 0 && f[i] != '/'; i--);
+      for (i = str_len (f) - 1; i > 0 && f[i] != '/'; i--);
       if (i > 0) {
         if (f[0] == '/') {
           if (i > sizeof (LastDir) - 1)
       if (i > 0) {
         if (f[0] == '/') {
           if (i > sizeof (LastDir) - 1)
@@ -785,8 +787,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         }
         else {
           getcwd (LastDir, sizeof (LastDir));
         }
         else {
           getcwd (LastDir, sizeof (LastDir));
-          safe_strcat (LastDir, sizeof (LastDir), "/");
-          safe_strncat (LastDir, sizeof (LastDir), f, i);
+          str_cat (LastDir, sizeof (LastDir), "/");
+          str_ncat (LastDir, sizeof (LastDir), f, i);
         }
       }
       else {
         }
       }
       else {
@@ -891,8 +893,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
           /* save the old directory */
           strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
 
           /* save the old directory */
           strfcpy (OldLastDir, LastDir, sizeof (OldLastDir));
 
-          if (mutt_strcmp (state.entry[menu->current].name, "..") == 0) {
-            if (mutt_strcmp ("..", LastDir + mutt_strlen (LastDir) - 2) == 0)
+          if (str_cmp (state.entry[menu->current].name, "..") == 0) {
+            if (str_cmp ("..", LastDir + str_len (LastDir) - 2) == 0)
               strcat (LastDir, "/..");  /* __STRCAT_CHECKED__ */
             else {
               char *p = strrchr (LastDir + 1, '/');
               strcat (LastDir, "/..");  /* __STRCAT_CHECKED__ */
             else {
               char *p = strrchr (LastDir + 1, '/');
@@ -920,7 +922,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
             strfcpy (LastDir, state.entry[menu->current].name,
                      sizeof (LastDir));
             /* tack on delimiter here */
             strfcpy (LastDir, state.entry[menu->current].name,
                      sizeof (LastDir));
             /* tack on delimiter here */
-            n = mutt_strlen (LastDir) + 1;
+            n = str_len (LastDir) + 1;
 
             /* special case "" needs no delimiter */
             url_parse_ciss (&url, state.entry[menu->current].name);
 
             /* special case "" needs no delimiter */
             url_parse_ciss (&url, state.entry[menu->current].name);
@@ -996,7 +998,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
 
         if (menu->tagged) {
           *numfiles = menu->tagged;
 
         if (menu->tagged) {
           *numfiles = menu->tagged;
-          tfiles = safe_calloc (*numfiles, sizeof (char *));
+          tfiles = mem_calloc (*numfiles, sizeof (char *));
           for (i = 0, j = 0; i < state.entrylen; i++) {
             struct folder_file ff = state.entry[i];
             char full[_POSIX_PATH_MAX];
           for (i = 0, j = 0; i < state.entrylen; i++) {
             struct folder_file ff = state.entry[i];
             char full[_POSIX_PATH_MAX];
@@ -1004,16 +1006,16 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
             if (ff.tagged) {
               mutt_concat_path (full, LastDir, ff.name, sizeof (full));
               mutt_expand_path (full, sizeof (full));
             if (ff.tagged) {
               mutt_concat_path (full, LastDir, ff.name, sizeof (full));
               mutt_expand_path (full, sizeof (full));
-              tfiles[j++] = safe_strdup (full);
+              tfiles[j++] = str_dup (full);
             }
           }
           *files = tfiles;
         }
         else if (f[0]) {        /* no tagged entries. return selected entry */
           *numfiles = 1;
             }
           }
           *files = tfiles;
         }
         else if (f[0]) {        /* no tagged entries. return selected entry */
           *numfiles = 1;
-          tfiles = safe_calloc (*numfiles, sizeof (char *));
+          tfiles = mem_calloc (*numfiles, sizeof (char *));
           mutt_expand_path (f, flen);
           mutt_expand_path (f, flen);
-          tfiles[0] = safe_strdup (f);
+          tfiles[0] = str_dup (f);
           *files = tfiles;
         }
       }
           *files = tfiles;
         }
       }
@@ -1091,8 +1093,8 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         if (mutt_yesorno (msg, M_NO) == M_YES) {
           if (!imap_delete_mailbox (Context, mx)) {
             /* free the mailbox from the browser */
         if (mutt_yesorno (msg, M_NO) == M_YES) {
           if (!imap_delete_mailbox (Context, mx)) {
             /* free the mailbox from the browser */
-            FREE (&((state.entry)[nentry].name));
-            FREE (&((state.entry)[nentry].desc));
+            mem_free (&((state.entry)[nentry].name));
+            mem_free (&((state.entry)[nentry].desc));
             /* and move all other entries up */
             if (nentry + 1 < state.entrylen)
               memmove (state.entry + nentry, state.entry + nentry + 1,
             /* and move all other entries up */
             if (nentry + 1 < state.entrylen)
               memmove (state.entry + nentry, state.entry + nentry + 1,
@@ -1107,7 +1109,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         }
         else
           mutt_message _("Mailbox not deleted.");
         }
         else
           mutt_message _("Mailbox not deleted.");
-        FREE (&mx.mbox);
+        mem_free (&mx.mbox);
       }
       break;
 #endif
       }
       break;
 #endif
@@ -1125,7 +1127,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
 #endif
       {
         /* add '/' at the end of the directory name if not already there */
 #endif
       {
         /* add '/' at the end of the directory name if not already there */
-        int len = mutt_strlen (LastDir);
+        int len = str_len (LastDir);
 
         if (len && LastDir[len - 1] != '/' && sizeof (buf) > len)
           buf[len] = '/';
 
         if (len && LastDir[len - 1] != '/' && sizeof (buf) > len)
           buf[len] = '/';
@@ -1179,7 +1181,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
 
       strfcpy (buf, NONULL (Mask.pattern), sizeof (buf));
       if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) {
 
       strfcpy (buf, NONULL (Mask.pattern), sizeof (buf));
       if (mutt_get_field (_("File Mask: "), buf, sizeof (buf), 0) == 0) {
-        regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t));
+        regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t));
         char *s = buf;
         int not = 0, err;
 
         char *s = buf;
         int not = 0, err;
 
@@ -1197,13 +1199,13 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
           regerror (err, rx, buf, sizeof (buf));
           regfree (rx);
         if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
           regerror (err, rx, buf, sizeof (buf));
           regfree (rx);
-          FREE (&rx);
+          mem_free (&rx);
           mutt_error ("%s", buf);
         }
         else {
           str_replace (&Mask.pattern, buf);
           regfree (Mask.rx);
           mutt_error ("%s", buf);
         }
         else {
           str_replace (&Mask.pattern, buf);
           regfree (Mask.rx);
-          FREE (&Mask.rx);
+          mem_free (&Mask.rx);
           Mask.rx = rx;
           Mask.not = not;
 
           Mask.rx = rx;
           Mask.not = not;
 
@@ -1384,11 +1386,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
            folder.ff->st = NULL;
            folder.ff->is_new = nd->new;
            folder.ff->nd = nd;
            folder.ff->st = NULL;
            folder.ff->is_new = nd->new;
            folder.ff->nd = nd;
-           FREE (&f->desc);
+           mem_free (&f->desc);
            mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
                  newsgroup_format_str, (unsigned long) &folder,
                  M_FORMAT_ARROWCURSOR);
            mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
                  newsgroup_format_str, (unsigned long) &folder,
                  M_FORMAT_ARROWCURSOR);
-           f->desc = safe_strdup (buffer); */
+           f->desc = str_dup (buffer); */
           if (menu->current + 1 < menu->max)
             menu->current++;
           menu->redraw = REDRAW_MOTION_RESYNCH;
           if (menu->current + 1 < menu->max)
             menu->current++;
           menu->redraw = REDRAW_MOTION_RESYNCH;
@@ -1428,7 +1430,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
     case OP_SUBSCRIBE_PATTERN:
     case OP_UNSUBSCRIBE_PATTERN:
       if (option (OPTNEWS)) {
     case OP_SUBSCRIBE_PATTERN:
     case OP_UNSUBSCRIBE_PATTERN:
       if (option (OPTNEWS)) {
-        regex_t *rx = (regex_t *) safe_malloc (sizeof (regex_t));
+        regex_t *rx = (regex_t *) mem_malloc (sizeof (regex_t));
         char *s = buf;
         int j = menu->current;
         NNTP_DATA *nd;
         char *s = buf;
         int j = menu->current;
         NNTP_DATA *nd;
@@ -1444,14 +1446,14 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
           else
             snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
           if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) {
           else
             snprintf (tmp, sizeof (tmp), _("Unsubscribe pattern: "));
           if (mutt_get_field (tmp, buf, sizeof (buf), 0) != 0 || !buf[0]) {
-            FREE (&rx);
+            mem_free (&rx);
             break;
           }
 
           if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
             regerror (err, rx, buf, sizeof (buf));
             regfree (rx);
             break;
           }
 
           if ((err = REGCOMP (rx, s, REG_NOSUB)) != 0) {
             regerror (err, rx, buf, sizeof (buf));
             regfree (rx);
-            FREE (&rx);
+            mem_free (&rx);
             mutt_error ("%s", buf);
             break;
           }
             mutt_error ("%s", buf);
             break;
           }
@@ -1482,11 +1484,11 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
                folder.f = NULL;
                folder.new = nd->new;
                folder.nd = nd;
                folder.f = NULL;
                folder.new = nd->new;
                folder.nd = nd;
-               FREE (&f->desc);
+               mem_free (&f->desc);
                mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
                        newsgroup_format_str, (unsigned long) &folder,
                        M_FORMAT_ARROWCURSOR);
                mutt_FormatString (buffer, sizeof (buffer), NONULL(GroupFormat),
                        newsgroup_format_str, (unsigned long) &folder,
                        M_FORMAT_ARROWCURSOR);
-               f->desc = safe_strdup (buffer);
+               f->desc = str_dup (buffer);
              } */
           }
           if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) {
              } */
           }
           if (i == OP_BROWSER_SUBSCRIBE || i == OP_BROWSER_UNSUBSCRIBE) {
@@ -1516,7 +1518,7 @@ void _mutt_select_file (char *f, size_t flen, int flags, char ***files,
         nntp_clear_cacheindex (news);
         if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE)
           regfree (rx);
         nntp_clear_cacheindex (news);
         if (i != OP_BROWSER_SUBSCRIBE && i != OP_BROWSER_UNSUBSCRIBE)
           regfree (rx);
-        FREE (&rx);
+        mem_free (&rx);
       }
 #ifdef USE_IMAP
       else
       }
 #ifdef USE_IMAP
       else