Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5a / a5026b997447734bd078be2e2d83e3e5d85e7d
1 Return-Path: <bijan.chokoufe@gmail.com>\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 arlo.cworth.org (Postfix) with ESMTP id A82766DE01EA\r
6  for <notmuch@notmuchmail.org>; Sat, 14 May 2016 08:41:57 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.64\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.64 tagged_above=-999 required=5 tests=[AWL=0.180, \r
12  DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13  FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01,\r
14  RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled\r
15 Received: from arlo.cworth.org ([127.0.0.1])\r
16  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
17  with ESMTP id tyk-CA4XD4Uz for <notmuch@notmuchmail.org>;\r
18  Sat, 14 May 2016 08:41:49 -0700 (PDT)\r
19 Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com\r
20  [74.125.82.67]) by arlo.cworth.org (Postfix) with ESMTPS id 57B266DE01D0 for\r
21  <notmuch@notmuchmail.org>; Sat, 14 May 2016 08:41:49 -0700 (PDT)\r
22 Received: by mail-wm0-f67.google.com with SMTP id e201so9357533wme.2\r
23  for <notmuch@notmuchmail.org>; Sat, 14 May 2016 08:41:49 -0700 (PDT)\r
24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
25  h=date:from:to:subject:message-id:references:mime-version\r
26  :content-disposition:content-transfer-encoding:in-reply-to\r
27  :user-agent; bh=sx7Z6PMn9DIW+syuDyg25KYV7aVN/K0EK0QhqmON3k0=;\r
28  b=hQoc1LuKRIibhGtS29Oz2WP70BQxF4Kldxs2Bkt8A1FKj3+EV5GfydSXsvVOAfeNw3\r
29  rE/uYbyFcU2RWZzvKnFPE4DZhR6Z0r56GpnMo8C9lFf6gLD1QGCk5o2mfoLJz/HRv5Lc\r
30  1HuHJJuxQ7kKsLMMZYxrFl+iytXxtc7JJxfCm8L0gaeWPSpzMIAl/n7xiCgwJ68J2dr/\r
31  ZzbUvQzmMmcCRoqL7vFIfcKtDlch2exYNefIfwYTCRcq8ddxTd3yX5K1d2Ibsfpozrrv\r
32  /CIzaprksBxG5ZiYmoLKOQsye7UY81lH/RqRGWkioelhO26aS2EB6+tTJGJy0/XA1tyc\r
33  T7UA==\r
34 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;\r
35  d=1e100.net; s=20130820;\r
36  h=x-gm-message-state:date:from:to:subject:message-id:references\r
37  :mime-version:content-disposition:content-transfer-encoding\r
38  :in-reply-to:user-agent;\r
39  bh=sx7Z6PMn9DIW+syuDyg25KYV7aVN/K0EK0QhqmON3k0=;\r
40  b=jdvUPxOuC7cYKwdToY+9b1pM0DsvYJv2sIBkrTHyWF0xfR/sWNd8qBj2BNzsebf227\r
41  d4mIak+BhEl2bw1MpDfpq+vI9NWnrvI428OWjic1XRdND8HhtNcLGx2EG9Yft4NNwa0r\r
42  4Rzn+c0xCrFt3uq19xm+dIazjodD6TE2M6/EfUPkQMaVveQ4rkgB+vP2WW395xJM6OJp\r
43  zNjdBrPzAk6MmqL0/BHIiMqB94q41X4N69UaPAuGNArvOcBpG2jw1mNn6OR3X5azQHsl\r
44  1Lf/7J/WRZdw7syulMKwMX212haA1tL9S1kvoILXL0XFaT3hnIOprk2JZcBh+IbxQLRA\r
45  LAvA==\r
46 X-Gm-Message-State:\r
47  AOPr4FWVyZBtE7IpFZiGupOJf67PyR0YhVAkeFhQWRh+0eN7uWd6PoKlxu62auOI5v0rcQ==\r
48 X-Received: by 10.28.211.10 with SMTP id k10mr9281155wmg.82.1463240507968;\r
49  Sat, 14 May 2016 08:41:47 -0700 (PDT)\r
50 Received: from localhost (ip5f5be327.dynamic.kabel-deutschland.de.\r
51  [95.91.227.39])\r
52  by smtp.gmail.com with ESMTPSA id az2sm24241802wjc.6.2016.05.14.08.41.46\r
53  for <notmuch@notmuchmail.org>\r
54  (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);\r
55  Sat, 14 May 2016 08:41:47 -0700 (PDT)\r
56 Date: Sat, 14 May 2016 17:41:46 +0200\r
57 From: Bijan Chokoufe Nejad <bijan.chokoufe@gmail.com>\r
58 To: notmuch@notmuchmail.org\r
59 Subject: Re: [RFC PATCH] RFC: expand_tilde () for potential future path\r
60  expansion\r
61 Message-ID: <20160514154146.GB5583@bijan-TPX1Yoga>\r
62 References: <1463225588-28059-1-git-send-email-tomi.ollila@iki.fi>\r
63 MIME-Version: 1.0\r
64 Content-Type: text/plain; charset=iso-8859-1\r
65 Content-Disposition: inline\r
66 Content-Transfer-Encoding: 8bit\r
67 In-Reply-To: <1463225588-28059-1-git-send-email-tomi.ollila@iki.fi>\r
68 User-Agent: Mutt/1.5.24 (2015-08-30)\r
69 X-BeenThere: notmuch@notmuchmail.org\r
70 X-Mailman-Version: 2.1.20\r
71 Precedence: list\r
72 List-Id: "Use and development of the notmuch mail system."\r
73  <notmuch.notmuchmail.org>\r
74 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
75  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
76 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
77 List-Post: <mailto:notmuch@notmuchmail.org>\r
78 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
79 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
80  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
81 X-List-Received-Date: Sat, 14 May 2016 15:41:57 -0000\r
82 \r
83 (Second Try: This time it should come from a mail adress of the mailing list)\r
84 \r
85 Woops. Now we did it twice. I have my implementation directly in\r
86 notmuch-config.c which makes it harder to test and to reuse elsewhere (not sure\r
87 that this is necessary though).\r
88 \r
89 I tested mine to work with\r
90 \r
91 ~\r
92 ~/\r
93 ~foo/.mail\r
94 ~foo/\r
95 ~foo\r
96 ~bar/.mail\r
97 ~bar/\r
98 ~bar\r
99 \r
100 (where bar is not a user in my system but foo is) and all cases work fine. I\r
101 send the patch and then we can discuss how to proceed. For me both versions look\r
102 good enough though.\r
103 \r
104 On 16-05-14, Tomi Ollila wrote:\r
105 > One implementation how to do this. Output of the "tests".\r
106 >\r
107 > $ sh expand-tilde.c\r
108 > + exec gcc -std=c99 -Wall -Wstrict-prototypes -Winit-self -Wformat=2 -Wcast-align -Wpointer-arith -Wextra -Wwrite-strings -Wcast-qual -Wshadow -Wmissing-include-dirs -Wundef -Wbad-function-cast -Wlogical-op -Waggregate-return -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls -Wnested-externs -Winline -Wvla -Woverlength-strings -Wpadded -O2 -o expand-tilde expand-tilde.c\r
109 > $\r
110 > $ ./expand-tilde\r
111 >\r
112 > input '~',  expanded '/home/too',  rest ''\r
113 > input '~root',  expanded '/root',  rest ''\r
114 >\r
115 > $ HOME=/a/b/c/ ./expand-tilde '~' '~'/ "~$USER" "~$USER/" '~'root '~'root/ '~none' '~none/'\r
116 >\r
117 > input '~',  expanded '/a/b/c/',  rest ''\r
118 > input '~/',  expanded '/a/b/c/',  rest '/'\r
119 > input '~too',  expanded '/home/too',  rest ''\r
120 > input '~too/',  expanded '/home/too',  rest '/'\r
121 > input '~root',  expanded '/root',  rest ''\r
122 > input '~root/',  expanded '/root',  rest '/'\r
123 > input '~none',  expanded '(null)',  rest '~none'\r
124 > input '~none/',  expanded '(null)',  rest '~none/'\r
125 >\r
126 > $ HOME= ./expand-tilde '~' '~'/ "~$USER" "~$USER/"\r
127 >\r
128 > input '~',  expanded '',  rest ''\r
129 > input '~/',  expanded '',  rest '/'\r
130 > input '~too',  expanded '/home/too',  rest ''\r
131 > input '~too/',  expanded '/home/too',  rest '/'\r
132 >\r
133 > $ ( unset HOME; ./expand-tilde '~' '~'/ "~$USER" "~$USER/" )\r
134 >\r
135 > input '~',  expanded '(null)',  rest '~'\r
136 > input '~/',  expanded '(null)',  rest '~/'\r
137 > input '~too',  expanded '/home/too',  rest ''\r
138 > input '~too/',  expanded '/home/too',  rest '/'\r
139 > ---\r
140 >  util/expand-tilde.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
141 >  1 file changed, 102 insertions(+)\r
142 >  create mode 100644 util/expand-tilde.c\r
143 >\r
144 > diff --git a/util/expand-tilde.c b/util/expand-tilde.c\r
145 > new file mode 100644\r
146 > index 0000000..e3097e6\r
147 > --- /dev/null\r
148 > +++ b/util/expand-tilde.c\r
149 > @@ -0,0 +1,102 @@\r
150 > +#if 0 /* -*- mode: c; c-file-style: "stroustrup"; tab-width: 8; -*-\r
151 > + set -eu; trg=`exec basename "$0" .c`; rm -f "$trg"\r
152 > + WARN="-Wall -Wstrict-prototypes -Winit-self -Wformat=2" # -pedantic\r
153 > + WARN="$WARN -Wcast-align -Wpointer-arith " # -Wfloat-equal #-Werror\r
154 > + WARN="$WARN -Wextra -Wwrite-strings -Wcast-qual -Wshadow" # -Wconversion\r
155 > + WARN="$WARN -Wmissing-include-dirs -Wundef -Wbad-function-cast -Wlogical-op"\r
156 > + WARN="$WARN -Waggregate-return -Wold-style-definition"\r
157 > + WARN="$WARN -Wmissing-prototypes -Wmissing-declarations -Wredundant-decls"\r
158 > + WARN="$WARN -Wnested-externs -Winline -Wvla -Woverlength-strings -Wpadded"\r
159 > + case ${1-} in '') set x -O2; shift; esac\r
160 > + #case ${1-} in '') set x -ggdb; shift; esac\r
161 > + set -x; exec ${CC:-gcc} -std=c99 $WARN "$@" -o "$trg" "$0"\r
162 > + exit $?\r
163 > + */\r
164 > +#endif\r
165 > +/*\r
166 > + * $ expand-tilde.c $\r
167 > + *\r
168 > + * Author: Tomi Ollila -- too ät iki piste fi\r
169 > + *\r
170 > + * Created: Sat 14 May 2016 13:10:35 EEST too\r
171 > + * Last modified: Sat 14 May 2016 14:22:10 +0300 too\r
172 > + *\r
173 > + * *** Public Domain ***\r
174 > + */\r
175 > +\r
176 > +#include <stdlib.h>\r
177 > +#include <sys/types.h>\r
178 > +#include <pwd.h>\r
179 > +\r
180 > +/* USER_NAME_MAX_LENGTH is not usually defined (publicly in standard paths). */\r
181 > +\r
182 > +#ifndef USER_NAME_MAX_LENGTH\r
183 > +#define USER_NAME_MAX_LENGTH 32\r
184 > +#endif\r
185 > +\r
186 > +static // for -Wmissing-prototypes\r
187 > +/* This is modeled after expand-file-name in emacs sources (fileio.c);\r
188 > + *  simplified and using constant buffer for user name.\r
189 > + *  neither emacs nor this implementation has restrictions in username chars\r
190 > + *  ...we may be looking forward for multibyte usernames...\r
191 > + */\r
192 > +const char * expand_tilde(const char * path, const char ** rest)\r
193 > +{\r
194 > +    if (path == NULL || path[0] != '~') {\r
195 > +        *rest = path;\r
196 > +        return NULL;\r
197 > +    }\r
198 > +\r
199 > +    if (path[1] == '/' || path[1] == '\0') {\r
200 > +        const char * home = getenv ("HOME");\r
201 > +        *rest = home? path + 1: path;\r
202 > +        return home;\r
203 > +    }\r
204 > +\r
205 > +    char username[USER_NAME_MAX_LENGTH + 1];\r
206 > +    int namepos = 0;\r
207 > +    const char * pathp = path + 1;\r
208 > +\r
209 > +    while (1) {\r
210 > +        username[namepos++] = pathp++[0];\r
211 > +        if (pathp[0] == '/' || pathp[0] == '\0')\r
212 > +            break;\r
213 > +        if (namepos >= USER_NAME_MAX_LENGTH) {\r
214 > +            *rest = path;\r
215 > +            return NULL;\r
216 > +        }\r
217 > +    }\r
218 > +    username[namepos] = '\0';\r
219 > +\r
220 > +    struct passwd * pw = getpwnam (username);\r
221 > +    if (pw == NULL) {\r
222 > +        *rest = path;\r
223 > +        return NULL;\r
224 > +    }\r
225 > +    *rest = path + 1 + namepos;\r
226 > +    return pw->pw_dir;\r
227 > + }\r
228 > +\r
229 > +#include <stdio.h>\r
230 > +\r
231 > +static void print_expanded(const char * path)\r
232 > +{\r
233 > +    const char * rest;\r
234 > +    const char * expanded = expand_tilde(path, &rest);\r
235 > +    printf("input '%s',  expanded '%s',  rest '%s'\n",\r
236 > +           path, expanded, rest);\r
237 > +}\r
238 > +\r
239 > +int main(int argc, char * argv[])\r
240 > +{\r
241 > +    printf("\n");\r
242 > +    if (argc < 2) {\r
243 > +        print_expanded("~\0-- this something not to be seen in output --");\r
244 > +        print_expanded("~root\0-- this something not to be seen in output --");\r
245 > +    } else {\r
246 > +        for (int i = 1; i < argc; i++)\r
247 > +            print_expanded(argv[i]);\r
248 > +    }\r
249 > +    printf("\n");\r
250 > +    return 0;\r
251 > +}\r
252 > --\r
253 > 2.8.2\r
254 >\r