comp.lang.ada
 help / color / mirror / Atom feed
From: Adam Beneschan <adam@irvine.com>
Subject: Re: Ada.Directories.Base_Name and dot files
Date: Wed, 7 Oct 2009 08:10:30 -0700 (PDT)
Date: 2009-10-07T08:10:30-07:00	[thread overview]
Message-ID: <b2bb6462-ac98-4324-98ea-55391a365dda@g22g2000prf.googlegroups.com> (raw)
In-Reply-To: 4acc8c20$0$284$14726298@news.sunsite.dk

On Oct 7, 5:40 am, Thomas Løcke <"tl at ada-dk.org"> wrote:
> Hey all,
>
> While working my way through the excellent Ada.Directories package, I've
> stumbled on a minor annoyance: The Base_Name function does not handle
> dot files very gracefully.
>
> Here's an example:
>
> ++++
> with Ada.Text_IO;
> with Ada.Directories;
>
> procedure Dot is
>     package IO renames Ada.Text_IO;
>     package D renames Ada.Directories;
>
> begin
>     IO.Put_Line (Item => "1: " & D.Base_Name (Name => "foo.txt"));
>     IO.Put_Line (Item => "2: " & D.Base_Name (Name => ".foo"));
>     IO.Put_Line (Item => "3: " & D.Base_Name (Name => ".foo.bar"));
> end Dot;
> ++++
>
> The output I get is this:
>
> ++++
> 1: foo
> 2:
> 3: .foo
> ++++
>
> What I had hoped for, was this:
>
> ++++
> 1: foo
> 2: .foo
> 3: .foo
> ++++
>
> With the current null string solution, you'd have to do some manual
> parsing to get to the actual basename of a dot file.
>
> Instead of returning a null string when the first character is a dot,
> couldn't Base_Name just as well just return the basename *with* the dot,
> because that is the actual basename for a dot file. The dot is part of
> the name.
>
> Is there a good reason for the current behavior?
>
> There's a comment in the body of Base_Name:
>
> ++++
> --  Look for the last dot in the file name and return the part of the
> --  file name preceding this last dot. If the first dot is the first
> --  character of the file name, the base name is the empty string.
> ++++
>
> So it's not like the programmers behind this wasn't aware of dot files,
> they've just opted for a somewhat odd solution, in my humble, and not
> very expert, opinion.  :o)

P.S. For more information, look at the discussion of AI95-248
(http://www.ada-auth.org/cgi-bin/cvsweb.cgi/ais/ai-00248.txt?rev=1.32)
starting at around November 21, 2003 (and a few earlier entries from
July of that year).  There was some discussion of what the best
behavior would be with regard to file names like that.  It was pointed
out that on Windows, a file named ".abc" is treated as any other file
with an extension of .abc---if you open it in Explorer, Windows uses
the "abc" to determine what application to try to open it with.  There
was also some feeling that the rules should be the same on Windows and
Unix, and some feeling that these are marginal cases we shouldn't
worry about, and some feeling that the Base_Name and Extension
functions shouldn't have been there at all.  The resulting solution is
a compromise.  My feeling is still that this is a somewhat "marginal"
case---i.e. many Unix file names don't fall into the base-name/
extension paradigm and it's not sensible to talk about base names or
extensions of such files, so therefore using Base_Name or Extension on
them is likely not to do what you'd expect.

                                   -- Adam



  parent reply	other threads:[~2009-10-07 15:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-07 12:40 Ada.Directories.Base_Name and dot files 
2009-10-07 14:46 ` Yannick Duchêne Hibou57
2009-10-07 17:06   ` 
2009-10-07 14:52 ` Adam Beneschan
2009-10-07 17:06   ` 
2009-10-07 15:10 ` Adam Beneschan [this message]
2009-10-07 15:37   ` Yannick Duchêne Hibou57
2009-10-11  2:39     ` Randy Brukardt
2009-10-07 20:11   ` 
2009-10-08  9:39 ` Stephen Leake
2009-10-08  9:58   ` 
2009-10-26 19:26     ` Type casting Bruno
2009-10-26 20:02       ` Jeffrey R. Carter
2009-10-26 20:09       ` Adam Beneschan
2009-10-26 19:27     ` Conversions Bruno
2009-10-26 20:09       ` Conversions Jeffrey R. Carter
2009-10-26 20:19       ` Conversions Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox