Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / d9 / 7e6f2404c0793c1a1b9a12f4bb139f562459d5
1 Return-Path: <bremner@tethera.net>\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 497DD431FD9\r
6         for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 16:39:50 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\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 Hoyt0peC-cq9 for <notmuch@notmuchmail.org>;\r
16         Tue, 26 Nov 2013 16:39:44 -0800 (PST)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id BA3AD431FAE\r
21         for <notmuch@notmuchmail.org>; Tue, 26 Nov 2013 16:39:44 -0800 (PST)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1VlTAC-0004bE-BX; Tue, 26 Nov 2013 20:39:32 -0400\r
25 Received: (nullmailer pid 32577 invoked by uid 1000); Wed, 27 Nov 2013\r
26         00:39:28 -0000\r
27 From: david@tethera.net\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [PATCH v2] util: detect byte order\r
30 Date: Tue, 26 Nov 2013 20:38:14 -0400\r
31 Message-Id: <1385512694-32526-1-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.8.4.2\r
33 In-Reply-To: <m2txezqcuf.fsf@guru.guru-group.fi>\r
34 References: <m2txezqcuf.fsf@guru.guru-group.fi>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Wed, 27 Nov 2013 00:39:50 -0000\r
48 \r
49 From: David Bremner <david@tethera.net>\r
50 \r
51 Unfortunately old versions of GCC and clang do not provide byte order\r
52 macros, so we re-invent them.\r
53 \r
54 If UTIL_BYTE_ORDER is not defined or defined to 0, we fall back to\r
55 macros supported by recent versions of GCC and clang\r
56 ---\r
57 \r
58 I think I got all of Tomi's comments, including the most serious one\r
59 about the test in endian-utils.h (LITTLE twice instead of BIG,\r
60 LITTLE).\r
61 \r
62  configure          | 24 ++++++++++++++++++++++--\r
63  lib/libsha1.c      | 21 +++++++--------------\r
64  util/endian-util.h | 38 ++++++++++++++++++++++++++++++++++++++\r
65  3 files changed, 67 insertions(+), 16 deletions(-)\r
66  create mode 100644 util/endian-util.h\r
67 \r
68 diff --git a/configure b/configure\r
69 index 1a8e939..a0c6771 100755\r
70 --- a/configure\r
71 +++ b/configure\r
72 @@ -441,6 +441,19 @@ else\r
73  EOF\r
74  fi\r
75  \r
76 +printf "Checking byte order... "\r
77 +cat> _byteorder.c <<EOF\r
78 +#include <stdio.h>\r
79 +#include <stdint.h>\r
80 +uint32_t test = 0x34333231;\r
81 +int main() { printf("%.4s\n", (const char*)&test); return 0; }\r
82 +EOF\r
83 +${CC} ${CFLAGS} _byteorder.c -o _byteorder > /dev/null 2>&1\r
84 +util_byte_order=$(./_byteorder)\r
85 +echo $util_byte_order\r
86 +\r
87 +#rm -f _byteorder _byteorder.c\r
88 +\r
89  if [ $errors -gt 0 ]; then\r
90      cat <<EOF\r
91  \r
92 @@ -702,6 +715,9 @@ prefix = ${PREFIX}\r
93  # LIBDIR_IN_LDCONFIG value below is still set correctly.\r
94  libdir = ${LIBDIR:=\$(prefix)/lib}\r
95  \r
96 +# byte order within a 32 bit word. 1234 = little, 4321 = big, 0 = guess\r
97 +UTIL_BYTE_ORDER = ${util_byte_order}\r
98 +\r
99  # Whether libdir is in a path configured into ldconfig\r
100  LIBDIR_IN_LDCONFIG = ${libdir_in_ldconfig}\r
101  \r
102 @@ -807,7 +823,9 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
103                    -DHAVE_STRSEP=\$(HAVE_STRSEP)                         \\\r
104                    -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\\r
105                    -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\\r
106 -                  -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
107 +                  -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)         \\\r
108 +                  -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
109 +\r
110  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
111                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
112                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
113 @@ -815,6 +833,8 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
114                      -DHAVE_STRSEP=\$(HAVE_STRSEP)                       \\\r
115                      -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\\r
116                      -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\\r
117 -                    -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)\r
118 +                    -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\\r
119 +                    -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
120 +\r
121  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
122  EOF\r
123 diff --git a/lib/libsha1.c b/lib/libsha1.c\r
124 index 87c7c52..aaaa4eb 100644\r
125 --- a/lib/libsha1.c\r
126 +++ b/lib/libsha1.c\r
127 @@ -34,7 +34,7 @@\r
128  */\r
129  \r
130  #include <string.h>     /* for memcpy() etc.        */\r
131 -\r
132 +#include "endian-util.h"\r
133  #include "libsha1.h"\r
134  \r
135  #if defined(__cplusplus)\r
136 @@ -49,20 +49,13 @@ extern "C"\r
137  \r
138  #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00))\r
139  \r
140 -/* The macros __BYTE_ORDER__ and __ORDER_*_ENDIAN__ are GNU C\r
141 - * extensions. They are also supported by clang as of v3.2 */\r
142 -\r
143 -#ifdef __BYTE_ORDER__\r
144 -#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
145 -#    define bsw_32(p,n) \\r
146 -       { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
147 -#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
148 -#    define bsw_32(p,n)\r
149 -#  else\r
150 -#    error "unknown byte order"\r
151 -#  endif\r
152 +#if (UTIL_BYTE_ORDER == UTIL_ORDER_LITTLE_ENDIAN)\r
153 +#  define bsw_32(p,n) \\r
154 +     { int _i = (n); while(_i--) ((uint32_t*)p)[_i] = bswap_32(((uint32_t*)p)[_i]); }\r
155 +#elif (UTIL_BYTE_ORDER == UTIL_ORDER_BIG_ENDIAN)\r
156 +#  define bsw_32(p,n)\r
157  #else\r
158 -#    error "macro __BYTE_ORDER__ is not defined"\r
159 +#  error "Unsupported byte order"\r
160  #endif\r
161  \r
162  #define SHA1_MASK   (SHA1_BLOCK_SIZE - 1)\r
163 diff --git a/util/endian-util.h b/util/endian-util.h\r
164 new file mode 100644\r
165 index 0000000..bc80c40\r
166 --- /dev/null\r
167 +++ b/util/endian-util.h\r
168 @@ -0,0 +1,38 @@\r
169 +/* this file mimics the macros present in recent GCC and CLANG */\r
170 +\r
171 +#ifndef _ENDIAN_UTIL_H\r
172 +#define _ENDIAN_UTIL_H\r
173 +\r
174 +/* This are prefixed with UTIL to avoid collisions\r
175 + *\r
176 + * You can use something like the following to define UTIL_BYTE_ORDER\r
177 + * in a configure script.\r
178 + */\r
179 +#if 0\r
180 +#include <stdio.h>\r
181 +#include <stdint.h>\r
182 +uint32_t test = 0x34333231;\r
183 +int main() { printf("%.4s\n", (const char*)&test); return 0; }\r
184 +#endif\r
185 +\r
186 +#define UTIL_ORDER_BIG_ENDIAN    4321\r
187 +#define UTIL_ORDER_LITTLE_ENDIAN  1234\r
188 +\r
189 +\r
190 +#if !defined(UTIL_BYTE_ORDER) || ((UTIL_BYTE_ORDER != UTIL_ORDER_BIG_ENDIAN) && \\r
191 +                                 (UTIL_BYTE_ORDER != UTIL_ORDER_LITTLE_ENDIAN))\r
192 +#undef UTIL_BYTE_ORDER\r
193 +#ifdef __BYTE_ORDER__\r
194 +#  if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)\r
195 +#    define UTIL_BYTE_ORDER UTIL_ORDER_LITTLE_ENDIAN\r
196 +#  elif (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)\r
197 +#    define UTIL_BYTE_ORDER UTIL_ORDER_BIG_ENDIAN\r
198 +#  else\r
199 +#    error "Unsupported __BYTE_ORDER__"\r
200 +#  endif\r
201 +#else\r
202 +#  error "UTIL_BYTE_ORDER not correctly defined and __BYTE_ORDER__ not defined."\r
203 +#endif\r
204 +#endif\r
205 +\r
206 +#endif\r
207 -- \r
208 1.8.4.2\r
209 \r