| 1 |
/* |
| 2 |
* Copyright (C) 1999-2009 Free Software Foundation, Inc. |
| 3 |
* This file is part of the GNU LIBICONV Library. |
| 4 |
* |
| 5 |
* The GNU LIBICONV Library is free software; you can redistribute it |
| 6 |
* and/or modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either version 2 |
| 8 |
* of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* The GNU LIBICONV Library is distributed in the hope that it will be |
| 11 |
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public |
| 16 |
* License along with the GNU LIBICONV Library; see the file COPYING.LIB. |
| 17 |
* If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* Part 2 of iconv_open. |
| 21 |
Input: |
| 22 |
struct conv_struct * cd; |
| 23 |
unsigned int from_index; |
| 24 |
int from_wchar; |
| 25 |
unsigned int to_index; |
| 26 |
int to_wchar; |
| 27 |
int transliterate; |
| 28 |
int discard_ilseq; |
| 29 |
Output: none. |
| 30 |
Side effects: Fills cd. |
| 31 |
*/ |
| 32 |
|
| 33 |
cd->iindex = from_index; |
| 34 |
cd->ifuncs = all_encodings[from_index].ifuncs; |
| 35 |
cd->oindex = to_index; |
| 36 |
cd->ofuncs = all_encodings[to_index].ofuncs; |
| 37 |
cd->oflags = all_encodings[to_index].oflags; |
| 38 |
/* Initialize the loop functions. */ |
| 39 |
#if HAVE_MBRTOWC |
| 40 |
if (to_wchar) { |
| 41 |
#if HAVE_WCRTOMB |
| 42 |
if (from_wchar) { |
| 43 |
cd->lfuncs.loop_convert = wchar_id_loop_convert; |
| 44 |
cd->lfuncs.loop_reset = wchar_id_loop_reset; |
| 45 |
} else |
| 46 |
#endif |
| 47 |
{ |
| 48 |
cd->lfuncs.loop_convert = wchar_to_loop_convert; |
| 49 |
cd->lfuncs.loop_reset = wchar_to_loop_reset; |
| 50 |
} |
| 51 |
} else |
| 52 |
#endif |
| 53 |
{ |
| 54 |
#if HAVE_WCRTOMB |
| 55 |
if (from_wchar) { |
| 56 |
cd->lfuncs.loop_convert = wchar_from_loop_convert; |
| 57 |
cd->lfuncs.loop_reset = wchar_from_loop_reset; |
| 58 |
} else |
| 59 |
#endif |
| 60 |
{ |
| 61 |
cd->lfuncs.loop_convert = unicode_loop_convert; |
| 62 |
cd->lfuncs.loop_reset = unicode_loop_reset; |
| 63 |
} |
| 64 |
} |
| 65 |
/* Initialize the states. */ |
| 66 |
memset(&cd->istate,'\0',sizeof(state_t)); |
| 67 |
memset(&cd->ostate,'\0',sizeof(state_t)); |
| 68 |
/* Initialize the operation flags. */ |
| 69 |
cd->transliterate = transliterate; |
| 70 |
cd->discard_ilseq = discard_ilseq; |
| 71 |
#ifndef LIBICONV_PLUG |
| 72 |
cd->fallbacks.mb_to_uc_fallback = NULL; |
| 73 |
cd->fallbacks.uc_to_mb_fallback = NULL; |
| 74 |
cd->fallbacks.mb_to_wc_fallback = NULL; |
| 75 |
cd->fallbacks.wc_to_mb_fallback = NULL; |
| 76 |
cd->fallbacks.data = NULL; |
| 77 |
cd->hooks.uc_hook = NULL; |
| 78 |
cd->hooks.wc_hook = NULL; |
| 79 |
cd->hooks.data = NULL; |
| 80 |
#endif |
| 81 |
/* Initialize additional fields. */ |
| 82 |
if (from_wchar != to_wchar) { |
| 83 |
struct wchar_conv_struct * wcd = (struct wchar_conv_struct *) cd; |
| 84 |
#if HAVE_WCRTOMB || HAVE_MBRTOWC |
| 85 |
memset(&wcd->state,'\0',sizeof(mbstate_t)); |
| 86 |
#endif |
| 87 |
} |
| 88 |
/* Done. */ |