Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / df / 42a3d5999a2d7f00e8e30764a96cb4d8426031
1 Return-Path: <tomi.ollila@iki.fi>\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 5186D431FAF\r
6         for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 14:34:21 -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 rnQ+3MEYycJ8 for <notmuch@notmuchmail.org>;\r
16         Sat, 24 Nov 2012 14:34:21 -0800 (PST)\r
17 Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34])\r
18         by olra.theworths.org (Postfix) with ESMTP id CD668431FAE\r
19         for <notmuch@notmuchmail.org>; Sat, 24 Nov 2012 14:34:20 -0800 (PST)\r
20 Received: from guru.guru-group.fi (localhost [IPv6:::1])\r
21         by guru.guru-group.fi (Postfix) with ESMTP id 44C7F10010B;\r
22         Sun, 25 Nov 2012 00:34:19 +0200 (EET)\r
23 From: Tomi Ollila <tomi.ollila@iki.fi>\r
24 To: markwalters1009 <markwalters1009@gmail.com>, notmuch@notmuchmail.org\r
25 Subject: Re: [PATCH v2 1/7] cli: allow query to come from stdin\r
26 In-Reply-To: <1353763256-32336-2-git-send-email-markwalters1009@gmail.com>\r
27 References: <1353763256-32336-1-git-send-email-markwalters1009@gmail.com>\r
28         <1353763256-32336-2-git-send-email-markwalters1009@gmail.com>\r
29 User-Agent: Notmuch/0.14+84~g8a199bf (http://notmuchmail.org) Emacs/24.2.1\r
30         (x86_64-unknown-linux-gnu)\r
31 X-Face: HhBM'cA~<r"^Xv\KRN0P{vn'Y"Kd;zg_y3S[4)KSN~s?O\"QPoL\r
32         $[Xv_BD:i/F$WiEWax}R(MPS`^UaptOGD`*/=@\1lKoVa9tnrg0TW?"r7aRtgk[F\r
33         !)g;OY^,BjTbr)Np:%c_o'jj,Z\r
34 Date: Sun, 25 Nov 2012 00:34:19 +0200\r
35 Message-ID: <m238zyk4us.fsf@guru.guru-group.fi>\r
36 MIME-Version: 1.0\r
37 Content-Type: text/plain\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Sat, 24 Nov 2012 22:34:21 -0000\r
51 \r
52 On Sat, Nov 24 2012, markwalters1009 wrote:\r
53 \r
54 > From: Mark Walters <markwalters1009@gmail.com>\r
55 >\r
56 > After this series there will be times when a caller will want to pass\r
57 > a very large query string to notmuch (eg a list of 10,000 message-ids)\r
58 > and this can exceed the size of ARG_MAX. Hence allow notmuch to take\r
59 > the query from stdin (if the query is -).\r
60 \r
61 \r
62 > ---\r
63 >  query-string.c |   41 +++++++++++++++++++++++++++++++++++++++++\r
64 >  1 files changed, 41 insertions(+), 0 deletions(-)\r
65 >\r
66 > diff --git a/query-string.c b/query-string.c\r
67 > index 6536512..b1fbdeb 100644\r
68 > --- a/query-string.c\r
69 > +++ b/query-string.c\r
70 > @@ -20,6 +20,44 @@\r
71 >  \r
72 >  #include "notmuch-client.h"\r
73 >  \r
74 > +/* Read a single query string from STDIN, using\r
75 > + * 'ctx' as the talloc owner for all allocations.\r
76 > + *\r
77 > + * This function returns NULL in case of insufficient memory or read\r
78 > + * errors.\r
79 > + */\r
80 > +static char *\r
81 > +query_string_from_stdin (void *ctx)\r
82 \r
83 Austin provided pretty nice alternative implementation of \r
84 query_string_from_stdin() in his reply so I decline to\r
85 comment minor formatting issue below :D\r
86 \r
87 > +{\r
88 > +    char *query_string;\r
89 > +    char buf[4096];\r
90 > +    ssize_t remain;\r
91 > +\r
92 > +    query_string = talloc_strdup (ctx, "");\r
93 > +    if (query_string == NULL)\r
94 > +     return NULL;\r
95 > +\r
96 > +    for (;;) {\r
97 > +     remain = read (STDIN_FILENO, buf, sizeof(buf) - 1);\r
98 > +     if (remain == 0)\r
99 > +         break;\r
100 > +     if (remain < 0) {\r
101 > +         if (errno == EINTR)\r
102 > +             continue;\r
103 > +         fprintf (stderr, "Error: reading from standard input: %s\n",\r
104 > +                  strerror (errno));\r
105 > +         return NULL;\r
106 > +     }\r
107 > +\r
108 > +     buf[remain] = '\0';\r
109 > +     query_string = talloc_strdup_append (query_string, buf);\r
110 > +     if (query_string == NULL)\r
111 > +         return NULL;\r
112 > +    }\r
113 > +\r
114 > +    return query_string;\r
115 > +}\r
116 > +\r
117 >  /* Construct a single query string from the passed arguments, using\r
118 >   * 'ctx' as the talloc owner for all allocations.\r
119 >   *\r
120 > @@ -35,6 +73,9 @@ query_string_from_args (void *ctx, int argc, char *argv[])\r
121 >      char *query_string;\r
122 >      int i;\r
123 >  \r
124 > +    if ((argc == 1) && (strcmp ("-", argv[0]) == 0))\r
125 \r
126 the argument order in strcmp() is not consistent with all the \r
127 other uses of strcmp () in the codebase.\r
128 \r
129 > +     return query_string_from_stdin (ctx);\r
130 > +\r
131 >      query_string = talloc_strdup (ctx, "");\r
132 >      if (query_string == NULL)\r
133 >       return NULL;\r
134 > -- \r
135 > 1.7.9.1\r
136 \r
137 Tomi\r