[PATCH] Add strcasestr v.3 - add compat implementation of strcasestr
authorDirk Hohndel <hohndel@x200.gr8dns.org>
Tue, 13 Apr 2010 16:47:48 +0000 (09:47 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:37 +0000 (09:36 -0800)
ef/cdd4ed2f32b6f00b265937cba678ff7e120bd0 [new file with mode: 0644]

diff --git a/ef/cdd4ed2f32b6f00b265937cba678ff7e120bd0 b/ef/cdd4ed2f32b6f00b265937cba678ff7e120bd0
new file mode 100644 (file)
index 0000000..8216174
--- /dev/null
@@ -0,0 +1,208 @@
+Return-Path: <hohndel@x200.gr8dns.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 0AE874196F2\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 09:47:54 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.999\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.999 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9, DKIM_ADSP_NXDOMAIN=0.9, NO_DNS_FOR_FROM=0.001]\r
+       autolearn=no\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 7SXldbhBi012 for <notmuch@notmuchmail.org>;\r
+       Tue, 13 Apr 2010 09:47:53 -0700 (PDT)\r
+X-Greylist: delayed 1811 seconds by postgrey-1.32 at olra;\r
+       Tue, 13 Apr 2010 09:47:52 PDT\r
+Received: from mail.hohndel.org (mail.hohndel.org [65.23.157.147])\r
+       by olra.theworths.org (Postfix) with ESMTP id DF86E431FC1\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 09:47:52 -0700 (PDT)\r
+Received: by mail.hohndel.org (Postfix, from userid 112)\r
+       id 2D6F3340FE; Tue, 13 Apr 2010 12:47:52 -0400 (EDT)\r
+Received: from x200.gr8dns.org (unknown [65.23.157.147])\r
+       by mail.hohndel.org (Postfix) with ESMTP id 85CE2340FA\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 12:47:49 -0400 (EDT)\r
+Received: by x200.gr8dns.org (Postfix, from userid 500)\r
+       id 6FD14C00E5; Tue, 13 Apr 2010 09:47:48 -0700 (PDT)\r
+From: Dirk Hohndel <hohndel@x200.gr8dns.org>\r
+To: <notmuch@notmuchmail.org>\r
+Subject: [PATCH] Add strcasestr v.3 - add compat implementation of strcasestr\r
+Date: Tue, 13 Apr 2010 09:47:48 -0700\r
+Message-ID: <m3vdbvb8p7.fsf@x200.gr8dns.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Mailman-Approved-At: Tue, 13 Apr 2010 11:39:58 -0700\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 16:47:54 -0000\r
+\r
+\r
+v.3 of this patch, now with the changes to makefiles, configure script\r
+compat.h and all new files that I need\r
+Please test on platforms lacking strcasestr\r
+\r
+Signed-off-by: Dirk Hohndel <hohndel@infradead.org>\r
+---\r
+ compat/Makefile.local    |    4 ++++\r
+ compat/compat.h          |    4 ++++\r
+ compat/have_strcasestr.c |   10 ++++++++++\r
+ compat/strcasestr.c      |   41 +++++++++++++++++++++++++++++++++++++++++\r
+ configure                |   20 ++++++++++++++++++--\r
+ 5 files changed, 77 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..2a17309 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..173ef68 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(const char *haystack, const char *needle);\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..c0fb762\r
+--- /dev/null\r
++++ b/compat/have_strcasestr.c\r
+@@ -0,0 +1,10 @@\r
++#define _GNU_SOURCE\r
++#include <strings.h>\r
++\r
++int main()\r
++{\r
++    char *found;\r
++    const char *haystack, *needle;\r
++\r
++    found = strcasestr(haystack, needle);\r
++}\r
+diff --git a/compat/strcasestr.c b/compat/strcasestr.c\r
+new file mode 100644\r
+index 0000000..50bc89d\r
+--- /dev/null\r
++++ b/compat/strcasestr.c\r
+@@ -0,0 +1,41 @@\r
++/*\r
++ * slow simplistic reimplementation of strcasestr for systems that\r
++ * don't include it in their library\r
++ *\r
++ * based on a GPL implementation in OpenTTD found under GPL v2\r
++\r
++   This program is free software; you can redistribute it and/or\r
++   modify it under the terms of the GNU General Public License as\r
++   published by the Free Software Foundation, version 2.\r
++\r
++   This program is distributed in the hope that it will be useful, but\r
++   WITHOUT ANY WARRANTY; without even the implied warranty of\r
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++   General Public License for more details.\r
++\r
++   You should have received a copy of the GNU General Public License\r
++   along with this program; if not, write to the Free Software\r
++   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
++   02110-1301, USA.  */\r
++\r
++/* Imported into notmuch by Dirk Hohndel - original author unknown. */\r
++/* the semantic here actually puzzles me:\r
++   how can haystack be const char * - yet the return value is char *\r
++   after all, it points to a sub-string of haystack... */\r
++\r
++#include <string.h>\r
++\r
++char *strcasestr(const char *haystack, const char *needle)\r
++{\r
++      size_t hay_len = strlen(haystack);\r
++      size_t needle_len = strlen(needle);\r
++      while (hay_len >= needle_len) {\r
++              if (strncasecmp(haystack, needle, needle_len) == 0) \r
++                  return (char *) haystack;\r
++\r
++              haystack++;\r
++              hay_len--;\r
++      }\r
++\r
++      return NULL;\r
++}\r
+diff --git a/configure b/configure\r
+index 5af7852..90a399c 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,10 @@ 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)             \\\r
++                     -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
+ CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+ EOF\r
+-- \r
+1.6.6.1\r
+\r
+\r
+-- \r
+Dirk Hohndel\r
+Intel Open Source Technology Center\r