[PATCH 3/4] Private strsep implementation
authorVladimir.Marek <Vladimir.Marek@oracle.com>
Mon, 9 Apr 2012 10:17:44 +0000 (12:17 +0200)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:46:10 +0000 (09:46 -0800)
24/12c55eae6fadba7cb85abff8cd524200cf3848 [new file with mode: 0644]

diff --git a/24/12c55eae6fadba7cb85abff8cd524200cf3848 b/24/12c55eae6fadba7cb85abff8cd524200cf3848
new file mode 100644 (file)
index 0000000..b964e73
--- /dev/null
@@ -0,0 +1,250 @@
+Return-Path: <Vladimir.Marek@oracle.com>\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 9137741647F\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 03:39:53 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.299\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.299 tagged_above=-999 required=5\r
+       tests=[RCVD_IN_DNSWL_MED=-2.3, UNPARSEABLE_RELAY=0.001]\r
+       autolearn=disabled\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 6EhFg7132Yzs for <notmuch@notmuchmail.org>;\r
+       Mon,  9 Apr 2012 03:39:52 -0700 (PDT)\r
+Received: from acsinet14.oracle.com (acsinet14.oracle.com [141.146.126.236])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id C08E841647C\r
+       for <notmuch@notmuchmail.org>; Mon,  9 Apr 2012 03:39:52 -0700 (PDT)\r
+Received: from acsinet15.oracle.com (acsinet15.oracle.com [141.146.126.227])\r
+       by acsinet14.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with\r
+       ESMTP id q39AIinF002233\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK)\r
+       for <notmuch@notmuchmail.org>; Mon, 9 Apr 2012 10:18:44 GMT\r
+Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237])\r
+       by acsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with\r
+       ESMTP id q39AIh6J031164\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK);\r
+       Mon, 9 Apr 2012 10:18:43 GMT\r
+Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158])\r
+       by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id\r
+       q39AIgD6012290\r
+       (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO);\r
+       Mon, 9 Apr 2012 10:18:42 GMT\r
+Received: from abhmt120.oracle.com (abhmt120.oracle.com [141.146.116.72])\r
+       by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id\r
+       q39AIfMD022174; Mon, 9 Apr 2012 05:18:42 -0500\r
+Received: from pub.czech.sun.com (/10.163.20.32)\r
+       by default (Oracle Beehive Gateway v4.0)\r
+       with ESMTP ; Mon, 09 Apr 2012 03:18:41 -0700\r
+From: Vladimir.Marek@oracle.com\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 3/4] Private strsep implementation\r
+Date: Mon,  9 Apr 2012 12:17:44 +0200\r
+Message-Id: <1333966665-10469-4-git-send-email-Vladimir.Marek@oracle.com>\r
+X-Mailer: git-send-email 1.7.3.2\r
+In-Reply-To: <1333966665-10469-1-git-send-email-Vladimir.Marek@oracle.com>\r
+References: <1333966665-10469-1-git-send-email-Vladimir.Marek@oracle.com>\r
+X-Source-IP: acsinet21.oracle.com [141.146.126.237]\r
+X-Auth-Type: Internal IP\r
+X-CT-RefId: str=0001.0A090202.4F82B783.00A1,ss=1,re=0.000,fgs=0\r
+Cc: Vladimir Marek <vlmarek@volny.cz>\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: Mon, 09 Apr 2012 10:39:53 -0000\r
+\r
+From: Vladimir Marek <vlmarek@volny.cz>\r
+\r
+strsep is not available on Solaris 10, so we stole the one used by mutt.\r
+\r
+Signed-off-by: Vladimir Marek <vlmarek@volny.cz>\r
+---\r
+ compat/Makefile.local |    4 +++\r
+ compat/compat.h       |    4 +++\r
+ compat/have_strsep.c  |   10 +++++++\r
+ compat/strsep.c       |   65 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ configure             |   21 ++++++++++++++-\r
+ 5 files changed, 102 insertions(+), 2 deletions(-)\r
+ create mode 100644 compat/have_strsep.c\r
+ create mode 100644 compat/strsep.c\r
+\r
+diff --git a/compat/Makefile.local b/compat/Makefile.local\r
+index 13f16cd..2c4f65f 100644\r
+--- a/compat/Makefile.local\r
++++ b/compat/Makefile.local\r
+@@ -13,4 +13,8 @@ ifneq ($(HAVE_STRCASESTR),1)\r
+ notmuch_compat_srcs += $(dir)/strcasestr.c\r
+ endif\r
\r
++ifneq ($(HAVE_STRSEP),1)\r
++notmuch_compat_srcs += $(dir)/strsep.c\r
++endif\r
++\r
+ SRCS := $(SRCS) $(notmuch_compat_srcs)\r
+diff --git a/compat/compat.h b/compat/compat.h\r
+index b2e2736..cf8d56d 100644\r
+--- a/compat/compat.h\r
++++ b/compat/compat.h\r
+@@ -46,6 +46,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);\r
+ char* strcasestr(const char *haystack, const char *needle);\r
+ #endif /* !HAVE_STRCASESTR */\r
\r
++#if !HAVE_STRSEP\r
++char *strsep(char **stringp, const char *delim);\r
++#endif /* !HAVE_STRSEP */\r
++\r
+ /* Silence gcc warnings about unused results.  These warnings exist\r
+  * for a reason; any use of this needs to be justified. */\r
+ #ifdef __GNUC__\r
+diff --git a/compat/have_strsep.c b/compat/have_strsep.c\r
+new file mode 100644\r
+index 0000000..5bd396c\r
+--- /dev/null\r
++++ b/compat/have_strsep.c\r
+@@ -0,0 +1,10 @@\r
++#define _GNU_SOURCE\r
++#include <string.h>\r
++\r
++int main()\r
++{\r
++    char *found;\r
++    char **stringp, const char *delim;\r
++\r
++    found = strsep(stringp, delim);\r
++}\r
+diff --git a/compat/strsep.c b/compat/strsep.c\r
+new file mode 100644\r
+index 0000000..78ab9e7\r
+--- /dev/null\r
++++ b/compat/strsep.c\r
+@@ -0,0 +1,65 @@\r
++/* Copyright (C) 1992, 93, 96, 97, 98, 99, 2004 Free Software Foundation, Inc.\r
++   This file is part of the GNU C Library.\r
++\r
++   The GNU C Library is free software; you can redistribute it and/or\r
++   modify it under the terms of the GNU Lesser General Public\r
++   License as published by the Free Software Foundation; either\r
++   version 2.1 of the License, or (at your option) any later version.\r
++\r
++   The GNU C Library is distributed in the hope that it will be useful,\r
++   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++   Lesser General Public License for more details.\r
++\r
++   You should have received a copy of the GNU Lesser General Public\r
++   License along with the GNU C Library; if not, write to the Free\r
++   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
++   02111-1307 USA.  */\r
++\r
++#include <string.h>\r
++\r
++/* Taken from glibc 2.6.1 */\r
++\r
++char *strsep (char **stringp, const char *delim)\r
++{\r
++  char *begin, *end;\r
++\r
++  begin = *stringp;\r
++  if (begin == NULL)\r
++    return NULL;\r
++\r
++  /* A frequent case is when the delimiter string contains only one\r
++     character.  Here we don't need to call the expensive `strpbrk'\r
++     function and instead work using `strchr'.  */\r
++  if (delim[0] == '\0' || delim[1] == '\0')\r
++    {\r
++      char ch = delim[0];\r
++\r
++      if (ch == '\0')\r
++      end = NULL;\r
++      else\r
++      {\r
++        if (*begin == ch)\r
++          end = begin;\r
++        else if (*begin == '\0')\r
++          end = NULL;\r
++        else\r
++          end = strchr (begin + 1, ch);\r
++      }\r
++    }\r
++  else\r
++    /* Find the end of the token.  */\r
++    end = strpbrk (begin, delim);\r
++\r
++  if (end)\r
++    {\r
++      /* Terminate the token and set *STRINGP past NUL character.  */\r
++      *end++ = '\0';\r
++      *stringp = end;\r
++    }\r
++  else\r
++    /* No more delimiters; this is the last token.  */\r
++    *stringp = NULL;\r
++\r
++  return begin;\r
++}\r
+diff --git a/configure b/configure\r
+index 6870341..a06df7c 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -486,6 +486,17 @@ else\r
+ fi\r
+ rm -f compat/have_strcasestr\r
\r
++printf "Checking for strsep... "\r
++if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep > /dev/null 2>&1\r
++then\r
++    printf "Yes.\n"\r
++    have_strsep=1\r
++else\r
++    printf "No (will use our own instead).\n"\r
++    have_strsep=0\r
++fi\r
++rm -f compat/have_strsep\r
++\r
+ printf "int main(void){return 0;}\n" > minimal.c\r
\r
+ printf "Checking for rpath support... "\r
+@@ -645,6 +656,10 @@ HAVE_GETLINE = ${have_getline}\r
+ # build its own version)\r
+ HAVE_STRCASESTR = ${have_strcasestr}\r
\r
++# Whether the strsep function is available (if not, then notmuch will\r
++# build its own version)\r
++HAVE_STRSEP = ${have_strsep}\r
++\r
+ # Supported platforms (so far) are: LINUX, MACOSX, SOLARIS\r
+ PLATFORM = ${platform}\r
\r
+@@ -689,10 +704,12 @@ WITH_ZSH = ${WITH_ZSH}\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) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
++                 \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\\r
++                 -DHAVE_STRSEP=\$(HAVE_STRSEP)\r
+ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
+                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
+-                     -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
++                   -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR) \\\r
++                   -DHAVE_STRSEP=\$(HAVE_STRSEP)\r
+ CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+ EOF\r
+-- \r
+1.7.3.2\r
+\r