Advertisement
Guest User

Untitled

a guest
Jan 8th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.60 KB | None | 0 0
  1. /* Copyright (C) 1999-2003, 2005-2006, 2008-2011 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 0x010E /* 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. #ifdef __cplusplus
  62. extern "C" {
  63. #endif
  64.  
  65.  
  66. /* Allocates descriptor for code conversion from encoding <E2><80><98>fromcode<E2><80><99> to
  67. encoding <E2><80><98>tocode<E2><80><99>. */
  68. #ifndef LIBICONV_PLUG
  69. #define iconv_open libiconv_open
  70. #endif
  71. extern iconv_t iconv_open (const char* tocode, const char* fromcode);
  72.  
  73. /* Converts, using conversion descriptor <E2><80><98>cd<E2><80><99>, at most <E2><80><98>*inbytesleft<E2><80><99> bytes
  74. starting at <E2><80><98>*inbuf<E2><80><99>, writing at most <E2><80><98>*outbytesleft<E2><80><99> bytes starting at
  75. <E2><80><98>*outbuf<E2><80><99>.
  76. Decrements <E2><80><98>*inbytesleft<E2><80><99> and increments <E2><80><98>*inbuf<E2><80><99> by the same amount.
  77. Decrements <E2><80><98>*outbytesleft<E2><80><99> and increments <E2><80><98>*outbuf<E2><80><99> by the same amount. */
  78. #ifndef LIBICONV_PLUG
  79. #define iconv libiconv
  80. #endif
  81. extern size_t iconv (iconv_t cd, const char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
  82.  
  83. /* Frees resources allocated for conversion descriptor <E2><80><98>cd<E2><80><99>. */
  84. #ifndef LIBICONV_PLUG
  85. #define iconv_close libiconv_close
  86. #endif
  87. extern int iconv_close (iconv_t cd);
  88.  
  89.  
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93.  
  94.  
  95. #ifndef LIBICONV_PLUG
  96.  
  97. /* Nonstandard extensions. */
  98.  
  99. #if 1
  100. #if 0
  101. /* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
  102. <wchar.h>.
  103. BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
  104. included before <wchar.h>. */
  105. #include <stddef.h>
  106. #include <stdio.h>
  107. #include <time.h>
  108. #endif
  109. #include <wchar.h>
  110. #endif
  111.  
  112. #ifdef __cplusplus
  113. extern "C" {
  114. #endif
  115. /* A type that holds all memory needed by a conversion descriptor.
  116. A pointer to such an object can be used as an iconv_t. */
  117. typedef struct {
  118. void* dummy1[28];
  119. #if 1
  120. mbstate_t dummy2;
  121. #endif
  122. } iconv_allocation_t;
  123.  
  124. /* Allocates descriptor for code conversion from encoding <E2><80><98>fromcode<E2><80><99> to
  125. encoding <E2><80><98>tocode<E2><80><99> into preallocated memory. Returns an error indicator
  126. (0 or -1 with errno set). */
  127. #define iconv_open_into libiconv_open_into
  128. extern int iconv_open_into (const char* tocode, const char* fromcode,
  129. iconv_allocation_t* resultp);
  130.  
  131. /* Control of attributes. */
  132. #define iconvctl libiconvctl
  133. extern int iconvctl (iconv_t cd, int request, void* argument);
  134.  
  135. /* Hook performed after every successful conversion of a Unicode character. */
  136. typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
  137. /* Hook performed after every successful conversion of a wide character. */
  138. typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
  139. /* Set of hooks. */
  140. struct iconv_hooks {
  141. iconv_unicode_char_hook uc_hook;
  142. iconv_wide_char_hook wc_hook;
  143. void* data;
  144. };
  145.  
  146. /* Fallback function. Invoked when a small number of bytes could not be
  147. converted to a Unicode character. This function should process all
  148. bytes from inbuf and may produce replacement Unicode characters by calling
  149. the write_replacement callback repeatedly. */
  150. typedef void (*iconv_unicode_mb_to_uc_fallback)
  151. (const char* inbuf, size_t inbufsize,
  152. void (*write_replacement) (const unsigned int *buf, size_t buflen,
  153. void* callback_arg),
  154. void* callback_arg,
  155. void* data);
  156. /* Fallback function. Invoked when a Unicode character could not be converted
  157. to the target encoding. This function should process the character and
  158. may produce replacement bytes (in the target encoding) by calling the
  159. write_replacement callback repeatedly. */
  160. typedef void (*iconv_unicode_uc_to_mb_fallback)
  161. (unsigned int code,
  162. void (*write_replacement) (const char *buf, size_t buflen,
  163. void* callback_arg),
  164. void* callback_arg,
  165. void* data);
  166. #if 1
  167. /* Fallback function. Invoked when a number of bytes could not be converted to
  168. a wide character. This function should process all bytes from inbuf and may
  169. produce replacement wide characters by calling the write_replacement
  170. callback repeatedly. */
  171. typedef void (*iconv_wchar_mb_to_wc_fallback)
  172. (const char* inbuf, size_t inbufsize,
  173. void (*write_replacement) (const wchar_t *buf, size_t buflen,
  174. void* callback_arg),
  175. void* callback_arg,
  176. void* data);
  177. /* Fallback function. Invoked when a wide character could not be converted to
  178. the target encoding. This function should process the character and may
  179. produce replacement bytes (in the target encoding) by calling the
  180. write_replacement callback repeatedly. */
  181. typedef void (*iconv_wchar_wc_to_mb_fallback)
  182. (wchar_t code,
  183. void (*write_replacement) (const char *buf, size_t buflen,
  184. void* callback_arg),
  185. void* callback_arg,
  186. void* data);
  187. #else
  188. /* If the wchar_t type does not exist, these two fallback functions are never
  189. invoked. Their argument list therefore does not matter. */
  190. typedef void (*iconv_wchar_mb_to_wc_fallback) ();
  191. typedef void (*iconv_wchar_wc_to_mb_fallback) ();
  192. #endif
  193. /* Set of fallbacks. */
  194. struct iconv_fallbacks {
  195. iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
  196. iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
  197. iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
  198. iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
  199. void* data;
  200. };
  201.  
  202. /* Requests for iconvctl. */
  203. #define ICONV_TRIVIALP 0 /* int *argument */
  204. #define ICONV_GET_TRANSLITERATE 1 /* int *argument */
  205. #define ICONV_SET_TRANSLITERATE 2 /* const int *argument */
  206. #define ICONV_GET_DISCARD_ILSEQ 3 /* int *argument */
  207. #define ICONV_SET_DISCARD_ILSEQ 4 /* const int *argument */
  208. #define ICONV_SET_HOOKS 5 /* const struct iconv_hooks *argument */
  209. #define ICONV_SET_FALLBACKS 6 /* const struct iconv_fallbacks *argument */
  210.  
  211. /* Listing of locale independent encodings. */
  212. #define iconvlist libiconvlist
  213. extern void iconvlist (int (*do_one) (unsigned int namescount,
  214. const char * const * names,
  215. void* data),
  216. void* data);
  217. /* Canonicalize an encoding name.
  218. The result is either a canonical encoding name, or name itself. */
  219. extern const char * iconv_canonicalize (const char * name);
  220.  
  221. /* Support for relocatable packages. */
  222.  
  223. /* Sets the original and the current installation prefix of the package.
  224. Relocation simply replaces a pathname starting with the original prefix
  225. by the corresponding pathname with the current prefix instead. Both
  226. prefixes should be directory names without trailing slash (i.e. use ""
  227. instead of "/"). */
  228. extern void libiconv_set_relocation_prefix (const char *orig_prefix,
  229. const char *curr_prefix);
  230.  
  231. #ifdef __cplusplus
  232. }
  233. #endif
  234.  
  235. #endif
  236.  
  237.  
  238. #endif /* _LIBICONV_H */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement