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, write to the Free Software Foundation, Inc., 51 Franklin Street, 18 * Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 21/* Part 2 of iconv_open. 22 Input: 23 struct conv_struct * cd; 24 unsigned int from_index; 25 int from_wchar; 26 unsigned int to_index; 27 int to_wchar; 28 int transliterate; 29 int discard_ilseq; 30 Output: none. 31 Side effects: Fills cd. 32 */ 33 34 cd->iindex = from_index; 35 cd->ifuncs = all_encodings[from_index].ifuncs; 36 cd->oindex = to_index; 37 cd->ofuncs = all_encodings[to_index].ofuncs; 38 cd->oflags = all_encodings[to_index].oflags; 39 /* Initialize the loop functions. */ 40#if HAVE_MBRTOWC 41 if (to_wchar) { 42#if HAVE_WCRTOMB 43 if (from_wchar) { 44 cd->lfuncs.loop_convert = wchar_id_loop_convert; 45 cd->lfuncs.loop_reset = wchar_id_loop_reset; 46 } else 47#endif 48 { 49 cd->lfuncs.loop_convert = wchar_to_loop_convert; 50 cd->lfuncs.loop_reset = wchar_to_loop_reset; 51 } 52 } else 53#endif 54 { 55#if HAVE_WCRTOMB 56 if (from_wchar) { 57 cd->lfuncs.loop_convert = wchar_from_loop_convert; 58 cd->lfuncs.loop_reset = wchar_from_loop_reset; 59 } else 60#endif 61 { 62 cd->lfuncs.loop_convert = unicode_loop_convert; 63 cd->lfuncs.loop_reset = unicode_loop_reset; 64 } 65 } 66 /* Initialize the states. */ 67 memset(&cd->istate,'\0',sizeof(state_t)); 68 memset(&cd->ostate,'\0',sizeof(state_t)); 69 /* Initialize the operation flags. */ 70 cd->transliterate = transliterate; 71 cd->discard_ilseq = discard_ilseq; 72 #ifndef LIBICONV_PLUG 73 cd->fallbacks.mb_to_uc_fallback = NULL; 74 cd->fallbacks.uc_to_mb_fallback = NULL; 75 cd->fallbacks.mb_to_wc_fallback = NULL; 76 cd->fallbacks.wc_to_mb_fallback = NULL; 77 cd->fallbacks.data = NULL; 78 cd->hooks.uc_hook = NULL; 79 cd->hooks.wc_hook = NULL; 80 cd->hooks.data = NULL; 81 #endif 82 /* Initialize additional fields. */ 83 if (from_wchar != to_wchar) { 84 struct wchar_conv_struct * wcd = (struct wchar_conv_struct *) cd; 85#if HAVE_WCRTOMB || HAVE_MBRTOWC 86 memset(&wcd->state,'\0',sizeof(mbstate_t)); 87#endif 88 } 89 /* Done. */ 90