Revert "we use glibc, and gconv. Don't need our own transcoding stuff, glibc does"
[apps/madmutt.git] / thread.c
index 36ed25e..c5cc040 100644 (file)
--- a/thread.c
+++ b/thread.c
@@ -7,20 +7,12 @@
  * please see the file GPL in the top level source directory.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
 
 #include "mutt.h"
 #include "sort.h"
 #include "thread.h"
 
-#include "lib/mem.h"
-#include "lib/intl.h"
-
-#include <string.h>
-#include <ctype.h>
-
 #define VISIBLE(hdr, ctx) (hdr->virtual >= 0 || (hdr->collapsed && (!ctx->pattern || hdr->limited)))
 
 /* determine whether a is a descendant of b */
@@ -123,13 +115,13 @@ static void calculate_visibility (CONTEXT * ctx, int *max_depth)
     tree = tree->next;
   *max_depth = 0;
 
-  FOREVER {
+  for (;;) {
     if (depth > *max_depth)
       *max_depth = depth;
 
     tree->subtree_visible = 0;
     if (tree->message) {
-      mem_free (&tree->message->tree);
+      p_delete(&tree->message->tree);
       if (VISIBLE (tree->message, ctx)) {
         tree->deep = 1;
         tree->visible = 1;
@@ -179,7 +171,7 @@ static void calculate_visibility (CONTEXT * ctx, int *max_depth)
   /* now fix up for the OPTHIDETOP* options if necessary */
   if (hide_top_limited || hide_top_missing) {
     tree = ctx->tree;
-    FOREVER {
+    for (;;) {
       if (!tree->visible && tree->deep && tree->subtree_visible < 2
           && ((tree->message && hide_top_limited)
               || (!tree->message && hide_top_missing)))
@@ -203,10 +195,6 @@ static void calculate_visibility (CONTEXT * ctx, int *max_depth)
 /* Since the graphics characters have a value >255, I have to resort to
  * using escape sequences to pass the information to print_enriched_string().
  * These are the macros M_TREE_* defined in mutt.h.
- *
- * ncurses should automatically use the default ASCII characters instead of
- * graphics chars on terminals which don't support them (see the man page
- * for curs_addch).
  */
 void mutt_draw_tree (CONTEXT * ctx)
 {
@@ -221,8 +209,8 @@ void mutt_draw_tree (CONTEXT * ctx)
    * From now on we can simply ignore invisible subtrees
    */
   calculate_visibility (ctx, &max_depth);
-  pfx = mem_malloc (width * max_depth + 2);
-  arrow = mem_malloc (width * max_depth + 2);
+  pfx = p_new(char, width * max_depth + 2);
+  arrow = p_new(char, width * max_depth + 2);
   while (tree) {
     if (depth) {
       myarrow = arrow + (depth - start_depth - (start_depth ? 0 : 1)) * width;
@@ -240,14 +228,14 @@ void mutt_draw_tree (CONTEXT * ctx)
       if (tree->visible) {
         myarrow[width] = M_TREE_RARROW;
         myarrow[width + 1] = 0;
-        new_tree = mem_malloc ((2 + depth * width));
+        new_tree = p_new(char, (2 + depth * width));
         if (start_depth > 1) {
-          strncpy (new_tree, pfx, (start_depth - 1) * width);
-          strfcpy (new_tree + (start_depth - 1) * width,
-                   arrow, (1 + depth - start_depth) * width + 2);
+          memcpy(new_tree, pfx, (start_depth - 1) * width);
+          m_strcpy(new_tree + (start_depth - 1) * width,
+                   (1 + depth - start_depth) * width + 2, arrow);
         }
         else
-          strfcpy (new_tree, arrow, 2 + depth * width);
+          m_strcpy(new_tree, 2 + depth * width, arrow);
         tree->message->tree = new_tree;
       }
     }
@@ -307,23 +295,23 @@ void mutt_draw_tree (CONTEXT * ctx)
     while (!tree->deep);
   }
 
-  mem_free (&pfx);
-  mem_free (&arrow);
+  p_delete(&pfx);
+  p_delete(&arrow);
 }
 
 /* since we may be trying to attach as a pseudo-thread a THREAD that
  * has no message, we have to make a list of all the subjects of its
  * most immediate existing descendants.  we also note the earliest
  * date on any of the parents and put it in *dateptr. */
-static LIST *make_subject_list (THREAD * cur, time_t * dateptr)
+static string_list_t *make_subject_list (THREAD * cur, time_t * dateptr)
 {
   THREAD *start = cur;
   ENVELOPE *env;
   time_t thisdate;
-  LIST *curlist, *oldlist, *newlist, *subjects = NULL;
+  string_list_t *curlist, *oldlist, *newlist, *subjects = NULL;
   int rc = 0;
 
-  FOREVER {
+  for (;;) {
     while (!cur->message)
       cur = cur->child;
 
@@ -339,12 +327,12 @@ static LIST *make_subject_list (THREAD * cur, time_t * dateptr)
         ((env->real_subj != env->subject) || (!option (OPTSORTRE)))) {
       for (curlist = subjects, oldlist = NULL;
            curlist; oldlist = curlist, curlist = curlist->next) {
-        rc = str_cmp (env->real_subj, curlist->data);
+        rc = m_strcmp(env->real_subj, curlist->data);
         if (rc >= 0)
           break;
       }
       if (!curlist || rc > 0) {
-        newlist = mem_calloc (1, sizeof (LIST));
+        newlist = p_new(string_list_t, 1);
         newlist->data = env->real_subj;
         if (oldlist) {
           newlist->next = oldlist->next;
@@ -377,7 +365,7 @@ static THREAD *find_subject (CONTEXT * ctx, THREAD * cur)
   struct hash_elem *ptr;
   THREAD *tmp, *last = NULL;
   int hash;
-  LIST *subjects = NULL, *oldlist;
+  string_list_t *subjects = NULL, *oldlist;
   time_t date = 0;
 
   subjects = make_subject_list (cur, &date);
@@ -399,13 +387,13 @@ static THREAD *find_subject (CONTEXT * ctx, THREAD * cur)
             (last->message->received < tmp->message->received) :
             (last->message->date_sent < tmp->message->date_sent))) &&
           tmp->message->env->real_subj &&
-          str_cmp (subjects->data, tmp->message->env->real_subj) == 0)
+          m_strcmp(subjects->data, tmp->message->env->real_subj) == 0)
         last = tmp;             /* best match so far */
     }
 
     oldlist = subjects;
     subjects = subjects->next;
-    mem_free (&oldlist);
+    p_delete(&oldlist);
   }
   return (last);
 }
@@ -462,7 +450,7 @@ static void pseudo_threads (CONTEXT * ctx)
       insert_message (&parent->child, parent, cur);
       parent->sort_children = 1;
       tmp = cur;
-      FOREVER {
+      for (;;) {
         while (!tmp->message)
           tmp = tmp->child;
 
@@ -472,7 +460,7 @@ static void pseudo_threads (CONTEXT * ctx)
          * parent, since otherwise they rightly belong to the message
          * we're attaching. */
         if (tmp == cur
-            || !str_cmp (tmp->message->env->real_subj,
+            || !m_strcmp(tmp->message->env->real_subj,
                              parent->message->env->real_subj)) {
           tmp->message->subject_changed = 0;
 
@@ -510,7 +498,7 @@ void mutt_clear_threads (CONTEXT * ctx)
   ctx->tree = NULL;
 
   if (ctx->thread_hash)
-    hash_destroy (&ctx->thread_hash, free);
+    hash_delete (&ctx->thread_hash, free);
 }
 
 static int compare_threads (const void *a, const void *b)
@@ -547,7 +535,7 @@ THREAD *mutt_sort_subthreads (THREAD * thread, int init)
 
   top = thread;
 
-  array = mem_calloc ((array_size = 256), sizeof (THREAD *));
+  array = p_new(THREAD *, (array_size = 256));
   while (1) {
     if (init || !thread->sort_key) {
       thread->sort_key = NULL;
@@ -579,7 +567,7 @@ THREAD *mutt_sort_subthreads (THREAD * thread, int init)
         /* put them into the array */
         for (i = 0; thread; i++, thread = thread->prev) {
           if (i >= array_size)
-            mem_realloc (&array, (array_size *= 2) * sizeof (THREAD *));
+            p_realloc(&array, array_size *= 2);
 
           array[i] = thread;
         }
@@ -639,7 +627,7 @@ THREAD *mutt_sort_subthreads (THREAD * thread, int init)
       }
       else {
         Sort ^= SORT_REVERSE;
-        mem_free (&array);
+        p_delete(&array);
         return (top);
       }
     }
@@ -670,7 +658,7 @@ static void check_subjects (CONTEXT * ctx, int init)
     if (!tmp)
       cur->subject_changed = 1;
     else if (cur->env->real_subj && tmp->message->env->real_subj)
-      cur->subject_changed = str_cmp (cur->env->real_subj,
+      cur->subject_changed = m_strcmp(cur->env->real_subj,
                                           tmp->message->env->
                                           real_subj) ? 1 : 0;
     else
@@ -684,7 +672,7 @@ void mutt_sort_threads (CONTEXT * ctx, int init)
   HEADER *cur;
   int i, oldsort, using_refs = 0;
   THREAD *thread, *new, *tmp, top;
-  LIST *ref = NULL;
+  string_list_t *ref = NULL;
 
   /* set Sort to the secondary method to support the set sort_aux=reverse-*
    * settings.  The sorting functions just look at the value of
@@ -697,7 +685,7 @@ void mutt_sort_threads (CONTEXT * ctx, int init)
     init = 1;
 
   if (init)
-    ctx->thread_hash = hash_create (ctx->msgcount * 2);
+    ctx->thread_hash = hash_new (ctx->msgcount * 2, 1);
 
   /* we want a quick way to see if things are actually attached to the top of the
    * thread tree or if they're just dangling, so we attach everything to a top
@@ -756,13 +744,13 @@ void mutt_sort_threads (CONTEXT * ctx, int init)
       else {
         new = (option (OPTDUPTHREADS) ? thread : NULL);
 
-        thread = mem_calloc (1, sizeof (THREAD));
+        thread = p_new(THREAD, 1);
         thread->message = cur;
         thread->check_subject = 1;
         cur->thread = thread;
         hash_insert (ctx->thread_hash,
                      cur->env->message_id ? cur->env->message_id : "",
-                     thread, 1);
+                     thread);
 
         if (new) {
           if (new->duplicate_thread)
@@ -822,7 +810,7 @@ void mutt_sort_threads (CONTEXT * ctx, int init)
         if (!cur->env->references)
           ref = ref->next;
         else {
-          if (str_cmp (ref->data, cur->env->references->data))
+          if (m_strcmp(ref->data, cur->env->references->data))
             ref = cur->env->references;
           else
             ref = cur->env->references->next;
@@ -837,8 +825,8 @@ void mutt_sort_threads (CONTEXT * ctx, int init)
         break;
 
       if ((new = hash_find (ctx->thread_hash, ref->data)) == NULL) {
-        new = mem_calloc (1, sizeof (THREAD));
-        hash_insert (ctx->thread_hash, ref->data, new, 1);
+        new = p_new(THREAD, 1);
+        hash_insert (ctx->thread_hash, ref->data, new);
       }
       else {
         if (new->duplicate_thread)
@@ -898,7 +886,7 @@ static HEADER *find_virtual (THREAD * cur, int reverse)
   while (reverse && cur->next)
     cur = cur->next;
 
-  FOREVER {
+  for (;;) {
     if (cur->message && cur->message->virtual >= 0)
       return (cur->message);
 
@@ -1080,7 +1068,7 @@ int _mutt_traverse_thread (CONTEXT * ctx, HEADER * cur, int flag)
       return (min_unread);
   }
 
-  FOREVER {
+  for (;;) {
     cur = thread->message;
 
     if (cur) {
@@ -1198,49 +1186,49 @@ int mutt_messages_in_thread (CONTEXT * ctx, HEADER * hdr, int flag)
 }
 
 
-HASH *mutt_make_id_hash (CONTEXT * ctx)
+hash_t *mutt_make_id_hash (CONTEXT * ctx)
 {
   int i;
   HEADER *hdr;
-  HASH *hash;
+  hash_t *hash;
 
-  hash = hash_create (ctx->msgcount * 2);
+  hash = hash_new (ctx->msgcount * 2, 0);
 
   for (i = 0; i < ctx->msgcount; i++) {
     hdr = ctx->hdrs[i];
     if (hdr->env->message_id)
-      hash_insert (hash, hdr->env->message_id, hdr, 0);
+      hash_insert (hash, hdr->env->message_id, hdr);
   }
 
   return hash;
 }
 
-HASH *mutt_make_subj_hash (CONTEXT * ctx)
+hash_t *mutt_make_subj_hash (CONTEXT * ctx)
 {
   int i;
   HEADER *hdr;
-  HASH *hash;
+  hash_t *hash;
 
-  hash = hash_create (ctx->msgcount * 2);
+  hash = hash_new (ctx->msgcount * 2, 1);
 
   for (i = 0; i < ctx->msgcount; i++) {
     hdr = ctx->hdrs[i];
     if (hdr->env->real_subj)
-      hash_insert (hash, hdr->env->real_subj, hdr, 1);
+      hash_insert(hash, hdr->env->real_subj, hdr);
   }
 
   return hash;
 }
 
-static void clean_references (THREAD * brk, THREAD * cur)
+static void clean_references (THREAD * tbrk, THREAD * cur)
 {
   THREAD *p;
-  LIST *ref = NULL;
+  string_list_t *ref = NULL;
   int done = 0;
 
   for (; cur; cur = cur->next, done = 0) {
     /* parse subthread recursively */
-    clean_references (brk, cur->child);
+    clean_references (tbrk, cur->child);
 
     if (!cur->message)
       break;                    /* skip pseudo-message */
@@ -1248,10 +1236,10 @@ static void clean_references (THREAD * brk, THREAD * cur)
     /* Looking for the first bad reference according to the new threading.
      * Optimal since Mutt stores the references in reverse order, and the
      * first loop should match immediatly for mails respecting RFC2822. */
-    for (p = brk; !done && p; p = p->parent)
+    for (p = tbrk; !done && p; p = p->parent)
       for (ref = cur->message->env->references; p->message && ref;
            ref = ref->next)
-        if (!str_casecmp (ref->data, p->message->env->message_id)) {
+        if (!m_strcasecmp(ref->data, p->message->env->message_id)) {
           done = 1;
           break;
         }
@@ -1260,7 +1248,7 @@ static void clean_references (THREAD * brk, THREAD * cur)
       HEADER *h = cur->message;
 
       /* clearing the References: header from obsolete Message-ID(s) */
-      mutt_free_list (&ref->next);
+      string_list_wipe(&ref->next);
 
       h->env->refs_changed = h->changed = 1;
     }
@@ -1269,9 +1257,9 @@ static void clean_references (THREAD * brk, THREAD * cur)
 
 void mutt_break_thread (HEADER * hdr)
 {
-  mutt_free_list (&hdr->env->in_reply_to);
-  mutt_free_list (&hdr->env->references);
-  hdr->env->irt_changed = hdr->env->refs_changed = 1;
+  string_list_wipe(&hdr->env->in_reply_to);
+  string_list_wipe(&hdr->env->references);
+  hdr->env->irt_changed = hdr->env->refs_changed = hdr->changed = 1;
   clean_references (hdr->thread, hdr->thread->child);
 }
 
@@ -1282,8 +1270,8 @@ static int link_threads (HEADER * parent, HEADER * child, CONTEXT * ctx)
 
   mutt_break_thread (child);
 
-  child->env->in_reply_to = mutt_new_list ();
-  child->env->in_reply_to->data = str_dup (parent->env->message_id);
+  child->env->in_reply_to = string_item_new();
+  child->env->in_reply_to->data = m_strdup(parent->env->message_id);
 
   mutt_set_flag (ctx, child, M_TAG, 0);