Back to index

glibc  2.9
gconv.h
Go to the documentation of this file.
00001 /* Copyright (C) 1997-1999, 2000-2002, 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /* This header provides no interface for a user to the internals of
00020    the gconv implementation in the libc.  Therefore there is no use
00021    for these definitions beside for writing additional gconv modules.  */
00022 
00023 #ifndef _GCONV_H
00024 #define _GCONV_H     1
00025 
00026 #include <features.h>
00027 #define __need_mbstate_t
00028 #define __need_wint_t
00029 #include <wchar.h>
00030 #define __need_size_t
00031 #define __need_wchar_t
00032 #include <stddef.h>
00033 
00034 /* ISO 10646 value used to signal invalid value.  */
00035 #define __UNKNOWN_10646_CHAR       ((wchar_t) 0xfffd)
00036 
00037 /* Error codes for gconv functions.  */
00038 enum
00039 {
00040   __GCONV_OK = 0,
00041   __GCONV_NOCONV,
00042   __GCONV_NODB,
00043   __GCONV_NOMEM,
00044 
00045   __GCONV_EMPTY_INPUT,
00046   __GCONV_FULL_OUTPUT,
00047   __GCONV_ILLEGAL_INPUT,
00048   __GCONV_INCOMPLETE_INPUT,
00049 
00050   __GCONV_ILLEGAL_DESCRIPTOR,
00051   __GCONV_INTERNAL_ERROR
00052 };
00053 
00054 
00055 /* Flags the `__gconv_open' function can set.  */
00056 enum
00057 {
00058   __GCONV_IS_LAST = 0x0001,
00059   __GCONV_IGNORE_ERRORS = 0x0002
00060 };
00061 
00062 
00063 /* Forward declarations.  */
00064 struct __gconv_step;
00065 struct __gconv_step_data;
00066 struct __gconv_loaded_object;
00067 struct __gconv_trans_data;
00068 
00069 
00070 /* Type of a conversion function.  */
00071 typedef int (*__gconv_fct) (struct __gconv_step *, struct __gconv_step_data *,
00072                          __const unsigned char **, __const unsigned char *,
00073                          unsigned char **, size_t *, int, int);
00074 
00075 /* Type of a specialized conversion function for a single byte to INTERNAL.  */
00076 typedef wint_t (*__gconv_btowc_fct) (struct __gconv_step *, unsigned char);
00077 
00078 /* Constructor and destructor for local data for conversion step.  */
00079 typedef int (*__gconv_init_fct) (struct __gconv_step *);
00080 typedef void (*__gconv_end_fct) (struct __gconv_step *);
00081 
00082 
00083 /* Type of a transliteration/transscription function.  */
00084 typedef int (*__gconv_trans_fct) (struct __gconv_step *,
00085                               struct __gconv_step_data *, void *,
00086                               __const unsigned char *,
00087                               __const unsigned char **,
00088                               __const unsigned char *, unsigned char **,
00089                               size_t *);
00090 
00091 /* Function to call to provide transliteration module with context.  */
00092 typedef int (*__gconv_trans_context_fct) (void *, __const unsigned char *,
00093                                      __const unsigned char *,
00094                                      unsigned char *, unsigned char *);
00095 
00096 /* Function to query module about supported encoded character sets.  */
00097 typedef int (*__gconv_trans_query_fct) (__const char *, __const char ***,
00098                                    size_t *);
00099 
00100 /* Constructor and destructor for local data for transliteration.  */
00101 typedef int (*__gconv_trans_init_fct) (void **, const char *);
00102 typedef void (*__gconv_trans_end_fct) (void *);
00103 
00104 struct __gconv_trans_data
00105 {
00106   /* Transliteration/Transscription function.  */
00107   __gconv_trans_fct __trans_fct;
00108   __gconv_trans_context_fct __trans_context_fct;
00109   __gconv_trans_end_fct __trans_end_fct;
00110   void *__data;
00111   struct __gconv_trans_data *__next;
00112 };
00113 
00114 
00115 /* Description of a conversion step.  */
00116 struct __gconv_step
00117 {
00118   struct __gconv_loaded_object *__shlib_handle;
00119   __const char *__modname;
00120 
00121   int __counter;
00122 
00123   char *__from_name;
00124   char *__to_name;
00125 
00126   __gconv_fct __fct;
00127   __gconv_btowc_fct __btowc_fct;
00128   __gconv_init_fct __init_fct;
00129   __gconv_end_fct __end_fct;
00130 
00131   /* Information about the number of bytes needed or produced in this
00132      step.  This helps optimizing the buffer sizes.  */
00133   int __min_needed_from;
00134   int __max_needed_from;
00135   int __min_needed_to;
00136   int __max_needed_to;
00137 
00138   /* Flag whether this is a stateful encoding or not.  */
00139   int __stateful;
00140 
00141   void *__data;             /* Pointer to step-local data.  */
00142 };
00143 
00144 /* Additional data for steps in use of conversion descriptor.  This is
00145    allocated by the `init' function.  */
00146 struct __gconv_step_data
00147 {
00148   unsigned char *__outbuf;    /* Output buffer for this step.  */
00149   unsigned char *__outbufend; /* Address of first byte after the output
00150                              buffer.  */
00151 
00152   /* Is this the last module in the chain.  */
00153   int __flags;
00154 
00155   /* Counter for number of invocations of the module function for this
00156      descriptor.  */
00157   int __invocation_counter;
00158 
00159   /* Flag whether this is an internal use of the module (in the mb*towc*
00160      and wc*tomb* functions) or regular with iconv(3).  */
00161   int __internal_use;
00162 
00163   __mbstate_t *__statep;
00164   __mbstate_t __state;      /* This element must not be used directly by
00165                         any module; always use STATEP!  */
00166 
00167   /* Transliteration information.  */
00168   struct __gconv_trans_data *__trans;
00169 };
00170 
00171 
00172 /* Combine conversion step description with data.  */
00173 typedef struct __gconv_info
00174 {
00175   size_t __nsteps;
00176   struct __gconv_step *__steps;
00177   __extension__ struct __gconv_step_data __data __flexarr;
00178 } *__gconv_t;
00179 
00180 #endif /* gconv.h */