* po/vi.po: Likewise.
[glibc/pb-stable.git] / locale / localeinfo.h
blob3661080bb256c04eb78e26e03105bdc714359755
1 /* Declarations for internal libc locale interfaces
2 Copyright (C) 1995-2003, 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA. */
21 #ifndef _LOCALEINFO_H
22 #define _LOCALEINFO_H 1
24 #include <stddef.h>
25 #include <langinfo.h>
26 #include <limits.h>
27 #include <locale.h>
28 #include <time.h>
29 #include <stdint.h>
30 #include <sys/types.h>
32 #include <intl/loadinfo.h> /* For loaded_l10nfile definition. */
34 /* Magic number at the beginning of a locale data file for CATEGORY. */
35 #define LIMAGIC(category) \
36 (category == LC_COLLATE \
37 ? ((unsigned int) (0x20051014 ^ (category))) \
38 : ((unsigned int) (0x20031115 ^ (category))))
40 /* Two special weight constants for the collation data. */
41 #define IGNORE_CHAR 2
43 /* We use a special value for the usage counter in `locale_data' to
44 signal that this data must never be removed anymore. */
45 #define MAX_USAGE_COUNT (UINT_MAX - 1)
46 #define UNDELETABLE UINT_MAX
48 /* Structure describing locale data in core for a category. */
49 struct locale_data
51 const char *name;
52 const char *filedata; /* Region mapping the file data. */
53 off_t filesize; /* Size of the file (and the region). */
54 enum /* Flavor of storage used for those. */
56 ld_malloced, /* Both are malloc'd. */
57 ld_mapped, /* name is malloc'd, filedata mmap'd */
58 ld_archive /* Both point into mmap'd archive regions. */
59 } alloc;
61 /* This provides a slot for category-specific code to cache data computed
62 about this locale. That code can set a cleanup function to deallocate
63 the data. */
64 struct
66 void (*cleanup) (struct locale_data *) internal_function;
67 union
69 void *data;
70 struct lc_time_data *time;
71 const struct gconv_fcts *ctype;
73 } private;
75 unsigned int usage_count; /* Counter for users. */
77 int use_translit; /* Nonzero if the mb*towv*() and wc*tomb()
78 functions should use transliteration. */
80 unsigned int nstrings; /* Number of strings below. */
81 union locale_data_value
83 const uint32_t *wstr;
84 const char *string;
85 unsigned int word; /* Note endian issues vs 64-bit pointers. */
87 values __flexarr; /* Items, usually pointers into `filedata'. */
90 /* We know three kinds of collation sorting rules. */
91 enum coll_sort_rule
93 illegal_0__,
94 sort_forward,
95 sort_backward,
96 illegal_3__,
97 sort_position,
98 sort_forward_position,
99 sort_backward_position,
100 sort_mask
103 /* We can map the types of the entries into a few categories. */
104 enum value_type
106 none,
107 string,
108 stringarray,
109 byte,
110 bytearray,
111 word,
112 stringlist,
113 wordarray,
114 wstring,
115 wstringarray,
116 wstringlist
120 /* Definitions for `era' information from LC_TIME. */
121 #define ERA_NAME_FORMAT_MEMBERS 4
122 #define ERA_M_NAME 0
123 #define ERA_M_FORMAT 1
124 #define ERA_W_NAME 2
125 #define ERA_W_FORMAT 3
128 /* Structure to access `era' information from LC_TIME. */
129 struct era_entry
131 uint32_t direction; /* Contains '+' or '-'. */
132 int32_t offset;
133 int32_t start_date[3];
134 int32_t stop_date[3];
135 const char *era_name;
136 const char *era_format;
137 const wchar_t *era_wname;
138 const wchar_t *era_wformat;
139 int absolute_direction;
140 /* absolute direction:
141 +1 indicates that year number is higher in the future. (like A.D.)
142 -1 indicates that year number is higher in the past. (like B.C.) */
145 /* Structure caching computed data about information from LC_TIME.
146 The `private.time' member of `struct locale_data' points to this. */
147 struct lc_time_data
149 struct era_entry *eras;
150 size_t num_eras;
151 int era_initialized;
153 const char **alt_digits;
154 const wchar_t **walt_digits;
155 int alt_digits_initialized;
156 int walt_digits_initialized;
160 /* LC_CTYPE specific:
161 Hardwired indices for standard wide character translation mappings. */
162 enum
164 __TOW_toupper = 0,
165 __TOW_tolower = 1
169 /* LC_CTYPE specific:
170 Access a wide character class with a single character index.
171 _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
172 c must be an `unsigned char'. desc must be a nonzero wctype_t. */
173 #define _ISCTYPE(c, desc) \
174 (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
176 /* Category name handling variables. */
177 #define CATNAMEMF(line) CATNAMEMF1 (line)
178 #define CATNAMEMF1(line) str##line
179 extern const union catnamestr_t
181 struct
183 #define DEFINE_CATEGORY(category, category_name, items, a) \
184 char CATNAMEMF (__LINE__)[sizeof (category_name)];
185 #include "categories.def"
186 #undef DEFINE_CATEGORY
188 char str[0];
189 } _nl_category_names attribute_hidden;
190 extern const uint8_t _nl_category_name_idxs[__LC_LAST] attribute_hidden;
191 extern const uint8_t _nl_category_name_sizes[__LC_LAST] attribute_hidden;
193 /* Name of the standard locales. */
194 extern const char _nl_C_name[] attribute_hidden;
195 extern const char _nl_POSIX_name[] attribute_hidden;
197 /* The standard codeset. */
198 extern const char _nl_C_codeset[] attribute_hidden;
200 /* This is the internal locale_t object that holds the global locale
201 controlled by calls to setlocale. A thread's TSD locale pointer
202 points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */
203 extern struct __locale_struct _nl_global_locale attribute_hidden;
205 /* This fetches the thread-local locale_t pointer, either one set with
206 uselocale or &_nl_global_locale. */
207 #define _NL_CURRENT_LOCALE (__libc_tsd_get (__locale_t, LOCALE))
208 #include <bits/libc-tsd.h>
209 __libc_tsd_define (extern, __locale_t, LOCALE)
212 /* For static linking it is desireable to avoid always linking in the code
213 and data for every category when we can tell at link time that they are
214 unused. We can manage this playing some tricks with weak references.
215 But with thread-local locale settings, it becomes quite ungainly unless
216 we can use __thread variables. So only in that case do we attempt this. */
217 #if !defined SHARED && defined HAVE___THREAD && defined HAVE_WEAK_SYMBOLS
218 # include <tls.h>
219 # define NL_CURRENT_INDIRECT 1
220 #endif
222 #ifdef NL_CURRENT_INDIRECT
224 /* For each category declare the thread-local variable for the current
225 locale data. This has an extra indirection so it points at the
226 __locales[CATEGORY] element in either _nl_global_locale or the current
227 locale object set by uselocale, which points at the actual data. The
228 reason for having these variables is so that references to particular
229 categories will link in the lc-CATEGORY.c module to define this symbol,
230 and we arrange that linking that module is what brings in all the code
231 associated with this category. */
232 #define DEFINE_CATEGORY(category, category_name, items, a) \
233 extern __thread struct locale_data *const *_nl_current_##category \
234 attribute_hidden attribute_tls_model_ie;
235 #include "categories.def"
236 #undef DEFINE_CATEGORY
238 /* Return a pointer to the current `struct locale_data' for CATEGORY. */
239 #define _NL_CURRENT_DATA(category) (*_nl_current_##category)
241 /* Extract the current CATEGORY locale's string for ITEM. */
242 #define _NL_CURRENT(category, item) \
243 ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].string)
245 /* Extract the current CATEGORY locale's string for ITEM. */
246 #define _NL_CURRENT_WSTR(category, item) \
247 ((wchar_t *) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].wstr)
249 /* Extract the current CATEGORY locale's word for ITEM. */
250 #define _NL_CURRENT_WORD(category, item) \
251 ((uint32_t) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].word)
253 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
254 #define _NL_CURRENT_DEFINE(category) \
255 __thread struct locale_data *const *_nl_current_##category \
256 attribute_hidden = &_nl_global_locale.__locales[category]; \
257 asm (_NL_CURRENT_DEFINE_STRINGIFY (ASM_GLOBAL_DIRECTIVE) \
258 " " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \
259 _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used, 1));
260 #define _NL_CURRENT_DEFINE_STRINGIFY(x) _NL_CURRENT_DEFINE_STRINGIFY_1 (x)
261 #define _NL_CURRENT_DEFINE_STRINGIFY_1(x) #x
262 #ifdef HAVE_ASM_SET_DIRECTIVE
263 # define _NL_CURRENT_DEFINE_ABS(sym, val) ".set " #sym ", " #val
264 #else
265 # define _NL_CURRENT_DEFINE_ABS(sym, val) #sym " = " #val
266 #endif
268 #else
270 /* All categories are always loaded in the shared library, so there is no
271 point in having lots of separate symbols for linking. */
273 /* Return a pointer to the current `struct locale_data' for CATEGORY. */
274 # define _NL_CURRENT_DATA(category) \
275 (_NL_CURRENT_LOCALE->__locales[category])
277 /* Extract the current CATEGORY locale's string for ITEM. */
278 # define _NL_CURRENT(category, item) \
279 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
281 /* Extract the current CATEGORY locale's string for ITEM. */
282 # define _NL_CURRENT_WSTR(category, item) \
283 ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
285 /* Extract the current CATEGORY locale's word for ITEM. */
286 # define _NL_CURRENT_WORD(category, item) \
287 ((uint32_t) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
289 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
290 # define _NL_CURRENT_DEFINE(category) \
291 /* No per-category variable here. */
293 #endif
296 /* Default search path if no LOCPATH environment variable. */
297 extern const char _nl_default_locale_path[] attribute_hidden;
299 /* Load the locale data for CATEGORY from the file specified by *NAME.
300 If *NAME is "", use environment variables as specified by POSIX, and
301 fill in *NAME with the actual name used. If LOCALE_PATH is not null,
302 those directories are searched for the locale files. If it's null,
303 the locale archive is checked first and then _nl_default_locale_path
304 is searched for locale files. */
305 extern struct locale_data *_nl_find_locale (const char *locale_path,
306 size_t locale_path_len,
307 int category, const char **name)
308 internal_function attribute_hidden;
310 /* Try to load the file described by FILE. */
311 extern void _nl_load_locale (struct loaded_l10nfile *file, int category)
312 internal_function attribute_hidden;
314 /* Free all resource. */
315 extern void _nl_unload_locale (struct locale_data *locale)
316 internal_function attribute_hidden;
318 /* Free the locale and give back all memory if the usage count is one. */
319 extern void _nl_remove_locale (int locale, struct locale_data *data)
320 internal_function attribute_hidden;
322 /* Find the locale *NAMEP in the locale archive, and return the
323 internalized data structure for its CATEGORY data. If this locale has
324 already been loaded from the archive, just returns the existing data
325 structure. If successful, sets *NAMEP to point directly into the mapped
326 archive string table; that way, the next call can short-circuit strcmp. */
327 extern struct locale_data *_nl_load_locale_from_archive (int category,
328 const char **namep)
329 internal_function attribute_hidden;
331 /* Subroutine of setlocale's __libc_subfreeres hook. */
332 extern void _nl_archive_subfreeres (void) attribute_hidden;
334 /* Subroutine of gconv-db's __libc_subfreeres hook. */
335 extern void _nl_locale_subfreeres (void) attribute_hidden;
337 /* Validate the contents of a locale file and set up the in-core
338 data structure to point into the data. This leaves the `alloc'
339 and `name' fields uninitialized, for the caller to fill in.
340 If any bogons are detected in the data, this will refuse to
341 intern it, and return a null pointer instead. */
342 extern struct locale_data *_nl_intern_locale_data (int category,
343 const void *data,
344 size_t datasize)
345 internal_function attribute_hidden;
348 /* Return `era' entry which corresponds to TP. Used in strftime. */
349 extern struct era_entry *_nl_get_era_entry (const struct tm *tp,
350 struct locale_data *lc_time)
351 internal_function attribute_hidden;
353 /* Return `era' cnt'th entry . Used in strptime. */
354 extern struct era_entry *_nl_select_era_entry (int cnt,
355 struct locale_data *lc_time)
356 internal_function attribute_hidden;
358 /* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */
359 extern const char *_nl_get_alt_digit (unsigned int number,
360 struct locale_data *lc_time)
361 internal_function attribute_hidden;
363 /* Similar, but now for wide characters. */
364 extern const wchar_t *_nl_get_walt_digit (unsigned int number,
365 struct locale_data *lc_time)
366 internal_function attribute_hidden;
368 /* Parse string as alternative digit and return numeric value. */
369 extern int _nl_parse_alt_digit (const char **strp,
370 struct locale_data *lc_time)
371 internal_function attribute_hidden;
373 /* Postload processing. */
374 extern void _nl_postload_ctype (void);
376 /* Functions used for the `private.cleanup' hook. */
377 extern void _nl_cleanup_time (struct locale_data *)
378 internal_function attribute_hidden;
381 #endif /* localeinfo.h */