Back to index

glibc  2.9
gettextP.h
Go to the documentation of this file.
00001 /* Header describing internals of libintl library.
00002    Copyright (C) 1995-1999, 2000, 2001, 2004-2005, 2007
00003    Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005    Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
00006 
00007    The GNU C Library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    The GNU C Library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with the GNU C Library; if not, write to the Free
00019    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00020    02111-1307 USA.  */
00021 
00022 #ifndef _GETTEXTP_H
00023 #define _GETTEXTP_H
00024 
00025 #include <stddef.h>         /* Get size_t.  */
00026 
00027 #ifdef _LIBC
00028 # include "../iconv/gconv_int.h"
00029 #else
00030 # if HAVE_ICONV
00031 #  include <iconv.h>
00032 # endif
00033 #endif
00034 
00035 #include "loadinfo.h"
00036 
00037 #include "gmo.h"            /* Get nls_uint32.  */
00038 
00039 /* @@ end of prolog @@ */
00040 
00041 #ifndef PARAMS
00042 # if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
00043 #  define PARAMS(args) args
00044 # else
00045 #  define PARAMS(args) ()
00046 # endif
00047 #endif
00048 
00049 #ifndef internal_function
00050 # define internal_function
00051 #endif
00052 
00053 #ifndef attribute_hidden
00054 # define attribute_hidden
00055 #endif
00056 
00057 /* Tell the compiler when a conditional or integer expression is
00058    almost always true or almost always false.  */
00059 #ifndef HAVE_BUILTIN_EXPECT
00060 # define __builtin_expect(expr, val) (expr)
00061 #endif
00062 
00063 #ifndef W
00064 # define W(flag, data) ((flag) ? SWAP (data) : (data))
00065 #endif
00066 
00067 
00068 #ifdef _LIBC
00069 # include <byteswap.h>
00070 # define SWAP(i) bswap_32 (i)
00071 #else
00072 static nls_uint32 SWAP PARAMS ((nls_uint32 i));
00073 
00074 static inline nls_uint32
00075 SWAP (i)
00076      nls_uint32 i;
00077 {
00078   return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
00079 }
00080 #endif
00081 
00082 
00083 /* In-memory representation of system dependent string.  */
00084 struct sysdep_string_desc
00085 {
00086   /* Length of addressed string, including the trailing NUL.  */
00087   size_t length;
00088   /* Pointer to addressed string.  */
00089   const char *pointer;
00090 };
00091 
00092 /* Cache of translated strings after charset conversion.
00093    Note: The strings are converted to the target encoding only on an as-needed
00094    basis.  */
00095 struct converted_domain
00096 {
00097   /* The target encoding name.  */
00098   const char *encoding;
00099   /* The descriptor for conversion from the message catalog's encoding to
00100      this target encoding.  */
00101 #ifdef _LIBC
00102   __gconv_t conv;
00103 #else
00104 # if HAVE_ICONV
00105   iconv_t conv;
00106 # endif
00107 #endif
00108   /* The table of translated strings after charset conversion.  */
00109   char **conv_tab;
00110 };
00111 
00112 /* The representation of an opened message catalog.  */
00113 struct loaded_domain
00114 {
00115   /* Pointer to memory containing the .mo file.  */
00116   const char *data;
00117   /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed.  */
00118   int use_mmap;
00119   /* Size of mmap()ed memory.  */
00120   size_t mmap_size;
00121   /* 1 if the .mo file uses a different endianness than this machine.  */
00122   int must_swap;
00123   /* Pointer to additional malloc()ed memory.  */
00124   void *malloced;
00125 
00126   /* Number of static strings pairs.  */
00127   nls_uint32 nstrings;
00128   /* Pointer to descriptors of original strings in the file.  */
00129   const struct string_desc *orig_tab;
00130   /* Pointer to descriptors of translated strings in the file.  */
00131   const struct string_desc *trans_tab;
00132 
00133   /* Number of system dependent strings pairs.  */
00134   nls_uint32 n_sysdep_strings;
00135   /* Pointer to descriptors of original sysdep strings.  */
00136   const struct sysdep_string_desc *orig_sysdep_tab;
00137   /* Pointer to descriptors of translated sysdep strings.  */
00138   const struct sysdep_string_desc *trans_sysdep_tab;
00139 
00140   /* Size of hash table.  */
00141   nls_uint32 hash_size;
00142   /* Pointer to hash table.  */
00143   const nls_uint32 *hash_tab;
00144   /* 1 if the hash table uses a different endianness than this machine.  */
00145   int must_swap_hash_tab;
00146 
00147   /* Cache of charset conversions of the translated strings.  */
00148   struct converted_domain *conversions;
00149   size_t nconversions;
00150   __libc_rwlock_define (, conversions_lock);
00151 
00152   const struct expression *plural;
00153   unsigned long int nplurals;
00154 };
00155 
00156 /* We want to allocate a string at the end of the struct.  But ISO C
00157    doesn't allow zero sized arrays.  */
00158 #ifdef __GNUC__
00159 # define ZERO 0
00160 #else
00161 # define ZERO 1
00162 #endif
00163 
00164 /* A set of settings bound to a message domain.  Used to store settings
00165    from bindtextdomain() and bind_textdomain_codeset().  */
00166 struct binding
00167 {
00168   struct binding *next;
00169   char *dirname;
00170   char *codeset;
00171   char domainname[ZERO];
00172 };
00173 
00174 /* A counter which is incremented each time some previous translations
00175    become invalid.
00176    This variable is part of the external ABI of the GNU libintl.  */
00177 extern int _nl_msg_cat_cntr;
00178 
00179 #ifndef _LIBC
00180 const char *_nl_locale_name PARAMS ((int category, const char *categoryname));
00181 #endif
00182 
00183 struct loaded_l10nfile *_nl_find_domain PARAMS ((const char *__dirname,
00184                                            char *__locale,
00185                                            const char *__domainname,
00186                                          struct binding *__domainbinding))
00187      internal_function;
00188 void _nl_load_domain PARAMS ((struct loaded_l10nfile *__domain,
00189                            struct binding *__domainbinding))
00190      internal_function;
00191 
00192 char *_nl_find_msg PARAMS ((struct loaded_l10nfile *domain_file,
00193                          struct binding *domainbinding, const char *msgid,
00194                          int convert, size_t *lengthp))
00195      internal_function;
00196 
00197 #ifdef _LIBC
00198 extern char *__gettext PARAMS ((const char *__msgid));
00199 extern char *__dgettext PARAMS ((const char *__domainname,
00200                              const char *__msgid));
00201 extern char *__dcgettext PARAMS ((const char *__domainname,
00202                               const char *__msgid, int __category));
00203 extern char *__ngettext PARAMS ((const char *__msgid1, const char *__msgid2,
00204                              unsigned long int __n));
00205 extern char *__dngettext PARAMS ((const char *__domainname,
00206                               const char *__msgid1, const char *__msgid2,
00207                               unsigned long int n));
00208 extern char *__dcngettext PARAMS ((const char *__domainname,
00209                                const char *__msgid1, const char *__msgid2,
00210                                unsigned long int __n, int __category));
00211 extern char *__dcigettext PARAMS ((const char *__domainname,
00212                                const char *__msgid1, const char *__msgid2,
00213                                int __plural, unsigned long int __n,
00214                                int __category));
00215 extern char *__textdomain PARAMS ((const char *__domainname));
00216 extern char *__bindtextdomain PARAMS ((const char *__domainname,
00217                                    const char *__dirname));
00218 extern char *__bind_textdomain_codeset PARAMS ((const char *__domainname,
00219                                           const char *__codeset));
00220 extern void _nl_finddomain_subfreeres PARAMS ((void)) attribute_hidden;
00221 extern void _nl_unload_domain PARAMS ((struct loaded_domain *__domain))
00222      internal_function attribute_hidden;
00223 #else
00224 extern char *libintl_gettext PARAMS ((const char *__msgid));
00225 extern char *libintl_dgettext PARAMS ((const char *__domainname,
00226                                    const char *__msgid));
00227 extern char *libintl_dcgettext PARAMS ((const char *__domainname,
00228                                    const char *__msgid, int __category));
00229 extern char *libintl_ngettext PARAMS ((const char *__msgid1,
00230                                    const char *__msgid2,
00231                                    unsigned long int __n));
00232 extern char *libintl_dngettext PARAMS ((const char *__domainname,
00233                                    const char *__msgid1,
00234                                    const char *__msgid2,
00235                                    unsigned long int __n));
00236 extern char *libintl_dcngettext PARAMS ((const char *__domainname,
00237                                     const char *__msgid1,
00238                                     const char *__msgid2,
00239                                     unsigned long int __n,
00240                                     int __category));
00241 extern char *libintl_dcigettext PARAMS ((const char *__domainname,
00242                                     const char *__msgid1,
00243                                     const char *__msgid2,
00244                                     int __plural, unsigned long int __n,
00245                                     int __category));
00246 extern char *libintl_textdomain PARAMS ((const char *__domainname));
00247 extern char *libintl_bindtextdomain PARAMS ((const char *__domainname,
00248                                         const char *__dirname));
00249 extern char *libintl_bind_textdomain_codeset PARAMS ((const char *__domainname,
00250                                                 const char *__codeset));
00251 #endif
00252 
00253 /* @@ begin of epilog @@ */
00254 
00255 #endif /* gettextP.h  */