Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 4a / b250dd412dbf4c89bf2a888eece8e289f015ac
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 15877431FD5\r
6         for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:17:08 -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\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 tNOHric-MyAQ for <notmuch@notmuchmail.org>;\r
16         Sat, 29 Mar 2014 11:16:59 -0700 (PDT)\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 99710431FBC\r
21         for <notmuch@notmuchmail.org>; Sat, 29 Mar 2014 11:16:52 -0700 (PDT)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1WTxoK-0007wv-Bu; Sat, 29 Mar 2014 15:16:52 -0300\r
25 Received: (nullmailer pid 29816 invoked by uid 1000); Sat, 29 Mar 2014\r
26         18:16:38 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [Patch v2 2/3] util: add gzreadline\r
30 Date: Sat, 29 Mar 2014 15:16:31 -0300\r
31 Message-Id: <1396116992-29640-3-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.9.0\r
33 In-Reply-To: <1396116992-29640-1-git-send-email-david@tethera.net>\r
34 References: <1396100785-8744-1-git-send-email-david@tethera.net>\r
35         <1396116992-29640-1-git-send-email-david@tethera.net>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.13\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Sat, 29 Mar 2014 18:17:08 -0000\r
49 \r
50 The idea is to provide a more or less drop in replacement for readline\r
51 to read from zlib/gzip streams.  Take the opportunity to replace\r
52 malloc with talloc.\r
53 ---\r
54  util/Makefile.local |  2 +-\r
55  util/zlib-extra.c   | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++\r
56  util/zlib-extra.h   | 10 +++++++++\r
57  3 files changed, 70 insertions(+), 1 deletion(-)\r
58  create mode 100644 util/zlib-extra.c\r
59  create mode 100644 util/zlib-extra.h\r
60 \r
61 diff --git a/util/Makefile.local b/util/Makefile.local\r
62 index 29c0ce6..e2a5b65 100644\r
63 --- a/util/Makefile.local\r
64 +++ b/util/Makefile.local\r
65 @@ -4,7 +4,7 @@ dir := util\r
66  extra_cflags += -I$(srcdir)/$(dir)\r
67  \r
68  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
69 -                 $(dir)/string-util.c $(dir)/talloc-extra.c\r
70 +                 $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c\r
71  \r
72  libutil_modules := $(libutil_c_srcs:.c=.o)\r
73  \r
74 diff --git a/util/zlib-extra.c b/util/zlib-extra.c\r
75 new file mode 100644\r
76 index 0000000..cda369f\r
77 --- /dev/null\r
78 +++ b/util/zlib-extra.c\r
79 @@ -0,0 +1,59 @@\r
80 +/* zlib-extra.c -  Extra or enhanced routines for compressed I/O.\r
81 + *\r
82 + * Copyright (c) 2014 David Bremner\r
83 + *\r
84 + * This program is free software: you can redistribute it and/or modify\r
85 + * it under the terms of the GNU General Public License as published by\r
86 + * the Free Software Foundation, either version 3 of the License, or\r
87 + * (at your option) any later version.\r
88 + *\r
89 + * This program is distributed in the hope that it will be useful,\r
90 + * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
91 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
92 + * GNU General Public License for more details.\r
93 + *\r
94 + * You should have received a copy of the GNU General Public License\r
95 + * along with this program.  If not, see http://www.gnu.org/licenses/ .\r
96 + *\r
97 + * Author: David Bremner <david@tethera.net>\r
98 + */\r
99 +\r
100 +#include "zlib-extra.h"\r
101 +#include <talloc.h>\r
102 +#include <stdio.h>\r
103 +#include <string.h>\r
104 +\r
105 +/* mimic POSIX/glibc getline, but on a zlib gzFile stream, and using talloc */\r
106 +ssize_t\r
107 +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream) {\r
108 +\r
109 +    size_t len=*n;\r
110 +    char *buf = *lineptr;\r
111 +    size_t offset = 0;\r
112 +\r
113 +    if (len == 0 || buf == NULL) {\r
114 +       /* XXX arbitrary choice of initial size */\r
115 +       len = BUFSIZ;\r
116 +       buf = talloc_size (ctx, len);\r
117 +    }\r
118 +\r
119 +    while (1) {\r
120 +\r
121 +       if (!gzgets (stream, buf + offset, len))\r
122 +           return -1;\r
123 +\r
124 +       /* XXX wasted effort re-counting length of whole line */\r
125 +       offset = strlen (buf);\r
126 +\r
127 +       if ( buf[offset-1] == '\n' )\r
128 +           break;\r
129 +\r
130 +       len *= 2;\r
131 +       buf = talloc_realloc (ctx, buf, char, len);\r
132 +\r
133 +    }\r
134 +\r
135 +    *lineptr = buf;\r
136 +    *n = len;\r
137 +    return offset;\r
138 +}\r
139 diff --git a/util/zlib-extra.h b/util/zlib-extra.h\r
140 new file mode 100644\r
141 index 0000000..c18480f\r
142 --- /dev/null\r
143 +++ b/util/zlib-extra.h\r
144 @@ -0,0 +1,10 @@\r
145 +#ifndef _ZLIB_EXTRA_H\r
146 +#define _ZLIB_EXTRA_H\r
147 +\r
148 +#include <zlib.h>\r
149 +\r
150 +/* Like getline, but read from a gzFile. Allocation is with talloc */\r
151 +ssize_t\r
152 +gzgetline (void *ctx, char **lineptr, size_t *n, gzFile stream);\r
153 +\r
154 +#endif\r
155 -- \r
156 1.9.0\r
157 \r