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