Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Thu, 10 Mar 2005 16:39:14 +0000 (16:39 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Thu, 10 Mar 2005 16:39:14 +0000 (16:39 +0000)
added extension to ifdef patch ('ifndef', feature_* tests) + doc

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@166 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog.mutt-ng
UPGRADING
doc/manual.sgml.head
init.c
init.h

index 3f2e302..953b256 100644 (file)
@@ -1,7 +1,7 @@
 Changes specific to mutt-ng:
 
 2005-03-10:
-  * included CD's ifdef patch
+  * included CD's ifdef patch plus extension ('ifndef', feature_*), see manual
 
 2005-03-05:
   * added color sidebar
index c2cc7d5..c446064 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -16,8 +16,9 @@ this still likely is incomplete. Please report missing items to
 
 2005-03-10
 
-  New Configuration Command (from CD's ifdef Patch):
+  New Configuration Command (based on CD's ifdef Patch):
     - ifdef
+    - ifndef
 
 2005-03-07
 
index f07f026..3397b32 100644 (file)
@@ -1709,19 +1709,51 @@ If the filename ends with a vertical bar (|), then <em/filename/ is
 considered to be an executable program from which to read input (eg.
 <tt>source ~/bin/myscript|</tt>).
 
-<sect1>Configuring features conditionnaly<label id="ifdef">
+<sect1>Configuring features conditionaly<label id="ifdef">
 <p>
 Usage: <tt/ifdef/ <em/item/ <em/command/
+Usage: <tt/ifndef/ <em/item/ <em/command/
 
-This command allows to test if a feature has been compiled in, before
-actually executing the command. Item can be either the name of a
-function or a variable.
+These command allows to test if a variable, function or certain feature
+is available or not respectively, before actually executing the command.
+<tt/ifdef/ (short for ``if defined) handles commands if upon
+availability while <tt/ifndef/ (short for ``if not defined'') does if
+not. The <em/command/ may be any valid fraction of a configuration file.
 
-Example:
+All names of variables and functions may be tested. Additionally, the
+following compile-features may be tested when prefixed with 'feature_':
+ncurses, slang, iconv, idn, dotlock, standalone, pop, nntp, imap, ssl,
+gnutls, sasl, sasl2, libesmtp, compressed, color, classic_pgp,
+classic_smime, gpgme, header_cache.
+
+Examples follow.
+
+To only source a file with IMAP related settings only if IMAP support is
+compiled in, use:
 <tscreen><verb>
-ifdef imap_keepalive 'source ~/.mutt/imap_setup'
+ifdef feature_imap 'source ~/.mutt-ng/imap_setup'
+# or
+# ifdef imap_user 'source ~/.mutt-ng/imap_setup'
+# or
+# ...
 </verb></tscreen>
 
+To exit mutt-ng directly if no NNTP support is compiled in:
+<tscreen><verb>
+ifndef feature_nntp 'push q'
+# or
+# ifndef newsrc 'push q'
+# or
+# ...
+</verb/</tscreen>
+
+To only set the <ref id="imap_mail_check"
+name="&lt;&dollar;imap&lowbar;mail&lowbar;check"> when the system's SVN
+is recent enough to have it:
+<tscreen><verb>
+ifdef imap_mail_check 'set imap_mail_check=300'
+</tscreen></verb>
+
 <sect1>Removing hooks<label id="unhook">
 <p>
 Usage: <tt/unhook/ &lsqb; * | <em/hook-type/ &rsqb;
diff --git a/init.c b/init.c
index 9c81fe1..5ac2110 100644 (file)
--- a/init.c
+++ b/init.c
@@ -567,19 +567,41 @@ static int parse_ifdef (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
          break;
        }
     }
+  /* check for feature_* */
+  if (!res) {
+    char* p = NULL;
+    i = 0;
+    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 (mutt_strlen (Features[i].name) == j &&
+            ascii_strncasecmp (Features[i].name, p, j)) {
+          res = 1;
+          break;
+        }
+        i++;
+      }
+    }
+  }
 
   if (!MoreArgs (s))
   {
-    snprintf (err->data, err->dsize, _("ifdef: too few arguments"));
+    if (data)
+      snprintf (err->data, err->dsize, _("ifdef: too few arguments"));
+    else
+      snprintf (err->data, err->dsize, _("ifndef: too few arguments"));
     return (-1);
   }
   mutt_extract_token (tmp, s, M_TOKEN_SPACE);
 
-  if (res)
+  if ((data && res) || (!data && !res))
   {
     if (mutt_parse_rc_line (tmp->data, &token, err) == -1)
     {
-      mutt_error ("Erreur: %s", err->data);
+      mutt_error ("Error: %s", err->data);
       FREE (&token.data);
       return (-1);
     }
diff --git a/init.h b/init.h
index e1bf9f1..d9e7620 100644 (file)
--- a/init.h
+++ b/init.h
@@ -72,6 +72,12 @@ struct option_t
   unsigned long init; /* initial value */
 };
 
+struct feature_t
+{
+  char* name;
+  short builtin;
+};
+
 #define UL (unsigned long)
 
 #endif /* _MAKEDOC */
@@ -3454,6 +3460,132 @@ struct option_t MuttVars[] = {
   { NULL }
 };
 
+const struct feature_t Features[] = {
+  { "ncurses", 
+#ifdef NCURSES_VERSION
+    1
+#else
+    0
+#endif
+  }, { "slang",
+#ifdef USE_SLANG_CURSES
+    1
+#else
+    0
+#endif
+  }, { "iconv",
+#ifdef _LIBICONV_VERSION
+    1
+#else
+    0
+#endif
+  }, { "idn",
+#ifdef HAVE_LIBIDN
+    1
+#else
+    0
+#endif
+  }, { "dotlock",
+#ifdef USE_DOTLOCK
+    1
+#else
+    0
+#endif
+  }, { "standalone",
+#ifdef DL_STANDALONE
+    1
+#else
+    0
+#endif
+  }, { "pop",
+#ifdef USE_POP
+    1
+#else
+    0
+#endif
+  }, { "nntp",
+#ifdef USE_NNTP
+    1
+#else
+    0
+#endif
+  }, { "imap",
+#ifdef USE_IMAP
+    1
+#else
+    0
+#endif
+  }, { "ssl",
+#ifdef USE_SSL
+    1
+#else
+    0
+#endif
+  }, { "gnutls",
+#ifdef USE_GNUTLS
+    1
+#else
+    0
+#endif
+  }, { "sasl",
+#ifdef USE_SASL
+    1
+#else
+    0
+#endif
+  }, { "sasl2",
+#ifdef USE_SASL2
+    1
+#else
+    0
+#endif
+  }, { "libesmtp",
+#ifdef USE_LIBESMTP
+    1
+#else
+    0
+#endif
+  }, { "compressed",
+#ifdef USE_COMPRESSED
+    1
+#else
+    0
+#endif
+  }, { "color",
+#ifdef HAVE_COLOR
+    1
+#else
+    0
+#endif
+  }, { "classic_pgp",
+#ifdef CRYPT_BACKEND_CLASSIC_PGP
+    1
+#else
+    0
+#endif
+  }, { "classic_smime",
+#ifdef CRYPT_BACKEND_CLASSIC_SMIME
+    1
+#else
+    0
+#endif
+  }, { "gpgme",
+#ifdef CRYPT_BACKEND_GPGME
+    1
+#else
+    0
+#endif
+  }, { "header_cache",
+#ifdef USE_HCACHE
+    1
+#else
+    0
+#endif
+  },
+  /* last */
+  { NULL,       0 }
+};
+
 const struct mapping_t SortMethods[] = {
   { "date",            SORT_DATE },
   { "date-sent",       SORT_DATE },
@@ -3571,8 +3703,9 @@ struct command_t Commands[] = {
   { "append-hook",     mutt_parse_hook,        M_APPENDHOOK },
 #endif
   { "hdr_order",       parse_list,             UL &HeaderOrderList },
+  { "ifdef",           parse_ifdef,            1 },
+  { "ifndef",          parse_ifdef,            0 },
 #ifdef HAVE_ICONV
-  { "ifdef",           parse_ifdef,            0 },
   { "iconv-hook",      mutt_parse_hook,        M_ICONVHOOK }, 
 #endif
   { "ignore",          parse_ignore,           0 },