comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm-host.bauhaus@maps.futureapps.de>
Subject: Re: What about a glob standard method in Ada.Command_Line ?
Date: Thu, 26 Aug 2010 02:59:25 +0200
Date: 2010-08-26T02:59:25+02:00	[thread overview]
Message-ID: <4c75bc6d$0$6973$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <f4mxb9xyoy13.1mmi2kht5gftp$.dlg@40tude.net>

On 8/25/10 9:39 PM, Dmitry A. Kazakov wrote:

>>    "*" ->  Search ->  Match (file name pattern) ->  ...
>
> What does this have to do with legality of names with spaces?
>
> How could it help to implement search for all files matched by a*¶?

I'm beginning to feel I have once again missed the proper
references for the meaning of words in our discussion.

You said, "You just do not need patterns in directory search."
Did this refer to the Pattern : String parameter of
(Start_)Search?   If so, I fully agree.

Here is what I wanted Matcher : access function (...) to be.

1. get rid of implementation-defined Pattern : String

2. do with the names what I want after they have been read:
   For example, call a function matching a name against some
    RE pattern

3. delegate the calling to (Start_)Search

(Otherwise, everything is pretty much like Search.)

Filenames "as is" means whatever the OS or run-time
passes to (Start_)Search, something that can be passed to
other operations that require a file name.

String is a most flexible data structure for file names
because it can store any kind of file name which I take to be
a sequence of bits. One could use Wide_Wide_String or
Storage_Element_Array for a file name as long as no attempt is
made to attribute meaning to file name other than an ordered
sequence of bits that identifies a file.  Anything more is
wishful thinking. Character strings are just more practical
than bit patterns or number sequences.

IOW, I simply do not care what standard meaning one might
attribute to the sequence of bytes that comes in.  If it
needs to be shown to a user, then "appropriate conversion",
in a best effort sense, is probably best, from bit string to
some other string.

When I said that case insensitivity is handled by RE pattern
matching, I did not mean that issues like moving collections of
files between case-sensitive and case-insensitive file systems
can be handled by RE pattern matching.

I still can't figure out why you have been referring to Name_Error.
The file names considered by my Start_Search variant necessarily
identify existing files.  In this sense, exceptions caused by anything
to do with existing file's names will not seem acceptable.

Here is code looking for a file named "aö" on a number of file
systems.  Source file encoding should be Latin-1.

with Ada.Text_IO;
with Ada.Directories;

procedure Filenames is

    Not_Found_Error : exception;

    procedure Show_String (S: String);
    -- tabular display of Characters in S, with hex codes

    function Find_Odd_Name return String;
    --  Look for a file named "aö" and return the characters of this name.
    --  Raises Not_Found_Error

    function Find_Odd_Name return String is
       use Ada.Directories;
       Search_For_Aö : Search_Type;
       Dir_Entry : Directory_Entry_Type;
       Aö8 : constant String :=  "aö";  -- UTF-8
       AöL : constant String :=  "aö";  -- Latin-1
       AöN : constant String :=  "ao" &
         Character'Val (16#CC#) &
         Character'Val (16#88#);  -- NFD (HFS+)
    begin
       Start_Search (Search => Search_For_Aö,
                     Directory => "News",
                     Pattern => "*");
       loop
          exit when not More_Entries (Search_For_Aö);
          Get_Next_Entry (Search_For_Aö, Dir_Entry);
          declare
             Name : constant String := Simple_Name (Dir_Entry);
          begin
             if
               Name = Aö8
               or Name = AöL
               or Name = AöN
             then
                End_Search(Search_For_Aö);
                return Name;
             end if;
          end;
       end loop;
       raise Not_Found_Error;
    end Find_Odd_Name;

    procedure Show_String (S: String) is
       package Hex_IO is new Ada.Text_IO.Integer_IO (Natural);
    begin
       Hex_IO.Default_Base := 16;
       for K in S'Range loop
          Ada.Text_IO.Put (S(K));
          Hex_IO.Put (Character'Pos(S(K)));
          Ada.Text_IO.New_Line;
       end loop;
    end Show_String;

begin
    declare
       Filename : constant String := Find_Odd_Name ;
    begin
       Show_String(Filename);
    end ;
end Filenames;


-- Georg



  reply	other threads:[~2010-08-26  0:59 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-21  4:47 What about a glob standard method in Ada.Command_Line ? Yannick Duchêne (Hibou57)
2010-08-21  6:41 ` J-P. Rosen
2010-08-21  7:21   ` Yannick Duchêne (Hibou57)
2010-08-21  9:11   ` Pascal Obry
2010-08-22 19:00     ` J-P. Rosen
2010-08-22 19:29       ` Yannick Duchêne (Hibou57)
2010-08-23 23:06       ` Randy Brukardt
2010-08-24  0:02         ` Yannick Duchêne (Hibou57)
2010-08-24  0:24           ` Adam Beneschan
2010-08-24 10:27             ` Georg Bauhaus
2010-08-24 14:24               ` Dmitry A. Kazakov
2010-08-24 15:42                 ` Georg Bauhaus
2010-08-24 16:04                   ` Dmitry A. Kazakov
2010-08-24 17:10                     ` Georg Bauhaus
2010-08-24 17:24                       ` Georg Bauhaus
2010-08-24 18:42                         ` Yannick Duchêne (Hibou57)
2010-08-24 18:51                           ` Simon Wright
2010-08-24 17:41                       ` Dmitry A. Kazakov
2010-08-24 21:32                         ` Georg Bauhaus
2010-08-25  7:55                           ` Dmitry A. Kazakov
2010-08-25  8:24                             ` Yannick Duchêne (Hibou57)
2010-08-25 20:15                               ` (see below)
2010-08-25 20:39                                 ` Yannick Duchêne (Hibou57)
2010-08-25 21:05                                   ` (see below)
2010-08-25 21:32                                     ` Yannick Duchêne (Hibou57)
2010-08-25  8:57                             ` Georg Bauhaus
2010-08-25  9:28                               ` Dmitry A. Kazakov
2010-08-25 11:09                                 ` Georg Bauhaus
2010-08-25 12:01                                   ` Dmitry A. Kazakov
2010-08-25 13:09                                     ` Georg Bauhaus
2010-08-25 13:30                                       ` Dmitry A. Kazakov
2010-08-25 14:20                                         ` Georg Bauhaus
2010-08-25 14:56                                           ` Dmitry A. Kazakov
2010-08-25 15:51                                             ` Georg Bauhaus
2010-08-25 16:46                                               ` Dmitry A. Kazakov
2010-08-25 18:44                                                 ` Georg Bauhaus
2010-08-25 19:39                                                   ` Dmitry A. Kazakov
2010-08-26  0:59                                                     ` Georg Bauhaus [this message]
2010-08-26  8:49                                                       ` Dmitry A. Kazakov
2010-09-02 19:25                                                         ` Randy Brukardt
2010-09-02 20:47                                                           ` Dmitry A. Kazakov
2010-09-02 19:08                                                       ` Randy Brukardt
2010-09-02 20:48                                                         ` Georg Bauhaus
2010-08-22 19:30     ` Yannick Duchêne (Hibou57)
2010-08-22 19:46       ` Dmitry A. Kazakov
2010-08-25 13:09 ` anon
2010-08-25 13:13   ` Georg Bauhaus
2010-08-25 13:28     ` J-P. Rosen
2010-08-25 20:29       ` Yannick Duchêne (Hibou57)
2010-08-25 14:14     ` Jeffrey Carter
2010-08-25 21:37     ` anon
2010-08-26  8:21       ` J-P. Rosen
2010-08-26 16:29         ` anon
2010-08-26 20:34           ` Yannick Duchêne (Hibou57)
2010-08-27  4:40             ` Yannick Duchêne (Hibou57)
2010-08-27 12:10           ` J-P. Rosen
2010-09-01  8:08             ` Ada compilers and Ada 2005 (was: What about a glob standard method in Ada.Command_Line ?) Georg Bauhaus
2010-09-01  9:45               ` Ada compilers and Ada 2005 Pascal Obry
2010-09-01 10:28                 ` J-P. Rosen
2010-09-02 19:37                   ` Randy Brukardt
replies disabled

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