Advertisement
Guest User

iconv.h

a guest
Jan 8th, 2012
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.31 KB | None | 0 0
  1. /* Copyright (C) 1999-2003, 2005-2006 Free Software Foundation, Inc.
  2.    This file is part of the GNU LIBICONV Library.
  3.  
  4.    The GNU LIBICONV Library is free software; you can redistribute it
  5.    and/or modify it under the terms of the GNU Library General Public
  6.    License as published by the Free Software Foundation; either version 2
  7.    of the License, or (at your option) any later version.
  8.  
  9.    The GNU LIBICONV Library is distributed in the hope that it will be
  10.    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public
  15.    License along with the GNU LIBICONV Library; see the file COPYING.LIB.
  16.    If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
  17.    Fifth Floor, Boston, MA 02110-1301, USA.  */
  18.  
  19. /* When installed, this file is called "iconv.h". */
  20.  
  21. #ifndef _LIBICONV_H
  22. #define _LIBICONV_H
  23.  
  24. #define _LIBICONV_VERSION 0x010B    /* version number: (major<<8) + minor */
  25. extern  int _libiconv_version; /* Likewise */
  26.  
  27. /* We would like to #include any system header file which could define
  28.    iconv_t, 1. in order to eliminate the risk that the user gets compilation
  29.    errors because some other system header file includes /usr/include/iconv.h
  30.    which defines iconv_t or declares iconv after this file, 2. when compiling
  31.    for LIBICONV_PLUG, we need the proper iconv_t type in order to produce
  32.    binary compatible code.
  33.    But gcc's #include_next is not portable. Thus, once libiconv's iconv.h
  34.    has been installed in /usr/local/include, there is no way any more to
  35.    include the original /usr/include/iconv.h. We simply have to get away
  36.    without it.
  37.    Ad 1. The risk that a system header file does
  38.    #include "iconv.h"  or  #include_next "iconv.h"
  39.    is small. They all do #include <iconv.h>.
  40.    Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It
  41.    has to be a scalar type because (iconv_t)(-1) is a possible return value
  42.    from iconv_open().) */
  43.  
  44. /* Define iconv_t ourselves. */
  45. #undef iconv_t
  46. #define iconv_t libiconv_t
  47. typedef void* iconv_t;
  48.  
  49. /* Get size_t declaration.
  50.    Get wchar_t declaration if it exists. */
  51. #include <stddef.h>
  52.  
  53. /* Get errno declaration and values. */
  54. #include <errno.h>
  55. /* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
  56.    have EILSEQ in a different header.  On these systems, define EILSEQ
  57.    ourselves. */
  58. #ifndef EILSEQ
  59. #define EILSEQ
  60. #endif
  61.  
  62.  
  63. #ifdef __cplusplus
  64. extern "C" {
  65. #endif
  66.  
  67.  
  68. /* Allocates descriptor for code conversion from encoding `fromcode' to
  69.    encoding `tocode'. */
  70. #ifndef LIBICONV_PLUG
  71. #define iconv_open libiconv_open
  72. #endif
  73. extern iconv_t iconv_open (const char* tocode, const char* fromcode);
  74.  
  75. /* Converts, using conversion descriptor `cd', at most `*inbytesleft' bytes
  76.    starting at `*inbuf', writing at most `*outbytesleft' bytes starting at
  77.    `*outbuf'.
  78.    Decrements `*inbytesleft' and increments `*inbuf' by the same amount.
  79.    Decrements `*outbytesleft' and increments `*outbuf' by the same amount. */
  80. #ifndef LIBICONV_PLUG
  81. #define iconv libiconv
  82. #endif
  83. extern size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
  84.  
  85. /* Frees resources allocated for conversion descriptor `cd'. */
  86. #ifndef LIBICONV_PLUG
  87. #define iconv_close libiconv_close
  88. #endif
  89. extern int iconv_close (iconv_t cd);
  90.  
  91.  
  92. #ifndef LIBICONV_PLUG
  93.  
  94. /* Nonstandard extensions. */
  95.  
  96. /* Control of attributes. */
  97. #define iconvctl libiconvctl
  98. extern int iconvctl (iconv_t cd, int request, void* argument);
  99.  
  100. /* Hook performed after every successful conversion of a Unicode character. */
  101. typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
  102. /* Hook performed after every successful conversion of a wide character. */
  103. typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
  104. /* Set of hooks. */
  105. struct iconv_hooks {
  106.   iconv_unicode_char_hook uc_hook;
  107.   iconv_wide_char_hook wc_hook;
  108.   void* data;
  109. };
  110.  
  111. /* Fallback function.  Invoked when a small number of bytes could not be
  112.    converted to a Unicode character.  This function should process all
  113.    bytes from inbuf and may produce replacement Unicode characters by calling
  114.    the write_replacement callback repeatedly.  */
  115. typedef void (*iconv_unicode_mb_to_uc_fallback)
  116.              (const char* inbuf, size_t inbufsize,
  117.               void (*write_replacement) (const unsigned int *buf, size_t buflen,
  118.                                          void* callback_arg),
  119.               void* callback_arg,
  120.               void* data);
  121. /* Fallback function.  Invoked when a Unicode character could not be converted
  122.    to the target encoding.  This function should process the character and
  123.    may produce replacement bytes (in the target encoding) by calling the
  124.    write_replacement callback repeatedly.  */
  125. typedef void (*iconv_unicode_uc_to_mb_fallback)
  126.              (unsigned int code,
  127.               void (*write_replacement) (const char *buf, size_t buflen,
  128.                                          void* callback_arg),
  129.               void* callback_arg,
  130.               void* data);
  131. #if 1
  132. /* Fallback function.  Invoked when a number of bytes could not be converted to
  133.    a wide character.  This function should process all bytes from inbuf and may
  134.    produce replacement wide characters by calling the write_replacement
  135.    callback repeatedly.  */
  136. typedef void (*iconv_wchar_mb_to_wc_fallback)
  137.              (const char* inbuf, size_t inbufsize,
  138.               void (*write_replacement) (const wchar_t *buf, size_t buflen,
  139.                                          void* callback_arg),
  140.               void* callback_arg,
  141.               void* data);
  142. /* Fallback function.  Invoked when a wide character could not be converted to
  143.    the target encoding.  This function should process the character and may
  144.    produce replacement bytes (in the target encoding) by calling the
  145.    write_replacement callback repeatedly.  */
  146. typedef void (*iconv_wchar_wc_to_mb_fallback)
  147.              (wchar_t code,
  148.               void (*write_replacement) (const char *buf, size_t buflen,
  149.                                          void* callback_arg),
  150.               void* callback_arg,
  151.               void* data);
  152. #else
  153. /* If the wchar_t type does not exist, these two fallback functions are never
  154.    invoked.  Their argument list therefore does not matter.  */
  155. typedef void (*iconv_wchar_mb_to_wc_fallback) ();
  156. typedef void (*iconv_wchar_wc_to_mb_fallback) ();
  157. #endif
  158. /* Set of fallbacks. */
  159. struct iconv_fallbacks {
  160.   iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
  161.   iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
  162.   iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
  163.   iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
  164.   void* data;
  165. };
  166.  
  167. /* Requests for iconvctl. */
  168. #define ICONV_TRIVIALP            0  /* int *argument */
  169. #define ICONV_GET_TRANSLITERATE   1  /* int *argument */
  170. #define ICONV_SET_TRANSLITERATE   2  /* const int *argument */
  171. #define ICONV_GET_DISCARD_ILSEQ   3  /* int *argument */
  172. #define ICONV_SET_DISCARD_ILSEQ   4  /* const int *argument */
  173. #define ICONV_SET_HOOKS           5  /* const struct iconv_hooks *argument */
  174. #define ICONV_SET_FALLBACKS       6  /* const struct iconv_fallbacks *argument */
  175.  
  176. /* Listing of locale independent encodings. */
  177. #define iconvlist libiconvlist
  178. extern void iconvlist (int (*do_one) (unsigned int namescount,
  179.                                       const char * const * names,
  180.                                       void* data),
  181.                        void* data);
  182.  
  183. /* Canonicalize an encoding name.
  184.    The result is either a canonical encoding name, or name itself. */
  185. extern const char * iconv_canonicalize (const char * name);
  186.  
  187. /* Support for relocatable packages.  */
  188.  
  189. /* Sets the original and the current installation prefix of the package.
  190.    Relocation simply replaces a pathname starting with the original prefix
  191.    by the corresponding pathname with the current prefix instead.  Both
  192.    prefixes should be directory names without trailing slash (i.e. use ""
  193.    instead of "/").  */
  194. extern void libiconv_set_relocation_prefix (const char *orig_prefix,
  195.                         const char *curr_prefix);
  196.  
  197. #endif
  198.  
  199.  
  200. #ifdef __cplusplus
  201. }
  202. #endif
  203.  
  204.  
  205. #endif /* _LIBICONV_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement