(root)/
gettext-0.22.4/
gettext-runtime/
intl/
gettextP.h
       1  /* Header describing internals of libintl library.
       2     Copyright (C) 1995-2023 Free Software Foundation, Inc.
       3     Written by Ulrich Drepper <drepper@cygnus.com>, 1995.
       4  
       5     This program is free software: you can redistribute it and/or modify
       6     it under the terms of the GNU Lesser General Public License as published by
       7     the Free Software Foundation; either version 2.1 of the License, or
       8     (at your option) any later version.
       9  
      10     This program is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      13     GNU Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public License
      16     along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
      17  
      18  #ifndef _GETTEXTP_H
      19  #define _GETTEXTP_H
      20  
      21  #include <stddef.h>		/* Get size_t.  */
      22  
      23  #ifdef _LIBC
      24  # include "../iconv/gconv_int.h"
      25  #else
      26  # if HAVE_ICONV
      27  #  include <iconv.h>
      28  # endif
      29  #endif
      30  
      31  /* Handle multi-threaded applications.  */
      32  #ifdef _LIBC
      33  # include <bits/libc-lock.h>
      34  # define gl_rwlock_define __libc_rwlock_define
      35  #else
      36  # include "glthread/lock.h"
      37  #endif
      38  
      39  #ifdef _LIBC
      40  struct loaded_domain;
      41  extern char *__gettext (const char *__msgid);
      42  extern char *__dgettext (const char *__domainname, const char *__msgid);
      43  extern char *__dcgettext (const char *__domainname, const char *__msgid,
      44  			  int __category);
      45  extern char *__ngettext (const char *__msgid1, const char *__msgid2,
      46  			 unsigned long int __n);
      47  extern char *__dngettext (const char *__domainname,
      48  			  const char *__msgid1, const char *__msgid2,
      49  			  unsigned long int n);
      50  extern char *__dcngettext (const char *__domainname,
      51  			   const char *__msgid1, const char *__msgid2,
      52  			   unsigned long int __n, int __category);
      53  extern char *__dcigettext (const char *__domainname,
      54  			   const char *__msgid1, const char *__msgid2,
      55  			   int __plural, unsigned long int __n,
      56  			   int __category);
      57  extern char *__textdomain (const char *__domainname);
      58  extern char *__bindtextdomain (const char *__domainname,
      59  			       const char *__dirname);
      60  extern char *__bind_textdomain_codeset (const char *__domainname,
      61  					const char *__codeset);
      62  extern void _nl_finddomain_subfreeres (void) attribute_hidden;
      63  extern void _nl_unload_domain (struct loaded_domain *__domain)
      64       internal_function attribute_hidden;
      65  #else
      66  /* Declare the exported libintl_* functions, in a way that allows us to
      67     call them under their real name.  */
      68  # undef _INTL_REDIRECT_INLINE
      69  # undef _INTL_REDIRECT_MACROS
      70  # define _INTL_REDIRECT_MACROS
      71  # include "libgnuintl.h"
      72  # ifdef IN_LIBGLOCALE
      73  extern char *gl_dcigettext (const char *__domainname,
      74  			    const char *__msgid1, const char *__msgid2,
      75  			    int __plural, unsigned long int __n,
      76  			    int __category,
      77  			    const char *__localename, const char *__encoding);
      78  # else
      79  extern char *libintl_dcigettext (const char *__domainname,
      80  				 const char *__msgid1, const char *__msgid2,
      81  				 int __plural, unsigned long int __n,
      82  				 int __category);
      83  # endif
      84  #endif
      85  
      86  #include "loadinfo.h"
      87  
      88  #include "gmo.h"		/* Get nls_uint32.  */
      89  
      90  /* @@ end of prolog @@ */
      91  
      92  #ifndef internal_function
      93  # define internal_function
      94  #endif
      95  
      96  #ifndef attribute_hidden
      97  # define attribute_hidden
      98  #endif
      99  
     100  /* Tell the compiler when a conditional or integer expression is
     101     almost always true or almost always false.  */
     102  #ifndef HAVE_BUILTIN_EXPECT
     103  # define __builtin_expect(expr, val) (expr)
     104  #endif
     105  
     106  #ifndef W
     107  # define W(flag, data) ((flag) ? SWAP (data) : (data))
     108  #endif
     109  
     110  
     111  #ifdef _LIBC
     112  # include <byteswap.h>
     113  # define SWAP(i) bswap_32 (i)
     114  #else
     115  static inline nls_uint32
     116  SWAP (nls_uint32 i)
     117  {
     118    return (i << 24) | ((i & 0xff00) << 8) | ((i >> 8) & 0xff00) | (i >> 24);
     119  }
     120  #endif
     121  
     122  
     123  /* In-memory representation of system dependent string.  */
     124  struct sysdep_string_desc
     125  {
     126    /* Length of addressed string, including the trailing NUL.  */
     127    size_t length;
     128    /* Pointer to addressed string.  */
     129    const char *pointer;
     130  };
     131  
     132  /* Cache of translated strings after charset conversion.
     133     Note: The strings are converted to the target encoding only on an as-needed
     134     basis.  */
     135  struct converted_domain
     136  {
     137    /* The target encoding name.  */
     138    const char *encoding;
     139    /* The descriptor for conversion from the message catalog's encoding to
     140       this target encoding.  */
     141  #ifdef _LIBC
     142    __gconv_t conv;
     143  #else
     144  # if HAVE_ICONV
     145    iconv_t conv;
     146  # endif
     147  #endif
     148    /* The table of translated strings after charset conversion.  */
     149    char **conv_tab;
     150  };
     151  
     152  /* The representation of an opened message catalog.  */
     153  struct loaded_domain
     154  {
     155    /* Pointer to memory containing the .mo file.  */
     156    const char *data;
     157    /* 1 if the memory is mmap()ed, 0 if the memory is malloc()ed.  */
     158    int use_mmap;
     159    /* Size of mmap()ed memory.  */
     160    size_t mmap_size;
     161    /* 1 if the .mo file uses a different endianness than this machine.  */
     162    int must_swap;
     163    /* Pointer to additional malloc()ed memory.  */
     164    void *malloced;
     165  
     166    /* Number of static strings pairs.  */
     167    nls_uint32 nstrings;
     168    /* Pointer to descriptors of original strings in the file.  */
     169    const struct string_desc *orig_tab;
     170    /* Pointer to descriptors of translated strings in the file.  */
     171    const struct string_desc *trans_tab;
     172  
     173    /* Number of system dependent strings pairs.  */
     174    nls_uint32 n_sysdep_strings;
     175    /* Pointer to descriptors of original sysdep strings.  */
     176    const struct sysdep_string_desc *orig_sysdep_tab;
     177    /* Pointer to descriptors of translated sysdep strings.  */
     178    const struct sysdep_string_desc *trans_sysdep_tab;
     179  
     180    /* Size of hash table.  */
     181    nls_uint32 hash_size;
     182    /* Pointer to hash table.  */
     183    const nls_uint32 *hash_tab;
     184    /* 1 if the hash table uses a different endianness than this machine.  */
     185    int must_swap_hash_tab;
     186  
     187    /* Cache of charset conversions of the translated strings.  */
     188    struct converted_domain *conversions;
     189    size_t nconversions;
     190    gl_rwlock_define (, conversions_lock)
     191  
     192    const struct expression *plural;
     193    unsigned long int nplurals;
     194  };
     195  
     196  /* We want to allocate a string at the end of the struct.  But ISO C
     197     doesn't allow zero sized arrays.  */
     198  #ifdef __GNUC__
     199  # define ZERO 0
     200  #else
     201  # define ZERO 1
     202  #endif
     203  
     204  /* A set of settings bound to a message domain.  Used to store settings
     205     from bindtextdomain() and bind_textdomain_codeset().  */
     206  struct binding
     207  {
     208    struct binding *next;
     209    char *dirname;
     210  #if defined _WIN32 && !defined __CYGWIN__
     211    wchar_t *wdirname;
     212  #endif
     213    char *codeset;
     214    char domainname[FLEXIBLE_ARRAY_MEMBER];
     215  };
     216  
     217  /* A counter which is incremented each time some previous translations
     218     become invalid.
     219     This variable is part of the external ABI of the GNU libintl.  */
     220  #if defined __KLIBC__ && !defined _LIBC
     221  # define _nl_msg_cat_cntr libintl_nl_msg_cat_cntr
     222  #endif
     223  #ifdef IN_LIBGLOCALE
     224  # include <glocale/config.h>
     225  extern LIBGLOCALE_DLL_EXPORTED int _nl_msg_cat_cntr;
     226  #else
     227  extern LIBINTL_DLL_EXPORTED int _nl_msg_cat_cntr;
     228  #endif
     229  
     230  #ifndef _LIBC
     231  extern const char *_nl_language_preferences_default (void);
     232  extern void gl_locale_name_canonicalize (char *name);
     233  /* extern const char *gl_locale_name_from_win32_LANGID (LANGID langid); */
     234  /* extern const char *gl_locale_name_from_win32_LCID (LCID lcid); */
     235  extern const char *gl_locale_name_thread_unsafe (int category,
     236  						 const char *categoryname);
     237  #endif
     238  
     239  struct loaded_l10nfile *_nl_find_domain (const char *__dirname,
     240  #if defined _WIN32 && !defined __CYGWIN__
     241  					 const wchar_t *__wdirname,
     242  #endif
     243  					 char *__locale,
     244  					 const char *__domainname,
     245  					 struct binding *__domainbinding)
     246       internal_function;
     247  void _nl_load_domain (struct loaded_l10nfile *__domain,
     248  		      struct binding *__domainbinding)
     249       internal_function;
     250  
     251  #ifdef IN_LIBGLOCALE
     252  char *_nl_find_msg (struct loaded_l10nfile *domain_file,
     253  		    struct binding *domainbinding, const char *encoding,
     254  		    const char *msgid,
     255  		    size_t *lengthp)
     256       internal_function;
     257  #else
     258  char *_nl_find_msg (struct loaded_l10nfile *domain_file,
     259  		    struct binding *domainbinding, const char *msgid,
     260  		    int convert, size_t *lengthp)
     261       internal_function;
     262  #endif
     263  
     264  /* The internal variables in the standalone libintl.a must have different
     265     names than the internal variables in GNU libc, otherwise programs
     266     using libintl.a cannot be linked statically.  */
     267  #if !defined _LIBC
     268  # define _nl_default_dirname libintl_nl_default_dirname
     269  # define _nl_domain_bindings libintl_nl_domain_bindings
     270  #endif
     271  
     272  /* Contains the default location of the message catalogs.  */
     273  extern const char _nl_default_dirname[];
     274  #ifdef _LIBC
     275  libc_hidden_proto (_nl_default_dirname)
     276  #endif
     277  
     278  /* List with bindings of specific domains.  */
     279  extern struct binding *_nl_domain_bindings;
     280  
     281  /* The internal variables in the standalone libintl.a must have different
     282     names than the internal variables in GNU libc, otherwise programs
     283     using libintl.a cannot be linked statically.  */
     284  #if !defined _LIBC
     285  # define _nl_default_default_domain libintl_nl_default_default_domain
     286  # define _nl_current_default_domain libintl_nl_current_default_domain
     287  #endif
     288  
     289  /* Name of the default text domain.  */
     290  extern const char _nl_default_default_domain[] attribute_hidden;
     291  
     292  /* Default text domain in which entries for gettext(3) are to be found.  */
     293  extern const char *_nl_current_default_domain attribute_hidden;
     294  
     295  extern void _nl_log_untranslated (const char *logfilename,
     296  				  const char *domainname,
     297  				  const char *msgid1, const char *msgid2,
     298  				  int plural);
     299  
     300  /* @@ begin of epilog @@ */
     301  
     302  #endif /* gettextP.h  */