Re: [WIP PATCH] emacs: query: completion for from: in searches
[notmuch-archives.git] / 21 / 439b6958805e8eb36551c1c1541975ca81c32a
1 Return-Path: <tomc@caurea.org>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1503B4196F2\r
6         for <notmuch@notmuchmail.org>; Mon, 12 Apr 2010 20:54:40 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.499\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.499 tagged_above=-999 required=5\r
12         tests=[BAYES_05=-0.5, WEIRD_QUOTING=0.001] autolearn=ham\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id ANZ-OVAlUPtu for <notmuch@notmuchmail.org>;\r
16         Mon, 12 Apr 2010 20:54:39 -0700 (PDT)\r
17 X-Greylist: delayed 537 seconds by postgrey-1.32 at olra;\r
18         Mon, 12 Apr 2010 20:54:38 PDT\r
19 Received: from scotch.caurea.org (ks311007.kimsufi.com [188.165.197.188])\r
20         by olra.theworths.org (Postfix) with ESMTP id E72EB431FC1\r
21         for <notmuch@notmuchmail.org>; Mon, 12 Apr 2010 20:54:38 -0700 (PDT)\r
22 Received: by scotch.caurea.org (Postfix, from userid 101)\r
23         id EB54012B1B4; Tue, 13 Apr 2010 05:45:53 +0200 (CEST)\r
24 From: Tomas Carnecky <tom@dbservice.com>\r
25 To: notmuch@notmuchmail.org\r
26 Subject: [PATCH] Add compat version of strcasestr\r
27 Date: Tue, 13 Apr 2010 05:45:51 +0200\r
28 Message-Id: <1271130351-21207-1-git-send-email-tom@dbservice.com>\r
29 X-Mailer: git-send-email 1.7.0.2\r
30 X-BeenThere: notmuch@notmuchmail.org\r
31 X-Mailman-Version: 2.1.13\r
32 Precedence: list\r
33 List-Id: "Use and development of the notmuch mail system."\r
34         <notmuch.notmuchmail.org>\r
35 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
36         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
37 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
38 List-Post: <mailto:notmuch@notmuchmail.org>\r
39 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
40 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
42 X-List-Received-Date: Tue, 13 Apr 2010 03:54:40 -0000\r
43 \r
44 strcasestr is not part of any standard (unlike for example strcasecmp) and thus\r
45 not available on all platforms (in my case Solaris).\r
46 \r
47 ---\r
48  compat/Makefile.local    |    4 ++++\r
49  compat/compat.h          |    4 ++++\r
50  compat/have_strcasestr.c |    8 ++++++++\r
51  compat/strcasestr.c      |   15 +++++++++++++++\r
52  configure                |   19 +++++++++++++++++--\r
53  5 files changed, 48 insertions(+), 2 deletions(-)\r
54  create mode 100644 compat/have_strcasestr.c\r
55  create mode 100644 compat/strcasestr.c\r
56 \r
57 diff --git a/compat/Makefile.local b/compat/Makefile.local\r
58 index 81e6c70..328eca2 100644\r
59 --- a/compat/Makefile.local\r
60 +++ b/compat/Makefile.local\r
61 @@ -8,3 +8,7 @@ notmuch_compat_srcs =\r
62  ifneq ($(HAVE_GETLINE),1)\r
63  notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c\r
64  endif\r
65 +\r
66 +ifneq ($(HAVE_STRCASESTR),1)\r
67 +notmuch_compat_srcs += $(dir)/strcasestr.c\r
68 +endif\r
69 diff --git a/compat/compat.h b/compat/compat.h\r
70 index d639e0f..be70bd8 100644\r
71 --- a/compat/compat.h\r
72 +++ b/compat/compat.h\r
73 @@ -38,4 +38,8 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);\r
74  \r
75  #endif /* !HAVE_GETLINE */\r
76  \r
77 +#if !HAVE_STRCASESTR\r
78 +char *strcasestr(char *a, char *b);\r
79 +#endif /* !HAVE_STRCASESTR */\r
80 +\r
81  #endif /* NOTMUCH_COMPAT_H */\r
82 diff --git a/compat/have_strcasestr.c b/compat/have_strcasestr.c\r
83 new file mode 100644\r
84 index 0000000..36e760d\r
85 --- /dev/null\r
86 +++ b/compat/have_strcasestr.c\r
87 @@ -0,0 +1,8 @@\r
88 +\r
89 +#include <string.h>\r
90 +#include <strings.h>\r
91 +\r
92 +int main()\r
93 +{\r
94 +       return strcasestr("","");\r
95 +}\r
96 diff --git a/compat/strcasestr.c b/compat/strcasestr.c\r
97 new file mode 100644\r
98 index 0000000..a4188b9\r
99 --- /dev/null\r
100 +++ b/compat/strcasestr.c\r
101 @@ -0,0 +1,15 @@\r
102 +\r
103 +#include <string.h>\r
104 +#include <strings.h>\r
105 +\r
106 +char *strcasestr(char *a, char *b)\r
107 +{\r
108 +  size_t l;\r
109 +  char f[3];\r
110 +  \r
111 +  snprintf(f, sizeof(f), "%c%c", tolower(*b), toupper(*b));\r
112 +  for (l = strcspn(a, f); l != strlen(a); l += strcspn(a + l + 1, f) + 1)\r
113 +    if (strncasecmp(a + l, b, strlen(b)) == 0)\r
114 +      return a + l;\r
115 +  return NULL;\r
116 +}      \r
117 diff --git a/configure b/configure\r
118 index 5af7852..add2da6 100755\r
119 --- a/configure\r
120 +++ b/configure\r
121 @@ -310,6 +310,17 @@ else\r
122  fi\r
123  rm -f compat/have_getline\r
124  \r
125 +printf "Checking for strcasestr... "\r
126 +if ${CC} -o compat/have_strcasestr compat/have_strcasestr.c > /dev/null 2>&1\r
127 +then\r
128 +    printf "Yes.\n"\r
129 +    have_strcasestr=1\r
130 +else\r
131 +    printf "No (will use our own instead).\n"\r
132 +    have_strcasestr=0\r
133 +fi\r
134 +rm -f compat/have_strcasestr\r
135 +\r
136  cat <<EOF\r
137  \r
138  All required packages were found. You may now run the following\r
139 @@ -384,6 +395,10 @@ zsh_completion_dir = \$(prefix)/share/zsh/functions/Completion/Unix\r
140  # build its own version)\r
141  HAVE_GETLINE = ${have_getline}\r
142  \r
143 +# Whether the strcasestr function is available (if not, then notmuch will\r
144 +# build its own version) \r
145 +HAVE_STRCASESTR = ${have_strcasestr} \r
146 +\r
147  # Flags needed to compile and link against Xapian\r
148  XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
149  XAPIAN_LDFLAGS = ${xapian_ldflags}\r
150 @@ -405,9 +420,9 @@ VALGRIND_CFLAGS = ${valgrind_cflags}\r
151  # Combined flags for compiling and linking against all of the above\r
152  CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
153                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\\r
154 -                  \$(VALGRIND_CFLAGS)\r
155 +                  \$(VALGRIND_CFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
156  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
157                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
158 -                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)\r
159 +                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS) -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)\r
160  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
161  EOF\r
162 -- \r
163 1.7.0.2\r
164 \r