comp.lang.ada
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* Re: [Ann] WinRt - version 3
  @ 2023-09-03  9:07  5% ` AlexG
  0 siblings, 0 replies; 45+ results
From: AlexG @ 2023-09-03  9:07 UTC (permalink / raw)


Below is a simple example of the Api usage

--------------------------------------------------------------------------------
with Ada.Wide_Text_IO;
with Ada.Strings.Wide_Unbounded;
with WinRt;                             
with WinRt.Windows.Foundation;
with WinRt.Windows.Networking;
with WinRt.Windows.Networking.Sockets;
with WinRt.Windows.Storage.Streams;
with WinRt.Windows.Web.Http;
--------------------------------------------------------------------------------
procedure WinRt3Test2 is

    use WinRt;
    use Ada.Strings.Wide_Unbounded;
    
    Hr : HResult := 0;
    
    function "+"(value : Wide_String) return Unbounded_Wide_String renames To_Unbounded_Wide_String;
    function "+"(value : Unbounded_Wide_String) return Wide_String renames To_Wide_String;

begin
    Hr := RoInitialize;
    if Hr = 0 then
    
        declare
            Uri                   : Windows.Foundation.Uri := Windows.Foundation.Constructor (+"http://www.google.com");
            HttpClient      : Windows.Web.Http.HttpClient := Windows.Web.Http.Constructor;
            Result             : WString;
        begin
            Result := HttpClient.GetStringAsync (Uri);
            Ada.Wide_Text_IO.Put_Line (+Result);
            HttpClient.Close;
        end;
        
        declare
            Host                 : Windows.Networking.HostName := Windows.Networking.Constructor(+"www.google.com");
            Port                  : WString := +"80";
            Socket             : Windows.Networking.Sockets.StreamSocket := Windows.Networking.Sockets.Constructor;
            DataWriter      : Windows.Storage.Streams.DataWriter := Windows.Storage.Streams.Constructor (Socket.get_OutputStream);
        begin
            Socket.ConnectAsync (Host, Port);
            Socket.Close;
        end;
    
        RoUninitialize;
    end if;
end;

^ permalink raw reply	[relevance 5%]

* Have I found an error in the index of the ARM?
@ 2020-02-27 22:54  6% mgr
  0 siblings, 0 replies; 45+ results
From: mgr @ 2020-02-27 22:54 UTC (permalink / raw)


Hello,

While generating some stubs (wiki draft) for the Ada Programming 
wikibook, I've found an inconsistency that ultimately comes from the 
index of Ada 2005 and 2012 Reference Manual.

The index in Wikibooks [1] was probably derived from the RM index [2]. I 
generated the stubs from the actual package names provided by GNAT 
implementation. As can be seen in the Wikibooks index, some  links are 
broken, despite having generated stubs for all the Ada children. The 
index in Wikibooks follows the RM index:

Ada.Wide_Text_IO.Bounded_IO   A.11(4/3)
Ada.Wide_Text_IO.Unbounded_IO   A.11(5/3)

Ada.Wide_Wide_Text_IO.Bounded_IO   A.11(4/3)
Ada.Wide_Wide_Text_IO.Unbounded_IO   A.11(5/3)

But in A.11 [3] the package names repeat Wide[_Wide] at the 
grandchildren level:
4/3
The specification of package Wide_Text_IO.Wide_Bounded_IO is the same as

5/3
The specification of package Wide_Text_IO.Wide_Unbounded_IO is the same

So generated stubs are not linked to the index. I guess the problem is 
in the RM index, because implementors have follow the letter of A.11.


[1] https://en.wikibooks.org/wiki/Ada_Programming/Libraries/Ada
[2] http://www.ada-auth.org/standards/12rm/html/RM-0-4.html
[3] http://www.ada-auth.org/standards/12rm/html/RM-A-11.html


^ permalink raw reply	[relevance 6%]

* Re: unicode and wide_text_io
  @ 2017-12-28 22:35  5%           ` G.B.
  0 siblings, 0 replies; 45+ results
From: G.B. @ 2017-12-28 22:35 UTC (permalink / raw)


On 28.12.17 16:47, 00120260b@gmail.com wrote:
> Then, how come the norm hasn't made it a bit easier to input/ouput post-latin-1 characters ? Why aren't other norms/characters set/encodings more like special cases ?
> 

Actually, output of non-7-bit, unambiguously encoded text
has been made reasonably easy, I'd say, also defaulting
to what should be expected:

with Ada.Wide_Text_IO.Text_Streams;
with Ada.Strings.UTF_Encoding.Wide_Strings;

procedure UTF is
    --  USD/EUR, i.e. "$/€"
    Ratio : constant Wide_String := "$/" & Wide_Character'Val (16#20AC#);

    use Ada.Wide_Text_Io, Ada.Strings;
begin
    Put_Line (Ratio); --  use defaults, traditional
    String'Write --  stream output, force UTF-8
      (Text_Streams.Stream (Current_Output),
       UTF_Encoding.Wide_Strings.Encode (Ratio));
end UTF;

The above source text uses only 7 bit encoding for post-
latin-1 strings. Only comment text is using a wide_character.

If, instead, source text is encoded by "more" bits, and using
post-latin-1 literals or identifiers, then the compiler
may need to be told. I think that BOMs may be of use, and
in any case, there are compiler switches or some other
vendor specific vocabulary describing source text.


^ permalink raw reply	[relevance 5%]

* Re: unicode and wide_text_io
  @ 2017-12-27 23:32  7%       ` Mehdi Saada
  0 siblings, 0 replies; 45+ results
From: Mehdi Saada @ 2017-12-27 23:32 UTC (permalink / raw)


I finally used ADA.WIDE_TEXT_IO for just the PUT procedure:
   procedure Put (
         Fichier : in     WIDE_TEXT_IO.FILE_TYPE;
         Item    : in     T_Rationnel        ) is

   begin -- Put
      P_Entier_wide.Put(
         File  => Fichier,
         Item  => Numer (Item),
         Width => 1);
      if Denom (Item) /= 1 then
         WIDE_TEXT_IO.Put(
            File => Fichier,
            Item => WIDE_CHARACTER'Val(2044));
         P_Entier_wide.Put(
            File  => Fichier,
            Item  => Denom (Item),
            Width => 1);
      end if;
   end Put;

   procedure Put (
         Item : in     T_Rationnel ) is
   begin -- Put
      Put(Fichier => WIDE_TEXT_IO.Standard_Output,
          Item    => Item);
   end Put;
Why would that be wrong, Dmitry ?

^ permalink raw reply	[relevance 7%]

* Re: Musing on defining attributes and the ability to define an "abstract type X"-interface.
  @ 2017-07-20 17:40  3%     ` Dmitry A. Kazakov
  0 siblings, 0 replies; 45+ results
From: Dmitry A. Kazakov @ 2017-07-20 17:40 UTC (permalink / raw)


On 2017-07-20 18:37, Shark8 wrote:
> On Thursday, July 20, 2017 at 1:52:14 AM UTC-6, Dmitry A. Kazakov wrote:
>> You need along with the array type:
>>
>> 1. Index type
>>
>> This is for 1D arrays. For ND arrays you need types in-between (tuples
>> of indices) and sub-arrays.
> 
> Making a specialized interface for 1D arrays seems, well... stupid,
> especially when we're talking about such a change to the language so as
> to easily open up the full generality.
> 
> IOW, why have just "index type" for an array? At this point you're
> just using generics, albeit with a different
> name. We need an array of indices of type, but not just any type,
> discrete-type. (pseudo-Ada: Function Index return Array (Positive range
> 1..Index_Count) of Discrete_Type)

Of course any type. The index type must implement index interface, which 
basically operations required to loop through the array.

>> 2. Index range type (or general index set type)
>> 3. Array element type
>> 4. Array set of elements type
> 
> What do you mean by "set of elements" type? Something like Pascal's Set?

Slice is a set of elements. For a ND array there are N-1 types of 
subsets unless you allow columns. Then it is more.

>>> (4) It seems ranges would have to become first-class types in order
>>> to satisfy the return-value of the Range attribute. (Though perhaps
>>> some compiler-magic like is done w/ Ada.Iterator_Interfaces and the
>>> for-loop might handle that...)
>>
>> Yes. And you need index operations defined on non-flattened indices and
>> sets of. Compare:
>>
>>      A (I, J)   -- Flatten
>>
>>      A ((I, J)) -- Elevated, same as
>>
>>       Point   := (I, J);
>>       Element := A (Point);
>>
> I *think* I get what you're saying here, but I'm not entirely sure I 
> do. (In essence you want to be able to have A(X,Y) be like a
> function-call with the first, and like a cursor with the second where X
> & Y are keys, and "element" is the element, no?)
> Care to elaborate?
Of course you need getter and setter. And you cannot deal with lists of 
arguments like in C. It must be reduced to:

    Get (Array, Index) return Element
    Set (Array, Index, Element)

where Index is just one object. The language magic must flatten and 
elevate tuples of arguments as necessary. And for slices it is:

    Get (Array, Index_Set) return Elements_Set
    Set (Array, Index_Set, Elements_Set)

E.g. for 1D, Index_Set is Index range, Elements_Set is array slice.

>>> (5) It is uncertain whether making these inheritable would be good:
>>> on the plus side you could define an abstract-type that held the READ
>>> and WRITE and other common attributes and have a hierarchy of
>>> "type-classes".
>>
>> It is an interesting question which was discussed in OO. E.g. if an
>> array of subtypes is a subtype (a subtype in general terms, rather than
>> Ada's sense). In some cases this is required, e.g. if we tried to bring
>> string types in order. Surely ASCII arrays must be compatible with
>> Latin-1 array etc.
> 
> Gag!
> No, an array of ASCII is *NO* compatible with an array of Latin-1;
> the  first is 7-bit data, the latter is 8-bit data.

So what? There is no logical reason for Latin-1's Put_Line not to work 
with ASCII. Note that in Ada string literal is compatible with all 
character arrays:

    Ada.Wide_Text_IO.Put_Line ("abcd");

and

    Ada.Text_IO.Put_Line ("abcd");

as simple as that.

>>> (6) The exposure of heretofore conceptual types. (e.g. Universal_Integer)
>>
>> Array requires positional access, just like discrete types have T'Pos
>> and T'Val. At leas for iteration, it does.
> 
> ??
> The concept of an array in Ada is that of a function:
>    The_Function (X,Y : Character) return Character; and
>    The_Array    (Character,Character) of Character;
> have very common interfaces for precisely this reason -- if anything
> we want to extend this to full completion.

Not really.

> eg given Y : Character := X('A', 'B'); what is X? An array, or a function?

Depends on the type of X. What we want is translation

    X('A','B') --> Get (X, ('A','B'))

Get is a primitive operation of X.

>>> (7) The exposure of the "type of a type".
>>
>> This is difficult to make consistent with inheritance and dynamic
>> dispatch. Dispatching tables tend to be global. With type types you need
>> tagged types come and go. Difficult.
> 
> Why would dispatching even be an issue?
> The compiler already knows what types what objects are; all this is
> saying is that there needs to be a type which indicates the type,

This is a whole different thing. Indicates /= is. The type with values 
indicating types already exists. It is Ada.Tags.Tag.

>>> (8) Would it be worth it for compiler-writers? Language maintainers?
>>> Language users? -- On the one hand being able to indicate explicitly
>>> that "definite type X" has *these* attributes while "Fixed-point type Y"
>>> has *those* attributes might be pretty nice... especially if we could
>>> make interfaces a bit more consistant. (e.g. allowing both
>>> Indefinite_Vector_Var'Length and Array_Var'Length.)
>>
>> Clearly an attribute is just a primitive operation. There cannot be any
>> discussion about it.
> 
> No, they are something different than a mere primitive operation.
> All discrete types have 'First, this doesn't mean that there's a
> First operation, per se, available to values of that type... but
> rather that  the thing "discrete types" has a function "First".

Attributes defined on types are operations with the type being a part of 
name, since we have no first class type objects, or operations defined 
on Ada.Tags.Tag. BTW, many such attributes must be object's operations, 
e.g. S'Image(X), should have been X'Image.

>>> (9) On the user-side I think it would be great to be able to have
>>> the  Ada.Containers.Vector Vector-type have a compatible interface to
>>> Array... we're halfway there with the Vector_Var'Iterate + For-loop anyway.
>>
>> Yes, having non-generic containers would be a huge relief.
> 
> Who said anything about non-generic containers?

With array interfaces you would need no that mess.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de


^ permalink raw reply	[relevance 3%]

* Re: GNAT bug in the GNAT GPL 2014 compiler?
  2015-03-25  7:35  4%   ` gorgelo
  2015-03-25  8:39  0%     ` Simon Wright
@ 2015-03-25  8:41  0%     ` Georg Bauhaus
  1 sibling, 0 replies; 45+ results
From: Georg Bauhaus @ 2015-03-25  8:41 UTC (permalink / raw)


On 25.03.15 08:35, gorgelo@hotmail.com wrote:
> Den tisdag 24 mars 2015 kl. 22:56:36 UTC+1 skrev Anh Vo:
>> On Tuesday, March 24, 2015 at 12:19:30 PM UTC-7, gor...@hotmail.com wrote:
>>>
>>> The compilation error is: amock-main_application.adb:170:61: missing "with Ada.Characters;"
>>>
>>> That file contains "with Ada.Characters.Conversions;" among the with-statements. Why does the compiler complain? If one comments out the line 170, the code compiles just fine.
>>>
>> Line 170 looks perfectly fine. Could you post the exact compilation error message. I am curious about this also.
>>
>> Anh Vo
>
> Here is the exact compilation error message:
>
> joakimstrandberg$ gprbuild -P amock.gpr
> gcc -c -gnat12 amock-main_application.adb
> amock-main_application.adb:170:61: missing "with Ada.Characters;"
> gprbuild: *** compilation phase failed
>
> It's not only the package Ada.Characters that the compiler complains about. It does not allow usage of Ada.Text_IO nor Ada.Wide_Text_IO. It seems that any usage of a subprogram in any of the child packages of the Ada package is forbidden in the body of the Amock.Main_Application package. I can't imagine it can be anything but a GNAT compiler bug. I am hoping to be proven wrong and that I've done some obvious mistake.

FWIW, the compiler accepts line 170 if the prefix "Standard" is
added to the expression assigned. Not sure what is going on,
but I'd suspect same naming overload.

diff --git a/source_files/amock-main_application.adb b/source_files/amock-main_application.adb
index 8cda6f5..93784b1 100644
--- a/source_files/amock-main_application.adb
+++ b/source_files/amock-main_application.adb
@@ -167,7 +167,7 @@ package body Amock.Main_Application is
           Input_Package             : Asis.Compilation_Unit;
           Input_Package_Declaration : Asis.Declaration;
  
-         Input_Package_Name_As_Wide_String : Wide_String := Ada.Characters.Conversions.To_Wide_String (Input_Package_Name);
+         Input_Package_Name_As_Wide_String : Wide_String := Standard.Ada.Characters.Conversions.To_Wide_String (Input_Package_Name);
        begin
           Asis.Implementation.Initialize ("-ws");
           Asis.Ada_Environments.Associate (My_Context, "My Asis Context", "-C1 .amock/command_line.adt");



^ permalink raw reply related	[relevance 0%]

* Re: GNAT bug in the GNAT GPL 2014 compiler?
  2015-03-25  7:35  4%   ` gorgelo
@ 2015-03-25  8:39  0%     ` Simon Wright
  2015-03-25  8:41  0%     ` Georg Bauhaus
  1 sibling, 0 replies; 45+ results
From: Simon Wright @ 2015-03-25  8:39 UTC (permalink / raw)


gorgelo@hotmail.com writes:

> Den tisdag 24 mars 2015 kl. 22:56:36 UTC+1 skrev Anh Vo:
>> On Tuesday, March 24, 2015 at 12:19:30 PM UTC-7, gor...@hotmail.com wrote:
>> >
>> > The compilation error is: amock-main_application.adb:170:61:
>> > missing "with Ada.Characters;"
>> >
>> > That file contains "with Ada.Characters.Conversions;" among the
>> > with-statements. Why does the compiler complain? If one comments
>> > out the line 170, the code compiles just fine.
>> >
>> Line 170 looks perfectly fine. Could you post the exact compilation
>> error message. I am curious about this also.
>>
>> Anh Vo
>
> Here is the exact compilation error message:
>
> joakimstrandberg$ gprbuild -P amock.gpr
> gcc -c -gnat12 amock-main_application.adb
> amock-main_application.adb:170:61: missing "with Ada.Characters;"
> gprbuild: *** compilation phase failed
>
> It's not only the package Ada.Characters that the compiler complains
> about. It does not allow usage of Ada.Text_IO nor Ada.Wide_Text_IO. It
> seems that any usage of a subprogram in any of the child packages of
> the Ada package is forbidden in the body of the Amock.Main_Application
> package. I can't imagine it can be anything but a GNAT compiler bug. I
> am hoping to be proven wrong and that I've done some obvious mistake.

I get the same behaviour with GCC 4.9.1 (I would have tried GCC 5.0.0
also but I don't have ASIS built for it).

Compiling with -gnatwa (all standard warnings) and commenting out the
"not referenced" packages and using pragma Unreferenced on the Control
parameters of Pre and Post made the error go away. Not much help for
your full code, of course.

Looks like a compiler bug to me.

^ permalink raw reply	[relevance 0%]

* Re: GNAT bug in the GNAT GPL 2014 compiler?
  @ 2015-03-25  7:35  4%   ` gorgelo
  2015-03-25  8:39  0%     ` Simon Wright
  2015-03-25  8:41  0%     ` Georg Bauhaus
  0 siblings, 2 replies; 45+ results
From: gorgelo @ 2015-03-25  7:35 UTC (permalink / raw)


Den tisdag 24 mars 2015 kl. 22:56:36 UTC+1 skrev Anh Vo:
> On Tuesday, March 24, 2015 at 12:19:30 PM UTC-7, gor...@hotmail.com wrote:
> > 
> > The compilation error is: amock-main_application.adb:170:61: missing "with Ada.Characters;"
> > 
> > That file contains "with Ada.Characters.Conversions;" among the with-statements. Why does the compiler complain? If one comments out the line 170, the code compiles just fine.
> > 
> Line 170 looks perfectly fine. Could you post the exact compilation error message. I am curious about this also.
> 
> Anh Vo

Here is the exact compilation error message: 

joakimstrandberg$ gprbuild -P amock.gpr 
gcc -c -gnat12 amock-main_application.adb
amock-main_application.adb:170:61: missing "with Ada.Characters;"
gprbuild: *** compilation phase failed

It's not only the package Ada.Characters that the compiler complains about. It does not allow usage of Ada.Text_IO nor Ada.Wide_Text_IO. It seems that any usage of a subprogram in any of the child packages of the Ada package is forbidden in the body of the Amock.Main_Application package. I can't imagine it can be anything but a GNAT compiler bug. I am hoping to be proven wrong and that I've done some obvious mistake.

Joakim Strandberg

^ permalink raw reply	[relevance 4%]

* Re: Q: Localizing type and package references
  2014-01-06  1:29  0% ` Jeffrey Carter
@ 2014-01-06  8:05  0%   ` Simon Wright
  0 siblings, 0 replies; 45+ results
From: Simon Wright @ 2014-01-06  8:05 UTC (permalink / raw)


Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org> writes:

> On 01/05/2014 04:55 PM, b.mcguinness747@gmail.com wrote:
>>
>> --------------------------------------------------------------------------------
>> -- Types - Declarations of data types and related packages
>> --------------------------------------------------------------------------------
>> with Ada.Characters;
>> with Ada.Characters.Wide_Latin_1;
>> with Ada.Strings;
>> with Ada.Strings.Wide_Maps;
>> with Ada.Strings.Wide_Unbounded;
>> with Ada.Wide_Characters;
>> with Ada.Wide_Characters.Handling;
>> with Ada.Wide_Text_IO;
>> with Ada.Wide_Text_IO.Text_Streams;
>>
>> package Types is
>>    package Chars         renames Ada.Characters.Wide_Latin_1;
>>    package Char_Handling renames Ada.Wide_Characters.Handling;
>>    package Char_IO       renames Ada.Wide_Text_IO;
>>    package Char_Maps     renames Ada.Strings.Wide_Maps;
>>    package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
>>    package Char_Strings  renames Ada.Strings.Wide_Unbounded;
>>
>>    subtype Char        is Wide_Character;
>>    subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
>> end Types;
>>
>> and then tried referencing this from the main program file with:
>>
>> with Types;
>> use  Types;
>>
>> with Char_Strings;
>>
>> but the compiler (Gnat 4.6) complains that there is no file called
>> char_strings.ads.  I am not sure if I have made a simple mistake that
>> can be easily corrected to make this work, or if there is a different
>> approach that I should be trying.
>
> You can only with a library-level package, one not declared in
> anything else. Char_Strings is declared in package types, so it's not
> library level and can't be withed.

So, you can either reclare package Chars etc at library level: for
example, in char_strings.ads,

   with Ada.Strings.Wide_Unbounded;
   package Char_Strings  renames Ada.Strings.Wide_Unbounded;

or you can change your main program file to say

   with Types;
   use Types;
   use Types.Chars;
   use Types.Char_Handling;
   ...

or perhaps

   with Types;
   use Types;
   procedure Main is
      use Chars;
      use Char_Handling;
      ...

^ permalink raw reply	[relevance 0%]

* Re: Q: Localizing type and package references
  2014-01-05 23:55  6% Q: Localizing type and package references b.mcguinness747
@ 2014-01-06  1:29  0% ` Jeffrey Carter
  2014-01-06  8:05  0%   ` Simon Wright
  0 siblings, 1 reply; 45+ results
From: Jeffrey Carter @ 2014-01-06  1:29 UTC (permalink / raw)


On 01/05/2014 04:55 PM, b.mcguinness747@gmail.com wrote:
>
> --------------------------------------------------------------------------------
> -- Types - Declarations of data types and related packages
> --------------------------------------------------------------------------------
> with Ada.Characters;
> with Ada.Characters.Wide_Latin_1;
> with Ada.Strings;
> with Ada.Strings.Wide_Maps;
> with Ada.Strings.Wide_Unbounded;
> with Ada.Wide_Characters;
> with Ada.Wide_Characters.Handling;
> with Ada.Wide_Text_IO;
> with Ada.Wide_Text_IO.Text_Streams;
>
> package Types is
>    package Chars         renames Ada.Characters.Wide_Latin_1;
>    package Char_Handling renames Ada.Wide_Characters.Handling;
>    package Char_IO       renames Ada.Wide_Text_IO;
>    package Char_Maps     renames Ada.Strings.Wide_Maps;
>    package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
>    package Char_Strings  renames Ada.Strings.Wide_Unbounded;
>
>    subtype Char        is Wide_Character;
>    subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
> end Types;
>
> and then tried referencing this from the main program file with:
>
> with Types;
> use  Types;
>
> with Char_Strings;
>
> but the compiler (Gnat 4.6) complains that there is no file called
> char_strings.ads.  I am not sure if I have made a simple mistake that
> can be easily corrected to make this work, or if there is a different
> approach that I should be trying.

You can only with a library-level package, one not declared in anything else. 
Char_Strings is declared in package types, so it's not library level and can't 
be withed.

-- 
Jeff Carter
"Spam! Spam! Spam! Spam! Spam! Spam! Spam! Spam!"
Monty Python's Flying Circus
53


^ permalink raw reply	[relevance 0%]

* Q: Localizing type and package references
@ 2014-01-05 23:55  6% b.mcguinness747
  2014-01-06  1:29  0% ` Jeffrey Carter
  0 siblings, 1 reply; 45+ results
From: b.mcguinness747 @ 2014-01-05 23:55 UTC (permalink / raw)


I want to write an Ada program using the Wide_Character type, but I might
want to move to Wide_Wide_Character later on.  So I want to localize all
references to Wide_Character and the associated standard Ada packages to
a single file that I can easily update.  If I was working in C++, I would
use typedefs to create pseudonyms and put these in a header file that I could
#include from various source files.  So I have tried to do something similar
in Ada.  I created the file types.ads:

--------------------------------------------------------------------------------
-- Types - Declarations of data types and related packages
--------------------------------------------------------------------------------
with Ada.Characters;
with Ada.Characters.Wide_Latin_1;
with Ada.Strings;
with Ada.Strings.Wide_Maps;
with Ada.Strings.Wide_Unbounded;
with Ada.Wide_Characters;
with Ada.Wide_Characters.Handling;
with Ada.Wide_Text_IO;
with Ada.Wide_Text_IO.Text_Streams;

package Types is
  package Chars         renames Ada.Characters.Wide_Latin_1;
  package Char_Handling renames Ada.Wide_Characters.Handling;
  package Char_IO       renames Ada.Wide_Text_IO;
  package Char_Maps     renames Ada.Strings.Wide_Maps;
  package Char_Streams  renames Ada.Wide_Text_IO.Text_Streams;
  package Char_Strings  renames Ada.Strings.Wide_Unbounded;

  subtype Char        is Wide_Character;
  subtype Char_String is Ada.Strings.Wide_Unbounded.Unbounded_Wide_String;
end Types;


and then tried referencing this from the main program file with:


with Types;
use  Types;

with Char_Strings;


but the compiler (Gnat 4.6) complains that there is no file called
char_strings.ads.  I am not sure if I have made a simple mistake that
can be easily corrected to make this work, or if there is a different
approach that I should be trying.

Help would be appreciated.

Thanks.

--- Brian


^ permalink raw reply	[relevance 6%]

* Re: Semantics of 'Image and 'Wide_Image on wide enumerations
  2010-12-03 20:56  0% ` Adam Beneschan
  2010-12-03 21:15  6%   ` Michael R
@ 2010-12-03 21:17  0%   ` Adam Beneschan
  1 sibling, 0 replies; 45+ results
From: Adam Beneschan @ 2010-12-03 21:17 UTC (permalink / raw)


On Dec 3, 12:56 pm, Adam Beneschan <a...@irvine.com> wrote:
> On Dec 3, 12:25 pm, Michael R <mich...@zanyblue.com> wrote:
>
>
>
>
>
> > Hi Folks,
>
> > I'm trying to figure out how to get wide enumeration types to generate
> > wide images of the values and am not getting results I would expect.
> > Using the simple 'Image, e.g.,
>
> > with Ada.Text_IO;
> > procedure WEnum1 is
> >    use Ada.Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Image (α));
> > end WEnum
>
> > Gives, (possibly encoded?):
>
> > $ gnatmake -gnat05 -gnatW8 wenum1.adb
> > gcc -c -gnat05 -gnatW8 wenum1.adb
> > gnatbind -x wenum1.ali
> > gnatlink wenum1.ali
> > $ ./wenum1
> > Alpha is Α[]
>
> > Using 'Wide_Image gives something more reasonable but not the actual
> > wide characters:
>
> > with Ada.Wide_Text_IO;
> > procedure WEnum2 is
> >    use Ada.Wide_Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Wide_Image (α));
> > end WEnum2;
>
> > $ gnatmake -gnat05 -gnatW8 wenum2.adb
> > gcc -c -gnat05 -gnatW8 wenum2.adb
> > gnatbind -x wenum2.ali
> > gnatlink wenum2.ali
> > $ ./wenum2
> > Alpha is Α
>
> > Is this the expected behaviour?
>
> I think that 'Image, 'Wide_Image, and 'Wide_Wide_Image of enumerations
> (other than character literals) put the output in upper case, where
> there is an upper case.  So what you're seeing is an upper-case alpha,
> which looks just like an A.

I didn't answer all parts of this...  For 'Image, if there are
characters in the image that aren't in the Character type, the result
is implementation-defined.  I don't know if the actual result you're
getting from GNAT has some meaning or is just random or is a bug;
you'd have to ask them.  But yes, the RM here doesn't say specifically
what you should expect, except that it's as least as long as the
'Wide_Wide_Image would be.

The relevant RM sections here are in 3.5, paragraphs 27.5 and 37.

                       -- Adam



^ permalink raw reply	[relevance 0%]

* Re: Semantics of 'Image and 'Wide_Image on wide enumerations
  2010-12-03 20:56  0% ` Adam Beneschan
@ 2010-12-03 21:15  6%   ` Michael R
  2010-12-03 21:17  0%   ` Adam Beneschan
  1 sibling, 0 replies; 45+ results
From: Michael R @ 2010-12-03 21:15 UTC (permalink / raw)


On Dec 3, 12:56 pm, Adam Beneschan <a...@irvine.com> wrote:
> On Dec 3, 12:25 pm, Michael R <mich...@zanyblue.com> wrote:
>
>
>
> > Hi Folks,
>
> > I'm trying to figure out how to get wide enumeration types to generate
> > wide images of the values and am not getting results I would expect.
> > Using the simple 'Image, e.g.,
>
> > with Ada.Text_IO;
> > procedure WEnum1 is
> >    use Ada.Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Image (α));
> > end WEnum
>
> > Gives, (possibly encoded?):
>
> > $ gnatmake -gnat05 -gnatW8 wenum1.adb
> > gcc -c -gnat05 -gnatW8 wenum1.adb
> > gnatbind -x wenum1.ali
> > gnatlink wenum1.ali
> > $ ./wenum1
> > Alpha is Α[]
>
> > Using 'Wide_Image gives something more reasonable but not the actual
> > wide characters:
>
> > with Ada.Wide_Text_IO;
> > procedure WEnum2 is
> >    use Ada.Wide_Text_IO;
> >    type Greek is (α, β, γ);
> > begin
> >    Put_Line ("Alpha is " & Greek'Wide_Image (α));
> > end WEnum2;
>
> > $ gnatmake -gnat05 -gnatW8 wenum2.adb
> > gcc -c -gnat05 -gnatW8 wenum2.adb
> > gnatbind -x wenum2.ali
> > gnatlink wenum2.ali
> > $ ./wenum2
> > Alpha is Α
>
> > Is this the expected behaviour?
>
> I think that 'Image, 'Wide_Image, and 'Wide_Wide_Image of enumerations
> (other than character literals) put the output in upper case, where
> there is an upper case.  So what you're seeing is an upper-case alpha,
> which looks just like an A.
>
>                         -- Adam

Hi,

Confirmed, I just didn't go far enough (it was outputting uppercase):

with Ada.Wide_Text_IO;
procedure WEnum2 is
   use Ada.Wide_Text_IO;
   type Greek is (α, β, γ);
begin
   for Letter in Greek'Range loop
      Put_Line (Greek'Wide_Image (Letter));
   end loop;
end WEnum2;

Gives,

$ gnatmake -gnat05 -gnatW8 wenum2.adb
gcc-4.4 -c -gnat05 -gnatW8 wenum2.adb
gnatbind -x wenum2.ali
gnatlink wenum2.ali
$ ./wenum2
Α
Β
Γ

Take care,
Michael.




^ permalink raw reply	[relevance 6%]

* Re: Semantics of 'Image and 'Wide_Image on wide enumerations
  2010-12-03 20:25  5% Semantics of 'Image and 'Wide_Image on wide enumerations Michael R
@ 2010-12-03 20:56  0% ` Adam Beneschan
  2010-12-03 21:15  6%   ` Michael R
  2010-12-03 21:17  0%   ` Adam Beneschan
  0 siblings, 2 replies; 45+ results
From: Adam Beneschan @ 2010-12-03 20:56 UTC (permalink / raw)


On Dec 3, 12:25 pm, Michael R <mich...@zanyblue.com> wrote:
> Hi Folks,
>
> I'm trying to figure out how to get wide enumeration types to generate
> wide images of the values and am not getting results I would expect.
> Using the simple 'Image, e.g.,
>
> with Ada.Text_IO;
> procedure WEnum1 is
>    use Ada.Text_IO;
>    type Greek is (α, β, γ);
> begin
>    Put_Line ("Alpha is " & Greek'Image (α));
> end WEnum
>
> Gives, (possibly encoded?):
>
> $ gnatmake -gnat05 -gnatW8 wenum1.adb
> gcc -c -gnat05 -gnatW8 wenum1.adb
> gnatbind -x wenum1.ali
> gnatlink wenum1.ali
> $ ./wenum1
> Alpha is Α[]
>
> Using 'Wide_Image gives something more reasonable but not the actual
> wide characters:
>
> with Ada.Wide_Text_IO;
> procedure WEnum2 is
>    use Ada.Wide_Text_IO;
>    type Greek is (α, β, γ);
> begin
>    Put_Line ("Alpha is " & Greek'Wide_Image (α));
> end WEnum2;
>
> $ gnatmake -gnat05 -gnatW8 wenum2.adb
> gcc -c -gnat05 -gnatW8 wenum2.adb
> gnatbind -x wenum2.ali
> gnatlink wenum2.ali
> $ ./wenum2
> Alpha is Α
>
> Is this the expected behaviour?

I think that 'Image, 'Wide_Image, and 'Wide_Wide_Image of enumerations
(other than character literals) put the output in upper case, where
there is an upper case.  So what you're seeing is an upper-case alpha,
which looks just like an A.

                        -- Adam




^ permalink raw reply	[relevance 0%]

* Semantics of 'Image and 'Wide_Image on wide enumerations
@ 2010-12-03 20:25  5% Michael R
  2010-12-03 20:56  0% ` Adam Beneschan
  0 siblings, 1 reply; 45+ results
From: Michael R @ 2010-12-03 20:25 UTC (permalink / raw)


Hi Folks,

I'm trying to figure out how to get wide enumeration types to generate
wide images of the values and am not getting results I would expect.
Using the simple 'Image, e.g.,

with Ada.Text_IO;
procedure WEnum1 is
   use Ada.Text_IO;
   type Greek is (α, β, γ);
begin
   Put_Line ("Alpha is " & Greek'Image (α));
end WEnum

Gives, (possibly encoded?):

$ gnatmake -gnat05 -gnatW8 wenum1.adb
gcc -c -gnat05 -gnatW8 wenum1.adb
gnatbind -x wenum1.ali
gnatlink wenum1.ali
$ ./wenum1
Alpha is Α[]

Using 'Wide_Image gives something more reasonable but not the actual
wide characters:

with Ada.Wide_Text_IO;
procedure WEnum2 is
   use Ada.Wide_Text_IO;
   type Greek is (α, β, γ);
begin
   Put_Line ("Alpha is " & Greek'Wide_Image (α));
end WEnum2;

$ gnatmake -gnat05 -gnatW8 wenum2.adb
gcc -c -gnat05 -gnatW8 wenum2.adb
gnatbind -x wenum2.ali
gnatlink wenum2.ali
$ ./wenum2
Alpha is Α

Is this the expected behaviour?  The RM doesn't really say anything
much about such wide values.

Take care,
Michael.



^ permalink raw reply	[relevance 5%]

* Re: Encapsulating Ada.Direct_IO
  2010-11-17  4:44  3% Encapsulating Ada.Direct_IO Bryan
@ 2010-11-17  5:20  0% ` Adam Beneschan
  0 siblings, 0 replies; 45+ results
From: Adam Beneschan @ 2010-11-17  5:20 UTC (permalink / raw)


On Nov 16, 8:44 pm, Bryan <brobinson....@gmail.com> wrote:
> I'm trying to port some code to Ada for dealing with Big5-encoded
> files. I realize that I might be able to use Ada.Wide_Text_IO, but I'm
> trying to learn Ada and understand the language better.  I'm still
> working on wrapping my head around types and packages.  My original
> code in C++ opens a file as binary and parses it byte by byte and
> breaking it into Big5 characters depending on the byte codes.  I
> thought I'd try to do something similar by encapsulating Ada.Direct_IO
> into a package.  I'm not having much luck, however.
>
> Spec file:
> ======================
> with Ada.Direct_IO;
> package Big5_Text_IO is
>   type File_Type is limited private;
>   procedure Close( File : in out File_Type );
> private
>   package Byte_IO is new Ada.Direct_IO(Character);
>   type File_Type is new Byte_IO.File_Type;
> end Big5_Text_IO;
> ======================
>
> Body file
> ======================
> package body Big5_Text_IO is
>   procedure Close( File : in out File_Type ) is
>   begin
>         Byte_IO.Close(File);
>   end Close;
> end Big5_Text_IO;
> ======================
>
> Test driver:
> ======================
> with Big5_Text_IO;
> with Ada.Text_IO;
> procedure Big5_Test is
>   Input_File : Big5_Text_IO.File_Type;
> begin
>   Ada.Text_IO.Put_Line("OK?");
> end Big5_Test;
> ======================
>
> If I leave out the Close method and remove the body file, I can build
> the test driver with no issues.  Otherwise, I get the following from
> GNAT:
>
> ======================
> gcc -c big5_text_io.adb
> big5_text_io.adb:6:23: expected private type "Ada.Direct_Io.File_Type"
> from instance at big5_text_io.ads:11
> big5_text_io.adb:6:23: found private type "Big5_Text_IO.File_Type"
> defined at big5_text_io.ads:12
> gnatmake: "big5_text_io.adb" compilation error
> ======================
>
> I would *greatly* appreciate any tips in how I can better design my
> package so that it can encapsulate Ada.Direct_IO or some other method
> of binary I/O.  I looked at the GNAT source and I'm hoping I won't
> have to emulate what they have done...its a bit over my head at this
> point.

You're close.  Try changing

   Byte_IO.Close (File);

to

   Byte_IO.Close (Byte_IO.File_Type (File));

When you declare a derived type "type T2 is new T1", then T2 and T1
are not the same type, so you can't use an object of type T2 where
something of type T1 is expected.  But you can use a type conversion.

Note: I'm at home so I can't try this easily.  I seem to recall that
there were some issues using this paradigm with limited types
(including an incompatibility with earlier versions of the language),
but I don't recall the details and it's hard for me to look them up
right now.  If it turns out the type conversion doesn't work, then you
might have to make File_Type a record in the private part:

   type File_Type is record
      F : Byte_IO.File_Type;
   end record;

and then use File.F whenever you want to use a Byte_IO operation,
e.g.:

   Byte_IO.Close (File.F);

Hope this helps,

                                  -- Adam



^ permalink raw reply	[relevance 0%]

* Encapsulating Ada.Direct_IO
@ 2010-11-17  4:44  3% Bryan
  2010-11-17  5:20  0% ` Adam Beneschan
  0 siblings, 1 reply; 45+ results
From: Bryan @ 2010-11-17  4:44 UTC (permalink / raw)


I'm trying to port some code to Ada for dealing with Big5-encoded
files. I realize that I might be able to use Ada.Wide_Text_IO, but I'm
trying to learn Ada and understand the language better.  I'm still
working on wrapping my head around types and packages.  My original
code in C++ opens a file as binary and parses it byte by byte and
breaking it into Big5 characters depending on the byte codes.  I
thought I'd try to do something similar by encapsulating Ada.Direct_IO
into a package.  I'm not having much luck, however.

Spec file:
======================
with Ada.Direct_IO;
package Big5_Text_IO is
  type File_Type is limited private;
  procedure Close( File : in out File_Type );
private
  package Byte_IO is new Ada.Direct_IO(Character);
  type File_Type is new Byte_IO.File_Type;
end Big5_Text_IO;
======================

Body file
======================
package body Big5_Text_IO is
  procedure Close( File : in out File_Type ) is
  begin
  	Byte_IO.Close(File);
  end Close;
end Big5_Text_IO;
======================

Test driver:
======================
with Big5_Text_IO;
with Ada.Text_IO;
procedure Big5_Test is
  Input_File : Big5_Text_IO.File_Type;
begin
  Ada.Text_IO.Put_Line("OK?");
end Big5_Test;
======================

If I leave out the Close method and remove the body file, I can build
the test driver with no issues.  Otherwise, I get the following from
GNAT:

======================
gcc -c big5_text_io.adb
big5_text_io.adb:6:23: expected private type "Ada.Direct_Io.File_Type"
from instance at big5_text_io.ads:11
big5_text_io.adb:6:23: found private type "Big5_Text_IO.File_Type"
defined at big5_text_io.ads:12
gnatmake: "big5_text_io.adb" compilation error
======================

I would *greatly* appreciate any tips in how I can better design my
package so that it can encapsulate Ada.Direct_IO or some other method
of binary I/O.  I looked at the GNAT source and I'm hoping I won't
have to emulate what they have done...its a bit over my head at this
point.



^ permalink raw reply	[relevance 3%]

* Re: Why is not Stream_Access defined Ada.Streams ?
  2010-05-07  1:02  5% Why is not Stream_Access defined Ada.Streams ? Yannick Duchêne (Hibou57)
@ 2010-05-07  2:24  0% ` Randy Brukardt
  0 siblings, 0 replies; 45+ results
From: Randy Brukardt @ 2010-05-07  2:24 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 950 bytes --]

"Yannick Duch�ne (Hibou57)" <yannick_duchene@yahoo.fr> wrote in message 
news:op.vca852lexmjfy8@garhos...
> Hi all and Hi others as well,
>
> My dirty stuff of the day : why is Stream_Access not defined once a time 
> in Ada.Streams and is instead defined elsewhere multiple times, like in 
> Ada.Streams.Stream_IO, Ada.Text_IO.Text_Streams, 
> Ada.Wide_Text_IO.Text_Streams and Ada.Wide_Wide_Text_IO.Text_Streams ?
>
> Isn't it funny design ?

Ada 95 didn't have anonymous access returns, so a named type had to be 
defined. I suspect that there was no intent that it be used for anything 
other than defining the result of these functions -- and there was no intent 
that that result be stored: just directly dereferenced and passed to a 
stream attribute.

If we were writing it today, I'm pretty sure that no named type would be 
used at all. But making a change like that now would be incompatible.

                                Randy.





^ permalink raw reply	[relevance 0%]

* Why is not Stream_Access defined Ada.Streams ?
@ 2010-05-07  1:02  5% Yannick Duchêne (Hibou57)
  2010-05-07  2:24  0% ` Randy Brukardt
  0 siblings, 1 reply; 45+ results
From: Yannick Duchêne (Hibou57) @ 2010-05-07  1:02 UTC (permalink / raw)


Hi all and Hi others as well,

My dirty stuff of the day : why is Stream_Access not defined once a time  
in Ada.Streams and is instead defined elsewhere multiple times, like in  
Ada.Streams.Stream_IO, Ada.Text_IO.Text_Streams,  
Ada.Wide_Text_IO.Text_Streams and Ada.Wide_Wide_Text_IO.Text_Streams ?

Isn't it funny design ?

-- 
No-no, this isn't an oops ...or I hope (TM) - Don't blame me... I'm just  
not lucky



^ permalink raw reply	[relevance 5%]

* Re: Asis.Ada_Environments.Associate (..., Parameters => ...);
  @ 2010-01-03 17:06  4%   ` Hibou57 (Yannick Duchêne)
  0 siblings, 0 replies; 45+ results
From: Hibou57 (Yannick Duchêne) @ 2010-01-03 17:06 UTC (permalink / raw)


On 3 jan, 09:19, Stephen Leake <stephen_le...@stephe-leake.org> wrote:
> No need to search the web; that file is included in the GNAT ASIS
> installation, in html, info, and pdf; gnat/share/doc/asis/*
I do not have a desktop search engine, this may be why I did not find
it there.
I've check it is, indeed.

> asis_rm.txt 3.1 says they are implementation specific.
>
> It appears the ASIS standard document is not freely available, so it's
> hard to be sure.
> --
> -- Stephe
As the specification file does not give any reference, I suppose too.

May be another GNAT specific stuff : I could not get ride of ASIS
warning messages while I open an ASIS context. No standard ASIS
methods seems to provide abilities to manage this. These messages are
written on an error stream, but I could not redirected these with
either Ada.Text_IO.Set_Error or Ada.Wide_Text_IO.Set_Error.



^ permalink raw reply	[relevance 4%]

* Re: gtksourceview for gtkada
  2009-07-14 19:29  4% ` Vadim Godunko
@ 2009-07-16 14:47  0%   ` jpablo
  0 siblings, 0 replies; 45+ results
From: jpablo @ 2009-07-16 14:47 UTC (permalink / raw)


Oh, thanks for your answer, but it's for a large work and it must be
done in GTK.


On Jul 14, 4:29 pm, Vadim Godunko <vgodu...@gmail.com> wrote:
> On Jul 14, 10:09 pm, jpablo <jpablo.luc...@gmail.com> wrote:> Hi,
>
> > I'm trying to make a simple text editor with syntax highlighting for a
> > specific language, and I'm using gtkada2 for it. The problem is that
> > gtkada2 doesn't seem to have the gtksourceview widget, that exists for
> > C, C++, python, etc.
>
> > Does anyone knows if that widget has been added by someone to the
> > usual widgets of the gtkada2 package?
>
> Alternatively, you can use QtAda and its QPlainTextEditor class. All
> you will need to do is provide your own subclass from
> QSyntaxHighlighter:
>
> 1       with Qt4.Objects;
> 2       with Qt4.Strings;
> 3       with Qt4.Syntax_Highlighters.Impl;
> 4       with Qt4.Text_Documents;
> 5
> 6       package Ada_Syntax_Highlighters is
> 7
> 8          type Ada_Syntax_Highlighter is new
> 9            Qt4.Syntax_Highlighters.Impl.Q_Syntax_Highlighter_Impl with
> null record;
> 10
> 11         overriding
> 12         procedure Highlight_Block
> 13          (Self : not null access Ada_Syntax_Highlighter;
> 14           Text : in              Qt4.Strings.Q_String);
> 15
> 16         type Ada_Syntax_Highlighter_Access is access
> Ada_Syntax_Highlighter;
> 17
> 18         function Create
> 19           (Parent : access Qt4.Text_Documents.Q_Text_Document'Class :=
> null)
> 20            return not null Ada_Syntax_Highlighter_Access;
> 21
> 22      end;
>
> 1       with Qt4.Colors;
> 2       with Ada_Syntax_Highlighters.Moc;
> 3       with Ada.Wide_Text_IO;
> 4
> 5       with Asis.Extensions.Syntax_Highlight;
> 6
> 7       package body Ada_Syntax_Highlighters is
> 8
> 9          ---------------------
> 10         -- Highlight_Block --
> 11         ---------------------
> 12
> 13         procedure Highlight_Block
> 14           (Self : not null access Ada_Syntax_Highlighter;
> 15            Text : in              Qt4.Strings.Q_String)
> 16         is
> 17            use type Qt4.Q_Integer;
> 18            use Asis.Extensions.Syntax_Highlight;
> 19
> 20      --      Length : constant Qt4.Q_Integer := Qt4.Strings.Length
> (Text);
> 21
> 22            Colors : constant array (Token_Kinds) of
> Qt4.Colors.Q_Color :=
> 23              (Comment     => Qt4.Colors.Create (0, 128, 128),
> 24               Identifier  => Qt4.Colors.Create (0, 0, 128),
> 25               Literal     => Qt4.Colors.Create (0, 128, 0),
> 26               Delimiter   => Qt4.Colors.Create (128, 128, 0),
> 27               Keyword     => Qt4.Colors.Create (128, 0, 128),
> 28               Error       => Qt4.Colors.Create (255, 0, 0));
> 29
> 30            procedure Set_Token
> 31              (From : Positive;
> 32               Count : Positive;
> 33               Kind : Token_Kinds) is
> 34            begin
> 35               Set_Format (Self,
> 36                           Qt4.Q_Integer (From) - 1,  -- zero based index
> 37                           Qt4.Q_Integer (Count),
> 38                           Colors (Kind));
> 39            end Set_Token;
> 40
> 41            procedure Go is new Parse (Set_Token);
> 42
> 43            State : Integer := Integer (Previous_Block_State (Self));
> 44         begin
> 45            if State = -1 then
> 46               State := Default_State;
> 47            end if;
> 48
> 49            Go (Qt4.Strings.To_Utf_16 (Text), State);
> 50
> 51            Set_Current_Block_State (Self, Qt4.Q_Integer (State));
> 52            Ada.Wide_Text_IO.Put_Line (">" & Qt4.Strings.To_Utf_16
> (Text));
> 53         end Highlight_Block;
> 54
> 55         ------------
> 56         -- Create --
> 57         ------------
> 58
> 59         function Create
> 60           (Parent : access Qt4.Text_Documents.Q_Text_Document'Class :=
> null)
> 61            return not null Ada_Syntax_Highlighter_Access
> 62         is
> 63            Self : constant not null Ada_Syntax_Highlighter_Access
> 64              := new Ada_Syntax_Highlighter;
> 65
> 66         begin
> 67            Qt4.Syntax_Highlighters.Impl.Constructors.Initialize (Self,
> Parent);
> 68
> 69            return Self;
> 70         end Create;
> 71
> 72      end Ada_Syntax_Highlighters;
>
> And attach it to QPlainTextEditor
>
> 23      with Qt_Ada.Application;
> 24      with Qt4.Core_Applications;
> 25      with Qt4.Fonts;
> 26      with Qt4.Objects;
> 27      with Qt4.Plain_Text_Edits.Constructors;
> 28      with Qt4.Strings;
> 29
> 30      with Ada_Syntax_Highlighters;
> 31
> 32      procedure Main is
> 33         Editor      : Qt4.Plain_Text_Edits.Q_Plain_Text_Edit_Access;
> 34         Highlighter :
> Ada_Syntax_Highlighters.Ada_Syntax_Highlighter_Access;
> 35
> 36      begin
> 37         Qt_Ada.Application.Initialize;
> 38
> 39         Editor :=
> 40           Qt4.Plain_Text_Edits.Constructors.Create
> 41            (Qt4.Strings.From_Utf_16 ("Quit"));
> 42         Highlighter := Ada_Syntax_Highlighters.Create (Editor.Document);
> 43
> 44         Editor.Resize (800, 600);
> 45         Editor.Show;
> 46
> 47         Qt_Ada.Application.Execute;
> 48      end Main;
>
> That's all... ;-)




^ permalink raw reply	[relevance 0%]

* Re: gtksourceview for gtkada
  @ 2009-07-14 19:29  4% ` Vadim Godunko
  2009-07-16 14:47  0%   ` jpablo
  0 siblings, 1 reply; 45+ results
From: Vadim Godunko @ 2009-07-14 19:29 UTC (permalink / raw)


On Jul 14, 10:09 pm, jpablo <jpablo.luc...@gmail.com> wrote:
> Hi,
>
> I'm trying to make a simple text editor with syntax highlighting for a
> specific language, and I'm using gtkada2 for it. The problem is that
> gtkada2 doesn't seem to have the gtksourceview widget, that exists for
> C, C++, python, etc.
>
> Does anyone knows if that widget has been added by someone to the
> usual widgets of the gtkada2 package?
>
Alternatively, you can use QtAda and its QPlainTextEditor class. All
you will need to do is provide your own subclass from
QSyntaxHighlighter:

1	with Qt4.Objects;
2	with Qt4.Strings;
3	with Qt4.Syntax_Highlighters.Impl;
4	with Qt4.Text_Documents;
5
6	package Ada_Syntax_Highlighters is
7
8	   type Ada_Syntax_Highlighter is new
9	     Qt4.Syntax_Highlighters.Impl.Q_Syntax_Highlighter_Impl with
null record;
10
11	   overriding
12	   procedure Highlight_Block
13	    (Self : not null access Ada_Syntax_Highlighter;
14	     Text : in              Qt4.Strings.Q_String);
15
16	   type Ada_Syntax_Highlighter_Access is access
Ada_Syntax_Highlighter;
17
18	   function Create
19	     (Parent : access Qt4.Text_Documents.Q_Text_Document'Class :=
null)
20	      return not null Ada_Syntax_Highlighter_Access;
21
22	end;

1	with Qt4.Colors;
2	with Ada_Syntax_Highlighters.Moc;
3	with Ada.Wide_Text_IO;
4
5	with Asis.Extensions.Syntax_Highlight;
6
7	package body Ada_Syntax_Highlighters is
8
9	   ---------------------
10	   -- Highlight_Block --
11	   ---------------------
12
13	   procedure Highlight_Block
14	     (Self : not null access Ada_Syntax_Highlighter;
15	      Text : in              Qt4.Strings.Q_String)
16	   is
17	      use type Qt4.Q_Integer;
18	      use Asis.Extensions.Syntax_Highlight;
19
20	--      Length : constant Qt4.Q_Integer := Qt4.Strings.Length
(Text);
21
22	      Colors : constant array (Token_Kinds) of
Qt4.Colors.Q_Color :=
23	        (Comment     => Qt4.Colors.Create (0, 128, 128),
24	         Identifier  => Qt4.Colors.Create (0, 0, 128),
25	         Literal     => Qt4.Colors.Create (0, 128, 0),
26	         Delimiter   => Qt4.Colors.Create (128, 128, 0),
27	         Keyword     => Qt4.Colors.Create (128, 0, 128),
28	         Error       => Qt4.Colors.Create (255, 0, 0));
29
30	      procedure Set_Token
31	        (From : Positive;
32	         Count : Positive;
33	         Kind : Token_Kinds) is
34	      begin
35	         Set_Format (Self,
36	                     Qt4.Q_Integer (From) - 1,  -- zero based index
37	                     Qt4.Q_Integer (Count),
38	                     Colors (Kind));
39	      end Set_Token;
40
41	      procedure Go is new Parse (Set_Token);
42
43	      State : Integer := Integer (Previous_Block_State (Self));
44	   begin
45	      if State = -1 then
46	         State := Default_State;
47	      end if;
48
49	      Go (Qt4.Strings.To_Utf_16 (Text), State);
50
51	      Set_Current_Block_State (Self, Qt4.Q_Integer (State));
52	      Ada.Wide_Text_IO.Put_Line (">" & Qt4.Strings.To_Utf_16
(Text));
53	   end Highlight_Block;
54
55	   ------------
56	   -- Create --
57	   ------------
58
59	   function Create
60	     (Parent : access Qt4.Text_Documents.Q_Text_Document'Class :=
null)
61	      return not null Ada_Syntax_Highlighter_Access
62	   is
63	      Self : constant not null Ada_Syntax_Highlighter_Access
64	        := new Ada_Syntax_Highlighter;
65
66	   begin
67	      Qt4.Syntax_Highlighters.Impl.Constructors.Initialize (Self,
Parent);
68
69	      return Self;
70	   end Create;
71
72	end Ada_Syntax_Highlighters;

And attach it to QPlainTextEditor

23	with Qt_Ada.Application;
24	with Qt4.Core_Applications;
25	with Qt4.Fonts;
26	with Qt4.Objects;
27	with Qt4.Plain_Text_Edits.Constructors;
28	with Qt4.Strings;
29
30	with Ada_Syntax_Highlighters;
31
32	procedure Main is
33	   Editor      : Qt4.Plain_Text_Edits.Q_Plain_Text_Edit_Access;
34	   Highlighter :
Ada_Syntax_Highlighters.Ada_Syntax_Highlighter_Access;
35
36	begin
37	   Qt_Ada.Application.Initialize;
38
39	   Editor :=
40	     Qt4.Plain_Text_Edits.Constructors.Create
41	      (Qt4.Strings.From_Utf_16 ("Quit"));
42	   Highlighter := Ada_Syntax_Highlighters.Create (Editor.Document);
43
44	   Editor.Resize (800, 600);
45	   Editor.Show;
46
47	   Qt_Ada.Application.Execute;
48	end Main;

That's all... ;-)



^ permalink raw reply	[relevance 4%]

* Re: Ada extension information
  2009-05-30  7:13  6% ` anon
@ 2009-05-30 10:13  0%   ` info
  0 siblings, 0 replies; 45+ results
From: info @ 2009-05-30 10:13 UTC (permalink / raw)


On May 30, 8:13 am, a...@anon.org (anon) wrote:
> The problem is, those extra routines that make use of the "C like conditional
> compiling statements" are define in the body and referenced in the private
> sections of "Ada.Text_IO" and "Ada.Wide_Text_IO" packages. The comments
> state that they are for a sub-package "Ada.Text_IO.Wide_Text_IO" that is not
> present in the source. In scanning all 2850 plus files in the 2009 GNAT, the
> only references to this sub-package is in comments from the following 3 files:
>
>   Ada.Text_IO
>   Ada.Wide_Text_IO
> and
>   System.WCh_WtS
>
> So, why are these routines in the two Text IO packages, and where is that
> child package "Ada.Text_IO.Wide_Text_IO"?  
>
> Now, if these routines are defined and reference only with-in the package
> they are defined, then why are these routines references in the specification
> private area, they should be at the top of the body, hidden from the
> specification side. Keeping the Ada Text packages more precise to the Ada
> language, instead of junking it up with references that are not used outside
> ofthat package.  
>
> Or is this somewhat of an advance copy of 2010/2011 version of
> Ada.Text_IO and a new "Ada.Text_IO.Wide_Text_IO" package.
>
> And there is no reference in the documentation of the "C like conditional
> compiling statements".
>
> From RM 1.1.3 "Conformity of an Implementation with the Standard"
>
>     6  Contain no variations except those explicitly permitted by this
>        International Standard, or those that are impossible or
>        impractical to avoid given the implementation's execution
>        environment;
>
>     7  Specify all such variations in the manner prescribed by this
>        International Standard.
>
> No True Ada programmer wants "Language extensions" without references.  
> And most would prefer some simple references that is stated with-in the RM,
> not just hinted to by the RM, like having a RM section on what type
> "conditional compiling statements" would be acceptable with a few examples.
>
> So where is the documentation that is requred by RM 1.1.3 ( 7 ). Plus,
> I have not found where "conditional compiling statements" are allow
> in Ada RM 1.1.3 ( 6 ). And in some cases "conditional compiling
> statements" kills the need for generic package.
>
> Plus, there is another Adacore pragma ( sample located in body of
> Ada.Sequential_IO ). This seams to bypass the requirement to use
> "-gnatX".
>
>       pragma Extensions_Allowed ( On | Off ) ;
>
> with no documentation in the GNAT Documentation User's Guide ( GNAT_UGN )
> or the GNAT Reference Manual ( GNAT_RM ).
>
> Plus, if Adacore want to extend Ada, they normally use a child package
> with-in the GNAT package structure to test the idea before forcing the
> changes into the the Ada package structure.
>
> And finally what other changes have been made and how to disable them. Aka
> to turn off all "conditional expressions"? And for that reason the "C like
> conditional compiling statements" should never be in the core Ada or core
> System packages that are define in the RM.
>
> In <d784432e-fa9d-4bc9-b849-ecb2208af...@c9g2000yqm.googlegroups.com>, i...@midoan.com writes:
> >Hello,
> >a-textio.adb released with GNAT 2009 GPL for windows, contains:
>
> >Item :=
> >              (if not Is_Start_Of_Encoding (Character'Val (ch),
> >File.WC_Method)
> >               then Character'Val (ch)
> >               else Get_Upper_Half_Char_Immed (Character'Val (ch),
> >File));
>
> >which is easy enough to understand but is not standard Ada.
>
> >GNAT 2009 tells me :
>
> >try.adb:5:09: conditional expression is an Ada extension
> >try.adb:5:09: use -gnatX switch to compile this unit
>
> >http://www.adacore.com/2009/03/29/NF-63-I317-009-gnat/discusses
> >this.
>
> >Is it not jumping the gun a little to use these extensions to document
> >standard libraries before they become official, or even documented?
>
> >More specifically where are these Ada extensions formally documented?
> >(Ada Conformity Assessment Authority seem to have discussion about
> >this up to 15th March 2009 !)
>
> >PS In the meantime Mika is broken if you use a-textio as distributed
> >with GNAT GPL  2009.
>
> >Sincerely,
> >http://www.midoan.com
>
>

Just to clarify what Mika, our test data generator, uniquely it
appears, does. During test data generation, and only if the user's
code uses standrad libraries, Mika analyses the standard libraries and
uses that information to simulate their behaviour. We believe that
this approach is more accurate, repeatable and thorough than other
alternatives such as writing manual stubs for them. It also offers the
possibility of generating more interesting tests that cover the CFG of
the standard libraries (not to test the standard libraries, but rather
to generate tests that are borderline and that may not be expected by
the developers).


It therefore makes our job easier if the libraries are written in
standard Ada. The fact that they are close to it is already a great
help for us: althought we cannot analyse everything, things left in
code during development (but would probably be removed in the final
version) such as usages of textio do not have to removed; the code
does not have to be modified.

We released a minor update yesterday, and Mika can now parse
conditional expressions in standard libraries.

Regards,
Midoan



^ permalink raw reply	[relevance 0%]

* Re: Ada extension information
  @ 2009-05-30  7:13  6% ` anon
  2009-05-30 10:13  0%   ` info
  0 siblings, 1 reply; 45+ results
From: anon @ 2009-05-30  7:13 UTC (permalink / raw)


The problem is, those extra routines that make use of the "C like conditional 
compiling statements" are define in the body and referenced in the private 
sections of "Ada.Text_IO" and "Ada.Wide_Text_IO" packages. The comments 
state that they are for a sub-package "Ada.Text_IO.Wide_Text_IO" that is not 
present in the source. In scanning all 2850 plus files in the 2009 GNAT, the 
only references to this sub-package is in comments from the following 3 files:

  Ada.Text_IO 
  Ada.Wide_Text_IO
and 
  System.WCh_WtS

So, why are these routines in the two Text IO packages, and where is that 
child package "Ada.Text_IO.Wide_Text_IO"?  

Now, if these routines are defined and reference only with-in the package 
they are defined, then why are these routines references in the specification 
private area, they should be at the top of the body, hidden from the 
specification side. Keeping the Ada Text packages more precise to the Ada 
language, instead of junking it up with references that are not used outside 
ofthat package.   

Or is this somewhat of an advance copy of 2010/2011 version of 
Ada.Text_IO and a new "Ada.Text_IO.Wide_Text_IO" package.


And there is no reference in the documentation of the "C like conditional 
compiling statements".

From RM 1.1.3 "Conformity of an Implementation with the Standard" 

    6  Contain no variations except those explicitly permitted by this
       International Standard, or those that are impossible or
       impractical to avoid given the implementation's execution
       environment;

    7  Specify all such variations in the manner prescribed by this
       International Standard.


No True Ada programmer wants "Language extensions" without references.  
And most would prefer some simple references that is stated with-in the RM, 
not just hinted to by the RM, like having a RM section on what type 
"conditional compiling statements" would be acceptable with a few examples. 

So where is the documentation that is requred by RM 1.1.3 ( 7 ). Plus, 
I have not found where "conditional compiling statements" are allow 
in Ada RM 1.1.3 ( 6 ). And in some cases "conditional compiling 
statements" kills the need for generic package.

Plus, there is another Adacore pragma ( sample located in body of 
Ada.Sequential_IO ). This seams to bypass the requirement to use 
"-gnatX". 

      pragma Extensions_Allowed ( On | Off ) ;

with no documentation in the GNAT Documentation User's Guide ( GNAT_UGN ) 
or the GNAT Reference Manual ( GNAT_RM ).

Plus, if Adacore want to extend Ada, they normally use a child package 
with-in the GNAT package structure to test the idea before forcing the 
changes into the the Ada package structure. 

And finally what other changes have been made and how to disable them. Aka 
to turn off all "conditional expressions"? And for that reason the "C like 
conditional compiling statements" should never be in the core Ada or core 
System packages that are define in the RM.




In <d784432e-fa9d-4bc9-b849-ecb2208afc73@c9g2000yqm.googlegroups.com>, info@midoan.com writes:
>Hello,
>a-textio.adb released with GNAT 2009 GPL for windows, contains:
>
>Item :=
>              (if not Is_Start_Of_Encoding (Character'Val (ch),
>File.WC_Method)
>               then Character'Val (ch)
>               else Get_Upper_Half_Char_Immed (Character'Val (ch),
>File));
>
>which is easy enough to understand but is not standard Ada.
>
>GNAT 2009 tells me :
>
>try.adb:5:09: conditional expression is an Ada extension
>try.adb:5:09: use -gnatX switch to compile this unit
>
>http://www.adacore.com/2009/03/29/NF-63-I317-009-gnat/ discusses
>this.
>
>Is it not jumping the gun a little to use these extensions to document
>standard libraries before they become official, or even documented?
>
>More specifically where are these Ada extensions formally documented?
>(Ada Conformity Assessment Authority seem to have discussion about
>this up to 15th March 2009 !)
>
>PS In the meantime Mika is broken if you use a-textio as distributed
>with GNAT GPL  2009.
>
>Sincerely,
>http://www.midoan.com




^ permalink raw reply	[relevance 6%]

* Re: Range types
  2007-10-23 23:52  4%         ` anon
@ 2007-10-24 12:57  0%           ` Christos Chryssochoidis
  0 siblings, 0 replies; 45+ results
From: Christos Chryssochoidis @ 2007-10-24 12:57 UTC (permalink / raw)


Thanks very much, for giving me in such detail the solution, anon!

Regards,

Christos Chryssochoidis

anon wrote:
> --
> -- Package example:
> --
> -- For non Greek keyboards use Wide_Character 
> --  { ["<xxxx>"]["<yyyy>"] } 
> --  where <xxxx> and <yyyy> are 4-hex-digits to represents
> --  the two Wide_Character values 
> --
> --  Example is 
> --    ["03d6"]["1eee"]  -- valid Greek string
> --    ["03d6"]h -- is not valid because character "h" is not
> --                 a valid Greek character.
> --
> 
> 
> with Ada.Wide_Text_IO ;
> use  Ada.Wide_Text_IO ;
> 
> procedure tst is
> 
>   --
>   -- Internal Packages:
>   --
>   package Greek is
> 
> 
>     function Is_Greek_Character ( GC : Wide_Character ) 
>                                 return Boolean ;
> 
> 
>     function Is_Greek_Character_2 ( GC : Wide_Character ) 
>                                 return Boolean ;
> 
>     function Is_Greek_Character ( GS : Wide_String ) 
>                                 return Boolean ;
> 
>   end Greek ;
> 
>   --
>   -- Internal Body Package 
>   --
>   package body Greek is
> 
>     -- --------------------------- --
>     -- Use for Is_Greek_Character  --
>     -- --------------------------- --
> 
>     --
>     -- creates a greek constraint type
>     --
>     subtype Greek_Base is Wide_Character 
>                                 range Wide_Character'Val ( 16#370# )
>                                    .. Wide_Character'Val ( 16#1FFF# ) ;
> 
>     --
>     -- creates an excluded type
>     --
>     subtype Greek_Exclude_Subtype is Greek_Base
>                                 range Greek_Base'Val ( 16#03D8# )
>                                    .. Greek_Base'Val ( 16#0FFF# ) ;
> 
>     -- ----------------------------- --
>     -- Use for Is_Greek_Character_2  --
>     -- ----------------------------- --
> 
>     --
>     -- create lower greek characters type
>     --
>     subtype Lower_Greek_Character is Wide_Character 
>                                 range Wide_Character'Val ( 16#0370# )
>                                    .. Wide_Character'Val ( 16#03D7# ) ;
>     --
>     -- create upper greek characters type
>     --
>     subtype Upper_Greek_Character is Wide_Character 
>                                range Wide_Character 'Val ( 16#1000# )  
>                                   .. Wide_Character 'Val ( 16#1FFF# ) ;
> 
> 
> 
> 
>   --
>   -- Is_Greek_Character 
>   --
>   function Is_Greek_Character ( GC : Wide_Character ) 
>                               return Boolean is
> 
>     begin
>       --
>       -- Is character within the Greek base
>       --
>       if GC in Greek_Base then
>         --
>         -- Is character apart of the the non-Greek sub type
>         --
>         if GC in Greek_Exclude_Subtype then    
>           return False ;
>         else
>           return True ;
>         end if ;
>       else
>         return False ;
>       end if ;
>     end ;
> 
> 
>   --
>   -- Is_Greek_Character version number 2
>   --
>   function Is_Greek_Character_2 ( GC : Wide_Character ) 
>                               return Boolean is
> 
>     begin
>       --
>       -- Could use:
>       -- 
>       -- when Lower_Greek_Character | Upper_Greek_Character =>
>       --    return True ;
>       --
>       case GC is 
>          when Lower_Greek_Character =>
>             return True ;
>          when Upper_Greek_Character =>
>             return True ;
>          when others =>
>             return False ;
>       end case ;
>     end ;
> 
> 
>   function Is_Greek_Character ( GS : Wide_String ) 
>                               return Boolean is
> 
>     begin
>       --
>       -- Could use:
>       -- 
>       --
>       for Index in 1 .. GS'Length loop
>         --
>         -- if index-character of a string is not a Greek character
>         --
>         if not Is_Greek_Character_2 ( GS ( Index ) ) then 
>           return False ;
>         end if ;
>       end loop ;
>       --
>       -- String contains all Greek characters
>       --
>       return True ;
>     end ;
> 
>   end Greek ;
> 
> 
>   stz : wide_string ( 1..2 ) ;
> 
>   use Greek ;
> 
> begin
> --
>   put ( "Enter (2 character Greek string) => " ) ;
>   get ( stz ) ;
> --
>   put ( "Testing => " ) ;
>   put ( stz ) ;
>   new_line ;  
> --
>   if Is_Greek_Character ( stz ) then
>     put_line ( "Greek String ? => Yes" ) ;
>   else
>     put_line ( "Greek String ? => No" ) ;
>     --
>     -- Char 1 ?
>     --
>     if Is_Greek_Character ( stz ( 1 ) ) then
>       put_line ( "Character (1) Greek ? => Yes" ) ;
>     else
>       put_line ( "Character (1) Greek ? => No" ) ;
>     end if ;    
> 
>     --
>     -- Char 2 ?
>     --
>     if Is_Greek_Character_2 ( stz ( 2 ) ) then
>       put_line ( "Character (2) Greek ? => Yes" ) ;
>     else
>       put_line ( "Character (1) Greek ? => No" ) ;
>     end if ;
>   end if ;    
> --
> end tst ;
> 
> 
> 
> In <1193051690.350063@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>> Jacob Sparre Andersen wrote:
>>> Christos Chryssochoidis wrote:
>>>
>>>> I would like to define a subtype of Wide_Character for a program
>>>> that processes (unicode) text. This type would represent the Greek
>>>> letters.
>>> This sounds like what enumerated types are for.  You could do it like
>>> this:
>>>
>>>    type Faroese_Letter is ('a', 'A', 'b', 'B', 'd', 'D', 'ð', 'Ð',
>>>                            'e', 'E', [...],
>>>                            'y', 'Y', 'ý', 'Ý', 'æ', 'Æ', 'ø', 'Ø');
>>>    -- optional representation clause
>>>
>>>    function To_Wide_Wide_Character (Item : in Faroese_Letter)
>>>      return Wide_Wide_Character;
>>>
>>>    function To_Faroese_Letter (Item : in Wide_Wide_Character)
>>>      return Faroese_Letter;
>>>
>>> The conversion functions could make use of representation clauses,
>>> "Image" and "Value" functions, or tables.
>>>
>>>> Greek letters in Unicode, with all their diacritics, are
>>>> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's
>>>> 360 characters to write in an enumeration... Since gaps are not
>>>> allowed in ranges, I 'm thinking instead of defining such a type, to
>>>> define a function that would accept a Wide_Character as argument and
>>>> return a boolean value indicating whether the given Wide_Character
>>>> falls in the ranges of the Greek characters.
>>> This could be done very simply using Ada.Strings.Maps.
>>>
>>> How you should do it depends strongly on what you actually need your
>>> Greek_Letter type for.
>>>
>>> Greetings,
>>>
>>> Jacob
>> Thanks! Ada.Strings.Wide_Maps seems very helpful for what I want to do. 
>> Basically, what I would like to do is to write a program that given a 
>> text file in utf8 encoding, which would contain ancient greek text, 
>> which is written with all the diacritic marks on the letters, this 
>> program would load the contents of the file in memory, strip the 
>> in-memory text contents from all the diacritics except those used in 
>> today's "modern" Greek, and write the modified contents to a new file of 
>> the user's choosing. For this it would be nice if there were some 
>> package for regular expressions for Ada. Then if I succeeded in the 
>> mentioned task,  I 'd like to do some natural language processing (NLP, 
>> that is linguistics processing) with my program, but I don't know if Ada 
>> would be an appropriate language for such a task (NLP). I've seen on the 
>> web references to NLP applications with functional languages or logic 
>> programming languages, but not many implemented with imperative 
>> languages... (Sorry for getting of topic...)
>>
>> Thanks very much,
>> Christos
> 



^ permalink raw reply	[relevance 0%]

* Re: Range types
  @ 2007-10-23 23:52  4%         ` anon
  2007-10-24 12:57  0%           ` Christos Chryssochoidis
  0 siblings, 1 reply; 45+ results
From: anon @ 2007-10-23 23:52 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 7135 bytes --]

--
-- Package example:
--
-- For non Greek keyboards use Wide_Character 
--  { ["<xxxx>"]["<yyyy>"] } 
--  where <xxxx> and <yyyy> are 4-hex-digits to represents
--  the two Wide_Character values 
--
--  Example is 
--    ["03d6"]["1eee"]  -- valid Greek string
--    ["03d6"]h -- is not valid because character "h" is not
--                 a valid Greek character.
--


with Ada.Wide_Text_IO ;
use  Ada.Wide_Text_IO ;

procedure tst is

  --
  -- Internal Packages:
  --
  package Greek is


    function Is_Greek_Character ( GC : Wide_Character ) 
                                return Boolean ;


    function Is_Greek_Character_2 ( GC : Wide_Character ) 
                                return Boolean ;

    function Is_Greek_Character ( GS : Wide_String ) 
                                return Boolean ;

  end Greek ;

  --
  -- Internal Body Package 
  --
  package body Greek is

    -- --------------------------- --
    -- Use for Is_Greek_Character  --
    -- --------------------------- --

    --
    -- creates a greek constraint type
    --
    subtype Greek_Base is Wide_Character 
                                range Wide_Character'Val ( 16#370# )
                                   .. Wide_Character'Val ( 16#1FFF# ) ;

    --
    -- creates an excluded type
    --
    subtype Greek_Exclude_Subtype is Greek_Base
                                range Greek_Base'Val ( 16#03D8# )
                                   .. Greek_Base'Val ( 16#0FFF# ) ;

    -- ----------------------------- --
    -- Use for Is_Greek_Character_2  --
    -- ----------------------------- --

    --
    -- create lower greek characters type
    --
    subtype Lower_Greek_Character is Wide_Character 
                                range Wide_Character'Val ( 16#0370# )
                                   .. Wide_Character'Val ( 16#03D7# ) ;
    --
    -- create upper greek characters type
    --
    subtype Upper_Greek_Character is Wide_Character 
                               range Wide_Character 'Val ( 16#1000# )  
                                  .. Wide_Character 'Val ( 16#1FFF# ) ;




  --
  -- Is_Greek_Character 
  --
  function Is_Greek_Character ( GC : Wide_Character ) 
                              return Boolean is

    begin
      --
      -- Is character within the Greek base
      --
      if GC in Greek_Base then
        --
        -- Is character apart of the the non-Greek sub type
        --
        if GC in Greek_Exclude_Subtype then    
          return False ;
        else
          return True ;
        end if ;
      else
        return False ;
      end if ;
    end ;


  --
  -- Is_Greek_Character version number 2
  --
  function Is_Greek_Character_2 ( GC : Wide_Character ) 
                              return Boolean is

    begin
      --
      -- Could use:
      -- 
      -- when Lower_Greek_Character | Upper_Greek_Character =>
      --    return True ;
      --
      case GC is 
         when Lower_Greek_Character =>
            return True ;
         when Upper_Greek_Character =>
            return True ;
         when others =>
            return False ;
      end case ;
    end ;


  function Is_Greek_Character ( GS : Wide_String ) 
                              return Boolean is

    begin
      --
      -- Could use:
      -- 
      --
      for Index in 1 .. GS'Length loop
        --
        -- if index-character of a string is not a Greek character
        --
        if not Is_Greek_Character_2 ( GS ( Index ) ) then 
          return False ;
        end if ;
      end loop ;
      --
      -- String contains all Greek characters
      --
      return True ;
    end ;

  end Greek ;


  stz : wide_string ( 1..2 ) ;

  use Greek ;

begin
--
  put ( "Enter (2 character Greek string) => " ) ;
  get ( stz ) ;
--
  put ( "Testing => " ) ;
  put ( stz ) ;
  new_line ;  
--
  if Is_Greek_Character ( stz ) then
    put_line ( "Greek String ? => Yes" ) ;
  else
    put_line ( "Greek String ? => No" ) ;
    --
    -- Char 1 ?
    --
    if Is_Greek_Character ( stz ( 1 ) ) then
      put_line ( "Character (1) Greek ? => Yes" ) ;
    else
      put_line ( "Character (1) Greek ? => No" ) ;
    end if ;    

    --
    -- Char 2 ?
    --
    if Is_Greek_Character_2 ( stz ( 2 ) ) then
      put_line ( "Character (2) Greek ? => Yes" ) ;
    else
      put_line ( "Character (1) Greek ? => No" ) ;
    end if ;
  end if ;    
--
end tst ;



In <1193051690.350063@athprx04>, Christos Chryssochoidis <C.Chryssochoidis@gmail.com> writes:
>Jacob Sparre Andersen wrote:
>> Christos Chryssochoidis wrote:
>> 
>>> I would like to define a subtype of Wide_Character for a program
>>> that processes (unicode) text. This type would represent the Greek
>>> letters.
>> 
>> This sounds like what enumerated types are for.  You could do it like
>> this:
>> 
>>    type Faroese_Letter is ('a', 'A', 'b', 'B', 'd', 'D', '�', '�',
>>                            'e', 'E', [...],
>>                            'y', 'Y', '�', '�', '�', '�', '�', '�');
>>    -- optional representation clause
>> 
>>    function To_Wide_Wide_Character (Item : in Faroese_Letter)
>>      return Wide_Wide_Character;
>> 
>>    function To_Faroese_Letter (Item : in Wide_Wide_Character)
>>      return Faroese_Letter;
>> 
>> The conversion functions could make use of representation clauses,
>> "Image" and "Value" functions, or tables.
>> 
>>> Greek letters in Unicode, with all their diacritics, are
>>> located in two separate ranges: 0370 - 03D7 and 1F00 - 1FFF. That's
>>> 360 characters to write in an enumeration... Since gaps are not
>>> allowed in ranges, I 'm thinking instead of defining such a type, to
>>> define a function that would accept a Wide_Character as argument and
>>> return a boolean value indicating whether the given Wide_Character
>>> falls in the ranges of the Greek characters.
>> 
>> This could be done very simply using Ada.Strings.Maps.
>> 
>> How you should do it depends strongly on what you actually need your
>> Greek_Letter type for.
>> 
>> Greetings,
>> 
>> Jacob
>
>Thanks! Ada.Strings.Wide_Maps seems very helpful for what I want to do. 
>Basically, what I would like to do is to write a program that given a 
>text file in utf8 encoding, which would contain ancient greek text, 
>which is written with all the diacritic marks on the letters, this 
>program would load the contents of the file in memory, strip the 
>in-memory text contents from all the diacritics except those used in 
>today's "modern" Greek, and write the modified contents to a new file of 
>the user's choosing. For this it would be nice if there were some 
>package for regular expressions for Ada. Then if I succeeded in the 
>mentioned task,  I 'd like to do some natural language processing (NLP, 
>that is linguistics processing) with my program, but I don't know if Ada 
>would be an appropriate language for such a task (NLP). I've seen on the 
>web references to NLP applications with functional languages or logic 
>programming languages, but not many implemented with imperative 
>languages... (Sorry for getting of topic...)
>
>Thanks very much,
>Christos




^ permalink raw reply	[relevance 4%]

* Re: Wide Character Problem in Ada.Numerics
  2007-04-23 21:29  5% Wide Character Problem in Ada.Numerics david.smith
@ 2007-04-24 17:54  0% ` Pascal Obry
  0 siblings, 0 replies; 45+ results
From: Pascal Obry @ 2007-04-24 17:54 UTC (permalink / raw)
  To: david.smith

david.smith@gmail.com a écrit :
> Hi, I'm new here and to Ada.  I'm having a problem compiling code
> using greek letters as identifiers.  The problem arises when I need to
> use the Ada.Numerics package.  My source code is UTF-8, and I'm
> entering the characters using a greek keymap in vim.  I'm using gnat/
> gcc-4.1 and the -gnatiw and -gnatW8 switches.
> 
> An example code I wrote compiles fine:
> ---
> with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
> with Ada.Float_Text_IO; use Ada.Float_Text_IO;
> procedure WCTest is
>    Σ : Wide_Character := 'π';
>    μ : Float := 0.01;
> begin
>    Put(Σ);
>    New_Line;
>    Put(μ);
> end WCTest;
> ---
> Output:
> π
>  1.00000E-02
> ---
> 
> When I next compile my real code with greek letters *and* using the
> Ada.Numerics package, I get the following error:
> 
> a-numeri.ads:25:04: illegal wide character

Did you try -gnatif option ?

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595



^ permalink raw reply	[relevance 0%]

* Wide Character Problem in Ada.Numerics
@ 2007-04-23 21:29  5% david.smith
  2007-04-24 17:54  0% ` Pascal Obry
  0 siblings, 1 reply; 45+ results
From: david.smith @ 2007-04-23 21:29 UTC (permalink / raw)


Hi, I'm new here and to Ada.  I'm having a problem compiling code
using greek letters as identifiers.  The problem arises when I need to
use the Ada.Numerics package.  My source code is UTF-8, and I'm
entering the characters using a greek keymap in vim.  I'm using gnat/
gcc-4.1 and the -gnatiw and -gnatW8 switches.

An example code I wrote compiles fine:
---
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
with Ada.Float_Text_IO; use Ada.Float_Text_IO;
procedure WCTest is
   Σ : Wide_Character := 'π';
   μ : Float := 0.01;
begin
   Put(Σ);
   New_Line;
   Put(μ);
end WCTest;
---
Output:
π
 1.00000E-02
---

When I next compile my real code with greek letters *and* using the
Ada.Numerics package, I get the following error:

a-numeri.ads:25:04: illegal wide character

This is the line that has the bracket notation definition of pi in
it.

Does anyone know what is going on?  Why is there an error in a system
file?

Thanks!




^ permalink raw reply	[relevance 5%]

* Re: Silly question about strings (was: Filenames in Ada)
  2005-11-24  3:21  4%   ` Silly question about strings (was: Filenames in Ada) Steve
@ 2005-11-24  4:58  0%     ` Larry Kilgallen
  0 siblings, 0 replies; 45+ results
From: Larry Kilgallen @ 2005-11-24  4:58 UTC (permalink / raw)


In article <oNmdneZx9ePFrBjenZ2dnUVZ_t2dnZ2d@comcast.com>, "Steve" <nospam_steved94@comcast.net> writes:
> This may be a silly question, but why aren't the character dependent
> packages generic?
>
> It seems odd to have separate packages:
>
>   Ada.Strings.Fixed;
>   Ada.Strings.Wide_Fixed;
>   Ada.Strings.Bounded;
>   Ada.Strings.Wide_Bounded;
>   Ada.Strings.Unbounded;
>   Ada.Strings.Wide_Unbounded;
>   Ada.Text_IO;
>   Ada.Wide_Text_IO;
>
> Instead of generic packages that use the character type as a parameter, with
> predefined instatiations for character and wide_character similar to what is
> done with numerics.  Perhaps something along the lines of:
>
>   package Ada.Strings.Fixed is new Ada.Strings.String_Base( Character );
>   package Ada.Strings.Wide_Fixed is new Ada.Strings.String_Base(
> Wide_Character );
>
> and so on...
>
> It seems like this would eliminate issues with different character sets, and
> avoid the need for a language revision when a 64 bit (or 128 bit) version of
> Unicode arrives.

I would expect those string packages (and especially the string IO
packages) would use operating system facilities in some implementations.
The underlying operating system calls might not be symmetric at all.
The bodies might not even be written in Ada.



^ permalink raw reply	[relevance 0%]

* Silly question about strings (was: Filenames in Ada)
  @ 2005-11-24  3:21  4%   ` Steve
  2005-11-24  4:58  0%     ` Larry Kilgallen
  0 siblings, 1 reply; 45+ results
From: Steve @ 2005-11-24  3:21 UTC (permalink / raw)


This may be a silly question, but why aren't the character dependent 
packages generic?

It seems odd to have separate packages:

  Ada.Strings.Fixed;
  Ada.Strings.Wide_Fixed;
  Ada.Strings.Bounded;
  Ada.Strings.Wide_Bounded;
  Ada.Strings.Unbounded;
  Ada.Strings.Wide_Unbounded;
  Ada.Text_IO;
  Ada.Wide_Text_IO;

Instead of generic packages that use the character type as a parameter, with 
predefined instatiations for character and wide_character similar to what is 
done with numerics.  Perhaps something along the lines of:

  package Ada.Strings.Fixed is new Ada.Strings.String_Base( Character );
  package Ada.Strings.Wide_Fixed is new Ada.Strings.String_Base( 
Wide_Character );

and so on...

It seems like this would eliminate issues with different character sets, and 
avoid the need for a language revision when a 64 bit (or 128 bit) version of 
Unicode arrives.

Steve
(The Duck) 





^ permalink raw reply	[relevance 4%]

* Re: Where is my ASIS mistake?
  2003-11-28 11:12  6% Where is my ASIS mistake? Xela
@ 2003-11-29 12:10  0% ` Alex Xela
  0 siblings, 0 replies; 45+ results
From: Alex Xela @ 2003-11-29 12:10 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 3106 bytes --]

--------------------------
I am not very familiar with the Gnat implementation of Asis.
In order I had a quick glance to the documentation. I suppose that my
problem is coming from the way I am handling the procedure
Asis.Ada_Environments.Associate.
I am thinking that my ""problem/question"" is solved!
---------------------------
"Xela" <xela2@free.fr> a �crit dans le message de
news:20031128-121211-658150@foorum.com...
>
> With a basic ASIS program I am attempting to list all units in my current
> library.
> In order, I wrote the following code:
> ------------
> with Asis;
> with Asis.Implementation;
> with Asis.Ada_Environments;
> with Asis.Compilation_Units;
> with Asis.Ada_Environments.Containers;
> with Ada.Text_Io;
> with Ada.Wide_Text_Io;
> procedure List_Units is
>     My_Context  : Asis.Context;
>     Sep : constant String := "------------------------------------------";
> begin
>     Asis.Implementation.Initialize;
>     Asis.Ada_Environments.Associate(My_Context, "My Context");
>     Asis.Ada_Environments.Open (My_Context);
>     declare
>         Libraries_List : Asis.Ada_Environments.Containers.Container_List
>             :=
Asis.Ada_Environments.Containers.Defining_Containers(My_Context);
>         Units_List :  Asis.Compilation_Unit_List
>             := Asis.Ada_Environments.Containers.Compilation_Units(
>             Libraries_List(1));
>     begin
>         for U in  Units_List'range loop
>             Ada.Text_Io.Put_Line(Sep);
>             Ada.Wide_Text_Io.Put_Line("Full Name =
"&Asis.Compilation_Units.
> Unit_Full_Name(Units_List(U)));
>             Ada.Wide_Text_Io.Put_Line("Texte Name=
"&Asis.Compilation_Units.
> Text_Name(Units_List(U)));
>             Ada.Text_Io.Put_Line("Unit Kind =
"&Asis.Unit_Kinds'Image(Asis.
> Compilation_Units.Unit_Kind(Units_List(U))));
>         end loop;
>     end;
>     Ada.Text_Io.Put_Line(Sep);
>     Asis.Ada_Environments.Close( My_Context );
>     Asis.Ada_Environments.Dissociate( My_Context );
>     Asis.Implementation.Finalize;
> end List_Units;
> --------
>
> If now I compile with gnat3.15p  the following code (gnatmake hello), and
also
> my List_units one :
>
> with Ada.Text_Io;
> procedure Hello is
> begin
>    Ada.Text_Io.Put_Line("hello!");
> end Hello;
>
> Executing list_units.exe give me:
>
> --------------------------------------
> Full Name = Standard
> Texte Name=
> Unit Kind = A_PACKAGE
> -------------------------------------- :-(
>
> Now with the same code, If I recompile my list_units program and I execute
it
> under an ObjectAda library registered with the hello unit the result is
the
> expecting one:
>
> ------------------------------------------
> Full Name = Hello
> Texte Name= d:\Cholay\Tmp\Exercices\hello.adb
> Unit Kind = A_PROCEDURE_BODY
> ------------------------------------------ :-)
>
> I am convincing with the fact that I am making a huge error but which one?
> Thanks for the help!
>
>
>
>
> -- 
> Ce message a ete poste via la plateforme Web club-Internet.fr
> This message has been posted by the Web platform club-Internet.fr
>
> http://forums.club-internet.fr/





^ permalink raw reply	[relevance 0%]

* Where is my ASIS mistake?
@ 2003-11-28 11:12  6% Xela
  2003-11-29 12:10  0% ` Alex Xela
  0 siblings, 1 reply; 45+ results
From: Xela @ 2003-11-28 11:12 UTC (permalink / raw)



With a basic ASIS program I am attempting to list all units in my current 
library.
In order, I wrote the following code:
------------
with Asis;
with Asis.Implementation;
with Asis.Ada_Environments;
with Asis.Compilation_Units;
with Asis.Ada_Environments.Containers;
with Ada.Text_Io;
with Ada.Wide_Text_Io;
procedure List_Units is
    My_Context  : Asis.Context;
    Sep : constant String := "------------------------------------------";
begin
    Asis.Implementation.Initialize;
    Asis.Ada_Environments.Associate(My_Context, "My Context");
    Asis.Ada_Environments.Open (My_Context);
    declare
        Libraries_List : Asis.Ada_Environments.Containers.Container_List
            := Asis.Ada_Environments.Containers.Defining_Containers(My_Context);
        Units_List :  Asis.Compilation_Unit_List
            := Asis.Ada_Environments.Containers.Compilation_Units(
            Libraries_List(1));
    begin
        for U in  Units_List'range loop
            Ada.Text_Io.Put_Line(Sep);
            Ada.Wide_Text_Io.Put_Line("Full Name = "&Asis.Compilation_Units.
Unit_Full_Name(Units_List(U)));
            Ada.Wide_Text_Io.Put_Line("Texte Name= "&Asis.Compilation_Units.
Text_Name(Units_List(U)));
            Ada.Text_Io.Put_Line("Unit Kind = "&Asis.Unit_Kinds'Image(Asis.
Compilation_Units.Unit_Kind(Units_List(U))));
        end loop;
    end;
    Ada.Text_Io.Put_Line(Sep);
    Asis.Ada_Environments.Close( My_Context );
    Asis.Ada_Environments.Dissociate( My_Context );
    Asis.Implementation.Finalize;
end List_Units;
--------

If now I compile with gnat3.15p  the following code (gnatmake hello), and also 
my List_units one :

with Ada.Text_Io;
procedure Hello is
begin
   Ada.Text_Io.Put_Line("hello!");
end Hello;

Executing list_units.exe give me:

--------------------------------------
Full Name = Standard
Texte Name= 
Unit Kind = A_PACKAGE
-------------------------------------- :-(

Now with the same code, If I recompile my list_units program and I execute it 
under an ObjectAda library registered with the hello unit the result is the 
expecting one:

------------------------------------------
Full Name = Hello
Texte Name= d:\Cholay\Tmp\Exercices\hello.adb
Unit Kind = A_PROCEDURE_BODY
------------------------------------------ :-)

I am convincing with the fact that I am making a huge error but which one?
Thanks for the help!




-- 
Ce message a ete poste via la plateforme Web club-Internet.fr
This message has been posted by the Web platform club-Internet.fr

http://forums.club-internet.fr/



^ permalink raw reply	[relevance 6%]

* Re: Interfacing Ada with C
  @ 2003-04-16  4:25  5%   ` Steve
  0 siblings, 0 replies; 45+ results
From: Steve @ 2003-04-16  4:25 UTC (permalink / raw)


"Steve" <nospam_steved94@attbi.com> wrote in message
news:pD3na.499811$sf5.816502@rwcrnsc52.ops.asp.att.net...
> A different way of doing this:
>
> In Ada you should be able to use Interfaces.C.Pointers and then declare
your
> procedure as follows:
>
>   package Interface_Wide_String is
>     new Interfaces.C.Pointers( Interfaces.C.size_T,
>                                Interfaces.C.WChar_T,
>                                Interfaces.C.WChar_Array,
>                                Interfaces.C.Wide_Nul );
[snip]
>
> I haven't tested this, but I think it will work (it compiles anyway).
>
> Steve
> (The Duck)
>
I created a small set of sources and tested my example (it does work).
Here's the source
for my test case:

------ File: clatest.c ------
#include <stdlib.h>

extern void One( wchar_t *text );
extern void adainit();
extern void adafinal();

int main(int argc, char* argv[])
{
    adainit();
    One( L"Hello from Ada" );
    adafinal();
    return 0;
}

------ File: One_Package.ads ------
with Interfaces.C;
with Interfaces.C.Pointers;

package One_Package is

  package Interface_Wide_String is
    new Interfaces.C.Pointers( Interfaces.C.size_T,
                               Interfaces.C.WChar_T,
                               Interfaces.C.WChar_Array,
                               Interfaces.C.Wide_Nul );

  procedure One( Name : in Interface_Wide_String.Pointer );
  pragma Export( C, One, "One" );

end One_Package;

------ File: One_Package.adb ------
with Ada.Wide_Text_Io;

package body One_Package is

  procedure One( Name : in Interface_Wide_String.Pointer ) is
  begin
    Ada.Wide_Text_Io.Put_Line( Interfaces.C.To_Ada(
Interface_Wide_String.Value( Name ) ) );
  end One;

end One_Package;

Steve
(The Duck)





^ permalink raw reply	[relevance 5%]

* Re: Redirecting Standard Error...
  2002-08-03  4:27  6% Redirecting Standard Error John M. Resler
@ 2002-08-05 15:41  5% ` Stephen Leake
  0 siblings, 0 replies; 45+ results
From: Stephen Leake @ 2002-08-05 15:41 UTC (permalink / raw)


"John M. Resler" <John-Resler@cox.net> writes:

> I have written an asis application that generates a lot of messages to
> standard error that are not pertinent to my application but
> nonetheless unsightly. I have attempted to redirect standard_error
> with the following lines to a log file and receive no exceptions but
> the asis initialization, association and open procedures continue to
> generate the standard_error output. Can anyone tell me over and above
> what I am doing, how I might get around this?

It may be that ASIS is using Ada.Text_IO for standard error, rather
than Ada.Wide_Text_IO; I have not checked.

> 
> 
>     -- code here for testing if file exists already, etc. --
>     redirect standard_error Ada.Wide_Text_IO.Open( File =>
>     Warnings_File, Mode => Ada.Wide_Text_IO.Append_File, Name =>
>     "asis_warnings.txt" );
> 
>     Ada.Wide_Text_IO.Set_Error( File => Warnings_File );
> 
>     -- initialize the asis environment
>     Asis.Implementation.Initialize;
>     Asis.Ada_Environments.Associate ( The_Context, "The_Context", "-CA");
>     Asis.Ada_Environments.Open ( The_Context );
> 

-- 
-- Stephe



^ permalink raw reply	[relevance 5%]

* Redirecting Standard Error...
@ 2002-08-03  4:27  6% John M. Resler
  2002-08-05 15:41  5% ` Stephen Leake
  0 siblings, 1 reply; 45+ results
From: John M. Resler @ 2002-08-03  4:27 UTC (permalink / raw)


I have written an asis application that generates a lot of messages to 
standard error that are not pertinent to my application but nonetheless 
unsightly. I have attempted to redirect standard_error with the 
following lines to a log file and receive no exceptions but the asis 
initialization, association and open procedures continue to generate the 
standard_error output. Can anyone tell me over and above what I am 
doing, how I might get around this?

    -- code here for testing if file exists already, etc.
    -- redirect standard_error
    Ada.Wide_Text_IO.Open( File => Warnings_File,
                           Mode => Ada.Wide_Text_IO.Append_File,
                           Name => "asis_warnings.txt" );

    Ada.Wide_Text_IO.Set_Error( File => Warnings_File );

    -- initialize the asis environment
    Asis.Implementation.Initialize;
    Asis.Ada_Environments.Associate ( The_Context, "The_Context", "-CA");
    Asis.Ada_Environments.Open ( The_Context );




^ permalink raw reply	[relevance 6%]

* Re: Text_IO on WinNT  problem
  @ 2001-09-25 18:07  4%   ` David Botton
  0 siblings, 0 replies; 45+ results
From: David Botton @ 2001-09-25 18:07 UTC (permalink / raw)
  To: comp.lang.ada

Take a look in the RM (A.11) for Ada.Wide_Text_IO;

David Botton

"Alfred Hilscher" <Alfred.Hilscher@icn.siemens.de> wrote in message
news:3BB0AAFD.9F006F92@icn.siemens.de...
> can I read (ASCII-) files that are stored as UNICODE with Text_IO ?





^ permalink raw reply	[relevance 4%]

* Re: implementation question about writing and reading from files
  2001-08-10 14:49  4%     ` Ted Dennison
@ 2001-08-10 15:44  0%       ` Warren W. Gay VE3WWG
  0 siblings, 0 replies; 45+ results
From: Warren W. Gay VE3WWG @ 2001-08-10 15:44 UTC (permalink / raw)


Ted Dennison wrote:
> In article <9kv5rs$6hosn$2@ID-102190.news.dfncis.de>, Francis Crick says...
> >And also, if I want to use a stream for keeping data in memory, how do i
> >that?  How do i instantiate a stream that I can just write to and read from
> >at my leisure?
> 
> The only language-defined streams are in Ada.Streams.Stream_IO,
> Ada.Text_IO.Text_Streams, and Ada.Wide_Text_IO.Text_Streams. I believe they all
> deal with files. If you want to use one to make yourself a buffer, you will have
> to code it yourself by deriving it from Ada.Streams.Root_Stream_Type and
> overriding "Read" and "Write".

If you want a number of examples of streams code, download the AdaVox software
from: http://members.home.net/ve3wwg

I am currently re-vamping AdaVox, because there are a number of design problems
in it, but in the originally released code (see above), you will find
some code that implements a stream buffer. Look for file wc-streams-buffer.ads.

I am sure you can improve upon it, but it will get you started at least.

> 
> >               Also, the data I'm moving is large, and chances are I won't
> >be using it for much else other than writing back to other file streams, so
> >how can i make the reading and writing as fast as possible?  Could I make it
> >read a whole mb in one go as a single unit?
> 
> The easiest way to do that is to unchecked_conversion your data (or better yet,
> a pointer to it) into a Ada.Streams.Stream_Element_Array, then call
> Ada.Streams.Write directly. If you just use the stream attributes, it will
> perform one write for each element, which I've found to be significantly slower
> (even when the target is a memory-based stream).

I think the GNAT implementation is built upon the stdio (C) package, ultimately.
One way to improve performance some, is to increase the buffer size of the 
underlying "file". You'll need to look at the GNAT User Guide to find out how.
You will need to open a C file, and then turn it into an Ada stream.
Maybe someone else can volunteer the details here (I'm too pressed for
time to look it up).

This won't compensate for the procedure(attribute) calls (that Ted referred to), 
but it will make each I/O a larger one.

> A good Ada book should go over the basics of this. Stream use is a complicated
> enough topic that you really ought to have such a resource to learn the basics
> from.

Otherwise, be prepared to look at the streams specs a lot (as I did).
-- 
Warren W. Gay VE3WWG
http://members.home.net/ve3wwg



^ permalink raw reply	[relevance 0%]

* Re: implementation question about writing and reading from files
  @ 2001-08-10 14:49  4%     ` Ted Dennison
  2001-08-10 15:44  0%       ` Warren W. Gay VE3WWG
  0 siblings, 1 reply; 45+ results
From: Ted Dennison @ 2001-08-10 14:49 UTC (permalink / raw)


In article <9kv5rs$6hosn$2@ID-102190.news.dfncis.de>, Francis Crick says...
>And also, if I want to use a stream for keeping data in memory, how do i
>that?  How do i instantiate a stream that I can just write to and read from
>at my leisure? 

The only language-defined streams are in Ada.Streams.Stream_IO,
Ada.Text_IO.Text_Streams, and Ada.Wide_Text_IO.Text_Streams. I believe they all
deal with files. If you want to use one to make yourself a buffer, you will have
to code it yourself by deriving it from Ada.Streams.Root_Stream_Type and
overriding "Read" and "Write". 

>               Also, the data I'm moving is large, and chances are I won't
>be using it for much else other than writing back to other file streams, so
>how can i make the reading and writing as fast as possible?  Could I make it
>read a whole mb in one go as a single unit?

The easiest way to do that is to unchecked_conversion your data (or better yet,
a pointer to it) into a Ada.Streams.Stream_Element_Array, then call
Ada.Streams.Write directly. If you just use the stream attributes, it will
perform one write for each element, which I've found to be significantly slower
(even when the target is a memory-based stream).

A good Ada book should go over the basics of this. Stream use is a complicated
enough topic that you really ought to have such a resource to learn the basics
from.

---
T.E.D.    homepage   - http://www.telepath.com/dennison/Ted/TED.html
          home email - mailto:dennison@telepath.com



^ permalink raw reply	[relevance 4%]

* Re: Hebrew language character set
  @ 2001-04-05 18:41  6%           ` Paul Storm
  0 siblings, 0 replies; 45+ results
From: Paul Storm @ 2001-04-05 18:41 UTC (permalink / raw)


I modified my program as follows, [begin code]

with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;

procedure aleph is
begin
  Ada.Wide_Text_IO.Put (Item => Wide_Character'Val(16#0590#));
end aleph;

[end code]

Now I get the following results,

D:\TEMP>gnatmake -gnatW8 aleph.adb
gcc -c -gnatW8 aleph.adb
gnatbind -x aleph.ali
gnatlink aleph.ali

D:\TEMP>aleph.exe
+�

I made some mistake in coding my character in decimal instead of hex??

I found this in the GNAT User's Guide, btw,

-gnatWe 
Specify the method of encoding for wide characters. e is one of the
following: 
h Hex encoding (brackets coding also recognized) 
u Upper half encoding (brackets encoding also recognized) 
s Shift/JIS encoding (brackets encoding also recognized) 
e EUC encoding (brackets encoding also recognized) 
8 UTF-8 encoding (brackets encoding also recognized) 
b Brackets encoding only (default value) 

For full details on the these encoding methods see See section Wide
Character Encodings. Note that brackets coding is always accepted, even
if one of the other options is specified, so for example -gnatW8
specifies that both brackets and UTF-8 encodings will be recognized. The
units that are with'ed directly or indirectly will be scanned using the
specified representation scheme, and so if one of the non-brackets
scheme is used, it must be used consistently throughout the program.
However, since brackets encoding is always recognized, it may be
conveniently used in standard libraries, allowing these libraries to be
used with any of the available coding schemes. scheme. If no -gnatW?
parameter is present, then the default representation is Brackets
encoding only. Note that the wide character representation that is
specified (explicitly or by default) for the main program also acts as
the default encoding used for Wide_Text_IO files if not specifically
overridden by a WCEM form parameter. 

Paul Storm



^ permalink raw reply	[relevance 6%]

* Re: Hebrew language character set
  2001-04-04 21:36  6%   ` Paul Storm
  2001-04-05  3:03  0%     ` David Starner
  2001-04-05  6:42  0%     ` Ehud Lamm
@ 2001-04-05 13:11  0%     ` Jean-Marc Bourguet
    2 siblings, 1 reply; 45+ results
From: Jean-Marc Bourguet @ 2001-04-05 13:11 UTC (permalink / raw)


Paul Storm wrote:
> 
> For those that are interested, I produce code that (I think) produces
> a Hebrew character.  Here is the code:
> 
> with Ada.Characters.Handling; use Ada.Characters.Handling;
> with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
> 
> procedure aleph is
> begin
>   Ada.Wide_Text_IO.Put (Item => Wide_Character'Val(1488));
> end aleph;
> 
> end of code
> 
> Here is the output.
> 
> ["05D0"]
> 
> end of output
> 
> 1448 decimal is 05D0 hexidecimal.
> 
> I said think produces.  I am thinking that my display showed the
> character as a code due to the lack of support for that character
> (set) on my system.  Can anyone confirm this for me?  Does that make
> sense?

I think this is one of the way gnat produces (and accept) wide
character.  You should be able to choose the format you want with the
FORM parameter.  Check the reference manual, there is a whole section on
wide characters.

-- Jean-Marc



^ permalink raw reply	[relevance 0%]

* Re: Hebrew language character set
  2001-04-04 21:36  6%   ` Paul Storm
  2001-04-05  3:03  0%     ` David Starner
@ 2001-04-05  6:42  0%     ` Ehud Lamm
  2001-04-05 13:11  0%     ` Jean-Marc Bourguet
  2 siblings, 0 replies; 45+ results
From: Ehud Lamm @ 2001-04-05  6:42 UTC (permalink / raw)


Paul Storm <paul.a.storm@lmco.com> wrote in message
news:3ACB85DF.9E6DBD03@lmco.com...
> For those that are interested, I produce code that (I think) produces
> a Hebrew character.  Here is the code:
>
> with Ada.Characters.Handling; use Ada.Characters.Handling;
> with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
>
> procedure aleph is
> begin
>   Ada.Wide_Text_IO.Put (Item => Wide_Character'Val(1488));
> end aleph;
>
> end of code
>
> Here is the output.
>
> ["05D0"]
>
> end of output
>

That's the output I get (the string literal, not the Hebrew echaracter) on
my PC, which has Hebrew support, Hebre enable windows etc. (I am in Israel).


Ehud





^ permalink raw reply	[relevance 0%]

* Re: Hebrew language character set
  2001-04-04 21:36  6%   ` Paul Storm
@ 2001-04-05  3:03  0%     ` David Starner
  2001-04-05  6:42  0%     ` Ehud Lamm
  2001-04-05 13:11  0%     ` Jean-Marc Bourguet
  2 siblings, 0 replies; 45+ results
From: David Starner @ 2001-04-05  3:03 UTC (permalink / raw)


On Wed, 04 Apr 2001 13:36:47 -0800, Paul Storm <paul.a.storm@lmco.com> wrote:
>For those that are interested, I produce code that (I think) produces
>a Hebrew character.  Here is the code:
>
>with Ada.Characters.Handling; use Ada.Characters.Handling;
>with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;
>
>procedure aleph is
>begin
>  Ada.Wide_Text_IO.Put (Item => Wide_Character'Val(1488));
>end aleph;
>
>end of code
>
>Here is the output.
>
>["05D0"]
>
>end of output
>
>1448 decimal is 05D0 hexidecimal.
>
>I said think produces.  I am thinking that my display showed the
>character as a code due to the lack of support for that character
>(set) on my system.  Can anyone confirm this for me?  Does that make
>sense?

Nope. It looks like your Ada system uses a ["abcd"] encoding by
default, since it has no way to know what the correct encoding
should be. If you're using GNAT, the GNAT RM has a section about
wide text IO and changing it to output in different encodings.
If you have a recent version (>4.0) of XFree86, you can run 
xterm -u8 which will properly understand UTF-8; otherwise, there's
probably no way to get readable Hebrew output.

-- 
David Starner - dstarner98@aasaa.ofe.org
Pointless website: http://dvdeug.dhis.org
"I don't care if Bill personally has my name and reads my email and 
laughs at me. In fact, I'd be rather honored." - Joseph_Greg



^ permalink raw reply	[relevance 0%]

* Re: Hebrew language character set
  @ 2001-04-04 21:36  6%   ` Paul Storm
  2001-04-05  3:03  0%     ` David Starner
                       ` (2 more replies)
  0 siblings, 3 replies; 45+ results
From: Paul Storm @ 2001-04-04 21:36 UTC (permalink / raw)


For those that are interested, I produce code that (I think) produces
a Hebrew character.  Here is the code:

with Ada.Characters.Handling; use Ada.Characters.Handling;
with Ada.Wide_Text_IO; use Ada.Wide_Text_IO;

procedure aleph is
begin
  Ada.Wide_Text_IO.Put (Item => Wide_Character'Val(1488));
end aleph;

end of code

Here is the output.

["05D0"]

end of output

1448 decimal is 05D0 hexidecimal.

I said think produces.  I am thinking that my display showed the
character as a code due to the lack of support for that character
(set) on my system.  Can anyone confirm this for me?  Does that make
sense?



^ permalink raw reply	[relevance 6%]

* Re: Wide_String, Chinese & Japanese text files
  1999-08-20  0:00  3% Wide_String, Chinese & Japanese text files Thierry Lelegard
@ 1999-08-21  0:00  0% ` Robert Dewar
  0 siblings, 0 replies; 45+ results
From: Robert Dewar @ 1999-08-21  0:00 UTC (permalink / raw)


In article <7pka2j$lnn$1@front2.grolier.fr>,
  "Thierry Lelegard" <lelegard@club-internet.fr> wrote:
> We are going to need to process, in Ada 95, text files
> containing Chinese and Japanese messages (for i18n purpose).
> I have absolutely no experience in handling this kind of
files.
> I do not even know the usual format of that kind of text
> files (8 or 16 bits/char).

There is no "usual format", there are many possible formats.
GNAT supports:

    Upper half coding (sometimes used for chinese, never as
    far as I know for japanese)

    Shift JIS coding (a common Japanese convention)

    EUC coding (another common Japanese convention)

    UTF-8 coding (an ISO standard, never seen it used in
    practice, but probably is, and will be more over time?)

    Brackets coding (a portable ASCII coding, primarily useful
    for standard texts, e.g. the ACVC tests, not used for real
    data information interchange).

    ESC coding (another very simple ASCII portable coding, using
    an ESC character instead of brackets, again, not used for
    real data information interchange.

> Due to the amount of possible combinations, I assume
> that at least some these languages require 16 bits per
> character.

You really need to familiarize yourself with the relevant
ISO standard, and with Unicode, yes, of course 16-bits
are required (in fact for full Chinese support, 32-bits
are required, Unicode supports only a subset of Chinese).

> So, before appointing people to write the messages, I
> have one request and one question.
>
> 1) Could anyone e-mail me a text file containing a
> typical example of 16 bits characters Chinese or
> Japanese text file, preferably from both UNIX
> Windows worlds if there are some incompatibilities
> such as the traditional LF vs CR/LF ?

No such thing, you really must find out the source encoding,
since there are multiple possibilities.

> 2) How could I handle this in Ada? I naively though
> that Ada.Wide_Text_IO would read 16 bits per character.
> However (at least with gnat), it writes and read 8 bits
> characters with "bracket coding" (as in Wide_String
> literals). Of course, Sequential_IO on Wide_Character
> or some kind of Stream_IO could do the trick but I
> wonder if there some "standard" or at least "usual"
> way to deal with this.

You really need to know much more than you do to be successful
here. I strongly suggest you contact your vendor for assistance.
In the case of GNAT, especially for a Japanese environment we
can give a lot of help to GNAT Professional users, since our
Japanese Distributor (Jun Shimura) has extensive technical
experience in this area (in fact we worked closely with him
to ensure that our implementations of Shift-JIS and EUC were
correct).

If your compiler supports only the brackets encoding standard,
it is probably useless for your purposes, and you should look
around for a compiler that supports the format in which your
messages will be processed.

> I must precise that we do not need to handle 16 bits
> Ada source files, simply text files containing messages.
> We already have the combined String/Wide_String support
> in our applications, we simply need to choose the best
> way to get the data from a file to a Wide_String. Then,
> the Wide_Strings will be sent in SNMP messages.

Robert Dewar
Ada Core Technologies


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.




^ permalink raw reply	[relevance 0%]

* Wide_String, Chinese & Japanese text files
@ 1999-08-20  0:00  3% Thierry Lelegard
  1999-08-21  0:00  0% ` Robert Dewar
  0 siblings, 1 reply; 45+ results
From: Thierry Lelegard @ 1999-08-20  0:00 UTC (permalink / raw)


Hello,

We are going to need to process, in Ada 95, text files
containing Chinese and Japanese messages (for i18n purpose).
I have absolutely no experience in handling this kind of files.
I do not even know the usual format of that kind of text
files (8 or 16 bits/char).

Due to the amount of possible combinations, I assume
that at least some these languages require 16 bits per
character.

So, before appointing people to write the messages, I
have one request and one question.

1) Could anyone e-mail me a text file containing a
typical example of 16 bits characters Chinese or
Japanese text file, preferably from both UNIX
Windows worlds if there are some incompatibilities
such as the traditional LF vs CR/LF ?

2) How could I handle this in Ada? I naively though
that Ada.Wide_Text_IO would read 16 bits per character.
However (at least with gnat), it writes and read 8 bits
characters with "bracket coding" (as in Wide_String
literals). Of course, Sequential_IO on Wide_Character
or some kind of Stream_IO could do the trick but I
wonder if there some "standard" or at least "usual"
way to deal with this.

I must precise that we do not need to handle 16 bits
Ada source files, simply text files containing messages.
We already have the combined String/Wide_String support
in our applications, we simply need to choose the best
way to get the data from a file to a Wide_String. Then,
the Wide_Strings will be sent in SNMP messages.

Thank you all in advance.

-Thierry
________________________________________________________
Thierry Lelegard, Paris, France
E-mail: lelegard@club-internet.fr






^ permalink raw reply	[relevance 3%]

Results 1-45 of 45 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
1999-08-20  0:00  3% Wide_String, Chinese & Japanese text files Thierry Lelegard
1999-08-21  0:00  0% ` Robert Dewar
2001-04-03 19:08     Hebrew language character set Paul Storm
2001-04-04 17:35     ` David Botton
2001-04-04 21:36  6%   ` Paul Storm
2001-04-05  3:03  0%     ` David Starner
2001-04-05  6:42  0%     ` Ehud Lamm
2001-04-05 13:11  0%     ` Jean-Marc Bourguet
2001-04-05 16:56           ` Paul Storm
2001-04-05 16:41             ` Florian Weimer
2001-04-05 18:41  6%           ` Paul Storm
2001-08-05 22:18     implementation question about writing and reading from files Francis Crick
2001-08-05 22:43     ` tmoran
2001-08-09 23:19       ` Francis Crick
2001-08-10 14:49  4%     ` Ted Dennison
2001-08-10 15:44  0%       ` Warren W. Gay VE3WWG
2001-09-25 16:04     Text_IO on WinNT problem Alfred Hilscher
2001-09-25 16:13     ` Lutz Donnerhacke
2001-09-25 18:07  4%   ` David Botton
2002-08-03  4:27  6% Redirecting Standard Error John M. Resler
2002-08-05 15:41  5% ` Stephen Leake
2003-04-14 21:39     Interfacing Ada with C Paul Anderson
2003-04-16  2:56     ` Steve
2003-04-16  4:25  5%   ` Steve
2003-11-28 11:12  6% Where is my ASIS mistake? Xela
2003-11-29 12:10  0% ` Alex Xela
2005-11-23 17:36     Filenames in Ada Martin Krischik
2005-11-23 22:18     ` Randy Brukardt
2005-11-24  3:21  4%   ` Silly question about strings (was: Filenames in Ada) Steve
2005-11-24  4:58  0%     ` Larry Kilgallen
2007-04-23 21:29  5% Wide Character Problem in Ada.Numerics david.smith
2007-04-24 17:54  0% ` Pascal Obry
2007-10-21 19:15     Range types Christos Chryssochoidis
2007-10-21 20:23     ` Niklas Holsti
2007-10-21 21:28       ` Christos Chryssochoidis
2007-10-22  7:23         ` Jacob Sparre Andersen
2007-10-22 11:14           ` Christos Chryssochoidis
2007-10-23 23:52  4%         ` anon
2007-10-24 12:57  0%           ` Christos Chryssochoidis
2009-05-28 18:26     Ada extension information info
2009-05-30  7:13  6% ` anon
2009-05-30 10:13  0%   ` info
2009-07-14 18:09     gtksourceview for gtkada jpablo
2009-07-14 19:29  4% ` Vadim Godunko
2009-07-16 14:47  0%   ` jpablo
2010-01-02 14:44     Asis.Ada_Environments.Associate (..., Parameters => ...); Hibou57 (Yannick Duchêne)
2010-01-03  8:19     ` Stephen Leake
2010-01-03 17:06  4%   ` Hibou57 (Yannick Duchêne)
2010-05-07  1:02  5% Why is not Stream_Access defined Ada.Streams ? Yannick Duchêne (Hibou57)
2010-05-07  2:24  0% ` Randy Brukardt
2010-11-17  4:44  3% Encapsulating Ada.Direct_IO Bryan
2010-11-17  5:20  0% ` Adam Beneschan
2010-12-03 20:25  5% Semantics of 'Image and 'Wide_Image on wide enumerations Michael R
2010-12-03 20:56  0% ` Adam Beneschan
2010-12-03 21:15  6%   ` Michael R
2010-12-03 21:17  0%   ` Adam Beneschan
2014-01-05 23:55  6% Q: Localizing type and package references b.mcguinness747
2014-01-06  1:29  0% ` Jeffrey Carter
2014-01-06  8:05  0%   ` Simon Wright
2015-03-24 19:19     GNAT bug in the GNAT GPL 2014 compiler? gorgelo
2015-03-24 21:56     ` Anh Vo
2015-03-25  7:35  4%   ` gorgelo
2015-03-25  8:39  0%     ` Simon Wright
2015-03-25  8:41  0%     ` Georg Bauhaus
2017-07-20  0:06     Musing on defining attributes and the ability to define an "abstract type X"-interface Shark8
2017-07-20  7:52     ` Dmitry A. Kazakov
2017-07-20 16:37       ` Shark8
2017-07-20 17:40  3%     ` Dmitry A. Kazakov
2017-12-27 18:08     unicode and wide_text_io Mehdi Saada
2017-12-27 22:32     ` Mehdi Saada
2017-12-27 22:33       ` Mehdi Saada
2017-12-27 22:48         ` Mehdi Saada
2017-12-27 23:32  7%       ` Mehdi Saada
2017-12-28 13:15     ` Mehdi Saada
2017-12-28 14:25       ` Dmitry A. Kazakov
2017-12-28 14:32         ` Simon Wright
2017-12-28 15:28           ` Niklas Holsti
2017-12-28 15:47             ` 00120260b
2017-12-28 22:35  5%           ` G.B.
2020-02-27 22:54  6% Have I found an error in the index of the ARM? mgr
2023-08-27  5:18     [Ann] WinRt - version 3 AlexG
2023-09-03  9:07  5% ` AlexG

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