]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - Ada95/src/terminal_interface-curses-forms-field_types.adb
ncurses 5.9 - patch 20130824
[ncurses.git] / Ada95 / src / terminal_interface-curses-forms-field_types.adb
index e003058b0ede8aa6fb5250fa24cc2205a1f48249..5195a20a499c32e8312baba36b6970b07a26bfa3 100644 (file)
@@ -7,7 +7,7 @@
 --                                 B O D Y                                  --
 --                                                                          --
 ------------------------------------------------------------------------------
--- Copyright (c) 1998 Free Software Foundation, Inc.                        --
+-- Copyright (c) 1998-2009,2011 Free Software Foundation, Inc.              --
 --                                                                          --
 -- Permission is hereby granted, free of charge, to any person obtaining a  --
 -- copy of this software and associated documentation files (the            --
 ------------------------------------------------------------------------------
 --  Author:  Juergen Pfeifer, 1996
 --  Version Control:
---  $Revision: 1.14 $
+--  $Revision: 1.25 $
+--  $Date: 2011/03/22 23:22:27 $
 --  Binding Version 01.00
 ------------------------------------------------------------------------------
-with Interfaces.C;
 with Terminal_Interface.Curses.Aux; use Terminal_Interface.Curses.Aux;
 with Ada.Unchecked_Deallocation;
-with Ada.Unchecked_Conversion;
+with System.Address_To_Access_Conversions;
+
 --  |
 --  |=====================================================================
 --  | man page form_fieldtype.3x
@@ -49,11 +50,10 @@ with Ada.Unchecked_Conversion;
 --  |
 package body Terminal_Interface.Curses.Forms.Field_Types is
 
-   use type Interfaces.C.int;
    use type System.Address;
 
-   function To_Argument_Access is new Ada.Unchecked_Conversion
-     (System.Address, Argument_Access);
+   package Argument_Conversions is
+      new System.Address_To_Access_Conversions (Argument);
 
    function Get_Fieldtype (F : Field) return C_Field_Type;
    pragma Import (C, Get_Fieldtype, "field_type");
@@ -67,7 +67,7 @@ package body Terminal_Interface.Curses.Forms.Field_Types is
    --  |
    --  |
    --  |
-   function Get_Type (Fld : in Field) return Field_Type_Access
+   function Get_Type (Fld : Field) return Field_Type_Access
    is
       Low_Level : constant C_Field_Type := Get_Fieldtype (Fld);
       Arg : Argument_Access;
@@ -79,11 +79,12 @@ package body Terminal_Interface.Curses.Forms.Field_Types is
            Low_Level = M_Generic_Type or else
            Low_Level = M_Choice_Router or else
            Low_Level = M_Generic_Choice then
-            Arg := To_Argument_Access (Get_Arg (Fld));
+            Arg := Argument_Access
+         (Argument_Conversions.To_Pointer (Get_Arg (Fld)));
             if Arg = null then
                raise Form_Exception;
             else
-               return Arg.Typ;
+               return Arg.all.Typ;
             end if;
          else
             raise Form_Exception;
@@ -91,67 +92,49 @@ package body Terminal_Interface.Curses.Forms.Field_Types is
       end if;
    end Get_Type;
 
-   function Make_Arg (Args : System.Address) return System.Address
-   is
-      --  Actually args is a double indirected pointer to the arguments
-      --  of a C variable argument list. In theory it is now quite
-      --  complicated to write portable routine that reads the arguments,
-      --  because one has to know the growth direction of the stack and
-      --  the sizes of the individual arguments.
-      --  Fortunately we are only interested in the first argument (#0),
-      --  we know its size and for the first arg we don't care about
-      --  into which stack direction we have to proceed. We simply
-      --  resolve the double indirection and thats it.
-      type V is access all System.Address;
-      function To_Access is new Ada.Unchecked_Conversion (System.Address,
-                                                          V);
-   begin
-      return To_Access (To_Access (Args).all).all;
-   end Make_Arg;
-
    function Copy_Arg (Usr : System.Address) return System.Address
    is
    begin
       return Usr;
    end Copy_Arg;
 
-   procedure Free_Arg (Usr : in System.Address)
+   procedure Free_Arg (Usr : System.Address)
    is
       procedure Free_Type is new Ada.Unchecked_Deallocation
         (Field_Type'Class, Field_Type_Access);
       procedure Freeargs is new Ada.Unchecked_Deallocation
         (Argument, Argument_Access);
 
-      To_Be_Free : Argument_Access := To_Argument_Access (Usr);
+      To_Be_Free : Argument_Access
+   := Argument_Access (Argument_Conversions.To_Pointer (Usr));
       Low_Level  : C_Field_Type;
    begin
       if To_Be_Free /= null then
-         if To_Be_Free.Usr /= System.Null_Address then
-            Low_Level := To_Be_Free.Cft;
-            if Low_Level.Freearg /= null then
-               Low_Level.Freearg (To_Be_Free.Usr);
+         if To_Be_Free.all.Usr /= System.Null_Address then
+            Low_Level := To_Be_Free.all.Cft;
+            if Low_Level.all.Freearg /= null then
+               Low_Level.all.Freearg (To_Be_Free.all.Usr);
             end if;
          end if;
-         if To_Be_Free.Typ /= null then
-            Free_Type (To_Be_Free.Typ);
+         if To_Be_Free.all.Typ /= null then
+            Free_Type (To_Be_Free.all.Typ);
          end if;
          Freeargs (To_Be_Free);
       end if;
    end Free_Arg;
 
-
    procedure Wrap_Builtin (Fld : Field;
                            Typ : Field_Type'Class;
                            Cft : C_Field_Type := C_Builtin_Router)
    is
-      Usr_Arg   : System.Address := Get_Arg (Fld);
+      Usr_Arg   : constant System.Address := Get_Arg (Fld);
       Low_Level : constant C_Field_Type := Get_Fieldtype (Fld);
       Arg : Argument_Access;
       Res : Eti_Error;
       function Set_Fld_Type (F    : Field := Fld;
                              Cf   : C_Field_Type := Cft;
                              Arg1 : Argument_Access) return C_Int;
-      pragma Import (C, Set_Fld_Type, "set_field_type");
+      pragma Import (C, Set_Fld_Type, "set_field_type_user");
 
    begin
       pragma Assert (Low_Level /= Null_Field_Type);
@@ -162,10 +145,10 @@ package body Terminal_Interface.Curses.Forms.Field_Types is
                               Typ => new Field_Type'Class'(Typ),
                               Cft => Get_Fieldtype (Fld));
          if Usr_Arg /= System.Null_Address then
-            if Low_Level.Copyarg /= null then
-               Arg.Usr := Low_Level.Copyarg (Usr_Arg);
+            if Low_Level.all.Copyarg /= null then
+               Arg.all.Usr := Low_Level.all.Copyarg (Usr_Arg);
             else
-               Arg.Usr := Usr_Arg;
+               Arg.all.Usr := Usr_Arg;
             end if;
          end if;
 
@@ -177,56 +160,60 @@ package body Terminal_Interface.Curses.Forms.Field_Types is
    end Wrap_Builtin;
 
    function Field_Check_Router (Fld : Field;
-                                Usr : System.Address) return C_Int
+                                Usr : System.Address) return Curses_Bool
    is
-      Arg  : constant Argument_Access := To_Argument_Access (Usr);
+      Arg  : constant Argument_Access
+   := Argument_Access (Argument_Conversions.To_Pointer (Usr));
    begin
-      pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type
-                     and then Arg.Typ /= null);
-      if Arg.Cft.Fcheck /= null then
-         return Arg.Cft.Fcheck (Fld, Arg.Usr);
+      pragma Assert (Arg /= null and then Arg.all.Cft /= Null_Field_Type
+                     and then Arg.all.Typ /= null);
+      if Arg.all.Cft.all.Fcheck /= null then
+         return Arg.all.Cft.all.Fcheck (Fld, Arg.all.Usr);
       else
          return 1;
       end if;
    end Field_Check_Router;
 
    function Char_Check_Router (Ch  : C_Int;
-                               Usr : System.Address) return C_Int
+                               Usr : System.Address) return Curses_Bool
    is
-      Arg  : constant Argument_Access := To_Argument_Access (Usr);
+      Arg  : constant Argument_Access
+   := Argument_Access (Argument_Conversions.To_Pointer (Usr));
    begin
-      pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type
-                     and then Arg.Typ /= null);
-      if Arg.Cft.Ccheck /= null then
-         return Arg.Cft.Ccheck (Ch, Arg.Usr);
+      pragma Assert (Arg /= null and then Arg.all.Cft /= Null_Field_Type
+                     and then Arg.all.Typ /= null);
+      if Arg.all.Cft.all.Ccheck /= null then
+         return Arg.all.Cft.all.Ccheck (Ch, Arg.all.Usr);
       else
          return 1;
       end if;
    end Char_Check_Router;
 
    function Next_Router (Fld : Field;
-                         Usr : System.Address) return C_Int
+                         Usr : System.Address) return Curses_Bool
    is
-      Arg  : constant Argument_Access := To_Argument_Access (Usr);
+      Arg  : constant Argument_Access
+   := Argument_Access (Argument_Conversions.To_Pointer (Usr));
    begin
-      pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type
-                     and then Arg.Typ /= null);
-      if Arg.Cft.Next /= null then
-         return Arg.Cft.Next (Fld, Arg.Usr);
+      pragma Assert (Arg /= null and then Arg.all.Cft /= Null_Field_Type
+                     and then Arg.all.Typ /= null);
+      if Arg.all.Cft.all.Next /= null then
+         return Arg.all.Cft.all.Next (Fld, Arg.all.Usr);
       else
          return 1;
       end if;
    end Next_Router;
 
    function Prev_Router (Fld : Field;
-                         Usr : System.Address) return C_Int
+                         Usr : System.Address) return Curses_Bool
    is
-      Arg  : constant Argument_Access := To_Argument_Access (Usr);
+      Arg  : constant Argument_Access :=
+               Argument_Access (Argument_Conversions.To_Pointer (Usr));
    begin
-      pragma Assert (Arg /= null and then Arg.Cft /= Null_Field_Type
-                     and then Arg.Typ /= null);
-      if Arg.Cft.Prev /= null then
-         return Arg.Cft.Prev (Fld, Arg.Usr);
+      pragma Assert (Arg /= null and then Arg.all.Cft /= Null_Field_Type
+                     and then Arg.all.Typ /= null);
+      if Arg.all.Cft.all.Prev /= null then
+         return Arg.all.Cft.all.Prev (Fld, Arg.all.Usr);
       else
          return 1;
       end if;