matreshka_league_21.0.0_0c8f4d47/tools/csmib/csmib-generator.adb

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
------------------------------------------------------------------------------
--                                                                          --
--                            Matreshka Project                             --
--                                                                          --
--         Localization, Internationalization, Globalization for Ada        --
--                                                                          --
--                              Tools Component                             --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2013-2017, Vadim Godunko <vgodunko@gmail.com>                --
-- All rights reserved.                                                     --
--                                                                          --
-- Redistribution and use in source and binary forms, with or without       --
-- modification, are permitted provided that the following conditions       --
-- are met:                                                                 --
--                                                                          --
--  * Redistributions of source code must retain the above copyright        --
--    notice, this list of conditions and the following disclaimer.         --
--                                                                          --
--  * 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.  --
--                                                                          --
--  * Neither the name of the Vadim Godunko, IE 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.             --
--                                                                          --
------------------------------------------------------------------------------
--  $Revision: 5774 $ $Date: 2017-09-15 15:53:25 +0300 (Пт, 15 сен 2017) $
------------------------------------------------------------------------------
with Ada.Integer_Wide_Wide_Text_IO;
with Ada.Strings.Wide_Wide_Fixed;
with Ada.Wide_Wide_Text_IO;

with League.Strings.Internals;
with Matreshka.Internals.Strings;
with Matreshka.Internals.Utf16;

package body CSMIB.Generator is

   use Ada.Integer_Wide_Wide_Text_IO;
   use Ada.Wide_Wide_Text_IO;

   procedure Generate_String_Constant (Number : Positive);
   --  Generates object declaration and initialization for specified string.

   ------------------------------
   -- Generate_String_Constant --
   ------------------------------

   procedure Generate_String_Constant (Number : Positive) is
      use type Matreshka.Internals.Utf16.Utf16_String_Index;

      Internal : constant Matreshka.Internals.Strings.Shared_String_Access
        := League.Strings.Internals.Internal (MIBs (Number).Name);

      procedure Put (Item : Matreshka.Internals.Utf16.Utf16_Code_Unit);

      ---------
      -- Put --
      ---------

      procedure Put (Item : Matreshka.Internals.Utf16.Utf16_Code_Unit) is
         use type Matreshka.Internals.Utf16.Utf16_Code_Unit;

         Hex    : constant
           array (Matreshka.Internals.Utf16.Utf16_Code_Unit range 0 .. 15)
             of Wide_Wide_Character := "0123456789ABCDEF";
         Result : Wide_Wide_String := "16#XXXX#";

      begin
         Result (4) := Hex (Item / 4096);
         Result (5) := Hex ((Item / 256) mod 16);
         Result (6) := Hex ((Item / 16) mod 16);
         Result (7) := Hex (Item mod 16);

         Put (Result);
      end Put;

   begin
      New_Line;
      Put ("   N");
      Put (Number, Width => 0);
      Put_Line (" : aliased Matreshka.Internals.Strings.Shared_String");
      Put ("     := (Capacity => ");
      Put (Integer (Internal.Capacity), Width => 0);
      Put_Line (",");
      Put ("         Unused   => ");
      Put (Integer (Internal.Unused), Width => 0);
      Put_Line (",");
      Put ("         Length   => ");
      Put (Internal.Length, Width => 0);
      Put_Line (",");
      Put_Line ("         Value    =>");
      Put ("            (");

      for J in 0 .. Internal.Unused - 1 loop
         if J /= 0 and J mod 4 = 0 then
            Put_Line (",");
            Put ("             ");

         elsif J /= 0 then
            Put (", ");
         end if;

         Put (Internal.Value (J));
      end loop;

      Put_Line (",");
      Put_Line ("             others => 16#0000#),");
      Put_Line ("           others => <>);");
      Put_Line ("   --  " & MIBs.Element (Number).Name.To_Wide_Wide_String);
   end Generate_String_Constant;

   --------------
   -- Generate --
   --------------

   procedure Generate is
   begin
      Put_Line
       ("--------------------------------------------------------------------"
          & "----------");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--                            Matreshka Project                     "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--         Localization, Internationalization, Globalization for Ada"
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--                        Runtime Library Component                 "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--------------------------------------------------------------------"
          & "----------");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("-- Copyright © 2010-2013, Vadim Godunko <vgodunko@gmail.com>        "
          & "        --");
      Put_Line
       ("-- All rights reserved.                                             "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("-- Redistribution and use in source and binary forms, with or withou"
          & "t       --");
      Put_Line
       ("-- modification, are permitted provided that the following condition"
          & "s       --");
      Put_Line
       ("-- are met:                                                         "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--  * Redistributions of source code must retain the above copyright"
          & "        --");
      Put_Line
       ("--    notice, this list of conditions and the following disclaimer. "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--  * Redistributions in binary form must reproduce the above copyri"
          & "ght     --");
      Put_Line
       ("--    notice, this list of conditions and the following disclaimer i"
          & "n the   --");
      Put_Line
       ("--    documentation and/or other materials provided with the distrib"
          & "ution.  --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--  * Neither the name of the Vadim Godunko, IE nor the names of its"
          & "        --");
      Put_Line
       ("--    contributors may be used to endorse or promote products derive"
          & "d from  --");
      Put_Line
       ("--    this software without specific prior written permission.      "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTO"
          & "RS      --");
      Put_Line
       ("-- ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT N"
          & "OT        --");
      Put_Line
       ("-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS"
          & " FOR    --");
      Put_Line
       ("-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRI"
          & "GHT     --");
      Put_Line
       ("-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDE"
          & "NTAL,   --");
      Put_Line
       ("-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT "
          & "LIMITED --");
      Put_Line
       ("-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DAT"
          & "A, OR   --");
      Put_Line
       ("-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEO"
          & "RY OF   --");
      Put_Line
       ("-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUD"
          & "ING     --");
      Put_Line
       ("-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THI"
          & "S       --");
      Put_Line
       ("-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     "
          & "        --");
      Put_Line
       ("--                                                                  "
          & "        --");
      Put_Line
       ("--------------------------------------------------------------------"
          & "----------");
      Put_Line
       ("--  $Revision" & "$ $Date" & "$");
      Put_Line
       ("--------------------------------------------------------------------"
          & "----------");
      New_Line;
      Put_Line ("with Matreshka.Internals.Strings;");
      New_Line;
      Put_Line
       ("private package Matreshka.Internals.Text_Codecs.IANA_Registry is");
      New_Line;
      Put_Line ("   pragma Preelaborate;");
      New_Line;
      Put_Line ("   type IANA_Record is record");
      Put_Line
       ("      Name :"
          & " not null Matreshka.Internals.Strings.Shared_String_Access;");
      Put_Line ("      MIB  : Character_Set;");
      Put_Line ("   end record;");

      --  Generate objects for normalized encoding names.

      for J in 1 .. Integer (MIBs.Length) loop
         Generate_String_Constant (J);
      end loop;

      --  Generate name to MIB mapping.

      New_Line;
      Put_Line
       ("   To_MIB : constant array (Positive range <>) of IANA_Record");
      Put ("     := (");

      for J in 1 .. Integer (MIBs.Length) loop
         if J /= 1 then
            Put_Line (",");
            Put ("         ");
         end if;

         Put ("(N");
         Put (J, Width => 0);
         Put ("'Access, ");
         Put (MIBs.Element (J).MIB, Width => 0);
         Put (")");
      end loop;

      Put_Line (");");
      New_Line;
      Put_Line ("end Matreshka.Internals.Text_Codecs.IANA_Registry;");
   end Generate;

end CSMIB.Generator;