iconv_open2.h 2.7 KB

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