aboutsummaryrefslogtreecommitdiff
path: root/iconvdata/iso646.c
blob: c0002ee202be3a7ff1036f4ce5619b504bcd0edb (plain)
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
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
/* Conversion to and from the various ISO 646 CCS.
   Copyright (C) 1998, 1999, 2000-2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, see
   <http://www.gnu.org/licenses/>.  */

/* The implementation of the conversion which can be performed by this
   module are not very sophisticated and not tuned at all.  There are
   zillions of ISO 646 derivates and supporting them all in a separate
   module is overkill since these coded character sets are hardly ever
   used anymore (except ANSI_X3.4-1968 == ASCII, which is compatible
   with ISO 8859-1).  The European variants are superceded by the
   various ISO 8859-? standards and the Asian variants are embedded in
   larger character sets.  Therefore this implementation is simply
   here to make it possible to do the conversion if it is necessary.
   The cost in the gconv-modules file is set to `2' and therefore
   allows one to easily provide a tuned implementation in case this
   proofs to be necessary.  */

#include <dlfcn.h>
#include <gconv.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

/* Definitions used in the body of the `gconv' function.  */
#define FROM_LOOP		from_ascii
#define TO_LOOP			to_ascii
#define DEFINE_INIT		0
#define DEFINE_FINI		0
#define MIN_NEEDED_FROM		1
#define MIN_NEEDED_TO		4
#define FROM_DIRECTION		(dir == from_iso646)
#define PREPARE_LOOP \
  enum direction dir = ((struct iso646_data *) step->__data)->dir;	      \
  enum variant var = ((struct iso646_data *) step->__data)->var;
#define EXTRA_LOOP_ARGS		, var


/* Direction of the transformation.  */
enum direction
{
  illegal_dir,
  to_iso646,
  from_iso646
};

enum variant
{
  illegal_var,
  GB,		/* BS_4730 */
  CA,		/* CSA_Z243.4-1985-1 */
  CA2,		/* CSA_Z243.4-1985-2 */
  DE,		/* DIN_66003 */
  DK,		/* DS_2089 */
  ES,		/* ES */
  ES2,		/* ES2 */
  CN,		/* GB_1988-80 */
  IT,		/* IT */
  JP,		/* JIS_C6220-1969-RO */
  JP_OCR_B,	/* JIS_C6229-1984-B */
  YU,		/* JUS_I.B1.002 */
  KR,		/* KSC5636 */
  HU,		/* MSZ_7795.3 */
  CU,		/* NC_NC00-10 */
  FR,		/* NF_Z_62-010 */
  FR1,		/* NF_Z_62-010_(1973) */
  NO,		/* NS_4551-1 */
  NO2,		/* NS_4551-2 */
  PT,		/* PT */
  PT2,		/* PT2 */
  SE,		/* SEN_850200_B */
  SE2		/* SEN_850200_C */
};

static const char *names[] =
{
  [GB] = "BS_4730//",
  [CA] = "CSA_Z243.4-1985-1//",
  [CA2] = "CSA_Z243.4-1985-2//",
  [DE] = "DIN_66003//",
  [DK] = "DS_2089//",
  [ES] = "ES//",
  [ES2] = "ES2//",
  [CN] = "GB_1988-80//",
  [IT] = "IT//",
  [JP] = "JIS_C6220-1969-RO//",
  [JP_OCR_B] = "JIS_C6229-1984-B//",
  [YU] = "JUS_I.B1.002//",
  [KR] = "KSC5636//",
  [HU] = "MSZ_7795.3//",
  [CU] = "NC_NC00-10//",
  [FR] = "NF_Z_62-010//",
  [FR1] = "NF_Z_62-010_1973//",	/* Note that we don't have the parenthesis
				   in the name.  */
  [NO] = "NS_4551-1//",
  [NO2] = "NS_4551-2//",
  [PT] = "PT//",
  [PT2] = "PT2//",
  [SE] = "SEN_850200_B//",
  [SE2] = "SEN_850200_C//"
};

struct iso646_data
{
  enum direction dir;
  enum variant var;
};


extern int gconv_init (struct __gconv_step *step);
int
gconv_init (struct __gconv_step *step)
{
  /* Determine which direction.  */
  struct iso646_data *new_data;
  enum direction dir = illegal_dir;
  enum variant var;
  int result;

  for (var = sizeof (names) / sizeof (names[0]) - 1; var > illegal_var; --var)
    if (__strcasecmp (step->__from_name, names[var]) == 0)
      {
	dir = from_iso646;
	break;
      }
    else if (__strcasecmp (step->__to_name, names[var]) == 0)
      {
	dir = to_iso646;
	break;
      }

  result = __GCONV_NOCONV;
  if (__builtin_expect (dir, from_iso646) != illegal_dir)
    {
      new_data = (struct iso646_data *) malloc (sizeof (struct iso646_data));

      result = __GCONV_NOMEM;
      if (new_data != NULL)
	{
	  new_data->dir = dir;
	  new_data->var = var;
	  step->__data = new_data;

	  if (dir == from_iso646)
	    {
	      step->__min_needed_from = MIN_NEEDED_FROM;
	      step->__max_needed_from = MIN_NEEDED_FROM;
	      step->__min_needed_to = MIN_NEEDED_TO;
	      step->__max_needed_to = MIN_NEEDED_TO;
	    }
	  else
	    {
	      step->__min_needed_from = MIN_NEEDED_TO;
	      step->__max_needed_from = MIN_NEEDED_TO;
	      step->__min_needed_to = MIN_NEEDED_FROM;
	      step->__max_needed_to = MIN_NEEDED_FROM;
	    }

	  step->__stateful = 0;

	  result = __GCONV_OK;
	}
    }

  return result;
}


extern void gconv_end (struct __gconv_step *data);
void
gconv_end (struct __gconv_step *data)
{
  free (data->__data);
}


/* First define the conversion function from ASCII to UCS4.  */
#define MIN_NEEDED_INPUT	MIN_NEEDED_FROM
#define MIN_NEEDED_OUTPUT	MIN_NEEDED_TO
#define LOOPFCT			FROM_LOOP
#define BODY \
  {									      \
    uint32_t ch;							      \
    int failure = __GCONV_OK;						      \
									      \
    ch = *inptr;							      \
    switch (ch)								      \
      {									      \
      case 0x23:							      \
	if (var == GB || var == ES || var == IT || var == FR || var == FR1)   \
	  ch = 0xa3;							      \
	else if (var == NO2)						      \
	  ch = 0xa7;							      \
	break;								      \
      case 0x24:							      \
	if (var == CN)							      \
	  ch = 0xa5;							      \
	else if (var == HU || var == CU || var == SE || var == SE2)	      \
	  ch = 0xa4;							      \
	break;								      \
      case 0x40:							      \
	if (var == CA || var == CA2 || var == FR || var == FR1)		      \
	  ch = 0xe0;							      \
	else if (var == DE || var == ES || var == IT || var == PT)	      \
	  ch = 0xa7;							      \
	else if (var == ES2)						      \
	  ch = 0x2022;							      \
	else if (var == YU)						      \
	  ch = 0x17d;							      \
	else if (var == HU)						      \
	  ch = 0xc1;							      \
	else if (var == PT2)						      \
	  ch = 0xb4;							      \
	else if (var == SE2)						      \
	  ch = 0xc9;							      \
	break;								      \
      case 0x5b:							      \
	if (var == CA || var == CA2)					      \
	  ch = 0xe2;							      \
	else if (var == DE || var == SE || var == SE2)			      \
	  ch = 0xc4;							      \
	else if (var == DK || var == NO || var == NO2)			      \
	  ch = 0xc6;							      \
	else if (var == ES || var == ES2 || var == CU)			      \
	  ch = 0xa1;							      \
	else if (var == IT || var == FR || var == FR1)			      \
	  ch = 0xb0;							      \
	else if (var == JP_OCR_B)					      \
	  ch = 0x2329;							      \
	else if (var == YU)						      \
	  ch = 0x160;							      \
	else if (var == HU)						      \
	  ch = 0xc9;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0xc3;							      \
	break;								      \
      case 0x5c:							      \
	if (var == CA || var == CA2 || var == IT || var == FR || var == FR1)  \
	  ch = 0xe7;							      \
	else if (var == DE || var == HU || var == SE || var == SE2)	      \
	  ch = 0xd6;							      \
	else if (var == DK || var == NO || var == NO2)			      \
	  ch = 0xd8;							      \
	else if (var == ES || var == ES2 || var == CU)			      \
	  ch = 0xd1;							      \
	else if (var == JP || var == JP_OCR_B)				      \
	  ch = 0xa5;							      \
	else if (var == YU)						      \
	  ch = 0x110;							      \
	else if (var == KR)						      \
	  ch = 0x20a9;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0xc7;							      \
	break;								      \
      case 0x5d:							      \
	if (var == CA || var == CA2)					      \
	  ch = 0xea;							      \
	else if (var == DE || var == HU)				      \
	  ch = 0xdc;							      \
	else if (var == DK || var == NO || var == NO2 || var == SE	      \
		 || var == SE2)						      \
	  ch = 0xc5;							      \
	else if (var == ES)						      \
	  ch = 0xbf;							      \
	else if (var == ES2)						      \
	  ch = 0xc7;							      \
	else if (var == IT)						      \
	  ch = 0xe9;							      \
	else if (var == JP_OCR_B)					      \
	  ch = 0x232a;							      \
	else if (var == YU)						      \
	  ch = 0x106;							      \
	else if (var == FR || var == FR1)				      \
	  ch = 0xa7;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0xd5;							      \
	break;								      \
      case 0x5e:							      \
	if (var == CA)							      \
	  ch = 0xee;							      \
	else if (var == CA2)						      \
	  ch = 0xc9;							      \
	else if (var == ES2 || var == CU)				      \
	  ch = 0xbf;							      \
	else if (var == YU)						      \
	  ch = 0x10c;							      \
	else if (var == SE2)						      \
	  ch = 0xdc;							      \
	break;								      \
      case 0x60:							      \
	if (var == CA || var == CA2)					      \
	  ch = 0xf4;							      \
	else if (var == IT)						      \
	  ch = 0xf9;							      \
	else if (var == JP_OCR_B)					      \
	  /* Illegal character.  */					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	else if (var == YU)						      \
	  ch = 0x17e;							      \
	else if (var == HU)						      \
	  ch = 0xe1;							      \
	else if (var == FR)						      \
	  ch = 0xb5;							      \
	else if (var == SE2)						      \
	  ch = 0xe9;							      \
	break;								      \
      case 0x7b:							      \
	if (var == CA || var == CA2 || var == HU || var == FR || var == FR1)  \
	  ch = 0xe9;							      \
	else if (var == DE || var == SE || var == SE2)			      \
	  ch = 0xe4;							      \
	else if (var == DK || var == NO || var == NO2)			      \
	  ch = 0xe6;							      \
	else if (var == ES)						      \
	  ch = 0xb0;							      \
	else if (var == ES2 || var == CU)				      \
	  ch = 0xb4;							      \
	else if (var == IT)						      \
	  ch = 0xe0;							      \
	else if (var == YU)						      \
	  ch = 0x161;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0xe3;							      \
	break;								      \
      case 0x7c:							      \
	if (var == CA || var == CA2 || var == FR || var == FR1)		      \
	  ch = 0xf9;							      \
	else if (var == DE || var == HU || var == SE || var == SE2)	      \
	  ch = 0xf6;							      \
	else if (var == DK || var == NO || var == NO2)			      \
	  ch = 0xf8;							      \
	else if (var == ES || var == ES2 || var == CU)			      \
	  ch = 0xf1;							      \
	else if (var == IT)						      \
	  ch = 0xf2;							      \
	else if (var == YU)						      \
	  ch = 0x111;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0xe7;							      \
	break;								      \
      case 0x7d:							      \
	if (var == CA || var == CA2 || var == IT || var == FR || var == FR1)  \
	  ch = 0xe8;							      \
	else if (var == DE || var == HU)				      \
	  ch = 0xfc;							      \
	else if (var == DK || var == NO || var == NO2 || var == SE	      \
		 || var == SE2)						      \
	  ch = 0xe5;							      \
	else if (var == ES || var == ES2)				      \
	  ch = 0xe7;							      \
	else if (var == YU)						      \
	  ch = 0x107;							      \
	else if (var == CU)						      \
	  ch = 0x5b;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0xf5;							      \
	break;								      \
      case 0x7e:							      \
	if (var == GB || var == CN || var == JP || var == NO || var == SE)    \
	  ch = 0x203e;							      \
	else if (var == CA || var == CA2)				      \
	  ch = 0xfb;							      \
	else if (var == DE)						      \
	  ch = 0xdf;							      \
	else if (var == ES2 || var == CU || var == FR || var == FR1)	      \
	  ch = 0xa8;							      \
	else if (var == IT)						      \
	  ch = 0xec;							      \
	else if (var == JP_OCR_B)					      \
	  /* Illegal character.  */					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	else if (var == YU)						      \
	  ch = 0x10d;							      \
	else if (var == HU)						      \
	  ch = 0x2dd;							      \
	else if (var == NO2)						      \
	  ch = 0x7c;							      \
	else if (var == PT)						      \
	  ch = 0xb0;							      \
	else if (var == SE2)						      \
	  ch = 0xfc;							      \
	break;								      \
      default:								      \
	break;								      \
      case 0x80 ... 0xff:						      \
	/* Illegal character.  */					      \
	failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      }									      \
									      \
    /* Hopefully gcc can recognize that the following `if' is only true	      \
       when we reach the default case in the `switch' statement.  */	      \
    if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT)      \
      {									      \
	STANDARD_FROM_LOOP_ERR_HANDLER (1);				      \
      }									      \
    else								      \
      {									      \
	put32 (outptr, ch);						      \
	outptr += 4;							      \
      }									      \
    ++inptr;								      \
  }
#define LOOP_NEED_FLAGS
#define EXTRA_LOOP_DECLS	, enum variant var
#include <iconv/loop.c>


/* Next, define the other direction.  */
#define MIN_NEEDED_INPUT	MIN_NEEDED_TO
#define MIN_NEEDED_OUTPUT	MIN_NEEDED_FROM
#define LOOPFCT			TO_LOOP
#define BODY \
  {									      \
    unsigned int ch;							      \
    int failure = __GCONV_OK;						      \
									      \
    ch = get32 (inptr);							      \
    switch (ch)								      \
      {									      \
      case 0x23:							      \
	if (var == GB || var == ES || var == IT || var == FR || var == FR1    \
	    || var == NO2)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x24:							      \
	if (var == CN || var == HU || var == CU || var == SE || var == SE2)   \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x40:							      \
	if (var == CA || var == CA2 || var == DE || var == ES || var == ES2   \
	    || var == IT || var == YU || var == HU || var == FR || var == FR1 \
	    || var == PT || var == PT2 || var == SE2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x5b:							      \
	if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
	    || var == ES2 || var == IT || var == JP_OCR_B || var == YU	      \
	    || var == HU || var == FR || var == FR1 || var == NO	      \
	    || var == NO2 || var == PT || var == PT2 || var == SE	      \
	    || var == SE2)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	else if (var == CU)						      \
	  ch = 0x7d;							      \
	break;								      \
      case 0x5c:							      \
	if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
	    || var == ES2 || var == IT || var == JP || var == JP_OCR_B	      \
	    || var == YU || var == KR || var == HU || var == CU || var == FR  \
	    || var == FR1 || var == NO || var == NO2 || var == PT	      \
	    || var == PT2 || var == SE || var == SE2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x5d:							      \
	if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
	    || var == ES2 || var == IT || var == JP_OCR_B || var == YU	      \
	    || var == HU || var == FR || var == FR1 || var == NO	      \
	    || var == NO2 || var == PT || var == PT2 || var == SE	      \
	    || var == SE2)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x5e:							      \
	if (var == CA || var == CA2 || var == ES2 || var == YU || var == CU   \
	    || var == SE2)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x60:							      \
	if (var == CA || var == CA2 || var == IT || var == JP_OCR_B	      \
	    || var == YU || var == HU || var == FR || var == SE2)	      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x7b:							      \
	if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
	    || var == ES2 || var == IT || var == YU || var == HU	      \
	    || var == CU || var == FR || var == FR1 || var == NO	      \
	    || var == NO2 || var == PT || var == PT2 || var == SE	      \
	    || var == SE2)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x7c:							      \
	if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
	    || var == ES2 || var == IT || var == YU || var == HU || var == CU \
	    || var == FR || var == FR1 || var == NO || var == PT	      \
	    || var == PT2 || var == SE || var == SE2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	else if (var == NO2)						      \
	  ch = 0x7e;							      \
	break;								      \
      case 0x7d:							      \
	if (var == CA || var == CA2 || var == DE || var == DK || var == ES    \
	    || var == ES2 || var == IT || var == YU || var == HU || var == CU \
	    || var == FR || var == FR1 || var == NO || var == NO2	      \
	    || var == PT || var == PT2 || var == SE || var == SE2)	      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x7e:							      \
	if (var == GB || var == CA || var == CA2 || var == DE || var == ES2   \
	    || var == CN || var == IT || var == JP || var == JP_OCR_B	      \
	    || var == YU || var == HU || var == CU || var == FR || var == FR1 \
	    || var == NO || var == NO2 || var == PT || var == SE	      \
	    || var == SE2)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xa1:							      \
	if (var != ES && var != ES2 && var != CU)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0xa3:							      \
	if (var != GB && var != ES && var != IT && var != FR && var != FR1)   \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x23;							      \
	break;								      \
      case 0xa4:							      \
	if (var != HU && var != CU && var != SE && var != SE2)		      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x24;							      \
	break;								      \
      case 0xa5:							      \
	if (var == CN)							      \
	  ch = 0x24;							      \
	else if (var == JP || var == JP_OCR_B)				      \
	  ch = 0x5c;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xa7:							      \
	if (var == DE || var == ES || var == IT || var == PT)		      \
	  ch = 0x40;							      \
	else if (var == FR || var == FR1)				      \
	  ch = 0x5d;							      \
	else if (var == NO2)						      \
	  ch = 0x23;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xa8:							      \
	if (var != ES2 && var != CU && var != FR && var != FR1)		      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0xb0:							      \
	if (var == ES)							      \
	  ch = 0x7b;							      \
	else if (var == IT || var == FR || var == FR1)			      \
	  ch = 0x5b;							      \
	else if (var == PT)						      \
	  ch = 0x7e;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xb4:							      \
	if (var == ES2 || var == CU)					      \
	  ch = 0x7b;							      \
	else if (var == PT2)						      \
	  ch = 0x40;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xb5:							      \
	if (var != FR)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x60;							      \
	break;								      \
      case 0xbf:							      \
	if (var == ES)							      \
	  ch = 0x5d;							      \
	else if (var == ES2 || var == CU)				      \
	  ch = 0x5e;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xc1:							      \
	if (var != HU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x40;							      \
	break;								      \
      case 0xc3:							      \
	if (var != PT && var != PT2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0xc4:							      \
	if (var != DE && var != SE && var != SE2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0xc5:							      \
	if (var != DK && var != NO && var != NO2 && var != SE && var != SE2)  \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5d;							      \
	break;								      \
      case 0xc6:							      \
	if (var != DK && var != NO && var != NO2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0xc7:							      \
	if (var == ES2)							      \
	  ch = 0x5d;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0x5c;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xc9:							      \
	if (var == CA2)							      \
	  ch = 0x5e;							      \
	else if (var == HU)						      \
	  ch = 0x5b;							      \
	else if (var == SE2)						      \
	  ch = 0x40;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xd1:							      \
	if (var != ES && var != ES2 && var != CU)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5c;							      \
	break;								      \
      case 0xd5:							      \
	if (var != PT && var != PT2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5d;							      \
	break;								      \
      case 0xd6:							      \
	if (var != DE && var != HU && var != SE && var != SE2)		      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5c;							      \
	break;								      \
      case 0xd8:							      \
	if (var != DK && var != NO && var != NO2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5c;							      \
	break;								      \
      case 0xdc:							      \
	if (var == DE || var == HU)					      \
	  ch = 0x5d;							      \
	else if (var == SE2)						      \
	  ch = 0x5e;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xdf:							      \
	if (var != DE)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0xe0:							      \
	if (var == CA || var == CA2 || var == FR || var == FR1)		      \
	  ch = 0x40;							      \
	else if (var == IT)						      \
	  ch = 0x7b;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xe1:							      \
	if (var != HU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x60;							      \
	break;								      \
      case 0xe2:							      \
	if (var != CA && var != CA2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0xe3:							      \
	if (var != PT && var != PT2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7b;							      \
	break;								      \
      case 0xe4:							      \
	if (var != DE && var != SE && var != SE2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7b;							      \
	break;								      \
      case 0xe5:							      \
	if (var != DK && var != NO && var != NO2 && var != SE && var != SE2)  \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7d;							      \
	break;								      \
      case 0xe6:							      \
	if (var != DK && var != NO && var != NO2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7b;							      \
	break;								      \
      case 0xe7:							      \
	if (var == CA || var == CA2 || var == IT || var == FR || var == FR1)  \
	  ch = 0x5c;							      \
	else if (var == ES || var == ES2)				      \
	  ch = 0x7d;							      \
	else if (var == PT || var == PT2)				      \
	  ch = 0x7c;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xe8:							      \
	if (var != CA && var != CA2 && var != IT && var != FR && var != FR1)  \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7d;							      \
	break;								      \
      case 0xe9:							      \
	if (var == CA || var == CA2 || var == HU || var == FR || var == FR1)  \
	  ch = 0x7b;							      \
	else if (var == IT)						      \
	  ch = 0x5d;							      \
	else if (var == SE2)						      \
	  ch = 0x60;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xea:							      \
	if (var != CA && var != CA2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5d;							      \
	break;								      \
      case 0xec:							      \
	if (var != IT)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0xee:							      \
	if (var != CA)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5e;							      \
	break;								      \
      case 0xf1:							      \
	if (var != ES && var != ES2 && var != CU)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7c;							      \
	break;								      \
      case 0xf2:							      \
	if (var != IT)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7c;							      \
	break;								      \
      case 0xf4:							      \
	if (var != CA && var != CA2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x60;							      \
	break;								      \
      case 0xf5:							      \
	if (var != PT && var != PT2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7d;							      \
	break;								      \
      case 0xf6:							      \
	if (var != DE && var != HU && var != SE && var != SE2)		      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7c;							      \
	break;								      \
      case 0xf8:							      \
	if (var != DK && var != NO && var != NO2)			      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7c;							      \
	break;								      \
      case 0xf9:							      \
	if (var == CA || var == CA2 || var == FR || var == FR1)		      \
	  ch = 0x7c;							      \
	else if (var == IT)						      \
	  ch = 0x60;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0xfb:							      \
	if (var != CA && var != CA2)					      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0xfc:							      \
	if (var == DE || var == HU)					      \
	  ch = 0x7d;							      \
	else if (var == SE2)						      \
	  ch = 0x7e;							      \
	else								      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	break;								      \
      case 0x160:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0x106:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5d;							      \
	break;								      \
      case 0x107:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7d;							      \
	break;								      \
      case 0x10c:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5e;							      \
	break;								      \
      case 0x10d:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0x110:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5c;							      \
	break;								      \
      case 0x111:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7c;							      \
	break;								      \
      case 0x161:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7b;							      \
	break;								      \
      case 0x17d:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x40;							      \
	break;								      \
      case 0x17e:							      \
	if (var != YU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x60;							      \
	break;								      \
      case 0x2dd:							      \
	if (var != HU)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0x2022:							      \
	if (var != ES2)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x40;							      \
	break;								      \
      case 0x203e:							      \
	if (var != GB && var != CN && var != JP && var != NO && var != SE)    \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x7e;							      \
	break;								      \
      case 0x20a9:							      \
	if (var != KR)							      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5c;							      \
	break;								      \
      case 0x2329:							      \
	if (var != JP_OCR_B)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5b;							      \
	break;								      \
      case 0x232a:							      \
	if (var != JP_OCR_B)						      \
	  failure = __GCONV_ILLEGAL_INPUT;				      \
	ch = 0x5d;							      \
	break;								      \
      default:								      \
	if (__builtin_expect (ch > 0x7f, 0))				      \
	  {								      \
	    UNICODE_TAG_HANDLER (ch, 4);				      \
	    failure = __GCONV_ILLEGAL_INPUT;				      \
	  }								      \
	break;								      \
      }									      \
									      \
    if (__builtin_expect (failure, __GCONV_OK) == __GCONV_ILLEGAL_INPUT)      \
      {									      \
	STANDARD_TO_LOOP_ERR_HANDLER (4);				      \
      }									      \
									      \
    *outptr++ = (unsigned char) ch;					      \
    inptr += 4;								      \
  }
#define LOOP_NEED_FLAGS
#define EXTRA_LOOP_DECLS	, enum variant var
#include <iconv/loop.c>


/* Now define the toplevel functions.  */
#include <iconv/skeleton.c>