1 /* Table for builtin transformation mapping.
2    Copyright (C) 1997-2022 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
4 
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Lesser General Public
7    License as published by the Free Software Foundation; either
8    version 2.1 of the License, or (at your option) any later version.
9 
10    The GNU C Library is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13    Lesser General Public License for more details.
14 
15    You should have received a copy of the GNU Lesser General Public
16    License along with the GNU C Library; if not, see
17    <https://www.gnu.org/licenses/>.  */
18 
19 #include <endian.h>
20 #include <limits.h>
21 #include <stdint.h>
22 #include <string.h>
23 
24 #include <gconv_int.h>
25 
26 #include <assert.h>
27 
28 
29 static const struct builtin_map
30 {
31   const char *name;
32   __gconv_fct fct;
33   __gconv_btowc_fct btowc_fct;
34 
35   int8_t min_needed_from;
36   int8_t max_needed_from;
37   int8_t min_needed_to;
38   int8_t max_needed_to;
39 
40 } map[] =
41 {
42 #define BUILTIN_TRANSFORMATION(From, To, Cost, Name, Fct, BtowcFct, \
43 			       MinF, MaxF, MinT, MaxT) \
44   {									      \
45     .name = Name,							      \
46     .fct = Fct,								      \
47     .btowc_fct = BtowcFct,						      \
48 									      \
49     .min_needed_from = MinF,						      \
50     .max_needed_from = MaxF,						      \
51     .min_needed_to = MinT,						      \
52     .max_needed_to = MaxT						      \
53   },
54 #define BUILTIN_ALIAS(From, To)
55 
56 #include <gconv_builtin.h>
57 };
58 
59 
60 void
__gconv_get_builtin_trans(const char * name,struct __gconv_step * step)61 __gconv_get_builtin_trans (const char *name, struct __gconv_step *step)
62 {
63   size_t cnt;
64 
65   for (cnt = 0; cnt < sizeof (map) / sizeof (map[0]); ++cnt)
66     if (strcmp (name, map[cnt].name) == 0)
67       break;
68 
69   assert (cnt < sizeof (map) / sizeof (map[0]));
70 
71   step->__fct = map[cnt].fct;
72   step->__btowc_fct = map[cnt].btowc_fct;
73   step->__init_fct = NULL;
74   step->__end_fct = NULL;
75   step->__shlib_handle = NULL;
76   step->__modname = NULL;
77 
78   step->__min_needed_from = map[cnt].min_needed_from;
79   step->__max_needed_from = map[cnt].max_needed_from;
80   step->__min_needed_to = map[cnt].min_needed_to;
81   step->__max_needed_to = map[cnt].max_needed_to;
82 
83   /* None of the builtin converters handles stateful encoding.  */
84   step->__stateful = 0;
85 }
86