From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 988 invoked by alias); 7 Feb 2013 07:00:24 -0000 Received: (qmail 862 invoked by uid 22791); 7 Feb 2013 07:00:22 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_05,KHOP_SPAMHAUS_DROP,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RCVD_IN_HOSTKARMA_NO,RCVD_IN_HOSTKARMA_YE,RCVD_VIA_APNIC,TW_CP,TW_YG X-Spam-Check-By: sourceware.org Received: from nskntmtas04p.mx.bigpond.com (HELO nskntmtas04p.mx.bigpond.com) (61.9.168.146) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Feb 2013 07:00:14 +0000 Received: from nskntcmgw06p ([61.9.169.166]) by nskntmtas04p.mx.bigpond.com with ESMTP id <20130207070013.IEQV27890.nskntmtas04p.mx.bigpond.com@nskntcmgw06p> for ; Thu, 7 Feb 2013 07:00:13 +0000 Received: from [10.0.2.15] ([101.171.98.232]) by nskntcmgw06p with BigPond Outbound id xK071k01150pubH01K0CvJ; Thu, 07 Feb 2013 07:00:13 +0000 X-Authority-Analysis: v=2.0 cv=FNSZNpUs c=1 sm=1 a=3L1OLwb3Joj1WY/vcEmyWw==:17 a=XMX6KyidB00A:10 a=BHxaS1_h5ssA:10 a=Yq1-IuWEI7QA:10 a=-sTO_XvcksqKKhBpDoMA:9 a=QEXdDO2ut3YA:10 a=D0cnbGPprnFPlVd5SEgA:9 a=3L1OLwb3Joj1WY/vcEmyWw==:117 Message-ID: <511350F3.8040702@shaddybaddah.name> Date: Thu, 07 Feb 2013 07:00:00 -0000 From: Shaddy Baddah User-Agent: Mozilla/5.0 (X11; Linux i686; rv:10.0.5) Gecko/20120624 Icedove/10.0.5 MIME-Version: 1.0 To: cygwin@cygwin.com Subject: Re: stat() and tilde prefix (was bad bash tab completion) References: <5024B4D4.6080409@shaddybaddah.name> <50F395D5.4050201@shaddybaddah.name> <20130114061747.GB16739@ednor.casa.cgf.cx> <20130114100002.GA22039@calimero.vinschen.de> <50F417F9.8040108@shaddybaddah.name> <20130114161307.GB8617@calimero.vinschen.de> <50F54C93.9090702@shaddybaddah.name> In-Reply-To: <50F54C93.9090702@shaddybaddah.name> Content-Type: multipart/mixed; boundary="------------050302060202000001090700" X-IsSubscribed: yes Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com X-SW-Source: 2013-02/txt/msg00067.txt.bz2 --------------050302060202000001090700 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1390 Hi, On 15 Jan 2013 23:33, Shaddy Baddah wrote: >>> From what I make of it, there needs to be a patch that, although can >>> work generically, adds checks only required for Cygwin. And therefore >>> is specific to the Cygwin package. >>> >>> The check would be an extension of the file_exists() function, perhaps >>> called tilde_file_exists(), which determines if the tilde prefix forms >>> a directory component of the path (strchr('/')?). If it does not, the >>> file_exists() check is sufficient. If it does, then the check of if >>> that directory exists is logically and'ed to the result of >>> file_exists(). >>> >>> Does that sound about right? >> >> A check like this might be a good idea. Ultimately I would be glad to >> be able to come up with more correct code in Cygwin while not getting >> slower, of course. But that's wishful thinking for now. > > Bash, patched in the way I have described, seems to fix the tab > completion issue. > > I will tidy up the work and publish the patch at some point soon. I may > have taken a naive approach, so review comments are welcome. Please find the patch discussed attached. It probably needs to be a bit more generic, maybe with some precompiler directives to limit it to cygwin? Although if it is just for cygwin, perhaps it can just go in the cygports patch? Do I need to put an "attn bash maintainer" on the subject line? --------------050302060202000001090700 Content-Type: text/x-patch; name="cygwin-181692-bash-tilde-fix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="cygwin-181692-bash-tilde-fix.diff" Content-length: 1561 diff --git a/bashline.c b/bashline.c index 3cbb18f..31841fa 100644 --- a/bashline.c +++ b/bashline.c @@ -3478,8 +3478,9 @@ quote_word_break_chars (text) if (mbschr (rl_completer_word_break_characters, *s)) *r++ = '\\'; /* XXX -- check for standalone tildes here and backslash-quote them */ - if (s == text && *s == '~' && file_exists (text)) + if (s == text && *s == '~' && tilde_file_exists (text)) { *r++ = '\\'; + } *r++ = *s; } *r = '\0'; diff --git a/general.c b/general.c index fdadf1d..b279cbe 100644 --- a/general.c +++ b/general.c @@ -544,6 +544,28 @@ file_exists (fn) } int +tilde_file_exists (fn) + char *fn; +{ + struct stat sb; + char *slash, *dirpart; + int istildedir; + + istildedir = 0; + + slash = strchr (fn, '/'); + if ((slash != 0) && (slash != fn)) + { + dirpart = (char *)xmalloc ((slash - fn) + 1); + strncpy (dirpart, fn, (slash - fn) + 1); + istildedir = file_isdir (dirpart); + free (dirpart); + } + + return (!((slash != 0) && (slash != fn) && ! istildedir) && (stat (fn, &sb) == 0)); +} + +int file_isdir (fn) char *fn; { diff --git a/general.h b/general.h index 2b31c58..f6b7ab4 100644 --- a/general.h +++ b/general.h @@ -302,6 +302,7 @@ extern int sh_openpipe __P((int *)); extern int sh_closepipe __P((int *)); extern int file_exists __P((char *)); +extern int tilde_file_exists __P((char *)); extern int file_isdir __P((char *)); extern int file_iswdir __P((char *)); extern int dot_or_dotdot __P((const char *)); --------------050302060202000001090700 Content-Type: text/plain; charset=us-ascii Content-length: 218 -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple --------------050302060202000001090700--