stop building doc/ atm
[apps/madmutt.git] / color.c
diff --git a/color.c b/color.c
index 34a3d70..4166468 100644 (file)
--- a/color.c
+++ b/color.c
@@ -1,28 +1,27 @@
 /*
+ * Copyright notice from original mutt:
  * Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
- * 
- *     This program is free software; you can redistribute it and/or modify
- *     it under the terms of the GNU General Public License as published by
- *     the Free Software Foundation; either version 2 of the License, or
- *     (at your option) any later version.
- * 
- *     This program is distributed in the hope that it will be useful,
- *     but WITHOUT ANY WARRANTY; without even the implied warranty of
- *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *     GNU General Public License for more details.
- * 
- *     You should have received a copy of the GNU General Public License
- *     along with this program; if not, write to the Free Software
- *     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
+ *
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * 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 <lib-lib/mem.h>
+#include <lib-lib/ascii.h>
+#include <lib-lib/str.h>
+#include <lib-lib/macros.h>
+#include <lib-lib/buffer.h>
+#include <lib-lib/mapping.h>
+
 #include "mutt.h"
 #include "mutt_curses.h"
-#include "mapping.h"
+
+#include "lib/debug.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -100,7 +99,7 @@ static struct mapping_t Fields[] = {
 
 static COLOR_LINE *mutt_new_color_line (void)
 {
-  COLOR_LINE *p = safe_calloc (1, sizeof (COLOR_LINE));
+  COLOR_LINE *p = p_new(COLOR_LINE, 1);
 
   p->fg = p->bg = -1;
 
@@ -127,29 +126,29 @@ static void mutt_free_color_line (COLOR_LINE ** l, int free_colors)
 
   regfree (&tmp->rx);
   mutt_pattern_free (&tmp->color_pattern);
-  FREE (&tmp->pattern);
-  FREE (l);
+  p_delete(&tmp->pattern);
+  p_delete(l);
 }
 
 void ci_start_color (void)
 {
-  memset (ColorDefs, A_NORMAL, sizeof (int) * MT_COLOR_MAX);
-  ColorQuote = (int *) safe_malloc (COLOR_QUOTE_INIT * sizeof (int));
-  memset (ColorQuote, A_NORMAL, sizeof (int) * COLOR_QUOTE_INIT);
-  ColorQuoteSize = COLOR_QUOTE_INIT;
-  ColorQuoteUsed = 0;
-
-  /* set some defaults */
-  ColorDefs[MT_COLOR_STATUS] = A_REVERSE;
-  ColorDefs[MT_COLOR_INDICATOR] = A_REVERSE;
-  ColorDefs[MT_COLOR_SEARCH] = A_REVERSE;
-  ColorDefs[MT_COLOR_MARKERS] = A_REVERSE;
-  /* special meaning: toggle the relevant attribute */
-  ColorDefs[MT_COLOR_BOLD] = 0;
-  ColorDefs[MT_COLOR_UNDERLINE] = 0;
+    memset(ColorDefs, A_NORMAL, sizeof(int) * MT_COLOR_MAX);
+    ColorQuote = p_new(int, COLOR_QUOTE_INIT);
+    memset(ColorQuote, A_NORMAL, sizeof(int) * COLOR_QUOTE_INIT);
+    ColorQuoteSize = COLOR_QUOTE_INIT;
+    ColorQuoteUsed = 0;
+
+    /* set some defaults */
+    ColorDefs[MT_COLOR_STATUS] = A_REVERSE;
+    ColorDefs[MT_COLOR_INDICATOR] = A_REVERSE;
+    ColorDefs[MT_COLOR_SEARCH] = A_REVERSE;
+    ColorDefs[MT_COLOR_MARKERS] = A_REVERSE;
+    /* special meaning: toggle the relevant attribute */
+    ColorDefs[MT_COLOR_BOLD] = 0;
+    ColorDefs[MT_COLOR_UNDERLINE] = 0;
 
 #ifdef HAVE_COLOR
-  start_color ();
+    start_color ();
 #endif
 }
 
@@ -163,21 +162,21 @@ static char *get_color_name (char *dest, size_t destlen, int val)
 
   switch (val) {
   case COLOR_YELLOW:
-    strfcpy (dest, missing[0], destlen);
+    m_strcpy(dest, destlen, missing[0]);
     return dest;
 
   case COLOR_WHITE:
-    strfcpy (dest, missing[1], destlen);
+    m_strcpy(dest, destlen, missing[1]);
     return dest;
 
   case COLOR_DEFAULT:
-    strfcpy (dest, missing[2], destlen);
+    m_strcpy(dest, destlen, missing[2]);
     return dest;
   }
 
   for (i = 0; Colors[i].name; i++) {
     if (Colors[i].value == val) {
-      strfcpy (dest, Colors[i].name, destlen);
+      m_strcpy(dest, destlen, Colors[i].name);
       return dest;
     }
   }
@@ -215,7 +214,7 @@ int mutt_alloc_color (int fg, int bg)
 
   /* find the smallest available index (object) */
   i = 1;
-  FOREVER {
+  for (;;) {
     p = ColorList;
     while (p) {
       if (p->index == i)
@@ -227,7 +226,7 @@ int mutt_alloc_color (int fg, int bg)
     i++;
   }
 
-  p = (COLOR_LIST *) safe_malloc (sizeof (COLOR_LIST));
+  p = p_new(COLOR_LIST, 1);
   p->next = ColorList;
   ColorList = p;
 
@@ -250,8 +249,7 @@ int mutt_alloc_color (int fg, int bg)
 
   init_pair (i, fg, bg);
 
-  dprint (1, (debugfile, "mutt_alloc_color(): Color pairs used so far: %d\n",
-              UserColors));
+  debug_print (1, ("Color pairs used so far: %d\n", UserColors));
 
   return (COLOR_PAIR (p->index));
 }
@@ -268,20 +266,18 @@ void mutt_free_color (int fg, int bg)
         return;
 
       UserColors--;
-      dprint (1,
-              (debugfile, "mutt_free_color(): Color pairs used so far: %d\n",
-               UserColors));
+      debug_print (1, ("Color pairs used so far: %d\n", UserColors));
 
       if (p == ColorList) {
         ColorList = ColorList->next;
-        FREE (&p);
+        p_delete(&p);
         return;
       }
       q = ColorList;
       while (q) {
         if (q->next == p) {
           q->next = p->next;
-          FREE (&p);
+          p_delete(&p);
           return;
         }
         q = q->next;
@@ -302,13 +298,13 @@ parse_color_name (const char *s, int *col, int *attr, int brite, BUFFER * err)
 {
   char *eptr;
 
-  if (mutt_strncasecmp (s, "bright", 6) == 0) {
+  if (m_strncasecmp(s, "bright", 6) == 0) {
     *attr |= brite;
     s += 6;
   }
 
   /* allow aliases for xterm color resources */
-  if (mutt_strncasecmp (s, "color", 5) == 0) {
+  if (m_strncasecmp(s, "color", 5) == 0) {
     s += 5;
     *col = strtol (s, &eptr, 10);
     if (!*s || *eptr || *col < 0 ||
@@ -355,7 +351,7 @@ int mutt_parse_unmono (BUFFER * buf, BUFFER * s, unsigned long data,
 }
 
 static int
-_mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data,
+_mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)),
                      BUFFER * err, short parse_uncolor)
 {
   int object = 0, do_cache = 0;
@@ -368,7 +364,7 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data,
     return (-1);
   }
 
-  if (mutt_strncmp (buf->data, "index", 5) != 0) {
+  if (m_strncmp(buf->data, "index", 5) != 0) {
     snprintf (err->data, err->dsize,
               _("%s: command valid only for index object"),
               parse_uncolor ? "uncolor" : "unmono");
@@ -406,7 +402,7 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data,
 
   do {
     mutt_extract_token (buf, s, 0);
-    if (!mutt_strcmp ("*", buf->data)) {
+    if (!m_strcmp("*", buf->data)) {
       for (tmp = ColorIndexList; tmp;) {
         if (!do_cache)
           do_cache = 1;
@@ -419,12 +415,10 @@ _mutt_parse_uncolor (BUFFER * buf, BUFFER * s, unsigned long data,
     else {
       for (last = NULL, tmp = ColorIndexList; tmp;
            last = tmp, tmp = tmp->next) {
-        if (!mutt_strcmp (buf->data, tmp->pattern)) {
+        if (!m_strcmp(buf->data, tmp->pattern)) {
           if (!do_cache)
             do_cache = 1;
-          dprint (1,
-                  (debugfile, "Freeing pattern \"%s\" from ColorIndexList\n",
-                   tmp->pattern));
+          debug_print (1, ("Freeing pattern \"%s\" from ColorIndexList\n", tmp->pattern));
           if (last)
             last->next = tmp->next;
           else
@@ -463,11 +457,11 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive,
 
   while (tmp) {
     if (sensitive) {
-      if (mutt_strcmp (s, tmp->pattern) == 0)
+      if (m_strcmp(s, tmp->pattern) == 0)
         break;
     }
     else {
-      if (mutt_strcasecmp (s, tmp->pattern) == 0)
+      if (m_strcasecmp(s, tmp->pattern) == 0)
         break;
     }
     tmp = tmp->next;
@@ -496,7 +490,7 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive,
     if (is_index) {
       int i;
 
-      strfcpy (buf, NONULL (s), sizeof (buf));
+      m_strcpy(buf, sizeof(buf), NONULL(s));
       mutt_check_simple (buf, sizeof (buf), NONULL (SimpleSearch));
       if ((tmp->color_pattern =
            mutt_pattern_comp (buf, M_FULL_MSG, err)) == NULL) {
@@ -516,7 +510,7 @@ add_pattern (COLOR_LINE ** top, const char *s, int sensitive,
       return (-1);
     }
     tmp->next = *top;
-    tmp->pattern = safe_strdup (s);
+    tmp->pattern = m_strdup(s);
 #ifdef HAVE_COLOR
     if (fg != -1 && bg != -1) {
       tmp->fg = fg;
@@ -538,12 +532,12 @@ parse_object (BUFFER * buf, BUFFER * s, int *o, int *ql, BUFFER * err)
   char *eptr;
 
   if (!MoreArgs (s)) {
-    strfcpy (err->data, _("Missing arguments."), err->dsize);
+    m_strcpy(err->data, err->dsize, _("Missing arguments."));
     return -1;
   }
 
   mutt_extract_token (buf, s, 0);
-  if (!mutt_strncmp (buf->data, "quoted", 6)) {
+  if (!m_strncmp(buf->data, "quoted", 6)) {
     if (buf->data[6]) {
       *ql = strtol (buf->data + 6, &eptr, 10);
       if (*eptr || q_level < 0) {
@@ -574,7 +568,7 @@ parse_color_pair (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr,
                   BUFFER * err)
 {
   if (!MoreArgs (s)) {
-    strfcpy (err->data, _("color: too few arguments"), err->dsize);
+    m_strcpy(err->data, err->dsize, _("color: too few arguments"));
     return (-1);
   }
 
@@ -584,7 +578,7 @@ parse_color_pair (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr,
     return (-1);
 
   if (!MoreArgs (s)) {
-    strfcpy (err->data, _("color: too few arguments"), err->dsize);
+    m_strcpy(err->data, err->dsize, _("color: too few arguments"));
     return (-1);
   }
 
@@ -609,7 +603,7 @@ parse_attr_spec (BUFFER * buf, BUFFER * s, int *fg, int *bg, int *attr,
     *bg = -1;
 
   if (!MoreArgs (s)) {
-    strfcpy (err->data, _("mono: too few arguments"), err->dsize);
+    m_strcpy(err->data, err->dsize, _("mono: too few arguments"));
     return (-1);
   }
 
@@ -667,7 +661,7 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err,
   if (object == MT_COLOR_HEADER || object == MT_COLOR_BODY
       || object == MT_COLOR_INDEX) {
     if (!MoreArgs (s)) {
-      strfcpy (err->data, _("too few arguments"), err->dsize);
+      m_strcpy(err->data, err->dsize, _("too few arguments"));
       return (-1);
     }
 
@@ -675,7 +669,7 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err,
   }
 
   if (MoreArgs (s)) {
-    strfcpy (err->data, _("too many arguments"), err->dsize);
+    m_strcpy(err->data, err->dsize, _("too many arguments"));
     return (-1);
   }
 
@@ -691,7 +685,7 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err,
       /* delay use_default_colors() until needed, since it initializes things */
       && (fg == COLOR_DEFAULT || bg == COLOR_DEFAULT)
       && use_default_colors () != OK) {
-    strfcpy (err->data, _("default colors not supported"), err->dsize);
+    m_strcpy(err->data, err->dsize, _("default colors not supported"));
     return (-1);
   }
 # endif /* HAVE_USE_DEFAULT_COLORS */
@@ -707,7 +701,7 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err,
   }
   else if (object == MT_COLOR_QUOTED) {
     if (q_level >= ColorQuoteSize) {
-      safe_realloc (&ColorQuote, (ColorQuoteSize += 2) * sizeof (int));
+      p_realloc(&ColorQuote, ColorQuoteSize += 2);
       ColorQuote[ColorQuoteSize - 2] = ColorDefs[MT_COLOR_QUOTED];
       ColorQuote[ColorQuoteSize - 1] = ColorDefs[MT_COLOR_QUOTED];
     }
@@ -740,7 +734,7 @@ _mutt_parse_color (BUFFER * buf, BUFFER * s, BUFFER * err,
 
 #ifdef HAVE_COLOR
 
-int mutt_parse_color (BUFFER * buff, BUFFER * s, unsigned long data,
+int mutt_parse_color (BUFFER * buff, BUFFER * s, unsigned long data __attribute__ ((unused)),
                       BUFFER * err)
 {
   int dry_run = 0;
@@ -753,7 +747,7 @@ int mutt_parse_color (BUFFER * buff, BUFFER * s, unsigned long data,
 
 #endif
 
-int mutt_parse_mono (BUFFER * buff, BUFFER * s, unsigned long data,
+int mutt_parse_mono (BUFFER * buff, BUFFER * s, unsigned long data __attribute__ ((unused)),
                      BUFFER * err)
 {
   int dry_run = 0;