iconv_open2.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. /* 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. cd->iindex = from_index;
  33. cd->ifuncs = all_encodings[from_index].ifuncs;
  34. cd->oindex = to_index;
  35. cd->ofuncs = all_encodings[to_index].ofuncs;
  36. cd->oflags = all_encodings[to_index].oflags;
  37. /* Initialize the loop functions. */
  38. #if HAVE_MBRTOWC
  39. if (to_wchar) {
  40. #if HAVE_WCRTOMB
  41. if (from_wchar) {
  42. cd->lfuncs.loop_convert = wchar_id_loop_convert;
  43. cd->lfuncs.loop_reset = wchar_id_loop_reset;
  44. } else
  45. #endif
  46. {
  47. cd->lfuncs.loop_convert = wchar_to_loop_convert;
  48. cd->lfuncs.loop_reset = wchar_to_loop_reset;
  49. }
  50. } else
  51. #endif
  52. {
  53. #if HAVE_WCRTOMB
  54. if (from_wchar) {
  55. cd->lfuncs.loop_convert = wchar_from_loop_convert;
  56. cd->lfuncs.loop_reset = wchar_from_loop_reset;
  57. } else
  58. #endif
  59. {
  60. cd->lfuncs.loop_convert = unicode_loop_convert;
  61. cd->lfuncs.loop_reset = unicode_loop_reset;
  62. }
  63. }
  64. /* Initialize the states. */
  65. memset(&cd->istate,'\0',sizeof(state_t));
  66. memset(&cd->ostate,'\0',sizeof(state_t));
  67. /* Initialize the operation flags. */
  68. cd->transliterate = transliterate;
  69. cd->discard_ilseq = discard_ilseq;
  70. #ifndef LIBICONV_PLUG
  71. cd->fallbacks.mb_to_uc_fallback = NULL;
  72. cd->fallbacks.uc_to_mb_fallback = NULL;
  73. cd->fallbacks.mb_to_wc_fallback = NULL;
  74. cd->fallbacks.wc_to_mb_fallback = NULL;
  75. cd->fallbacks.data = NULL;
  76. cd->hooks.uc_hook = NULL;
  77. cd->hooks.wc_hook = NULL;
  78. cd->hooks.data = NULL;
  79. #endif
  80. /* Initialize additional fields. */
  81. if (from_wchar != to_wchar) {
  82. struct wchar_conv_struct * wcd = (struct wchar_conv_struct *) cd;
  83. #if HAVE_WCRTOMB || HAVE_MBRTOWC
  84. memset(&wcd->state,'\0',sizeof(mbstate_t));
  85. #endif
  86. }
  87. /* Done. */