Re: Filenames in Ada



Dmitry A. Kazakov wrote:

> On Wed, 23 Nov 2005 18:36:47 +0100, Martin Krischik wrote:
>
>> However, filenames in music collections contain all sort of funny
>> characters (especially the my wife's music - allmost entirely in
>> Cyrillic) - no big deal for modern file systems. But a big deal for Ada
>> as it seams. Not only are all filenames in Ada.Directories of type String
>> - actually all filenames anywhere are just String.

>> How does one deal with modern (utf-8) filenames in Ada?
>
> An interesting question! Indeed the file name parameter is of String type.
>
> Well, some quick check. The following works fine under Fedora / GNAT:
>
> with Ada.Text_IO; use Ada.Text_IO;
> with Strings_Edit.UTF8.Handling; use Strings_Edit.UTF8.Handling;
>
> procedure UTF8_Test is
> Name : Wide_String :=
> ( Wide_Character'Val (1092)
> & Wide_Character'Val (1072)
> & Wide_Character'Val (1081)
> & Wide_Character'Val (1083)
> );
> File : File_Type;
> begin
> Create (File, Out_File, To_UTF8 (Name));
> Close (File);
> end UTF8_Test;

Nice and good to know. Only I never did open any files since I was still
reading the directories with Ada.Directories to know what to write into the
files.

Find the code at:
http://cvs.sourceforge.net/viewcvs.py/wikibook-ada/demos/Source/make_m3u.adb?only_with_tag=HEAD&view=markup

at let it loose at a directory with Cyrillic filenames.

> If you have Cyrillic code page installed you will see the file name
> correctly spelt in Russian. No wonder, Fedora Linux is natively UTF-8!

So is SuSE since 9.0.

> Though it cannot work under Windows, because GNAT run-time translates
> Create into some CreateFileA Windows API. Moreover Windows is UTF-16. So
> there is no chance for Ada.Text_IO.Create. I presume one could directly
> use CreateFileW from Windows API with a Wide_String file name, but that's
> another story.

I fear that is the only option available. But how to turn the Windows
filehandle into a Ada one...

>> Is there a chance for an add-on package (to late for Ada 2005) or are we
>> snookered until Ada 2015.

> I don't see any great problem here. I would add UTF-8 variants for all
> calls where a file name is mentioned. We could even switch from Latin-1 to
> UTF-8. This seems to be independent on Text_IO vs. Wide_Text_IO issue.

I am not sure. There are quite a few OS dependent functions involved here.

Martin
--
mailto://krischik@xxxxxxxxxxxxxxxxxxxxx
Ada programming at: http://ada.krischik.com
.



Relevant Pages

  • Re: Filenames in Ada
    ... Martin Dowie wrote: ... But a big deal for Ada ... Not only are all filenames in Ada.Directories of type String ...
    (comp.lang.ada)
  • Filenames in Ada
    ... I was just starting to write a little demo program for Ada.Directories. ... was the generation of m3u files for music collection. ... filenames in music collections contain all sort of funny characters ... How does one deal with modern filenames in Ada? ...
    (comp.lang.ada)
  • Re: The case insensitive #include statement horror...
    ... like the case-insensitivity of the Windows file system, ... it's more like asking the programmer switching case sensitivity in their ... It enlarges the namespace of possible filenames... ... If there really were no reason to have upper ...
    (microsoft.public.vc.language)
  • Re: Got it working, kind of. was Re: Adding network and internet to Warp 4
    ... Windows Explorer and I see long filenames. ... from an OS/2 window, ... Advanced install when I installed it, and I don't remember there being ...
    (comp.os.os2.misc)
  • Re: Got it working, kind of. was Re: Adding network and internet to Warp 4
    ... Windows Explorer and I see long filenames. ... Firefox ver 3 shows up as Firefox_.zip. ... Advanced install when I installed it, and I don't remember there being ...
    (comp.os.os2.misc)