* File name wild cards
@ 2018-08-15 20:45 Bill Findlay
2018-08-16 7:46 ` Jeffrey R. Carter
2018-08-16 7:47 ` Dmitry A. Kazakov
0 siblings, 2 replies; 5+ messages in thread
From: Bill Findlay @ 2018-08-15 20:45 UTC (permalink / raw)
Can anyone point me to a portable way of doing wildcard filename lookups?
In Ada.Directories we have;
> type Search_Type is limited private;
> procedure Start_Search (Search: in out Search_Type;
> Directory: in String;
> Pattern: in String;
> Filter: in Filter_Type := (others => True));
etc
But the interpretation of Pattern is implementation defined.
Worse, I cannot find any interpretation in the GNAT documentation.
--
Bill Findlay
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File name wild cards
2018-08-15 20:45 File name wild cards Bill Findlay
@ 2018-08-16 7:46 ` Jeffrey R. Carter
2018-08-16 14:26 ` Bill Findlay
2018-08-16 7:47 ` Dmitry A. Kazakov
1 sibling, 1 reply; 5+ messages in thread
From: Jeffrey R. Carter @ 2018-08-16 7:46 UTC (permalink / raw)
On 08/15/2018 10:45 PM, Bill Findlay wrote:
> Can anyone point me to a portable way of doing wildcard filename lookups?
>
> In Ada.Directories we have;
>
>> type Search_Type is limited private;
>> procedure Start_Search (Search: in out Search_Type;
>> Directory: in String;
>> Pattern: in String;
>> Filter: in Filter_Type := (others => True));
>
> etc
> But the interpretation of Pattern is implementation defined.
I interpret this as being like the Form parameter for opening a file. It's
whatever's meaningful for the actual platform being used.
There's no way to be completely portable, since even the way one specifies a
directory can vary significantly between file systems.
Assuming you have a way of specifying the directory that is acceptably portable
for your uses, one way to portably select only files that match some pattern is
to pass Pattern => "" and select files that match your pattern internally,
perhaps using a regular-expression pkg.
However, if by portable you mean between Unix-like and Windows systems, and you
restrict yourself to the current directory (or directories you can construct
from it using Hierarchical_File_Names), then I've found that '*' and '?' are
portable enough for my needs.
For example, the program that selected the signature on this msg used Directory
=> "." and Pattern => "signature???.txt".
--
Jeff Carter
"Have you gone berserk? Can't you see that that man is a ni?"
Blazing Saddles
38
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File name wild cards
2018-08-15 20:45 File name wild cards Bill Findlay
2018-08-16 7:46 ` Jeffrey R. Carter
@ 2018-08-16 7:47 ` Dmitry A. Kazakov
2018-08-16 14:29 ` Bill Findlay
1 sibling, 1 reply; 5+ messages in thread
From: Dmitry A. Kazakov @ 2018-08-16 7:47 UTC (permalink / raw)
On 2018-08-15 22:45, Bill Findlay wrote:
> Can anyone point me to a portable way of doing wildcard filename lookups?
>
> In Ada.Directories we have;
>
>> type Search_Type is limited private;
>> procedure Start_Search (Search: in out Search_Type;
>> Directory: in String;
>> Pattern: in String;
>> Filter: in Filter_Type := (others => True));
>
> etc
> But the interpretation of Pattern is implementation defined.
> Worse, I cannot find any interpretation in the GNAT documentation.
AFAIK Ada.Directories is non-portable anyway. I hope this will be fixed
in Ada 2020 in a way that would abstract the file system as a set of
nice ADTs.
I do portable file lookup this admittedly ugly way:
1. I use Ada bindings to GLib. GLib has portable directory walk, which
maintains UTF-8 names regardless the underlying OS:
http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#5
Dir_Open, Dir_Read_Name etc.
2. I check names for artifacts like "." and ".." and translate \ to /.
3. I use wild-card matcher for UTF-8 encoded strings:
http://www.dmitry-kazakov.de/ada/strings_edit.htm#7.5
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File name wild cards
2018-08-16 7:46 ` Jeffrey R. Carter
@ 2018-08-16 14:26 ` Bill Findlay
0 siblings, 0 replies; 5+ messages in thread
From: Bill Findlay @ 2018-08-16 14:26 UTC (permalink / raw)
On 16 Aug 2018, Jeffrey R. Carter wrote
(in article <pl3a5c$rre$1@dont-email.me>):
> On 08/15/2018 10:45 PM, Bill Findlay wrote:
> > Can anyone point me to a portable way of doing wildcard filename lookups?
> >
> > In Ada.Directories we have;
> >
> > > type Search_Type is limited private;
> > > procedure Start_Search (Search: in out Search_Type;
> > > Directory: in String;
> > > Pattern: in String;
> > > Filter: in Filter_Type := (others => True));
> >
> > etc
> > But the interpretation of Pattern is implementation defined.
>
> I interpret this as being like the Form parameter for opening a file. It's
> whatever's meaningful for the actual platform being used.
>
> There's no way to be completely portable, since even the way one specifies a
> directory can vary significantly between file systems.
I had been told that Java had a portable way of doing it, but was sceptical
for exactly the reason you state.
> Assuming you have a way of specifying the directory that is acceptably portable
> for your uses, one way to portably select only files that match some pattern is
> to pass Pattern => "" and select files that match your pattern internally,
> perhaps using a regular-expression pkg.
Simple, obvious, why didn't I think of that? 8-)
Thanks, Jeff.
--
Bill Findlay
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: File name wild cards
2018-08-16 7:47 ` Dmitry A. Kazakov
@ 2018-08-16 14:29 ` Bill Findlay
0 siblings, 0 replies; 5+ messages in thread
From: Bill Findlay @ 2018-08-16 14:29 UTC (permalink / raw)
On 16 Aug 2018, Dmitry A. Kazakov wrote
(in article <pl3a6i$15s1$1@gioia.aioe.org>):
> On 2018-08-15 22:45, Bill Findlay wrote:
> > Can anyone point me to a portable way of doing wildcard filename lookups?
> >
> > In Ada.Directories we have;
> >
> > > type Search_Type is limited private;
> > > procedure Start_Search (Search: in out Search_Type;
> > > Directory: in String;
> > > Pattern: in String;
> > > Filter: in Filter_Type := (others => True));
> >
> > etc
> > But the interpretation of Pattern is implementation defined.
> > Worse, I cannot find any interpretation in the GNAT documentation.
>
> AFAIK Ada.Directories is non-portable anyway. I hope this will be fixed
> in Ada 2020 in a way that would abstract the file system as a set of
> nice ADTs.
>
> I do portable file lookup this admittedly ugly way:
>
> 1. I use Ada bindings to GLib. GLib has portable directory walk, which
> maintains UTF-8 names regardless the underlying OS:
>
> http://www.dmitry-kazakov.de/ada/gtkada_contributions.htm#5
>
> Dir_Open, Dir_Read_Name etc.
>
> 2. I check names for artifacts like "." and ".." and translate \ to /.
>
> 3. I use wild-card matcher for UTF-8 encoded strings:
>
> http://www.dmitry-kazakov.de/ada/strings_edit.htm#7.5
Thanks for those suggestions, Dmitry.
My program is non-GUI, and I want to avoid using any non-Ada.* libraries.
--
Bill Findlay
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-16 14:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-15 20:45 File name wild cards Bill Findlay
2018-08-16 7:46 ` Jeffrey R. Carter
2018-08-16 14:26 ` Bill Findlay
2018-08-16 7:47 ` Dmitry A. Kazakov
2018-08-16 14:29 ` Bill Findlay
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox