Rocco Rutte:
[apps/madmutt.git] / init.c
diff --git a/init.c b/init.c
index eab1c57..079ecc7 100644 (file)
--- a/init.c
+++ b/init.c
@@ -32,6 +32,7 @@
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/rx.h"
+#include "lib/list.h"
 #include "lib/debug.h"
 
 #include <ctype.h>
@@ -123,7 +124,7 @@ int mutt_option_index (char *s)
   int i;
 
   for (i = 0; MuttVars[i].option; i++)
-    if (safe_strcmp (s, MuttVars[i].option) == 0) {
+    if (mutt_strcmp (s, MuttVars[i].option) == 0) {
       if (MuttVars[i].type == DT_SYN)
         syn_add (mutt_option_index ((char *) MuttVars[i].data), i);
       return (MuttVars[i].type ==
@@ -259,8 +260,8 @@ int mutt_extract_token (BUFFER * dest, BUFFER * tok, int flags)
         FREE (&expn.data);
       }
       else if (expn.data) {
-        expnlen = safe_strlen (expn.data);
-        tok->dsize = expnlen + safe_strlen (tok->dptr) + 1;
+        expnlen = mutt_strlen (expn.data);
+        tok->dsize = expnlen + mutt_strlen (tok->dptr) + 1;
         ptr = safe_malloc (tok->dsize);
         memcpy (ptr, expn.data, expnlen);
         strcpy (ptr + expnlen, tok->dptr);      /* __STRCPY_CHECKED__ */
@@ -428,7 +429,7 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
 
   /* Being first is a special case. */
   spam = *list;
-  if (spam->rx && !safe_strcmp (spam->rx->pattern, pat)) {
+  if (spam->rx && !mutt_strcmp (spam->rx->pattern, pat)) {
     *list = spam->next;
     rx_free (&spam->rx);
     FREE(&spam->template);
@@ -438,7 +439,7 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
 
   prev = spam;
   for (spam = prev->next; spam;) {
-    if (!safe_strcmp (spam->rx->pattern, pat)) {
+    if (!mutt_strcmp (spam->rx->pattern, pat)) {
       prev->next = spam->next;
       rx_free (&spam->rx);
       FREE(spam->template);
@@ -458,7 +459,7 @@ static void remove_from_list (LIST ** l, const char *str)
 {
   LIST *p, *last = NULL;
 
-  if (safe_strcmp ("*", str) == 0)
+  if (mutt_strcmp ("*", str) == 0)
     mutt_free_list (l);         /* ``unCMD *'' means delete all current entries */
   else {
     p = *l;
@@ -484,8 +485,8 @@ static int remove_from_rx_list (list2_t** l, const char *str)
 {
   int i = 0;
 
-  if (safe_strcmp ("*", str) == 0) {
-    list_del (l, rx_free);
+  if (mutt_strcmp ("*", str) == 0) {
+    list_del (l, (list_del_t*) rx_free);
     return (0);
   }
   else {
@@ -517,8 +518,8 @@ static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
         continue;
 
       for (j = 0; b[j].name; j++)
-        if (!ascii_strncasecmp (tmp->data, b[j].name, safe_strlen (tmp->data))
-            && (safe_strlen (b[j].name) == safe_strlen (tmp->data))) {
+        if (!ascii_strncasecmp (tmp->data, b[j].name, mutt_strlen (tmp->data))
+            && (mutt_strlen (b[j].name) == mutt_strlen (tmp->data))) {
           res = 1;
           break;
         }
@@ -528,13 +529,13 @@ static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
     char *p = NULL;
 
     i = 0;
-    j = safe_strlen (tmp->data);
+    j = mutt_strlen (tmp->data);
     /* need at least input of 'feature_X' */
     if (j >= 7) {
       p = tmp->data + 7;
       j -= 7;
       while (Features[i].name) {
-        if (safe_strlen (Features[i].name) == j &&
+        if (mutt_strlen (Features[i].name) == j &&
             ascii_strncasecmp (Features[i].name, p, j)) {
           res = 1;
           break;
@@ -640,7 +641,7 @@ static int parse_unalternates (BUFFER * buf, BUFFER * s, unsigned long data,
     mutt_extract_token (buf, s, 0);
     remove_from_rx_list (&Alternates, buf->data);
 
-    if (safe_strcmp (buf->data, "*") &&
+    if (mutt_strcmp (buf->data, "*") &&
         add_to_rx_list (&UnAlternates, buf->data, REG_ICASE, err) != 0)
       return -1;
 
@@ -696,9 +697,9 @@ static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data,
     /* nospam only ever has one parameter. */
 
     /* "*" is a special case. */
-    if (!safe_strcmp (buf->data, "*")) {
+    if (!mutt_strcmp (buf->data, "*")) {
       mutt_free_spam_list (&SpamList);
-      list_del (&NoSpamList, rx_free);
+      list_del (&NoSpamList, (list_del_t*) rx_free);
       return 0;
     }
 
@@ -726,7 +727,7 @@ static int parse_unlist (BUFFER * buf, BUFFER * s, unsigned long data,
     /*
      * Check for deletion of entire list
      */
-    if (safe_strcmp (buf->data, "*") == 0) {
+    if (mutt_strcmp (buf->data, "*") == 0) {
       mutt_free_list ((LIST **) data);
       break;
     }
@@ -760,7 +761,7 @@ static int parse_unlists (BUFFER * buf, BUFFER * s, unsigned long data,
     remove_from_rx_list (&SubscribedLists, buf->data);
     remove_from_rx_list (&MailLists, buf->data);
 
-    if (safe_strcmp (buf->data, "*") &&
+    if (mutt_strcmp (buf->data, "*") &&
         add_to_rx_list (&UnMailLists, buf->data, REG_ICASE, err) != 0)
       return -1;
   }
@@ -794,7 +795,7 @@ static int parse_unsubscribe (BUFFER * buf, BUFFER * s, unsigned long data,
     mutt_extract_token (buf, s, 0);
     remove_from_rx_list (&SubscribedLists, buf->data);
 
-    if (safe_strcmp (buf->data, "*") &&
+    if (mutt_strcmp (buf->data, "*") &&
         add_to_rx_list (&UnSubscribedLists, buf->data, REG_ICASE, err) != 0)
       return -1;
   }
@@ -811,7 +812,7 @@ static int parse_unalias (BUFFER * buf, BUFFER * s, unsigned long data,
   do {
     mutt_extract_token (buf, s, 0);
 
-    if (safe_strcmp ("*", buf->data) == 0) {
+    if (mutt_strcmp ("*", buf->data) == 0) {
       if (CurrentMenu == MENU_ALIAS) {
         for (tmp = Aliases; tmp; tmp = tmp->next)
           tmp->del = 1;
@@ -922,13 +923,13 @@ parse_unmy_hdr (BUFFER * buf, BUFFER * s, unsigned long data, BUFFER * err)
 
   do {
     mutt_extract_token (buf, s, 0);
-    if (safe_strcmp ("*", buf->data) == 0)
+    if (mutt_strcmp ("*", buf->data) == 0)
       mutt_free_list (&UserHeader);
     else {
       tmp = UserHeader;
       last = NULL;
 
-      l = safe_strlen (buf->data);
+      l = mutt_strlen (buf->data);
       if (buf->data[l - 1] == ':')
         l--;
 
@@ -1106,9 +1107,9 @@ static void mutt_restore_default (struct option_t *p)
         char *s = (char *) p->init;
 
         pp->rx = safe_calloc (1, sizeof (regex_t));
-        if (safe_strcmp (p->option, "mask") != 0)
+        if (mutt_strcmp (p->option, "mask") != 0)
           flags |= mutt_which_case ((const char *) p->init);
-        if (safe_strcmp (p->option, "mask") == 0 && *s == '!') {
+        if (mutt_strcmp (p->option, "mask") == 0 && *s == '!') {
           s++;
           pp->not = 1;
         }
@@ -1175,7 +1176,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
     mutt_extract_token (tmp, s, M_TOKEN_EQUAL);
 
     if ((idx = mutt_option_index (tmp->data)) == -1 &&
-        !(reset && !safe_strcmp ("all", tmp->data))) {
+        !(reset && !mutt_strcmp ("all", tmp->data))) {
       snprintf (err->data, err->dsize, _("%s: unknown variable"), tmp->data);
       return (-1);
     }
@@ -1192,7 +1193,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
         return (-1);
       }
 
-      if (!safe_strcmp ("all", tmp->data)) {
+      if (!mutt_strcmp ("all", tmp->data)) {
         for (idx = 0; MuttVars[idx].option; idx++)
           mutt_restore_default (&MuttVars[idx]);
         return 0;
@@ -1276,7 +1277,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
         }
         else if (DTYPE (MuttVars[idx].type) == DT_STR) {
           *((char **) MuttVars[idx].data) = safe_strdup (tmp->data);
-          if (safe_strcmp (MuttVars[idx].option, "charset") == 0)
+          if (mutt_strcmp (MuttVars[idx].option, "charset") == 0)
             mutt_set_charset (Charset);
         }
         else {
@@ -1298,7 +1299,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
       }
 
       if (option (OPTATTACHMSG)
-          && !safe_strcmp (MuttVars[idx].option, "reply_regexp")) {
+          && !mutt_strcmp (MuttVars[idx].option, "reply_regexp")) {
         snprintf (err->data, err->dsize,
                   "Operation not permitted when in attach-message mode.");
         r = -1;
@@ -1310,15 +1311,15 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
       /* copy the value of the string */
       mutt_extract_token (tmp, s, 0);
 
-      if (!ptr->pattern || safe_strcmp (ptr->pattern, tmp->data) != 0) {
+      if (!ptr->pattern || mutt_strcmp (ptr->pattern, tmp->data) != 0) {
         int not = 0;
 
         /* $mask is case-sensitive */
-        if (safe_strcmp (MuttVars[idx].option, "mask") != 0)
+        if (mutt_strcmp (MuttVars[idx].option, "mask") != 0)
           flags |= mutt_which_case (tmp->data);
 
         p = tmp->data;
-        if (safe_strcmp (MuttVars[idx].option, "mask") == 0) {
+        if (mutt_strcmp (MuttVars[idx].option, "mask") == 0) {
           if (*p == '!') {
             not = 1;
             p++;
@@ -1347,7 +1348,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
         /* $reply_regexp and $alterantes require special treatment */
 
         if (Context && Context->msgcount &&
-            safe_strcmp (MuttVars[idx].option, "reply_regexp") == 0) {
+            mutt_strcmp (MuttVars[idx].option, "reply_regexp") == 0) {
           regmatch_t pmatch[1];
           int i;
 
@@ -1423,12 +1424,12 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
         *ptr = (short) val;
 
       /* these ones need a sanity check */
-      if (safe_strcmp (MuttVars[idx].option, "history") == 0) {
+      if (mutt_strcmp (MuttVars[idx].option, "history") == 0) {
         if (*ptr < 0)
           *ptr = 0;
         mutt_init_history ();
       }
-      else if (safe_strcmp (MuttVars[idx].option, "pager_index_lines") == 0) {
+      else if (mutt_strcmp (MuttVars[idx].option, "pager_index_lines") == 0) {
         if (*ptr < 0)
           *ptr = 0;
       }
@@ -1649,7 +1650,7 @@ int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err)
 
   memset (&expn, 0, sizeof (expn));
   expn.data = expn.dptr = line;
-  expn.dsize = safe_strlen (line);
+  expn.dsize = mutt_strlen (line);
 
   *err->data = 0;
 
@@ -1663,7 +1664,7 @@ int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err)
     }
     mutt_extract_token (token, &expn, 0);
     for (i = 0; Commands[i].name; i++) {
-      if (!safe_strcmp (token->data, Commands[i].name)) {
+      if (!mutt_strcmp (token->data, Commands[i].name)) {
         if (Commands[i].func (token, &expn, Commands[i].data, err) != 0)
           goto finish;
         break;
@@ -1771,8 +1772,8 @@ int mutt_command_complete (char *buffer, size_t len, int pos, int numtabs)
     /* loop through all the possible prefixes (no, inv, ...) */
     if (!safe_strncmp (buffer, "set", 3)) {
       for (num = 0; prefixes[num]; num++) {
-        if (!safe_strncmp (pt, prefixes[num], safe_strlen (prefixes[num]))) {
-          pt += safe_strlen (prefixes[num]);
+        if (!safe_strncmp (pt, prefixes[num], mutt_strlen (prefixes[num]))) {
+          pt += mutt_strlen (prefixes[num]);
           break;
         }
       }
@@ -1882,7 +1883,7 @@ int mutt_var_value_complete (char *buffer, size_t len, int pos)
 
     strfcpy (var, pt, sizeof (var));
     /* ignore the trailing '=' when comparing */
-    var[safe_strlen (var) - 1] = 0;
+    var[mutt_strlen (var) - 1] = 0;
     if ((idx = mutt_option_index (var)) == -1)
       return 0;                 /* no such variable. */
     else {
@@ -2100,7 +2101,7 @@ void mutt_init (int skip_sys_rc, LIST * commands)
   else
 #endif /* DOMAIN */
   if (*DOMAIN != '@') {
-    Fqdn = safe_malloc (safe_strlen (DOMAIN) + safe_strlen (Hostname) + 2);
+    Fqdn = safe_malloc (mutt_strlen (DOMAIN) + mutt_strlen (Hostname) + 2);
     sprintf (Fqdn, "%s.%s", NONULL (Hostname), DOMAIN); /* __SPRINTF_CHECKED__ */
   }
   else
@@ -2169,7 +2170,7 @@ void mutt_init (int skip_sys_rc, LIST * commands)
 
     memset (&buf, 0, sizeof (buf));
     buf.data = buf.dptr = buffer;
-    buf.dsize = safe_strlen (buffer);
+    buf.dsize = mutt_strlen (buffer);
 
     memset (&token, 0, sizeof (token));
     parse_my_hdr (&token, &buf, 0, &err);
@@ -2325,3 +2326,50 @@ int mutt_get_hook_type (const char *name)
       return c->data;
   return 0;
 }
+
+static int opt_cmp (const void* a, const void* b) {
+  return (mutt_strcmp ((*(struct option_t**) a)->option,
+                       (*(struct option_t**) b)->option));
+}
+
+/* dump out the value of all the variables we have */
+int mutt_dump_variables (void) {
+  int i;
+
+  char errbuff[STRING];
+  char command[STRING];
+  list2_t* tmp = NULL;
+
+  BUFFER err, token;
+
+  memset (&err, 0, sizeof (err));
+  memset (&token, 0, sizeof (token));
+
+  err.data = errbuff;
+  err.dsize = sizeof (errbuff);
+
+  /* get all non-synonyms into list... */
+  for (i = 0; MuttVars[i].option; i++) {
+    if (MuttVars[i].type == DT_SYN)
+      continue;
+    list_push_back (&tmp, &MuttVars[i]);
+  }
+  if (!list_empty(tmp)) {
+    /* ...and dump list sorted */
+    qsort (tmp->data, tmp->length, sizeof (void*), opt_cmp);
+    for (i = 0; i < tmp->length; i++) {
+      snprintf (command, sizeof (command), "set ?%s\n",
+                ((struct option_t*) tmp->data[i])->option);
+      if (mutt_parse_rc_line (command, &token, &err) == -1) {
+        fprintf (stderr, "%s\n", err.data);
+        FREE (&token.data);
+        list_del (&tmp, NULL);
+        return 1;
+      }
+      printf("%s\n", err.data);
+    }
+  }
+  FREE (&token.data);
+  list_del (&tmp, NULL);
+  return 0;
+}