You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ifdef.patch 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. From: Cedric Duval <cedricduval@free.fr>
  2. Date: Thu, 27 Feb 2014 12:06:21 +0100
  3. Subject: ifdef
  4. This command allows to test if a feature has been compiled in before
  5. actually attempting to configure / use it.
  6. Syntax:
  7. ifdef <item> <command>
  8. where <item> can be the name of a variable, function, or command.
  9. Examples:
  10. ifdef imap-fetch-mail 'source ~/.mutt/imap_setup'
  11. ifdef trash set trash=~/Mail/trash
  12. * Patch last synced with upstream:
  13. - Date: 2007-02-15
  14. - File:
  15. http://cedricduval.free.fr/mutt/patches/download/patch-1.5.4.cd.ifdef.1
  16. * Changes made:
  17. - Updated to 1.5.13
  18. - Also look for commands
  19. - Use mutt_strcmp in favor of ascii_strncasecmp to compare strings.
  20. Signed-off-by: Matteo F. Vescovi <mfvescovi@gmail.com>
  21. Gbp-Pq: Topic features
  22. ---
  23. doc/manual.xml.head | 22 ++++++++++++++++++++
  24. init.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++
  25. init.h | 2 ++
  26. 3 files changed, 83 insertions(+)
  27. diff --git a/doc/manual.xml.head b/doc/manual.xml.head
  28. index 0093685..18ae918 100644
  29. --- a/doc/manual.xml.head
  30. +++ b/doc/manual.xml.head
  31. @@ -4378,6 +4378,28 @@ from which to read input (e.g. <literal><command>source</command>
  32. </sect1>
  33. +<sect1 id="ifdef">
  34. +
  35. +<title>Configuring features conditionally</title>
  36. +
  37. +<para>
  38. +Usage: <literal>ifdef</literal> <emphasis>item</emphasis> <emphasis>command</emphasis>
  39. +</para>
  40. +
  41. +<para>
  42. +This command allows to test if a feature has been compiled in, before
  43. +actually executing the command. Item can be either the name of a
  44. +function, variable, or command. Example:
  45. +</para>
  46. +
  47. +<para>
  48. +<screen>
  49. +ifdef imap_keepalive 'source ~/.mutt/imap_setup'
  50. +</screen>
  51. +</para>
  52. +
  53. +</sect1>
  54. +
  55. <sect1 id="unhook">
  56. <title>Removing Hooks</title>
  57. diff --git a/init.c b/init.c
  58. index 4897b9e..cc3cf4b 100644
  59. --- a/init.c
  60. +++ b/init.c
  61. @@ -601,6 +601,65 @@ static void remove_from_list (LIST **l, const char *str)
  62. }
  63. }
  64. +static int parse_ifdef (BUFFER *tmp, BUFFER *s, unsigned long data, BUFFER *err)
  65. +{
  66. + int i, j, res = 0;
  67. + BUFFER token;
  68. +
  69. + memset (&token, 0, sizeof (token));
  70. + mutt_extract_token (tmp, s, 0);
  71. +
  72. + /* is the item defined as a variable? */
  73. + res = (mutt_option_index (tmp->data) != -1);
  74. +
  75. + /* a function? */
  76. + if (!res)
  77. + for (i = 0; !res && i < MENU_MAX; i++)
  78. + {
  79. + struct binding_t *b = km_get_table (Menus[i].value);
  80. +
  81. + if (!b)
  82. + continue;
  83. +
  84. + for (j = 0; b[j].name; j++)
  85. + if (!mutt_strcmp (tmp->data, b[j].name))
  86. + {
  87. + res = 1;
  88. + break;
  89. + }
  90. + }
  91. +
  92. + /* a command? */
  93. + if (!res)
  94. + for (i = 0; Commands[i].name; i++)
  95. + {
  96. + if (!mutt_strcmp (tmp->data, Commands[i].name))
  97. + {
  98. + res = 1;
  99. + break;
  100. + }
  101. + }
  102. +
  103. + if (!MoreArgs (s))
  104. + {
  105. + snprintf (err->data, err->dsize, _("ifdef: too few arguments"));
  106. + return (-1);
  107. + }
  108. + mutt_extract_token (tmp, s, M_TOKEN_SPACE);
  109. +
  110. + if (res)
  111. + {
  112. + if (mutt_parse_rc_line (tmp->data, &token, err) == -1)
  113. + {
  114. + mutt_error ("Erreur: %s", err->data);
  115. + FREE (&token.data);
  116. + return (-1);
  117. + }
  118. + FREE (&token.data);
  119. + }
  120. + return 0;
  121. +}
  122. +
  123. static int parse_unignore (BUFFER *buf, BUFFER *s, unsigned long data, BUFFER *err)
  124. {
  125. do
  126. diff --git a/init.h b/init.h
  127. index 395cd3f..80d05ce 100644
  128. --- a/init.h
  129. +++ b/init.h
  130. @@ -3487,6 +3487,7 @@ static int parse_lists (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  131. static int parse_unlists (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  132. static int parse_alias (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  133. static int parse_unalias (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  134. +static int parse_ifdef (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  135. static int parse_ignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  136. static int parse_unignore (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  137. static int parse_source (BUFFER *, BUFFER *, unsigned long, BUFFER *);
  138. @@ -3537,6 +3538,7 @@ const struct command_t Commands[] = {
  139. { "group", parse_group, M_GROUP },
  140. { "ungroup", parse_group, M_UNGROUP },
  141. { "hdr_order", parse_list, UL &HeaderOrderList },
  142. + { "ifdef", parse_ifdef, 0 },
  143. #ifdef HAVE_ICONV
  144. { "iconv-hook", mutt_parse_hook, M_ICONVHOOK },
  145. #endif