[PATCH] Add compat version of strcasestr
authorTomas Carnecky <tom@dbservice.com>
Tue, 13 Apr 2010 03:45:51 +0000 (05:45 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:36 +0000 (09:36 -0800)
21/439b6958805e8eb36551c1c1541975ca81c32a [new file with mode: 0644]

diff --git a/21/439b6958805e8eb36551c1c1541975ca81c32a b/21/439b6958805e8eb36551c1c1541975ca81c32a
new file mode 100644 (file)
index 0000000..cbd5830
--- /dev/null
@@ -0,0 +1,164 @@
+Return-Path: <tomc@caurea.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 1503B4196F2\r
+       for <notmuch@notmuchmail.org>; Mon, 12 Apr 2010 20:54:40 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.499\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.499 tagged_above=-999 required=5\r
+       tests=[BAYES_05=-0.5, WEIRD_QUOTING=0.001] autolearn=ham\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id ANZ-OVAlUPtu for <notmuch@notmuchmail.org>;\r
+       Mon, 12 Apr 2010 20:54:39 -0700 (PDT)\r
+X-Greylist: delayed 537 seconds by postgrey-1.32 at olra;\r
+       Mon, 12 Apr 2010 20:54:38 PDT\r
+Received: from scotch.caurea.org (ks311007.kimsufi.com [188.165.197.188])\r
+       by olra.theworths.org (Postfix) with ESMTP id E72EB431FC1\r
+       for <notmuch@notmuchmail.org>; Mon, 12 Apr 2010 20:54:38 -0700 (PDT)\r
+Received: by scotch.caurea.org (Postfix, from userid 101)\r
+       id EB54012B1B4; Tue, 13 Apr 2010 05:45:53 +0200 (CEST)\r
+From: Tomas Carnecky <tom@dbservice.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Add compat version of strcasestr\r
+Date: Tue, 13 Apr 2010 05:45:51 +0200\r
+Message-Id: <1271130351-21207-1-git-send-email-tom@dbservice.com>\r
+X-Mailer: git-send-email 1.7.0.2\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 13 Apr 2010 03:54:40 -0000\r
+\r
+strcasestr is not part of any standard (unlike for example strcasecmp) and thus\r
+not available on all platforms (in my case Solaris).\r
+\r
+---\r
+ compat/Makefile.local    |    4 ++++\r
+ compat/compat.h          |    4 ++++\r
+ compat/have_strcasestr.c |    8 ++++++++\r
+ compat/strcasestr.c      |   15 +++++++++++++++\r
+ configure                |   19 +++++++++++++++++--\r
+ 5 files changed, 48 insertions(+), 2 deletions(-)\r
+ create mode 100644 compat/have_strcasestr.c\r
+ create mode 100644 compat/strcasestr.c\r
+\r
+diff --git a/compat/Makefile.local b/compat/Makefile.local\r
+index 81e6c70..328eca2 100644\r
+--- a/compat/Makefile.local\r
++++ b/compat/Makefile.local\r
+@@ -8,3 +8,7 @@ notmuch_compat_srcs =\r
+ ifneq ($(HAVE_GETLINE),1)\r
+ notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c\r
+ endif\r
++\r
++ifneq ($(HAVE_STRCASESTR),1)\r
++notmuch_compat_srcs += $(dir)/strcasestr.c\r
++endif\r
+diff --git a/compat/compat.h b/compat/compat.h\r
+index d639e0f..be70bd8 100644\r
+--- a/compat/compat.h\r
++++ b/compat/compat.h\r
+@@ -38,4 +38,8 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);\r
\r
+ #endif /* !HAVE_GETLINE */\r
\r
++#if !HAVE_STRCASESTR\r
++char *strcasestr(char *a, char *b);\r
++#endif /* !HAVE_STRCASESTR */\r
++\r
+ #endif /* NOTMUCH_COMPAT_H */\r
+diff --git a/compat/have_strcasestr.c b/compat/have_strcasestr.c\r
+new file mode 100644\r
+index 0000000..36e760d\r
+--- /dev/null\r
++++ b/compat/have_strcasestr.c\r
+@@ -0,0 +1,8 @@\r
++\r
++#include <string.h>\r
++#include <strings.h>\r
++\r
++int main()\r
++{\r
++      return strcasestr("","");\r
++}\r
+diff --git a/compat/strcasestr.c b/compat/strcasestr.c\r
+new file mode 100644\r
+index 0000000..a4188b9\r
+--- /dev/null\r
++++ b/compat/strcasestr.c\r
+@@ -0,0 +1,15 @@\r
++\r
++#include <string.h>\r
++#include <strings.h>\r
++\r
++char *strcasestr(char *a, char *b)\r
++{\r
++  size_t l;\r
++  char f[3];\r
++  \r
++  snprintf(f, sizeof(f), "%c%c", tolower(*b), toupper(*b));\r
++  for (l = strcspn(a, f); l != strlen(a); l += strcspn(a + l + 1, f) + 1)\r
++    if (strncasecmp(a + l, b, strlen(b)) == 0)\r
++      return a + l;\r
++  return NULL;\r
++}     \r
+diff --git a/configure b/configure\r
+index 5af7852..add2da6 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -310,6 +310,17 @@ else\r
+ fi\r
+ rm -f compat/have_getline\r
\r
++printf "Checking for strcasestr... "\r
++if ${CC} -o compat/have_strcasestr compat/have_strcasestr.c > /dev/null 2>&1\r
++then\r
++    printf "Yes.\n"\r
++    have_strcasestr=1\r
++else\r
++    printf "No (will use our own instead).\n"\r
++    have_strcasestr=0\r
++fi\r
++rm -f compat/have_strcasestr\r
++\r
+ cat <<EOF\r
\r
+ All required packages were found. You may now run the following\r
+@@ -384,6 +395,10 @@ zsh_completion_dir = \$(prefix)/share/zsh/functions/Completion/Unix\r
+ # build its own version)\r
+ HAVE_GETLINE = ${have_getline}\r
\r
++# Whether the strcasestr function is available (if not, then notmuch will\r
++# build its own version) \r
++HAVE_STRCASESTR = ${have_strcasestr} \r
++\r
+ # Flags needed to compile and link against Xapian\r
+ XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
+ XAPIAN_LDFLAGS = ${xapian_ldflags}\r
+@@ -405,9 +420,9 @@ VALGRIND_CFLAGS = ${valgrind_cflags}\r
+ # Combined flags for compiling and linking against all of the above\r
+ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
+                  \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\\r
+-                 \$(VALGRIND_CFLAGS)\r
++                 \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
+ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
+                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+-                   \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)\r
++                   \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
+ CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+ EOF\r
+-- \r
+1.7.0.2\r
+\r