------------------------------------------------------------------------------
--                                                                          --
--                    Copyright (C) 2015, AdaCore                           --
--                                                                          --
--  Redistribution and use in source and binary forms, with or without      --
--  modification, are permitted provided that the following conditions are  --
--  met:                                                                    --
--     1. Redistributions of source code must retain the above copyright    --
--        notice, this list of conditions and the following disclaimer.     --
--     2. Redistributions in binary form must reproduce the above copyright --
--        notice, this list of conditions and the following disclaimer in   --
--        the documentation and/or other materials provided with the        --
--        distribution.                                                     --
--     3. Neither the name of STMicroelectronics nor the names of its       --
--        contributors may be used to endorse or promote products derived   --
--        from this software without specific prior written permission.     --
--                                                                          --
--   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    --
--   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      --
--   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  --
--   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   --
--   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
--   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       --
--   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  --
--   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  --
--   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    --
--   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  --
--   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   --
--                                                                          --
------------------------------------------------------------------------------

--  This file provides type definitions for the STM32F4 (ARM Cortex M4F)
--  microcontrollers from ST Microelectronics.

with Interfaces;
with System.Storage_Elements;
use System;
use type System.Storage_Elements.Storage_Offset;

package STM32F4 is

   type Word      is new Interfaces.Unsigned_32;  -- for shift/rotate
   type Half_Word is new Interfaces.Unsigned_16;  -- for shift/rotate
   type Byte      is new Interfaces.Unsigned_8;   -- for shift/rotate

   type Bits_1  is mod 2**1  with Size => 1;
   type Bits_2  is mod 2**2  with Size => 2;
   type Bits_3  is mod 2**3  with Size => 3;
   type Bits_4  is mod 2**4  with Size => 4;
   type Bits_5  is mod 2**5  with Size => 5;
   type Bits_6  is mod 2**6  with Size => 6;
   type Bits_7  is mod 2**7  with Size => 7;
   type Bits_8  is mod 2**8  with Size => 8;
   type Bits_9  is mod 2**9  with Size => 9;
   type Bits_10 is mod 2**10 with Size => 10;
   type Bits_11 is mod 2**11 with Size => 11;
   type Bits_12 is mod 2**12 with Size => 12;
   type Bits_13 is mod 2**13 with Size => 13;
   type Bits_14 is mod 2**14 with Size => 14;
   type Bits_15 is mod 2**15 with Size => 15;
   type Bits_16 is mod 2**16 with Size => 16;
   type Bits_17 is mod 2**17 with Size => 17;
   type Bits_18 is mod 2**18 with Size => 18;
   type Bits_19 is mod 2**19 with Size => 19;
   type Bits_20 is mod 2**20 with Size => 20;
   type Bits_21 is mod 2**21 with Size => 21;
   type Bits_22 is mod 2**22 with Size => 22;
   type Bits_23 is mod 2**23 with Size => 23;
   type Bits_24 is mod 2**24 with Size => 24;
   type Bits_25 is mod 2**25 with Size => 25;
   type Bits_26 is mod 2**26 with Size => 26;
   type Bits_27 is mod 2**27 with Size => 27;
   type Bits_28 is mod 2**28 with Size => 28;
   type Bits_29 is mod 2**29 with Size => 29;
   type Bits_30 is mod 2**30 with Size => 30;

   type Bits_32x1 is array (0 .. 31) of Bits_1 with Size => 32;
   type Bits_16x2 is array (0 .. 15) of Bits_2 with Size => 32;
   type Bits_8x4  is array (0 ..  7) of Bits_4 with Size => 32;

   --  Define address bases for the various system components

   Peripheral_Base : constant Address := System'To_Address (16#4000_0000#);

   APB1_Peripheral_Base : constant Address := Peripheral_Base;
   APB2_Peripheral_Base : constant Address := Peripheral_Base + 16#0001_0000#;
   AHB1_Peripheral_Base : constant Address := Peripheral_Base + 16#0002_0000#;
   AHB2_Peripheral_Base : constant Address := Peripheral_Base + 16#1000_0000#;

   GPIOA_Base : constant Address := AHB1_Peripheral_Base + 16#0000#;
   GPIOB_Base : constant Address := AHB1_Peripheral_Base + 16#0400#;
   GPIOC_Base : constant Address := AHB1_Peripheral_Base + 16#0800#;
   GPIOD_Base : constant Address := AHB1_Peripheral_Base + 16#0C00#;
   GPIOE_Base : constant Address := AHB1_Peripheral_Base + 16#1000#;
   GPIOF_Base : constant Address := AHB1_Peripheral_Base + 16#1400#;
   GPIOG_Base : constant Address := AHB1_Peripheral_Base + 16#1800#;
   GPIOH_Base : constant Address := AHB1_Peripheral_Base + 16#1C00#;
   GPIOI_Base : constant Address := AHB1_Peripheral_Base + 16#2000#;
   GPIOJ_Base : constant Address := AHB1_Peripheral_Base + 16#2400#;
   GPIOK_Base : constant Address := AHB1_Peripheral_Base + 16#2800#;

   RCC_Base     : constant Address := AHB1_Peripheral_Base + 16#3800#;
   FLASH_Base   : constant Address := AHB1_Peripheral_Base + 16#3C00#;
   DMA1_Base    : constant Address := AHB1_Peripheral_Base + 16#6000#;
   DMA2_Base    : constant Address := AHB1_Peripheral_Base + 16#6400#;
   ETH_Base     : constant Address := AHB1_Peripheral_Base + 16#8000#;
   ETH_MAC_Base : constant Address := ETH_Base;
   ETH_MMC_Base : constant Address := ETH_Base + 16#0100#;
   ETH_PTP_Base : constant Address := ETH_Base + 16#0700#;
   ETH_DMA_Base : constant Address := ETH_Base + 16#1000#;
   DMA2D_BASE   : constant Address := AHB1_Peripheral_Base + 16#B000#;

   RNG_BASE     : constant Address := AHB2_Peripheral_Base + 16#6_0800#;

   TIM2_Base    : constant Address := APB1_Peripheral_Base + 16#0000#;
   TIM3_Base    : constant Address := APB1_Peripheral_Base + 16#0400#;
   TIM4_Base    : constant Address := APB1_Peripheral_Base + 16#0800#;
   TIM5_Base    : constant Address := APB1_Peripheral_Base + 16#0C00#;
   TIM6_Base    : constant Address := APB1_Peripheral_Base + 16#1000#;
   TIM7_Base    : constant Address := APB1_Peripheral_Base + 16#1400#;
   TIM12_Base   : constant Address := APB1_Peripheral_Base + 16#1800#;
   TIM13_Base   : constant Address := APB1_Peripheral_Base + 16#1C00#;
   TIM14_Base   : constant Address := APB1_Peripheral_Base + 16#2000#;
   RTC_Base     : constant Address := APB1_Peripheral_Base + 16#2800#;
   WWDG_Base    : constant Address := APB1_Peripheral_Base + 16#2C00#;
   IWDG_Base    : constant Address := APB1_Peripheral_Base + 16#3000#;
   I2S2ext_Base : constant Address := APB1_Peripheral_Base + 16#3400#;
   SPI2_Base    : constant Address := APB1_Peripheral_Base + 16#3800#;
   SPI3_Base    : constant Address := APB1_Peripheral_Base + 16#3C00#;
   I2S3ext_Base : constant Address := APB1_Peripheral_Base + 16#4000#;
   USART2_Base  : constant Address := APB1_Peripheral_Base + 16#4400#;
   USART3_Base  : constant Address := APB1_Peripheral_Base + 16#4800#;
   UART4_Base   : constant Address := APB1_Peripheral_Base + 16#4C00#;
   UART5_Base   : constant Address := APB1_Peripheral_Base + 16#5000#;
   I2C1_Base    : constant Address := APB1_Peripheral_Base + 16#5400#;
   I2C2_Base    : constant Address := APB1_Peripheral_Base + 16#5800#;
   I2C3_Base    : constant Address := APB1_Peripheral_Base + 16#5C00#;
   CAN1_Base    : constant Address := APB1_Peripheral_Base + 16#6400#;
   CAN2_Base    : constant Address := APB1_Peripheral_Base + 16#6800#;
   PWR_Base     : constant Address := APB1_Peripheral_Base + 16#7000#;
   DAC_Base     : constant Address := APB1_Peripheral_Base + 16#7400#;
   UART7_BASE   : constant Address := APB1_Peripheral_Base + 16#7800#;
   UART8_BASE   : constant Address := APB1_Peripheral_Base + 16#7C00#;

   TIM1_Base   : constant Address := APB2_Peripheral_Base + 16#0000#;
   TIM8_Base   : constant Address := APB2_Peripheral_Base + 16#0400#;
   USART1_Base : constant Address := APB2_Peripheral_Base + 16#1000#;
   USART6_Base : constant Address := APB2_Peripheral_Base + 16#1400#;
   ADC1_Base   : constant Address := APB2_Peripheral_Base + 16#2000#;
   ADC2_Base   : constant Address := APB2_Peripheral_Base + 16#2100#;
   ADC3_Base   : constant Address := APB2_Peripheral_Base + 16#2200#;
   ADC_Base    : constant Address := APB2_Peripheral_Base + 16#2300#;
   SDIO_Base   : constant Address := APB2_Peripheral_Base + 16#2C00#;
   SPI1_Base   : constant Address := APB2_Peripheral_Base + 16#3000#;
   SPI4_BASE   : constant Address := APB2_Peripheral_Base + 16#3400#;
   SYSCFG_Base : constant Address := APB2_Peripheral_Base + 16#3800#;
   EXTI_Base   : constant Address := APB2_Peripheral_Base + 16#3C00#;
   TIM9_Base   : constant Address := APB2_Peripheral_Base + 16#4000#;
   TIM10_Base  : constant Address := APB2_Peripheral_Base + 16#4400#;
   TIM11_Base  : constant Address := APB2_Peripheral_Base + 16#4800#;
   SPI5_BASE   : constant Address := APB2_Peripheral_Base + 16#5000#;
   SPI6_BASE   : constant Address := APB2_Peripheral_Base + 16#5400#;
   SAI1_BASE   : constant Address := APB2_Peripheral_Base + 16#5800#;
   LTDC_BASE   : constant Address := APB2_Peripheral_Base + 16#6800#;

end STM32F4;

------------------------------------------------------------------------------
--                                                                          --
--                    Copyright (C) 2015, AdaCore                           --
--                                                                          --
--  Redistribution and use in source and binary forms, with or without      --
--  modification, are permitted provided that the following conditions are  --
--  met:                                                                    --
--     1. Redistributions of source code must retain the above copyright    --
--        notice, this list of conditions and the following disclaimer.     --
--     2. Redistributions in binary form must reproduce the above copyright --
--        notice, this list of conditions and the following disclaimer in   --
--        the documentation and/or other materials provided with the        --
--        distribution.                                                     --
--     3. Neither the name of STMicroelectronics nor the names of its       --
--        contributors may be used to endorse or promote products derived   --
--        from this software without specific prior written permission.     --
--                                                                          --
--   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    --
--   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      --
--   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  --
--   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   --
--   HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, --
--   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       --
--   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  --
--   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  --
--   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    --
--   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  --
--   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   --
--                                                                          --
------------------------------------------------------------------------------

--  This file provides type definitions for the STM32F4 (ARM Cortex M4F)
--  microcontrollers from ST Microelectronics.

with Interfaces;
with System.Storage_Elements;
use System;
use type System.Storage_Elements.Storage_Offset;

package STM32F4 is

   type Word      is new Interfaces.Unsigned_32;  -- for shift/rotate
   type Half_Word is new Interfaces.Unsigned_16;  -- for shift/rotate
   type Byte      is new Interfaces.Unsigned_8;   -- for shift/rotate

   type Bits_1  is mod 2**1  with Size => 1;
   type Bits_2  is mod 2**2  with Size => 2;
   type Bits_3  is mod 2**3  with Size => 3;
   type Bits_4  is mod 2**4  with Size => 4;
   type Bits_5  is mod 2**5  with Size => 5;
   type Bits_6  is mod 2**6  with Size => 6;
   type Bits_7  is mod 2**7  with Size => 7;
   type Bits_8  is mod 2**8  with Size => 8;
   type Bits_9  is mod 2**9  with Size => 9;
   type Bits_10 is mod 2**10 with Size => 10;
   type Bits_11 is mod 2**11 with Size => 11;
   type Bits_12 is mod 2**12 with Size => 12;
   type Bits_13 is mod 2**13 with Size => 13;
   type Bits_14 is mod 2**14 with Size => 14;
   type Bits_15 is mod 2**15 with Size => 15;
   type Bits_16 is mod 2**16 with Size => 16;
   type Bits_17 is mod 2**17 with Size => 17;
   type Bits_18 is mod 2**18 with Size => 18;
   type Bits_19 is mod 2**19 with Size => 19;
   type Bits_20 is mod 2**20 with Size => 20;
   type Bits_21 is mod 2**21 with Size => 21;
   type Bits_22 is mod 2**22 with Size => 22;
   type Bits_23 is mod 2**23 with Size => 23;
   type Bits_24 is mod 2**24 with Size => 24;
   type Bits_25 is mod 2**25 with Size => 25;
   type Bits_26 is mod 2**26 with Size => 26;
   type Bits_27 is mod 2**27 with Size => 27;
   type Bits_28 is mod 2**28 with Size => 28;
   type Bits_29 is mod 2**29 with Size => 29;
   type Bits_30 is mod 2**30 with Size => 30;

   type Bits_32x1 is array (0 .. 31) of Bits_1 with Pack, Size => 32;
   type Bits_16x2 is array (0 .. 15) of Bits_2 with Pack, Size => 32;
   type Bits_8x4  is array (0 ..  7) of Bits_4 with Pack, Size => 32;

   --  Define address bases for the various system components

   Peripheral_Base : constant Address := System'To_Address (16#4000_0000#);

   APB1_Peripheral_Base : constant Address := Peripheral_Base;
   APB2_Peripheral_Base : constant Address := Peripheral_Base + 16#0001_0000#;
   AHB1_Peripheral_Base : constant Address := Peripheral_Base + 16#0002_0000#;
   AHB2_Peripheral_Base : constant Address := Peripheral_Base + 16#1000_0000#;

   GPIOA_Base : constant Address := AHB1_Peripheral_Base + 16#0000#;
   GPIOB_Base : constant Address := AHB1_Peripheral_Base + 16#0400#;
   GPIOC_Base : constant Address := AHB1_Peripheral_Base + 16#0800#;
   GPIOD_Base : constant Address := AHB1_Peripheral_Base + 16#0C00#;
   GPIOE_Base : constant Address := AHB1_Peripheral_Base + 16#1000#;
   GPIOF_Base : constant Address := AHB1_Peripheral_Base + 16#1400#;
   GPIOG_Base : constant Address := AHB1_Peripheral_Base + 16#1800#;
   GPIOH_Base : constant Address := AHB1_Peripheral_Base + 16#1C00#;
   GPIOI_Base : constant Address := AHB1_Peripheral_Base + 16#2000#;
   GPIOJ_Base : constant Address := AHB1_Peripheral_Base + 16#2400#;
   GPIOK_Base : constant Address := AHB1_Peripheral_Base + 16#2800#;

   RCC_Base     : constant Address := AHB1_Peripheral_Base + 16#3800#;
   FLASH_Base   : constant Address := AHB1_Peripheral_Base + 16#3C00#;
   DMA1_Base    : constant Address := AHB1_Peripheral_Base + 16#6000#;
   DMA2_Base    : constant Address := AHB1_Peripheral_Base + 16#6400#;
   ETH_Base     : constant Address := AHB1_Peripheral_Base + 16#8000#;
   ETH_MAC_Base : constant Address := ETH_Base;
   ETH_MMC_Base : constant Address := ETH_Base + 16#0100#;
   ETH_PTP_Base : constant Address := ETH_Base + 16#0700#;
   ETH_DMA_Base : constant Address := ETH_Base + 16#1000#;
   DMA2D_BASE   : constant Address := AHB1_Peripheral_Base + 16#B000#;

   RNG_BASE     : constant Address := AHB2_Peripheral_Base + 16#6_0800#;

   TIM2_Base    : constant Address := APB1_Peripheral_Base + 16#0000#;
   TIM3_Base    : constant Address := APB1_Peripheral_Base + 16#0400#;
   TIM4_Base    : constant Address := APB1_Peripheral_Base + 16#0800#;
   TIM5_Base    : constant Address := APB1_Peripheral_Base + 16#0C00#;
   TIM6_Base    : constant Address := APB1_Peripheral_Base + 16#1000#;
   TIM7_Base    : constant Address := APB1_Peripheral_Base + 16#1400#;
   TIM12_Base   : constant Address := APB1_Peripheral_Base + 16#1800#;
   TIM13_Base   : constant Address := APB1_Peripheral_Base + 16#1C00#;
   TIM14_Base   : constant Address := APB1_Peripheral_Base + 16#2000#;
   RTC_Base     : constant Address := APB1_Peripheral_Base + 16#2800#;
   WWDG_Base    : constant Address := APB1_Peripheral_Base + 16#2C00#;
   IWDG_Base    : constant Address := APB1_Peripheral_Base + 16#3000#;
   I2S2ext_Base : constant Address := APB1_Peripheral_Base + 16#3400#;
   SPI2_Base    : constant Address := APB1_Peripheral_Base + 16#3800#;
   SPI3_Base    : constant Address := APB1_Peripheral_Base + 16#3C00#;
   I2S3ext_Base : constant Address := APB1_Peripheral_Base + 16#4000#;
   USART2_Base  : constant Address := APB1_Peripheral_Base + 16#4400#;
   USART3_Base  : constant Address := APB1_Peripheral_Base + 16#4800#;
   UART4_Base   : constant Address := APB1_Peripheral_Base + 16#4C00#;
   UART5_Base   : constant Address := APB1_Peripheral_Base + 16#5000#;
   I2C1_Base    : constant Address := APB1_Peripheral_Base + 16#5400#;
   I2C2_Base    : constant Address := APB1_Peripheral_Base + 16#5800#;
   I2C3_Base    : constant Address := APB1_Peripheral_Base + 16#5C00#;
   CAN1_Base    : constant Address := APB1_Peripheral_Base + 16#6400#;
   CAN2_Base    : constant Address := APB1_Peripheral_Base + 16#6800#;
   PWR_Base     : constant Address := APB1_Peripheral_Base + 16#7000#;
   DAC_Base     : constant Address := APB1_Peripheral_Base + 16#7400#;
   UART7_BASE   : constant Address := APB1_Peripheral_Base + 16#7800#;
   UART8_BASE   : constant Address := APB1_Peripheral_Base + 16#7C00#;

   TIM1_Base   : constant Address := APB2_Peripheral_Base + 16#0000#;
   TIM8_Base   : constant Address := APB2_Peripheral_Base + 16#0400#;
   USART1_Base : constant Address := APB2_Peripheral_Base + 16#1000#;
   USART6_Base : constant Address := APB2_Peripheral_Base + 16#1400#;
   ADC1_Base   : constant Address := APB2_Peripheral_Base + 16#2000#;
   ADC2_Base   : constant Address := APB2_Peripheral_Base + 16#2100#;
   ADC3_Base   : constant Address := APB2_Peripheral_Base + 16#2200#;
   ADC_Base    : constant Address := APB2_Peripheral_Base + 16#2300#;
   SDIO_Base   : constant Address := APB2_Peripheral_Base + 16#2C00#;
   SPI1_Base   : constant Address := APB2_Peripheral_Base + 16#3000#;
   SPI4_BASE   : constant Address := APB2_Peripheral_Base + 16#3400#;
   SYSCFG_Base : constant Address := APB2_Peripheral_Base + 16#3800#;
   EXTI_Base   : constant Address := APB2_Peripheral_Base + 16#3C00#;
   TIM9_Base   : constant Address := APB2_Peripheral_Base + 16#4000#;
   TIM10_Base  : constant Address := APB2_Peripheral_Base + 16#4400#;
   TIM11_Base  : constant Address := APB2_Peripheral_Base + 16#4800#;
   SPI5_BASE   : constant Address := APB2_Peripheral_Base + 16#5000#;
   SPI6_BASE   : constant Address := APB2_Peripheral_Base + 16#5400#;
   SAI1_BASE   : constant Address := APB2_Peripheral_Base + 16#5800#;
   LTDC_BASE   : constant Address := APB2_Peripheral_Base + 16#6800#;

end STM32F4;

Revert "Removed aspect "Pack", because it conflicts with aspect "Size""

Removing aspect Pack produces an compile error.

This reverts commit 48aec31d3ed3c685ecf9e4d584d10ecec775d6bb.


-----------------------------------------------------------------------
--  util-commands-consoles - Console interface
--  Copyright (C) 2014, 2015, 2017 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Unbounded;
generic
   type Field_Type is (<>);
   type Notice_Type is (<>);
package Util.Commands.Consoles is

   type Justify_Type is (J_LEFT,           --  Justify left   |item    |
                         J_RIGHT,          --  Justify right  |    item|
                         J_CENTER,         --  Justify center |  item  |
                         J_RIGHT_NO_FILL   --  Justify right  |item|
                        );

   type Console_Type is abstract tagged limited private;
   type Console_Access is access all Console_Type'Class;

   --  Report an error message.
   procedure Error (Console : in out Console_Type;
                    Message : in String) is abstract;

   --  Report a notice message.
   procedure Notice (Console : in out Console_Type;
                     Kind    : in Notice_Type;
                     Message : in String) is abstract;

   --  Print the field value for the given field.
   procedure Print_Field (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Value   : in String;
                          Justify : in Justify_Type := J_LEFT) is abstract;

   --  Print the title for the given field.
   procedure Print_Title (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Title   : in String) is abstract;

   --  Start a new title in a report.
   procedure Start_Title (Console : in out Console_Type) is abstract;

   --  Finish a new title in a report.
   procedure End_Title (Console : in out Console_Type) is abstract;

   --  Start a new row in a report.
   procedure Start_Row (Console : in out Console_Type) is abstract;

   --  Finish a new row in a report.
   procedure End_Row (Console : in out Console_Type) is abstract;

   --  Print the title for the given field and setup the associated field size.
   procedure Print_Title (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Title   : in String;
                          Length  : in Positive);

   --  Format the integer and print it for the given field.
   procedure Print_Field (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Value   : in Integer;
                          Justify : in Justify_Type := J_LEFT);

   --  Format the integer and print it for the given field.
   procedure Print_Field (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Value   : in Ada.Strings.Unbounded.Unbounded_String;
                          Justify : in Justify_Type := J_LEFT);

   --  Get the field count that was setup through the Print_Title calls.
   function Get_Field_Count (Console : in Console_Type) return Natural;

   --  Reset the field count.
   procedure Clear_Fields (Console : in out Console_Type);

private

   type Field_Size_Array is array (Field_Type) of Natural;

   type Field_List_Array is array (1 .. Field_Type'Pos (Field_Type'Last)) of Field_Type;

   type Console_Type is abstract tagged limited record
      Sizes       : Field_Size_Array := (others => 1);
      Cols        : Field_Size_Array := (others => 1);
      Fields      : Field_List_Array;
      Field_Count : Natural := 0;
   end record;

end Util.Commands.Consoles;

-----------------------------------------------------------------------
--  util-commands-consoles -- Console interface
--  Copyright (C) 2014, 2015, 2017, 2018 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Unbounded;
generic
   type Field_Type is (<>);
   type Notice_Type is (<>);
package Util.Commands.Consoles is

   type Justify_Type is (J_LEFT,           --  Justify left   |item    |
                         J_RIGHT,          --  Justify right  |    item|
                         J_CENTER,         --  Justify center |  item  |
                         J_RIGHT_NO_FILL   --  Justify right  |item|
                        );

   type Console_Type is abstract tagged limited private;
   type Console_Access is access all Console_Type'Class;

   --  Report an error message.
   procedure Error (Console : in out Console_Type;
                    Message : in String) is abstract;

   --  Report a notice message.
   procedure Notice (Console : in out Console_Type;
                     Kind    : in Notice_Type;
                     Message : in String) is abstract;

   --  Print the field value for the given field.
   procedure Print_Field (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Value   : in String;
                          Justify : in Justify_Type := J_LEFT) is abstract;

   --  Print the title for the given field.
   procedure Print_Title (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Title   : in String) is abstract;

   --  Start a new title in a report.
   procedure Start_Title (Console : in out Console_Type) is abstract;

   --  Finish a new title in a report.
   procedure End_Title (Console : in out Console_Type) is abstract;

   --  Start a new row in a report.
   procedure Start_Row (Console : in out Console_Type) is abstract;

   --  Finish a new row in a report.
   procedure End_Row (Console : in out Console_Type) is abstract;

   --  Print the title for the given field and setup the associated field size.
   procedure Print_Title (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Title   : in String;
                          Length  : in Positive);

   --  Format the integer and print it for the given field.
   procedure Print_Field (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Value   : in Integer;
                          Justify : in Justify_Type := J_LEFT);

   --  Format the integer and print it for the given field.
   procedure Print_Field (Console : in out Console_Type;
                          Field   : in Field_Type;
                          Value   : in Ada.Strings.Unbounded.Unbounded_String;
                          Justify : in Justify_Type := J_LEFT);

   --  Get the field count that was setup through the Print_Title calls.
   function Get_Field_Count (Console : in Console_Type) return Natural;

   --  Reset the field count.
   procedure Clear_Fields (Console : in out Console_Type);

private

   type Field_Size_Array is array (Field_Type) of Natural;

   type Field_List_Array is array (1 .. Field_Type'Pos (Field_Type'Last)) of Field_Type;

   type Console_Type is abstract tagged limited record
      Sizes       : Field_Size_Array := (others => 1);
      Cols        : Field_Size_Array := (others => 1);
      Fields      : Field_List_Array;
      Field_Count : Natural := 0;
   end record;

end Util.Commands.Consoles;

Fix header style

Fix header style


with Ada.Text_IO;
with Spatial_Data; Use Spatial_Data;

procedure Spatial1 is

   package TIO renames Ada.Text_IO;

   procedure print (shape : Geometry; label : String);
   procedure print (shape : Geometry; label : String) is
   begin
      TIO.Put_Line ("===== " & label & " =====");
      TIO.Put_Line ("MySQL: " & mysql_text (shape));
      TIO.Put_Line ("  WKT: " & Well_Known_Text (shape)); -- (shape));
      TIO.Put_Line ("");
   end print;

   magic_point   : constant Geometric_Point := (18.2, -3.4);
   magic_linestr : constant Geometric_Line_String := ((0.5, 2.0), (11.0, 4.4), (12.0, 8.1));
   magic_polygon : constant Geometric_Polygon := ((0.5, 2.0), (11.0, 4.4), (12.0, 8.1), (0.005, 2.0));

   my_point   : Geometry := initialize_as_point (magic_point);
   my_line    : Geometry := initialize_as_line (((4.0, 2.23), (0.25, 5.1)));
   my_linestr : Geometry := initialize_as_line_string (magic_linestr);
   my_polygon : Geometry := initialize_as_polygon (magic_polygon);

   my_circle  : Geometry := initialize_as_circle (((2.0, 1.0), 4.5));
   my_infline : Geometry := initialize_as_infinite_line (((0.0, 0.0), (2.0, 2.0)));

begin

   --  critical checklist
   --  =========================================================
   --  single point                                           61
   --  single line (converts to line string)                  62
   --  single infinite line (!)                               66
   --  single line_string                                     63
   --  single polygon                                         64
   --  single polygon with 1 hole                          91-94
   --  single polygon with 2 holes                         95-98
   --  single circle (!)                                      67
   --  point + point = multipoint                          76-78
   --  point + line_string = collection                  106-108
   --  point + polygon = collection                      110-112
   --  point + polygon with 1 hole = 2 item collection   114-115
   --  point + polygon hole = EXCEPTION                  117-126
   --  line_string + line_string = multiline               80-81
   --  line_string + point + point = collection          128-130
   --  line_string + polygon = collection                132-135
   --  line_string + polygon + hole = 2 item collection  136-137
   --  polygon + point = 2 item collection               139-142
   --  polygon + line_string = 2 item collection         143-146
   --  polygon + hole + point + point = 3 item collection    147-151
   --  polygon + hole + polygon = 2 item multipolygon        153-156
   --  polygon + hole + polygon + point = 3 item collection  158-159
   --  polygon + polygon + hole = 2 item multipolygon        161-165
   --  polygon + polygon + hole + line_string = 3 item col.  166-167
   --  polygon + hole + polygon + hole = 2 item multipolygon 169-174
   --  polygon + hole + point = 2 item collection            175-179
   --  polygon + hole + line_string = 2 item collection

   print (my_point,   "SINGLE POINT");
   print (my_line,    "SINGLE LINE");
   print (my_linestr, "SINGLE LINE STRING (THREE POINT)");
   print (my_polygon, "SINGLE POLYGON (3 SIDES)");
   print (my_circle,  "SINGLE CIRCLE (not legal for MySQL or WKT)");
   print (my_infline, "INFINITE LINE (converted to regular line on MySQL or WKT)");

   declare
      pt1 : Geometric_Point := (9.2, 4.773);
      pt2 : Geometric_Point := (-7.01, -4.9234);
      pt3 : Geometric_Point := (4.5, 6.0);
      altpoly : Geometric_Polygon := ((1.0, 2.0), (3.2, 4.5), (8.8, 7.7), (1.0, 2.0));
      polyhole1 : Geometry;
      polyhole2 : Geometry;
   begin
      append_point (my_point, pt1);
      append_point (my_point, pt2);
      print (my_point, "MULTIPOINT COLLECTION");

      append_line_string (my_linestr, ((pt3, pt1, pt2)));
      print (my_linestr, "MULTILINESTRING COLLECTION");

      append_point (my_linestr, pt1);
      append_point (my_linestr, pt2);
      print (my_linestr, "MIXED COLLECTION #1");

      append_point (my_line, pt1);
      append_point (my_line, pt2);
      print (my_line, "MIXED COLLECTION #2");

      append_polygon_hole  (my_polygon, (altpoly));
      polyhole1 := my_polygon;
      print (polyhole1, "STILL SINGLE POLYGON #1");

      polyhole2 := polyhole1;
      append_polygon_hole (polyhole2, ((13.5, 15.35), (98.1, 11.7), (-13.75, 0.0004), (13.5, 15.35)));
      print (polyhole2, "STILL SINGLE POLYGON #2");

      append_polygon (my_polygon, ((5.0, 6.0), (1.4, 2.2), (18.1, 24.0), (5.0, 6.0)));
      print (my_polygon, "POLYGON COLLECTION #1");

      append_point (my_polygon, pt1);
      append_point (my_polygon, pt2);
      print (my_polygon, "MIXED COLLECTION #3");

      my_point := initialize_as_point (magic_point);
      append_line_string (my_point, magic_linestr);
      print (my_point, "MIXED COLLECTION #4");

      my_point := initialize_as_point (magic_point);
      append_polygon (my_point, magic_polygon);
      print (my_point, "MIXED COLLECTION #5");

      append_polygon_hole (my_point, altpoly);
      print (my_point, "MIXED COLLECTION #5 ENHANCED");

      my_point := initialize_as_point (magic_point);
      begin
         append_polygon_hole (my_point, altpoly);
      print (my_point, "MIXED COLLECTION #5 NEVER SEE THIS");
      exception
         when others =>
            TIO.Put_Line ("You can't add a polygon hole before adding " &
                          "a polygon");
            TIO.Put_Line ("");
      end;

      my_linestr := initialize_as_line_string (magic_linestr);
      append_point (my_linestr, pt1);
      print (my_linestr, "MIXED COLLECTION #6");

      my_linestr := initialize_as_line_string (magic_linestr);
      append_polygon (my_linestr, magic_polygon);
      print (my_linestr, "MIXED COLLECTION #7");

      append_polygon_hole (my_linestr, altpoly);
      print (my_linestr, "MIXED COLLECTION #7 ENHANCED");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_point (my_polygon, pt2);
      print (my_polygon, "MIXED COLLECTION #8");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_line_string (my_polygon, magic_linestr);
      print (my_polygon, "MIXED COLLECTION #9");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_polygon_hole (my_polygon, altpoly);
      append_point (my_polygon, pt1);
      append_point (my_polygon, pt2);
      print (my_polygon, "MIXED COLLECTION #10");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_polygon_hole (my_polygon, altpoly);
      append_polygon (my_polygon, ((5.0, 6.0), (1.4, 2.2), (18.1, 24.0), (5.0, 6.0)));
      print (my_polygon, "POLYGON COLLECTION #2");

      append_point (my_polygon, pt2);
      print (my_polygon, "MIXED COLLECTION #11");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_polygon (my_polygon, ((5.0, 6.0), (1.4, 2.2), (18.1, 24.0), (5.0, 6.0)));
      append_polygon_hole (my_polygon, altpoly);
      print (my_polygon, "POLYGON COLLECTION #3");

      append_line_string (my_polygon, magic_linestr);
      print (my_polygon, "MIXED COLLECTION #12");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_polygon_hole (my_polygon, altpoly);
      append_polygon (my_polygon, ((5.0, 6.0), (1.4, 2.2), (18.1, 24.0), (5.0, 6.0)));
      append_polygon_hole (my_polygon, ((13.5, 15.35), (98.1, 11.7), (-13.75, 0.0004), (13.5, 15.35)));
      print (my_polygon, "POLYGON COLLECTION #4");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_polygon_hole (my_polygon, altpoly);
      append_point (my_polygon, pt3);
      print (my_polygon, "MIXED COLLECTION #13");

      my_polygon := initialize_as_polygon (magic_polygon);
      append_polygon_hole (my_polygon, altpoly);
      append_line_string (my_polygon, magic_linestr);
      print (my_polygon, "MIXED COLLECTION #14");
   end;

end Spatial1;

with Ada.Text_IO;
with Spatial_Data; Use Spatial_Data;

procedure Spatial1 is

   package TIO renames Ada.Text_IO;

   procedure print (shape : Geometry; label : String);
   procedure print (shape : Geometry; label : String) is
   begin
      TIO.Put_Line ("===== " & label & " =====");
      TIO.Put_Line ("MySQL: " & mysql_text (shape));
      TIO.Put_Line ("  WKT: " & Well_Known_Text (shape)); -- (shape));
      TIO.Put_Line ("");
   end print;

   magic_point   : constant Geometric_Point := (18.2, -3.4);
   magic_linestr : constant Geometric_Line_String := ((0.5, 2.0), (11.0, 4.4), (12.0, 8.1));
   magic_polygon : constant Geometric_Polygon := start_polygon (((0.5, 2.0), (11.0, 4.4), (12.0, 8.1), (0.005, 2.0)));

   my_point   : Geometry := initialize_as_point (magic_point);
   my_linestr : Geometry := initialize_as_line (magic_linestr);
   my_polygon : Geometry := initialize_as_polygon (magic_polygon);

   pt1 : Geometric_Point := (9.2, 4.773);
   pt2 : Geometric_Point := (-7.01, -4.9234);
   pt3 : Geometric_Point := (4.5, 6.0);
   altpoly : Geometric_Ring := ((1.0, 2.0), (3.2, 4.5), (8.8, 7.7), (1.0, 2.0));
   polyhole : Geometric_Polygon;

begin

   --  critical checklist
   --  =========================================================
   --  single point                                           59
   --  single line_string                                     60
   --  single polygon                                         61
   --  single polygon with 1 hole                          71-74
   --  single polygon with 2 holes                         66-70
   --  point + point = multipoint                          72-77
   --  point + line_string = collection                   94-100
   --  point + point(s) = collection                     102-108
   --  point + polygon = collection                      110-115
   --  point + polygon with 2 holex = 2 item collection  117-122
   --  line_string + line_string = multiline               87-92
   --  line_string + point + point = collection          124-130
   --  line_string + polygon = collection                132-137
   --  line_string + polygon w/holes = 2 item collection 139-144
   --  polygon + point = 2 item collection                   146-151
   --  polygon + line_string = 2 item collection             153-158
   --  polygon + hole + point + point = 3 item collection    160-167
   --  polygon + hole + polygon + point = 3 item collection  169-176
   --  polygon + polygon + hole = 2 item multipolygon        178-182
   --  polygon + polygon + hole + line_string = 3 item col.  178-185
   --  polygon + hole + polygon + hole = 2 item multipolygon 187-196
   --  polygon + hole + point = 2 item collection            198-204
   --  polygon + hole + line_string = 2 item collection      206-212

   print (my_point,   "SINGLE POINT");
   print (my_linestr, "SINGLE LINE STRING (THREE POINT)");
   print (my_polygon, "SINGLE POLYGON (3 SIDES)");

   polyhole := magic_polygon;
   append_inner_ring (polyhole, altpoly);

   declare
      shape : Geometry := initialize_as_polygon (polyhole);
   begin
      print (shape, "STILL SINGLE POLYGON #1");
   end;

   append_inner_ring (polyhole, ((13.5, 15.35), (98.1, 11.7), (-13.75, 0.0004), (13.5, 15.35)));
   declare
      shape : Geometry := initialize_as_polygon (polyhole);
   begin
      print (shape, "STILL SINGLE POLYGON #2");
   end;

   declare
      MP : Geometry := initialize_as_multi_point (magic_point);
   begin
      augment_multi_point (MP, pt1);
      augment_multi_point (MP, pt2);
      print (MP, "MULTIPOINT COLLECTION");
   end;

   declare
      MLS : Geometry := initialize_as_multi_line (magic_linestr);
   begin
      augment_multi_line (MLS, ((pt3, pt1, pt2)));
      print (MLS, "MULTILINESTRING COLLECTION");
   end;

   declare
      shape : Geometry :=
        initialize_as_collection (initialize_as_point (pt1));
   begin
      augment_collection (shape, my_linestr);
      print (shape, "MIXED COLLECTION #1 (PT + LINE)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_point);
   begin
      augment_collection (shape, initialize_as_point (pt1));
      augment_collection (shape, initialize_as_point (pt2));
      print (shape, "MIXED COLLECTION #2 (ALL POINTS)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_point);
   begin
      augment_collection (shape, my_polygon);
      print (shape, "MIXED COLLECTION #3 (PT + POLY)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_point);
   begin
      augment_collection (shape, initialize_as_polygon (polyhole));
      print (shape, "MIXED COLLECTION #4 (PT + CMPLX POLY)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_linestr);
   begin
      augment_collection (shape, initialize_as_point (pt1));
      augment_collection (shape, initialize_as_point (pt2));
      print (shape, "MIXED COLLECTION #5 (LINE + 2 PT)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_linestr);
   begin
      augment_collection (shape, my_polygon);
      print (shape, "MIXED COLLECTION #6 (LINE + POLY)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_linestr);
   begin
      augment_collection (shape, initialize_as_polygon (polyhole));
      print (shape, "MIXED COLLECTION #6 ENHANCED (LINE + CMPLX POLY)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_polygon);
   begin
      augment_collection (shape, initialize_as_point (pt2));
      print (shape, "MIXED COLLECTION #7 (POLY + PT)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_polygon);
   begin
      augment_collection (shape, my_linestr);
      print (shape, "MIXED COLLECTION #7 (POLY + LINE)");
   end;

   declare
      shape : Geometry :=
        initialize_as_collection (initialize_as_polygon (polyhole));
   begin
      augment_collection (shape, initialize_as_point (pt1));
      augment_collection (shape, initialize_as_point (pt2));
      print (shape, "MIXED COLLECTION #8 (CMPLX POLY + 2 PT)");
   end;

   declare
      shape : Geometry :=
        initialize_as_collection (initialize_as_polygon (polyhole));
   begin
      augment_collection (shape, my_polygon);
      augment_collection (shape, initialize_as_point (pt2));
      print (shape, "MIXED COLLECTION #9 (CMPLX POLY + POLY + PT)");
   end;

   declare
      shape : Geometry := initialize_as_collection (my_polygon);
   begin
      augment_collection (shape, initialize_as_polygon (polyhole));
      print (shape, "MIXED COLLECTION #10 (POLY + CMPLX POLY)");
      augment_collection (shape, my_linestr);
      print (shape, "MIXED COLLECTION #11 (POLY + CMPLX POLY + LINE)");
   end;

   declare
      shape : Geometry :=
        initialize_as_collection (initialize_as_polygon (polyhole));
      new_poly : Geometric_Polygon;
   begin
      new_poly := start_polygon (((5.0, 6.0), (1.4, 2.2), (18.1, 24.0), (5.0, 6.0)));
      append_inner_ring (new_poly, ((5.0, 6.0), (1.4, 2.2), (18.1, 24.0), (5.0, 6.0)));
      augment_collection (shape, initialize_as_polygon (new_poly));
      print (shape, "MIXED COLLECTION #12 (2 CMPLX POLY)");
   end;

   declare
      shape : Geometry :=
        initialize_as_collection (initialize_as_polygon (polyhole));
   begin
      augment_collection (shape, initialize_as_point (pt3));
      print (shape, "MIXED COLLECTION #13 (CMPLX POLY + PT)");
   end;

   declare
      shape : Geometry :=
        initialize_as_collection (initialize_as_polygon (polyhole));
   begin
      augment_collection (shape, my_linestr);
      print (shape, "MIXED COLLECTION #13 (CMPLX POLY + Line)");
   end;

   -----------------------------------
   --  Additional collection tests  --
   -----------------------------------

   --  Have a collection inside a collection

   declare
      shape  : Geometry := initialize_as_collection (my_point);
      shape2 : geometry :=
        initialize_as_collection (initialize_as_point (pt3));
   begin
      augment_collection (shape2, my_linestr);
      augment_collection (shape, shape2);
--      print (shape, "COLLECTION THAT CONTAINS ANOTHER COLLECTION");
   end;

end Spatial1;

Update spatial1 testcase

Update spatial1 testcase

Save major progress which proves just about everything works.  The
newest test shows that collection inside collection might have an issue
though.


-----------------------------------------------------------------------
--  asf-parts -- ASF Parts
--  Copyright (C) 2011, 2012 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------

with Ada.Finalization;
with Servlet.Parts;

--  The ASF.Parts package is an Ada implementation of the Java servlet part
--  (JSR 315 3. The Request) provided by the <tt>javax.servlet.http.Part</tt> class.
package ASF.Parts is

   --  ------------------------------
   --  Multi part content
   --  ------------------------------
   --  The Part type describes a mime part received in a request.
   --  The content is stored in a file and several operations are provided
   --  to manage the content.
   subtype Part is Servlet.Parts.Part;

   --  Get the size of the mime part.
   function Get_Size (Data : in Part) return Natural is abstract;

   --  Get the content name submitted in the mime part.
   function Get_Name (Data : in Part) return String is abstract;

   --  Get the path of the local file which contains the part.
   function Get_Local_Filename (Data : in Part) return String is abstract;

   --  Get the content type of the part.
   function Get_Content_Type (Data : in Part) return String is abstract;

   --  Write the part data item to the file.  This method is not guaranteed to succeed
   --  if called more than once for the same part. This allows a particular implementation
   --  to use, for example, file renaming, where possible, rather than copying all of
   --  the underlying data, thus gaining a significant performance benefit.
   procedure Save (Data : in Part;
                   Path : in String);

   --  Deletes the underlying storage for a file item, including deleting any associated
   --  temporary disk file.
   procedure Delete (Data : in out Part);

end ASF.Parts;

-----------------------------------------------------------------------
--  asf-parts -- ASF Parts
--  Copyright (C) 2011, 2012, 2018 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------

with Servlet.Parts;

--  The ASF.Parts package is an Ada implementation of the Java servlet part
--  (JSR 315 3. The Request) provided by the <tt>javax.servlet.http.Part</tt> class.
package ASF.Parts is

   --  ------------------------------
   --  Multi part content
   --  ------------------------------
   --  The Part type describes a mime part received in a request.
   --  The content is stored in a file and several operations are provided
   --  to manage the content.
   subtype Part is Servlet.Parts.Part;

end ASF.Parts;

Fix compilation warnings

Fix compilation warnings


-----------------------------------------------------------------------
--  mat-targets-gtkmat - Gtk target management
--  Copyright (C) 2014 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------

with Gtk.Widget;
with Gtkada.Builder;

--  with MAT.Consoles.Gtkmat;
package MAT.Targets.Gtkmat is

   type Target_Type is new MAT.Targets.Target_Type with private;
   type Target_Type_Access is access all Target_Type'Class;

   --  Initialize the target instance.
   overriding
   procedure Initialize (Target : in out Target_Type);

   --  Initialize the widgets and create the Gtk gui.
   procedure Initialize_Widget (Target : in out Target_Type;
                                Widget : out Gtk.Widget.Gtk_Widget);

   --  Create a process instance to hold and keep track of memory and other information about
   --  the given process ID.
   overriding
   procedure Create_Process (Target  : in out Target_Type;
                             Pid     : in MAT.Types.Target_Process_Ref;
                             Path    : in Ada.Strings.Unbounded.Unbounded_String;
                             Process : out Target_Process_Type_Access);

   --  Enter in the interactive loop reading the commands from the standard input
   --  and executing the commands.
   overriding
   procedure Interactive (Target : in out Target_Type);

   --  Set the UI label with the given value.
   procedure Set_Label (Target : in Target_Type;
                        Name   : in String;
                        Value  : in String);

private

   task type Gtk_Loop is
      entry Start (Target : in Target_Type_Access);
   end Gtk_Loop;

   type Target_Type is new MAT.Targets.Target_Type with record
      Builder  : Gtkada.Builder.Gtkada_Builder;
      Gui_Task : Gtk_Loop;
   end record;

end MAT.Targets.Gtkmat;

-----------------------------------------------------------------------
--  mat-targets-gtkmat - Gtk target management
--  Copyright (C) 2014 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------

with Gtk.Widget;
with Gtkada.Builder;

--  with MAT.Consoles.Gtkmat;
package MAT.Targets.Gtkmat is

   type Target_Type is new MAT.Targets.Target_Type with private;
   type Target_Type_Access is access all Target_Type'Class;

   --  Initialize the target instance.
   overriding
   procedure Initialize (Target : in out Target_Type);

   --  Initialize the widgets and create the Gtk gui.
   procedure Initialize_Widget (Target : in out Target_Type;
                                Widget : out Gtk.Widget.Gtk_Widget);

   --  Create a process instance to hold and keep track of memory and other information about
   --  the given process ID.
   overriding
   procedure Create_Process (Target  : in out Target_Type;
                             Pid     : in MAT.Types.Target_Process_Ref;
                             Path    : in Ada.Strings.Unbounded.Unbounded_String;
                             Process : out Target_Process_Type_Access);

   --  Enter in the interactive loop reading the commands from the standard input
   --  and executing the commands.
   overriding
   procedure Interactive (Target : in out Target_Type);

   --  Set the UI label with the given value.
   procedure Set_Label (Target : in Target_Type;
                        Name   : in String;
                        Value  : in String);

   --  Refresh the information about the current process.
   procedure Refresh_Process (Target  : in out Target_Type);

private

   task type Gtk_Loop is
      entry Start (Target : in Target_Type_Access);
   end Gtk_Loop;

   type Target_Type is new MAT.Targets.Target_Type with record
      Builder  : Gtkada.Builder.Gtkada_Builder;
      Gui_Task : Gtk_Loop;
      Previous_Event_Counter : Integer := 0;
   end record;

end MAT.Targets.Gtkmat;

Declare the Refresh_Process procedure and keep track of the last event counter


-----------------------------------------------------------------------
--  awa-storages-stores -- The storage interface
--  Copyright (C) 2012 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with ADO.Sessions;

with AWA.Storages.Models;

--  == Store Service ==
--  The `AWA.Storages.Stores` package defines the interface that a store must implement to
--  be able to save and retrieve a data content.
package AWA.Storages.Stores is

   --  ------------------------------
   --  Store Service
   --  ------------------------------
   type Store is limited interface;
   type Store_Access is access all Store'Class;

   --  Save the file represented by the `Path` variable into a store and associate that
   --  content with the storage reference represented by `Into`.
   procedure Save (Storage : in Store;
                   Into    : in out AWA.Storages.Models.Storage_Ref'Class;
                   Path    : in String) is abstract;

   procedure Load (Storage : in Store;
                   From    : in AWA.Storages.Models.Storage_Ref'Class;
                   Into    : in String) is abstract;

end AWA.Storages.Stores;

-----------------------------------------------------------------------
--  awa-storages-stores -- The storage interface
--  Copyright (C) 2012 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with ADO.Sessions;

with AWA.Storages.Models;

--  == Store Service ==
--  The `AWA.Storages.Stores` package defines the interface that a store must implement to
--  be able to save and retrieve a data content.
package AWA.Storages.Stores is

   --  ------------------------------
   --  Store Service
   --  ------------------------------
   type Store is limited interface;
   type Store_Access is access all Store'Class;

   --  Save the file represented by the `Path` variable into a store and associate that
   --  content with the storage reference represented by `Into`.
   procedure Save (Storage : in Store;
                   Session : in out ADO.Sessions.Master_Session;
                   Into    : in out AWA.Storages.Models.Storage_Ref'Class;
                   Path    : in String) is abstract;

   procedure Load (Storage : in Store;
                   Session : in out ADO.Sessions.Master_Session;
                   From    : in AWA.Storages.Models.Storage_Ref'Class;
                   Into    : in String) is abstract;

end AWA.Storages.Stores;

Add the database session as parameter to the store implementation


with System;

package body POSIX.File is

  function C_Open_Boundary
    (File_Name : in String;
     Flags     : in Flags_t;
     Mode      : in Permissions.Mode_t) return Descriptor_t is
    --# hide C_Open_Boundary

    function C_Open
      (File_Name : in System.Address;
       Flags     : in Flags_t;
       Mode      : in Permissions.Mode_t) return Descriptor_t;
    pragma Import (C, C_Open, "open");

  begin
    return C_Open
      (File_Name => File_Name (File_Name'First)'Address,
       Flags     => Flags,
       Mode      => Mode);
  end C_Open_Boundary;

  procedure Open
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Flags        : in Flags_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t)
  is
    C_Flags     : Flags_t;
    C_File_Name : File_Name_t := File_Name_t'(File_Name_Index_t => Character'Val (0));
  begin
    -- Reject long filename.
    if File_Name'Last >= File_Name_t'Last then
      Descriptor  := -1;
      Error_Value := Error.Error_Name_Too_Long;
    else
      -- Set flags for non-blocking.
      if Non_Blocking then
        C_Flags := Flags or O_NONBLOCK;
      else
        C_Flags := Flags;
      end if;

      -- Copy and null-terminate filename.
      for Index in Positive range File_Name'First .. File_Name'Last loop
        C_File_Name (Index) := File_Name (Index);
      end loop;
      C_File_Name (File_Name'Last + 1) := Character'Val (0);

      -- Call system open() procedure.
      Descriptor := C_Open_Boundary
        (File_Name => C_File_Name,
         Flags     => C_Flags,
         Mode      => Mode);
      if Descriptor = -1 then
        Error_Value := Error.Get_Error;
      else
        Error_Value := Error.Error_None;
      end if;
    end if;
  end Open;

  procedure Open_Read_Only
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Read_Only,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Read_Only;

  procedure Open_Write_Only
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Write_Only,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Write_Only;

  procedure Open_Exclusive
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Create or Exclusive or Write_Only,
       Mode         => Mode,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Exclusive;

  procedure Open_Append
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Append or Create or Write_Only,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Append;

  procedure Open_Truncate
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Write_Only or Truncate or Create,
       Mode         => Mode,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Truncate;

  procedure Open_Read_Write
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Read_Write,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Read_Write;

  procedure Open_Create
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Write_Only or Create,
       Mode         => Mode,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Create;

end POSIX.File;

with System;

package body POSIX.File is

  function C_open_Boundary
    (File_Name : in String;
     Flags     : in Flags_t;
     Mode      : in Permissions.Mode_t) return Descriptor_t is
    --# hide C_open_Boundary

    function C_open
      (File_Name : in System.Address;
       Flags     : in Flags_t;
       Mode      : in Permissions.Mode_t) return Descriptor_t;
    pragma Import (C, C_open, "open");

  begin
    return C_open
      (File_Name => File_Name (File_Name'First)'Address,
       Flags     => Flags,
       Mode      => Mode);
  end C_open_Boundary;

  procedure Open
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Flags        : in Flags_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t)
  is
    C_Flags     : Flags_t;
    C_File_Name : File_Name_t := File_Name_t'(File_Name_Index_t => Character'Val (0));
  begin
    -- Reject long filename.
    if File_Name'Last >= File_Name_t'Last then
      Descriptor  := -1;
      Error_Value := Error.Error_Name_Too_Long;
    else
      -- Set flags for non-blocking.
      if Non_Blocking then
        C_Flags := Flags or O_NONBLOCK;
      else
        C_Flags := Flags;
      end if;

      -- Copy and null-terminate filename.
      for Index in Positive range File_Name'First .. File_Name'Last loop
        C_File_Name (Index) := File_Name (Index);
      end loop;
      C_File_Name (File_Name'Last + 1) := Character'Val (0);

      -- Call system open() procedure.
      Descriptor := C_open_Boundary
        (File_Name => C_File_Name,
         Flags     => C_Flags,
         Mode      => Mode);
      if Descriptor = -1 then
        Error_Value := Error.Get_Error;
      else
        Error_Value := Error.Error_None;
      end if;
    end if;
  end Open;

  procedure Open_Read_Only
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Read_Only,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Read_Only;

  procedure Open_Write_Only
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Write_Only,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Write_Only;

  procedure Open_Exclusive
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Create or Exclusive or Write_Only,
       Mode         => Mode,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Exclusive;

  procedure Open_Append
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Append or Create or Write_Only,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Append;

  procedure Open_Truncate
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Write_Only or Truncate or Create,
       Mode         => Mode,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Truncate;

  procedure Open_Read_Write
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Read_Write,
       Mode         => Permissions.None,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Read_Write;

  procedure Open_Create
    (File_Name    : in String;
     Non_Blocking : in Boolean;
     Mode         : in Permissions.Mode_t;
     Descriptor   : out Descriptor_t;
     Error_Value  : out Error.Error_t) is
  begin
    Open
      (File_Name    => File_Name,
       Non_Blocking => Non_Blocking,
       Flags        => Write_Only or Create,
       Mode         => Mode,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
  end Open_Create;

  procedure Change_Descriptor_Mode
    (Descriptor  : in Descriptor_t;
     Mode        : in Permissions.Mode_t;
     Error_Value : out Error.Error_t)
  is
    Return_Value : Error.Return_Value_t;

    function C_fchmod
      (Descriptor : in Descriptor_t;
       Mode       : in Permissions.Mode_t) return Error.Return_Value_t;
    pragma Import (C, C_fchmod, "fchmod");
  begin
    Return_Value := C_fchmod
      (Descriptor => Descriptor,
       Mode       => Mode);
    case Return_Value is
      when -1 => Error_Value := Error.Get_Error;
      when 0  => Error_Value := Error.Error_None;
    end case;
  end Change_Descriptor_Mode;

  procedure Change_Mode
    (File_Name   : in String;
     Mode        : in Permissions.Mode_t;
     Error_Value : out Error.Error_t)
  is
    Descriptor : Descriptor_t;
  begin
    Open_Read_Only
      (File_Name    => File_Name,
       Non_Blocking => False,
       Descriptor   => Descriptor,
       Error_Value  => Error_Value);
    if Error_Value /= Error.Error_None then
      Change_Descriptor_Mode
        (Descriptor  => Descriptor,
         Mode        => Mode,
         Error_Value => Error_Value);
    end if;
  end Change_Mode;

end POSIX.File;

Add Change_Mode and Change_Descriptor_Mode bodies.


-----------------------------------------------------------------------
--  wiki-render-wiki -- Wiki to Wiki renderer
--  Copyright (C) 2015, 2016, 2020 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Wide_Wide_Maps;
with Ada.Strings.Wide_Wide_Unbounded;

with Wiki.Documents;
with Wiki.Attributes;
with Wiki.Streams;
with Wiki.Strings;

--  == Wiki Renderer ==
--  The <tt>Wiki_Renderer</tt> allows to render a wiki document into another wiki content.
--  The formatting rules are ignored except for the paragraphs and sections.
package Wiki.Render.Wiki is

   use Standard.Wiki.Attributes;

   --  ------------------------------
   --  Wiki to HTML writer
   --  ------------------------------
   type Wiki_Renderer is new Renderer with private;

   --  Set the output stream.
   procedure Set_Output_Stream (Engine   : in out Wiki_Renderer;
                                Stream   : in Streams.Output_Stream_Access;
                                Format   : in Wiki_Syntax);

   --  Render the node instance from the document.
   overriding
   procedure Render (Engine : in out Wiki_Renderer;
                     Doc    : in Documents.Document;
                     Node   : in Nodes.Node_Type);

   --  Add a section header in the document.
   procedure Render_Header (Engine : in out Wiki_Renderer;
                            Header : in Wide_Wide_String;
                            Level  : in Positive);

   --  Add a paragraph (<p>).  Close the previous paragraph if any.
   --  The paragraph must be closed at the next paragraph or next header.
   procedure Add_Paragraph (Engine : in out Wiki_Renderer);

   --  Add a blockquote (<blockquote>).  The level indicates the blockquote nested level.
   --  The blockquote must be closed at the next header.
   procedure Add_Blockquote (Engine : in out Wiki_Renderer;
                             Level    : in Natural);

   --  Add a list item (<li>).  Close the previous paragraph and list item if any.
   --  The list item will be closed at the next list item, next paragraph or next header.
   procedure Add_List_Item (Engine : in out Wiki_Renderer;
                            Level    : in Positive;
                            Ordered  : in Boolean);

   --  Render a link.
   procedure Render_Link (Engine : in out Wiki_Renderer;
                          Name     : in Strings.WString;
                          Attrs    : in Attributes.Attribute_List);

   --  Render an image.
   procedure Render_Image (Engine : in out Wiki_Renderer;
                           Title  : in Strings.WString;
                           Attrs  : in Attributes.Attribute_List);

   --  Render a quote.
   procedure Render_Quote (Engine : in out Wiki_Renderer;
                           Title  : in Strings.WString;
                           Attrs  : in Attributes.Attribute_List);

   --  Add a text block with the given format.
   procedure Render_Text (Engine : in out Wiki_Renderer;
                          Text   : in Wide_Wide_String;
                          Format : in Format_Map);

   --  Render a text block that is pre-formatted.
   procedure Render_Preformatted (Engine : in out Wiki_Renderer;
                                  Text   : in Strings.WString;
                                  Format : in Strings.WString);

   procedure Render_Tag (Engine : in out Wiki_Renderer;
                         Doc    : in Documents.Document;
                         Node   : in Nodes.Node_Type);

   --  Finish the document after complete wiki text has been parsed.
   procedure Finish (Engine : in out Wiki_Renderer;
                     Doc    : in Documents.Document);

   --  Set the text style format.
   procedure Set_Format (Engine : in out Wiki_Renderer;
                         Format   : in Format_Map);

private

   use Ada.Strings.Wide_Wide_Unbounded;

   type Wide_String_Access is access constant Wide_Wide_String;

   type Wiki_Tag_Type is (Header_Start, Header_End,
                          Img_Start, Img_End,
                          Link_Start, Link_End, Link_Separator,
                          Quote_Start, Quote_End, Quote_Separator,
                          Preformat_Start, Preformat_End,
                          List_Start, List_Item, List_Ordered_Item,
                          Line_Break, Escape_Rule,
                          Horizontal_Rule,
                          Blockquote_Start, Blockquote_End);

   type Wiki_Tag_Array is array (Wiki_Tag_Type) of Wide_String_Access;

   type Wiki_Format_Array is array (Format_Type) of Wide_String_Access;

   --  Emit a new line.
   procedure New_Line (Engine : in out Wiki_Renderer);

   procedure Close_Paragraph (Engine : in out Wiki_Renderer);
   procedure Start_Keep_Content (Engine : in out Wiki_Renderer);

   type List_Style_Array is array (1 .. 32) of Boolean;

   EMPTY_TAG : aliased constant Wide_Wide_String := "";

   type Wiki_Renderer is new Renderer with record
      Output              : Streams.Output_Stream_Access := null;
      Syntax              : Wiki_Syntax := SYNTAX_CREOLE;
      Format              : Format_Map := (others => False);
      Tags                : Wiki_Tag_Array := (others => EMPTY_TAG'Access);
      Style_Start_Tags    : Wiki_Format_Array := (others => EMPTY_TAG'Access);
      Style_End_Tags      : Wiki_Format_Array := (others => EMPTY_TAG'Access);
      Escape_Set          : Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Set;
      Has_Paragraph       : Boolean := False;
      Has_Item            : Boolean := False;
      Need_Paragraph      : Boolean := False;
      Empty_Line          : Boolean := True;
      Keep_Content        : Boolean := False;
      In_List             : Boolean := False;
      Invert_Header_Level : Boolean := False;
      Allow_Link_Language : Boolean := False;
      Link_First          : Boolean := False;
      Html_Blockquote     : Boolean := False;
      Line_Count          : Natural := 0;
      Current_Level       : Natural := 0;
      Quote_Level         : Natural := 0;
      UL_List_Level       : Natural := 0;
      OL_List_Level       : Natural := 0;
      Current_Style       : Format_Map := (others => False);
      Content             : Unbounded_Wide_Wide_String;
      Link_Href           : Unbounded_Wide_Wide_String;
      Link_Title          : Unbounded_Wide_Wide_String;
      Link_Lang           : Unbounded_Wide_Wide_String;
   end record;

end Wiki.Render.Wiki;

-----------------------------------------------------------------------
--  wiki-render-wiki -- Wiki to Wiki renderer
--  Copyright (C) 2015, 2016, 2020 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with Ada.Strings.Wide_Wide_Maps;
with Ada.Strings.Wide_Wide_Unbounded;

with Wiki.Documents;
with Wiki.Attributes;
with Wiki.Streams;
with Wiki.Strings;

--  == Wiki Renderer ==
--  The <tt>Wiki_Renderer</tt> allows to render a wiki document into another wiki content.
--  The formatting rules are ignored except for the paragraphs and sections.
package Wiki.Render.Wiki is

   use Standard.Wiki.Attributes;

   --  ------------------------------
   --  Wiki to HTML writer
   --  ------------------------------
   type Wiki_Renderer is new Renderer with private;

   --  Set the output stream.
   procedure Set_Output_Stream (Engine   : in out Wiki_Renderer;
                                Stream   : in Streams.Output_Stream_Access;
                                Format   : in Wiki_Syntax);

   --  Render the node instance from the document.
   overriding
   procedure Render (Engine : in out Wiki_Renderer;
                     Doc    : in Documents.Document;
                     Node   : in Nodes.Node_Type);

   --  Add a section header in the document.
   procedure Render_Header (Engine : in out Wiki_Renderer;
                            Header : in Wide_Wide_String;
                            Level  : in Positive);

   --  Add a paragraph (<p>).  Close the previous paragraph if any.
   --  The paragraph must be closed at the next paragraph or next header.
   procedure Add_Paragraph (Engine : in out Wiki_Renderer);

   --  Add a blockquote (<blockquote>).  The level indicates the blockquote nested level.
   --  The blockquote must be closed at the next header.
   procedure Add_Blockquote (Engine : in out Wiki_Renderer;
                             Level    : in Natural);

   --  Add a list item (<li>).  Close the previous paragraph and list item if any.
   --  The list item will be closed at the next list item, next paragraph or next header.
   procedure Add_List_Item (Engine : in out Wiki_Renderer;
                            Level    : in Positive;
                            Ordered  : in Boolean);

   --  Render a link.
   procedure Render_Link (Engine : in out Wiki_Renderer;
                          Name     : in Strings.WString;
                          Attrs    : in Attributes.Attribute_List);

   --  Render an image.
   procedure Render_Image (Engine : in out Wiki_Renderer;
                           Title  : in Strings.WString;
                           Attrs  : in Attributes.Attribute_List);

   --  Render a quote.
   procedure Render_Quote (Engine : in out Wiki_Renderer;
                           Title  : in Strings.WString;
                           Attrs  : in Attributes.Attribute_List);

   --  Add a text block with the given format.
   procedure Render_Text (Engine : in out Wiki_Renderer;
                          Text   : in Wide_Wide_String;
                          Format : in Format_Map);

   --  Render a text block that is pre-formatted.
   procedure Render_Preformatted (Engine : in out Wiki_Renderer;
                                  Text   : in Strings.WString;
                                  Format : in Strings.WString);

   procedure Render_Tag (Engine : in out Wiki_Renderer;
                         Doc    : in Documents.Document;
                         Node   : in Nodes.Node_Type);

   --  Finish the document after complete wiki text has been parsed.
   procedure Finish (Engine : in out Wiki_Renderer;
                     Doc    : in Documents.Document);

   --  Set the text style format.
   procedure Set_Format (Engine : in out Wiki_Renderer;
                         Format   : in Format_Map);

private

   use Ada.Strings.Wide_Wide_Unbounded;

   type Wide_String_Access is access constant Wide_Wide_String;

   type Wiki_Tag_Type is (Header_Start, Header_End,
                          Img_Start, Img_End,
                          Link_Start, Link_End, Link_Separator,
                          Quote_Start, Quote_End, Quote_Separator,
                          Preformat_Start, Preformat_End,
                          List_Start, List_Item, List_Ordered_Item,
                          Line_Break, Escape_Rule,
                          Horizontal_Rule,
                          Blockquote_Start, Blockquote_End);

   type Wiki_Tag_Array is array (Wiki_Tag_Type) of Wide_String_Access;

   type Wiki_Format_Array is array (Format_Type) of Wide_String_Access;

   --  Emit a new line.
   procedure New_Line (Engine   : in out Wiki_Renderer;
                       Optional : in Boolean := False);
   procedure Need_Separator_Line (Engine   : in out Wiki_Renderer);

   procedure Close_Paragraph (Engine : in out Wiki_Renderer);
   procedure Start_Keep_Content (Engine : in out Wiki_Renderer);

   type List_Style_Array is array (1 .. 32) of Boolean;

   EMPTY_TAG : aliased constant Wide_Wide_String := "";

   type Wiki_Renderer is new Renderer with record
      Output              : Streams.Output_Stream_Access := null;
      Syntax              : Wiki_Syntax := SYNTAX_CREOLE;
      Format              : Format_Map := (others => False);
      Tags                : Wiki_Tag_Array := (others => EMPTY_TAG'Access);
      Style_Start_Tags    : Wiki_Format_Array := (others => EMPTY_TAG'Access);
      Style_End_Tags      : Wiki_Format_Array := (others => EMPTY_TAG'Access);
      Escape_Set          : Ada.Strings.Wide_Wide_Maps.Wide_Wide_Character_Set;
      Has_Paragraph       : Boolean := False;
      Has_Item            : Boolean := False;
      Need_Paragraph      : Boolean := False;
      Empty_Line          : Boolean := True;
      Keep_Content        : Boolean := False;
      In_List             : Boolean := False;
      Invert_Header_Level : Boolean := False;
      Allow_Link_Language : Boolean := False;
      Link_First          : Boolean := False;
      Html_Blockquote     : Boolean := False;
      Need_Newline        : Boolean := False;
      Line_Count          : Natural := 0;
      Current_Level       : Natural := 0;
      Quote_Level         : Natural := 0;
      UL_List_Level       : Natural := 0;
      OL_List_Level       : Natural := 0;
      Current_Style       : Format_Map := (others => False);
      Content             : Unbounded_Wide_Wide_String;
      Link_Href           : Unbounded_Wide_Wide_String;
      Link_Title          : Unbounded_Wide_Wide_String;
      Link_Lang           : Unbounded_Wide_Wide_String;
   end record;

end Wiki.Render.Wiki;

Declare the Need_Separator_Line procedure


-----------------------------------------------------------------------
--  awa-users-module -- User management module
--  Copyright (C) 2009, 2010, 2011, 2012 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with ASF.Applications;

with ASF.Security.Servlets;

with AWA.Modules;
with AWA.Users.Services;
with AWA.Users.Filters;
with AWA.Users.Servlets;

--  == Introduction ==
--  The Users.Module manages the creation, update, removal and authentication of users
--  in an application.  The module provides the foundations for user management in
--  a web application.
--
--  A user can register himself by using a subscription form.  In that case, a verification mail
--  is sent and the user has to follow the verification link defined in the mail to finish
--  the registration process.  The user will authenticate using a password.
--
--  A user can also use an OpenID account and be automatically registered.
--
--  A user can have one or several permissions that allow to protect the application data.
--  User permissions are managed by the Permissions.Module.
--
--  == Configuration ==
--  The *users* module uses a set of configuration properties to configure the OpenID
--  integration.
--
--  @include users.xml
--
--  @include awa-users-services.ads
--
--  @include users.xml
--
--  == Model ==
--  [http://ada-awa.googlecode.com/svn/wiki/awa_user_model.png]
--
--  @include User.hbm.xml
package AWA.Users.Modules is

   NAME : constant String := "users";

   type User_Module is new AWA.Modules.Module with private;
   type User_Module_Access is access all User_Module'Class;

   --  Initialize the user module.
   overriding
   procedure Initialize (Plugin : in out User_Module;
                         App    : in AWA.Modules.Application_Access;
                         Props  : in ASF.Applications.Config);

   --  Get the user manager.
   function Get_User_Manager (Plugin : in User_Module) return Services.User_Service_Access;

   --  Create a user manager.  This operation can be overriden to provide another
   --  user service implementation.
   function Create_User_Manager (Plugin : in User_Module) return Services.User_Service_Access;

   --  Get the user module instance associated with the current application.
   function Get_User_Module return User_Module_Access;

   --  Get the user manager instance associated with the current application.
   function Get_User_Manager return Services.User_Service_Access;

private

   type User_Module is new AWA.Modules.Module with record
      Manager     : Services.User_Service_Access := null;
      Key_Filter  : aliased AWA.Users.Filters.Verify_Filter;
      Auth_Filter : aliased AWA.Users.Filters.Auth_Filter;
      Auth        : aliased ASF.Security.Servlets.Request_Auth_Servlet;
      Verify_Auth : aliased AWA.Users.Servlets.Verify_Auth_Servlet;
   end record;

end AWA.Users.Modules;

-----------------------------------------------------------------------
--  awa-users-module -- User management module
--  Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Stephane Carrez
--  Written by Stephane Carrez (Stephane.Carrez@gmail.com)
--
--  Licensed under the Apache License, Version 2.0 (the "License");
--  you may not use this file except in compliance with the License.
--  You may obtain a copy of the License at
--
--      http://www.apache.org/licenses/LICENSE-2.0
--
--  Unless required by applicable law or agreed to in writing, software
--  distributed under the License is distributed on an "AS IS" BASIS,
--  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
--  See the License for the specific language governing permissions and
--  limitations under the License.
-----------------------------------------------------------------------
with ASF.Applications;

with ASF.Security.Servlets;

with AWA.Modules;
with AWA.Users.Services;
with AWA.Users.Filters;
with AWA.Users.Servlets;

--  == Introduction ==
--  The Users.Module manages the creation, update, removal and authentication of users
--  in an application.  The module provides the foundations for user management in
--  a web application.
--
--  A user can register himself by using a subscription form.  In that case, a verification mail
--  is sent and the user has to follow the verification link defined in the mail to finish
--  the registration process.  The user will authenticate using a password.
--
--  A user can also use an OpenID account and be automatically registered.
--
--  A user can have one or several permissions that allow to protect the application data.
--  User permissions are managed by the Permissions.Module.
--
--  == Configuration ==
--  The *users* module uses a set of configuration properties to configure the OpenID
--  integration.
--
--  @include users.xml
--
--  @include awa-users-services.ads
--
--  @include users.xml
--
--  == Model ==
--  [http://ada-awa.googlecode.com/svn/wiki/awa_user_model.png]
--
--  @include User.hbm.xml
package AWA.Users.Modules is

   NAME : constant String := "users";

   type User_Module is new AWA.Modules.Module with private;
   type User_Module_Access is access all User_Module'Class;

   --  Initialize the user module.
   overriding
   procedure Initialize (Plugin : in out User_Module;
                         App    : in AWA.Modules.Application_Access;
                         Props  : in ASF.Applications.Config);

   --  Get the user manager.
   function Get_User_Manager (Plugin : in User_Module) return Services.User_Service_Access;

   --  Create a user manager.  This operation can be overriden to provide another
   --  user service implementation.
   function Create_User_Manager (Plugin : in User_Module) return Services.User_Service_Access;

   --  Get the user module instance associated with the current application.
   function Get_User_Module return User_Module_Access;

   --  Get the user manager instance associated with the current application.
   function Get_User_Manager return Services.User_Service_Access;

private

   type User_Module is new AWA.Modules.Module with record
      Manager     : Services.User_Service_Access := null;
      Key_Filter  : aliased AWA.Users.Filters.Verify_Filter;
      Auth_Filter : aliased AWA.Users.Filters.Auth_Filter;
      Auth        : aliased AWA.Users.Servlets.Request_Auth_Servlet;
      Verify_Auth : aliased AWA.Users.Servlets.Verify_Auth_Servlet;
   end record;

end AWA.Users.Modules;

Use the authenticate servlet defined in the AWA.Users.Servlets package