Re: Filenames in Ada
- From: Martin Krischik <krischik@xxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 24 Nov 2005 20:13:01 +0100
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
.
- Follow-Ups:
- Re: Filenames in Ada
- From: Dmitry A. Kazakov
- Re: Filenames in Ada
- References:
- Filenames in Ada
- From: Martin Krischik
- Re: Filenames in Ada
- From: Dmitry A. Kazakov
- Filenames in Ada
- Prev by Date: Re: Filenames in Ada
- Next by Date: Re: Filenames in Ada
- Previous by thread: Re: Filenames in Ada
- Next by thread: Re: Filenames in Ada
- Index(es):
Relevant Pages
|