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