matreshka_league_21.0.0_0c8f4d47/tools/shiftjis/gen_shiftjis.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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
------------------------------------------------------------------------------
--                                                                          --
--                            Matreshka Project                             --
--                                                                          --
--         Localization, Internationalization, Globalization for Ada        --
--                                                                          --
--                              Tools Component                             --
--                                                                          --
------------------------------------------------------------------------------
--                                                                          --
-- Copyright © 2010, 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: 1060 $ $Date: 2010-11-01 00:17:01 +0300 (Пн, 01 ноя 2010) $
------------------------------------------------------------------------------
--  This program generates tables for Shift JIS codec.
with Ada.Command_Line;
with Ada.Strings.Fixed;
with Ada.Text_IO;

procedure Gen_SHIFTJIS is

   type Code_Unit_32 is mod 2**32;
   type Code_Unit_16 is mod 2**16;
   type Code_Unit_8 is mod 2**8;

   type Code_Unit_32_Array is array (Code_Unit_8) of Code_Unit_32;
   type Code_Unit_32_Array_Access is access all Code_Unit_32_Array;

   type Expansion is record
      First  : Code_Unit_32;
      Second : Code_Unit_32;
   end record;

   function Image (Item : Code_Unit_8) return String;
   function Image (Item : Code_Unit_32) return String;

   -----------
   -- Image --
   -----------

   function Image (Item : Code_Unit_8) return String is
      Hex : constant array (Code_Unit_8 range 0 .. 15) of Character
        := "0123456789ABCDEF";

   begin
      return Result : String (1 .. 2) do
         Result (1) := Hex (Item / 16);
         Result (2) := Hex (Item mod 16);
      end return;
   end Image;

   -----------
   -- Image --
   -----------

   function Image (Item : Code_Unit_32) return String is
      Hex : constant array (Code_Unit_32 range 0 .. 15) of Character
        := "0123456789ABCDEF";

   begin
      if Item <= 16#FFFF# then
         return Result : String (1 .. 4) do
            Result (1) := Hex (Item / 16 ** 3);
            Result (2) := Hex ((Item / 16 ** 2) mod 16);
            Result (3) := Hex ((Item / 16) mod 16);
            Result (4) := Hex (Item mod 16);
         end return;

      else
         return Result : String (1 .. 7) do
            Result (1) := Hex (Item / 16 ** 5);
            Result (2) := Hex ((Item / 16 ** 4) mod 16);
            Result (3) := '_';
            Result (4) := Hex ((Item / 16 ** 3) mod 16);
            Result (5) := Hex ((Item / 16 ** 2) mod 16);
            Result (6) := Hex ((Item / 16) mod 16);
            Result (7) := Hex (Item mod 16);
         end return;
      end if;
   end Image;

   Undefined       : constant Code_Unit_32 := 16#FFFF_FFFF#;
   Reserved        : constant Code_Unit_32 := 16#FFFF_FFFE#;
   Double_Bytes    : constant Code_Unit_32 := 16#FFFF_FFFD#;
   First_Expansion : constant Code_Unit_32 := 16#FFFF_FF00#;

   File         : Ada.Text_IO.File_Type;
   Buffer       : String (1 .. 256);
   Last         : Natural;
   First        : Positive;
   Tab          : Natural;
   Plus         : Natural;
   Encoded_Code : Code_Unit_16;
   Low_Code     : Code_Unit_8;
   High_Code    : Code_Unit_8;
   Unicode_Code : Code_Unit_32;

   Single_Map     : array (Code_Unit_8) of Code_Unit_32
     := (others => Undefined);
   Double_Map     : array (Code_Unit_8) of Code_Unit_32_Array_Access;
   Expansion_List :
     array (First_Expansion .. First_Expansion + 32) of Expansion;
   Last_Expansion : Code_Unit_32 := First_Expansion - 1;
   Valid_Second   : array (Code_Unit_8) of Boolean := (others => False);

begin
   Ada.Text_IO.Open
    (File, Ada.Text_IO.In_File, Ada.Command_Line.Argument (1));

   while not Ada.Text_IO.End_Of_File (File) loop
      Ada.Text_IO.Get_Line (File, Buffer, Last);

      if Last /= 0 and Buffer (1) /= '#' then
         First := Buffer'First;

         Tab :=
           Ada.Strings.Fixed.Index (Buffer (First .. Last), "" & ASCII.HT);
         Encoded_Code :=
           Code_Unit_16'Value ("16#" & Buffer (First + 2 .. Tab - 1) & '#');
         Low_Code := Code_Unit_8 (Encoded_Code mod 256);
         High_Code := Code_Unit_8 (Encoded_Code / 256);
         First := Tab + 1;

         Tab :=
           Ada.Strings.Fixed.Index
            (Buffer (First .. Last), "" & ASCII.HT);

         if High_Code = 0 then
            if First = Tab then
               Single_Map (Low_Code) := Reserved;

            else
               Unicode_Code :=
                 Code_Unit_32'Value
                  ("16#" & Buffer (First + 2 .. Tab - 1) & '#');
               Single_Map (Low_Code) := Unicode_Code;
            end if;

         else
            if Double_Map (High_Code) = null then
               Double_Map (High_Code) :=
                 new Code_Unit_32_Array'(others => Undefined);
               Single_Map (High_Code) := Double_Bytes;
            end if;

            if First = Tab then
               Double_Map (High_Code) (Low_Code) := Reserved;

            else
               Plus :=
                 Ada.Strings.Fixed.Index (Buffer (First + 2 .. Tab - 1), "+");

               if Plus = 0 then
                  Unicode_Code :=
                    Code_Unit_32'Value
                     ("16#" & Buffer (First + 2 .. Tab - 1) & '#');
                  Double_Map (High_Code) (Low_Code) := Unicode_Code;

               else
                  Last_Expansion := Last_Expansion + 1;
                  Expansion_List (Last_Expansion) :=
                    (Code_Unit_32'Value
                      ("16#" & Buffer (First + 2 .. Plus - 1) & '#'),
                     Code_Unit_32'Value
                      ("16#" & Buffer (Plus + 1 .. Tab - 1) & '#'));
                  Double_Map (High_Code) (Low_Code) := Last_Expansion;
               end if;
            end if;
         end if;
      end if;
   end loop;

   Ada.Text_IO.Close (File);

   --  Analysis

   for J in Double_Map'Range loop
      if Double_Map (J) /= null then
         for K in Double_Map (J)'Range loop
            if Double_Map (J) (K) /= Undefined then
               Valid_Second (K) := True;
            end if;
         end loop;
      end if;
   end loop;

   --  Generation

   Ada.Text_IO.Put_Line
    ("-----------------------------------------------------------------------"
       & "-------");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                            Matreshka Project                        "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--         Localization, Internationalization, Globalization for Ada   "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                        Runtime Library Component                    "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-----------------------------------------------------------------------"
       & "-------");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- Copyright © 2010, Vadim Godunko <vgodunko@gmail.com>                "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- All rights reserved.                                                "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- Redistribution and use in source and binary forms, with or without  "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- modification, are permitted provided that the following conditions  "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- are met:                                                            "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--  * Redistributions of source code must retain the above copyright   "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--    notice, this list of conditions and the following disclaimer.    "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--  * Redistributions in binary form must reproduce the above copyright"
       & "     --");
   Ada.Text_IO.Put_Line
    ("--    notice, this list of conditions and the following disclaimer in t"
       & "he   --");
   Ada.Text_IO.Put_Line
    ("--    documentation and/or other materials provided with the distributi"
       & "on.  --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--  * Neither the name of the Vadim Godunko, IE nor the names of its   "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--    contributors may be used to endorse or promote products derived f"
       & "rom  --");
   Ada.Text_IO.Put_Line
    ("--    this software without specific prior written permission.         "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- ""AS IS"" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "
       & "       --");
   Ada.Text_IO.Put_Line
    ("-- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FO"
       & "R    --");
   Ada.Text_IO.Put_Line
    ("-- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT"
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTA"
       & "L,   --");
   Ada.Text_IO.Put_Line
    ("-- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIM"
       & "ITED --");
   Ada.Text_IO.Put_Line
    ("-- TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, "
       & "OR   --");
   Ada.Text_IO.Put_Line
    ("-- PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY "
       & "OF   --");
   Ada.Text_IO.Put_Line
    ("-- LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING"
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS  "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.        "
       & "     --");
   Ada.Text_IO.Put_Line
    ("--                                                                     "
       & "     --");
   Ada.Text_IO.Put_Line
    ("-----------------------------------------------------------------------"
       & "-------");
   Ada.Text_IO.Put_Line
    ("--  $Revision: 1060 $ $Date: 2010-11-01 00:17:01 +0300 (Пн, 01 ноя 2010) $");
   Ada.Text_IO.Put_Line
    ("-----------------------------------------------------------------------"
       & "-------");
   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line
    ("private package Matreshka.Internals.Text_Codecs.SHIFTJIS.Tables is");
   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("   pragma Preelaborate;");

   --  Generate meta class table
   --
   --  0 - Single/Valid
   --  1 - Single/Invalid
   --  2 - First/Valid
   --  3 - First/Invalid
   --  4 - Invalid/Valid
   --  5 - Invalid/Invalid

   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("   Meta_Class :");
   Ada.Text_IO.Put_Line ("     constant array (Ada.Streams.Stream_Element)");
   Ada.Text_IO.Put_Line ("       of SHIFTJIS_Meta_Class");
   Ada.Text_IO.Put ("         := (");

   for J in Single_Map'Range loop
      if Single_Map (J) = Undefined or Single_Map (J) = Reserved then
         if Valid_Second (J) then
            Ada.Text_IO.Put ("4");

         else
            Ada.Text_IO.Put ("5");
         end if;

      elsif Single_Map (J) = Double_Bytes then
         if Valid_Second (J) then
            Ada.Text_IO.Put ("2");

         else
            Ada.Text_IO.Put ("3");
         end if;

      else
         if Valid_Second (J) then
            Ada.Text_IO.Put ("0");

         else
            Ada.Text_IO.Put ("1");
         end if;
      end if;

      if J = 255 then
         Ada.Text_IO.Put_Line (");");

      elsif J mod 16 = 15 then
         Ada.Text_IO.Put_Line (",");
         Ada.Text_IO.Put ("             ");

      else
         Ada.Text_IO.Put (", ");
      end if;
   end loop;

   --  Generate single byte conversion table

   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("   Decode_Single :");
   Ada.Text_IO.Put_Line ("     constant array (Ada.Streams.Stream_Element)");
   Ada.Text_IO.Put_Line ("       of Matreshka.Internals.Unicode.Code_Point");
   Ada.Text_IO.Put ("         := (");

   for J in Single_Map'Range loop
      if Single_Map (J) = Undefined
        or Single_Map (J) = Reserved
        or Single_Map (J) = Double_Bytes
      then
         Ada.Text_IO.Put ("16#0000#");

      else
         Ada.Text_IO.Put ("16#" & Image (Single_Map (J)) & '#');
      end if;

      if J = 255 then
         Ada.Text_IO.Put_Line (");");

      elsif J mod 4 = 3 then
         Ada.Text_IO.Put_Line (",");
         Ada.Text_IO.Put ("             ");

      else
         Ada.Text_IO.Put (", ");
      end if;
   end loop;

   --  Generate secondary tables for double byte conversion

   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("   Decode_Double_Invalid : aliased constant SHIFTJIS_Code_Point_Array");
   Ada.Text_IO.Put_Line ("     := (16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#,");
   Ada.Text_IO.Put_Line ("         16#0000#, 16#0000#, 16#0000#, 16#0000#);");

   for J in Double_Map'Range loop
      if Double_Map (J) /= null then
         Ada.Text_IO.New_Line;
         Ada.Text_IO.Put_Line
          ("   Decode_Double_"
             & Image (J)
             & " : aliased constant SHIFTJIS_Code_Point_Array");
         Ada.Text_IO.Put ("     := (");

         for K in Double_Map (J)'Range loop
            if Double_Map (J) (K) = Undefined
              or Double_Map (J) (K) = Reserved
            then
               Ada.Text_IO.Put ("16#0000#");

            elsif Double_Map (J) (K) >= First_Expansion then
               Ada.Text_IO.Put
                ("16#"
                   & Image (Double_Map (J) (K) - First_Expansion + 1)
                   & '#');

            else
               Ada.Text_IO.Put ("16#" & Image (Double_Map (J) (K)) & '#');
            end if;

            if K = 255 then
               Ada.Text_IO.Put_Line (");");

            elsif K mod 4 = 3 then
               Ada.Text_IO.Put_Line (",");
               Ada.Text_IO.Put ("         ");

            else
               Ada.Text_IO.Put (", ");
            end if;
         end loop;
      end if;
   end loop;

   --  Generate double byte encoding table

   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("   Decode_Double :");
   Ada.Text_IO.Put_Line ("     constant array (Ada.Streams.Stream_Element)");
   Ada.Text_IO.Put_Line ("       of not null SHIFTJIS_Code_Point_Array_Access");
   Ada.Text_IO.Put ("         := (");

   for J in Double_Map'Range loop
      if Double_Map (J) /= null then
          Ada.Text_IO.Put ("Decode_Double_" & Image (J) & "'Access");

      else
          Ada.Text_IO.Put ("Decode_Double_Invalid'Access");
      end if;

      if J = 255 then
         Ada.Text_IO.Put_Line (");");

      elsif J mod 2 = 1 then
         Ada.Text_IO.Put_Line (",");
         Ada.Text_IO.Put ("             ");

      else
         Ada.Text_IO.Put (", ");
      end if;
   end loop;

   --  Generate expansion table

   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line ("   Expansion :");
   Ada.Text_IO.Put_Line
    ("     constant array (Matreshka.Internals.Unicode.Code_Unit_32 range 1 .."
       & Code_Unit_32'Image (Last_Expansion - First_Expansion + 1)
       & ")");
   Ada.Text_IO.Put_Line ("       of SHIFTJIS_Expansion_Pair");
   Ada.Text_IO.Put ("         := (");

   for J in First_Expansion .. Last_Expansion loop
      Ada.Text_IO.Put
       ("(16#"
          & Image (Expansion_List (J).First)
          & "#, 16#"
          & Image (Expansion_List (J).Second)
          & "#)");

      if J = Last_Expansion then
         Ada.Text_IO.Put_Line (");");

      elsif J mod 2 = 1 then
         Ada.Text_IO.Put_Line (",");
         Ada.Text_IO.Put ("             ");

      else
         Ada.Text_IO.Put (", ");
      end if;
   end loop;

   Ada.Text_IO.New_Line;
   Ada.Text_IO.Put_Line
    ("end Matreshka.Internals.Text_Codecs.SHIFTJIS.Tables;");
end Gen_SHIFTJIS;