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
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
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
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
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
61 Message-ID: <20160514154146.GB5583@bijan-TPX1Yoga>
\r
62 References: <1463225588-28059-1-git-send-email-tomi.ollila@iki.fi>
\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
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
83 (Second Try: This time it should come from a mail adress of the mailing list)
\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
89 I tested mine to work with
\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
104 On 16-05-14, Tomi Ollila wrote:
\r
105 > One implementation how to do this. Output of the "tests".
\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
112 > input '~', expanded '/home/too', rest ''
\r
113 > input '~root', expanded '/root', rest ''
\r
115 > $ HOME=/a/b/c/ ./expand-tilde '~' '~'/ "~$USER" "~$USER/" '~'root '~'root/ '~none' '~none/'
\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
126 > $ HOME= ./expand-tilde '~' '~'/ "~$USER" "~$USER/"
\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
133 > $ ( unset HOME; ./expand-tilde '~' '~'/ "~$USER" "~$USER/" )
\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
140 > util/expand-tilde.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++
\r
141 > 1 file changed, 102 insertions(+)
\r
142 > create mode 100644 util/expand-tilde.c
\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
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
166 > + * $ expand-tilde.c $
\r
168 > + * Author: Tomi Ollila -- too ät iki piste fi
\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
173 > + * *** Public Domain ***
\r
176 > +#include <stdlib.h>
\r
177 > +#include <sys/types.h>
\r
178 > +#include <pwd.h>
\r
180 > +/* USER_NAME_MAX_LENGTH is not usually defined (publicly in standard paths). */
\r
182 > +#ifndef USER_NAME_MAX_LENGTH
\r
183 > +#define USER_NAME_MAX_LENGTH 32
\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
192 > +const char * expand_tilde(const char * path, const char ** rest)
\r
194 > + if (path == NULL || path[0] != '~') {
\r
199 > + if (path[1] == '/' || path[1] == '\0') {
\r
200 > + const char * home = getenv ("HOME");
\r
201 > + *rest = home? path + 1: path;
\r
205 > + char username[USER_NAME_MAX_LENGTH + 1];
\r
206 > + int namepos = 0;
\r
207 > + const char * pathp = path + 1;
\r
210 > + username[namepos++] = pathp++[0];
\r
211 > + if (pathp[0] == '/' || pathp[0] == '\0')
\r
213 > + if (namepos >= USER_NAME_MAX_LENGTH) {
\r
218 > + username[namepos] = '\0';
\r
220 > + struct passwd * pw = getpwnam (username);
\r
221 > + if (pw == NULL) {
\r
225 > + *rest = path + 1 + namepos;
\r
226 > + return pw->pw_dir;
\r
229 > +#include <stdio.h>
\r
231 > +static void print_expanded(const char * path)
\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
239 > +int main(int argc, char * argv[])
\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
246 > + for (int i = 1; i < argc; i++)
\r
247 > + print_expanded(argv[i]);
\r