From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2189 invoked by alias); 17 Jan 2017 18:36:18 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 40375 Received: (qmail 18126 invoked from network); 17 Jan 2017 18:36:18 -0000 X-Qmail-Scanner-Diagnostics: from mailout3.w1.samsung.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(210.118.77.13):SA:0(-8.2/5.0):. Processed in 1.085518 secs); 17 Jan 2017 18:36:18 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-8.2 required=5.0 tests=RCVD_IN_DNSWL_HI, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: p.stephenson@samsung.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at samsung.com does not designate permitted sender hosts) X-AuditID: cbfec7f4-f79716d000006f65-54-587e641969e3 Date: Tue, 17 Jan 2017 18:36:06 +0000 From: Peter Stephenson To: Zsh hackers list Subject: Re: PATCH: autoload with explicit path Message-id: <20170117183606.5d1db3de@pwslap01u.europe.root.pri> In-reply-to: <20170110193102.7725620a@ntlworld.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrDIsWRmVeSWpSXmKPExsWy7djPc7qSKXURBj/P61scbH7I5MDoserg B6YAxigum5TUnMyy1CJ9uwSujEmXfzIWTB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AkWAVWJ9m3rwGw2AUOJqZtm g9kiAloSO06eZAKxhQX0JaZ/7gUbxCtgL/F/+3WwGk4BY4mWlbuZIYZOZpKYcngPK0iCH6jh 6t9PTBD32UvMvHKGEaJZUOLH5HssIDYz0ILN25pYIWx5ic1r3jJDXKoucePubvYJjMKzkLTM QtIyC0nLAkbmVYwiqaXFuem5xYZ6xYm5xaV56XrJ+bmbGIFxtO3Yz807GC9tDD7EKMDBqMTD GyBaFyHEmlhWXJl7iFGCg1lJhHdSAlCINyWxsiq1KD++qDQntfgQoykwZCYyS4km5wNjPK8k 3tDE0NzS0MjYwsLcyEhJnLfkw5VwIYH0xJLU7NTUgtQimD4mDk6pBkbZK1KHP3zNWs/Yxzhz O+dq5Qn/OuaH3bl6oTf3i2r/ulW3f5U49Nl8fbb3sOJNv+xLyRvSLuWGm8itSDW4F8u5ZPUM HRkLPblvH51myZlGRM2+Kby7rjKi3NZxZc6mh6cC65zOfQlc9GbrwVW7RI497N849/qR2Wdm Xw7Ukyh+wvZun0iXd6mLEktxRqKhFnNRcSIA8L/NdbkCAAA= X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20170117183609eucas1p1ca9f8c6f4d38aaabd8ce159a66860ad9 X-Msg-Generator: CA X-Sender-IP: 182.198.249.179 X-Local-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUb?= =?UTF-8?B?7IK87ISx7KCE7J6QG1ByaW5jaXBhbCBFbmdpbmVlciwgU29mdHdhcmU=?= X-Global-Sender: =?UTF-8?B?UGV0ZXIgU3RlcGhlbnNvbhtTQ1NDLURhdGEgUGxhbmUbU2Ft?= =?UTF-8?B?c3VuZyBFbGVjdHJvbmljcxtQcmluY2lwYWwgRW5naW5lZXIsIFNvZnR3YXJl?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDA1Q0QwNTAwNTg=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20161212160617epcas2p16960e3d95c694147035f760090e6011b X-RootMTR: 20161212160617epcas2p16960e3d95c694147035f760090e6011b References: <20161211221844.5e51affe@ntlworld.com> <161212080550.ZM935@torch.brasslantern.com> <20161212163124.6654f077@pwslap01u.europe.root.pri> <20170110193102.7725620a@ntlworld.com> Currently, autoload /path/to/foo autoload foo leaves foo marked as to be loaded from /path/to/foo. I should probably document this (and that therefore to unmark the path you need to unfunction). I think this is the right way of doing it as the explicit path should continue to override the more vague autoload with no path indicated, and this is safer in case some code decides it needs a function and inadvertently resets the path the user carefully decided to give the function. However, you could argue that "autoload foo" should reset foo to reload from $fpath, as the shell would do if it encountered that command on its own. You can in any case change an explicitly marked path seamlessly by issuing a new command with an absolute path. I have found a bug, though: "autoload /path/to/foo" takes effect even if foo is already loaded, which isn't supposed to happen. Test for this tomorrow. Second hunk is a minor efficiency change: I noticed findcmd() with second argument 1 returns a dupstring() value anyway. pws diff --git a/Src/builtin.c b/Src/builtin.c index b1b6e2e..7a04a79 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3369,6 +3369,31 @@ bin_functions(char *name, char **argv, Options ops, int func) removetrapnode(signum); } + if (**argv == '/') { + char *base = strrchr(*argv, '/') + 1; + if (*base && + (shf = (Shfunc) shfunctab->getnode(shfunctab, base))) { + char *dir; + /* turn on/off the given flags */ + shf->node.flags = + (shf->node.flags | (on & ~PM_UNDEFINED)) & ~off; + if (shf->node.flags & PM_UNDEFINED) { + /* update path if not yet loaded */ + if (base == *argv + 1) + dir = "/"; + else { + dir = *argv; + base[-1] = '\0'; + } + dircache_set(&shf->filename, NULL); + dircache_set(&shf->filename, dir); + } + if (check_autoload(shf, shf->node.nam, ops, func)) + returnval = 1; + continue; + } + } + /* Add a new undefined (autoloaded) function to the * * hash table with the corresponding flags set. */ shf = (Shfunc) zshcalloc(sizeof *shf); diff --git a/Src/subst.c b/Src/subst.c index 737a0a9..670f3f0 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -622,7 +622,7 @@ filesub(char **namptr, int assign) char * equalsubstr(char *str, int assign, int nomatch) { - char *pp, *cnam, *cmdstr, *ret; + char *pp, *cnam, *cmdstr; for (pp = str; !isend2(*pp); pp++) ; @@ -634,10 +634,10 @@ equalsubstr(char *str, int assign, int nomatch) zerr("%s not found", cmdstr); return NULL; } - ret = dupstring(cnam); if (*pp) - ret = dyncat(ret, pp); - return ret; + return dyncat(cnam, pp); + else + return cnam; /* already duplicated */ } /**/