WITH   Ada.Unchecked_Conversion ;
WITH   Interfaces.C ;
WITH   System ;
WITH   Win32 ;
WITH   Win32.Crt.Strings ;
WITH   Win32.Windef ;
WITH   Win32.Wingdi ;
WITH   Win32.Winuser ;

PACKAGE BODY   CharTb32_Pkg  IS

   FUNCTION   CP   ( I_Str : Win32.CHAR_Array )  RETURN  Win32.LPCSTR  IS
      FUNCTION   UC  IS
         new Ada.Unchecked_Conversion ( System.Address , Win32.LPCSTR );
   BEGIN
      RETURN  UC ( I_Str(I_Str'First)'Address );
   END CP;

   FUNCTION   CPS   ( I_Str : Win32.CHAR_Array )  RETURN  Win32.LPSTR  IS
      FUNCTION   UC  IS
         new Ada.Unchecked_Conversion ( System.Address , Win32.LPSTR );
   BEGIN
      RETURN  UC ( I_Str(I_Str'First)'Address );
   END CPS;

   USE TYPE   Win32.CHAR_Array ;      --- To get "&"

   Nul : Win32.Char RENAMES Win32.Nul ;

   IgnoredI : Win32.INT ;
   IgnoredP : Win32.PSTR ;

   C_MainPMTitle : CONSTANT Win32.CHAR_Array := "Information"  &  Nul ;

   CRLF : CONSTANT Win32.CHAR_Array := Win32.Char(Character'Val(13))  &  Win32.Char(Character'Val(10));

   C_HexCh : CONSTANT Win32.CHAR_Array := "0123456789ABCDEF" ;
   C_TitleLn1 : CONSTANT Win32.CHAR_Array := "   0123456789ABCDEF"  &  CRLF  &  Nul ;
   C_TitleLn2 : CONSTANT Win32.CHAR_Array := "   ----------------"  &  CRLF  &  Nul ;
   CRLFz : CONSTANT Win32.CHAR_Array := Win32.Char(Character'Val(13))  &  Win32.Char(Character'Val(10))  &  Nul ;

   L_Buffer : ALIASED Win32.CHAR_Array(0..4096);
   L_Buf01z : ALIASED Win32.CHAR_Array(0..1);
   L_Buf03z : ALIASED Win32.CHAR_Array(0..3);

   PROCEDURE   ShowCharTb32  IS
      L_Code : Standard.INTEGER ;
   BEGIN
      L_Buffer(0) := Nul ;

      IgnoredP := Win32.Crt.Strings.StrCat ( CPS(L_Buffer) , CP(C_TitleLn1) );
      IgnoredP := Win32.Crt.Strings.StrCat ( CPS(L_Buffer) , CP(C_TitleLn2) );

      L_Buf01z(1) := Nul ;
      L_Buf03z := "00>"  &  Nul ;

      ----- LOOP 1
      FOR L_i in 0..15 LOOP
         ----- Line address in hexa
         L_Buf03z(0) := C_HexCh(L_i);
         IgnoredP := Win32.Crt.Strings.StrCat ( CPS(L_Buffer) , CP(L_Buf03z) );

         ----- LOOP 2
         FOR L_j in 0..15 LOOP
            L_Code := L_i*16  +  L_j ;

            ----- Write char  ( Ignoring problem chars )
            IF (L_Code = 0) or (L_Code = 9) or (L_Code = 10) or (L_Code = 13)
            THEN
               L_Buf01z(0) := '-' ;
            ELSE
               L_Buf01z(0) := Win32.Char(Character'Val(L_Code));
            END IF;
            IgnoredP := Win32.Crt.Strings.StrCat ( CPS(L_Buffer) , CP(L_Buf01z) );
         END LOOP;--j

         IgnoredP := Win32.Crt.Strings.StrCat ( CPS(L_Buffer) , CP(CRLFz) );
      END LOOP;--i

      IgnoredI := Win32.Winuser.MessageBox ( System.Null_Address
                                           , CP(L_Buffer)
                                           , CP(C_MainPMTitle)
                                           , Win32.Winuser.MB_OK or Win32.Winuser.MB_ICONEXCLAMATION );
   END ShowCharTb32;
END CharTb32_Pkg;
