(open_archive): Replace using label 'again' with a loop to work around gcc 3.2 bug.
[glibc.git] / locale / localeinfo.h
blob4e8c86edfaa3cf19caec5260bec6c63f235accc6
1 /* Declarations for internal libc locale interfaces
2 Copyright (C) 1995-2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _LOCALEINFO_H
21 #define _LOCALEINFO_H 1
23 #include <stddef.h>
24 #include <langinfo.h>
25 #include <limits.h>
26 #include <locale.h>
27 #include <time.h>
28 #include <stdint.h>
29 #include <sys/types.h>
31 #include <intl/loadinfo.h> /* For loaded_l10nfile definition. */
33 /* Magic number at the beginning of a locale data file for CATEGORY. */
34 #define LIMAGIC(category) ((unsigned int) (0x20000828 ^ (category)))
36 /* Two special weight constants for the collation data. */
37 #define IGNORE_CHAR 2
39 /* We use a special value for the usage counter in `locale_data' to
40 signal that this data must never be removed anymore. */
41 #define MAX_USAGE_COUNT (UINT_MAX - 1)
42 #define UNDELETABLE UINT_MAX
44 /* Structure describing locale data in core for a category. */
45 struct locale_data
47 const char *name;
48 const char *filedata; /* Region mapping the file data. */
49 off_t filesize; /* Size of the file (and the region). */
50 enum /* Flavor of storage used for those. */
52 ld_malloced, /* Both are malloc'd. */
53 ld_mapped, /* name is malloc'd, filedata mmap'd */
54 ld_archive /* Both point into mmap'd archive regions. */
55 } alloc;
57 unsigned int usage_count; /* Counter for users. */
59 int use_translit; /* Nonzero if the mb*towv*() and wc*tomb()
60 functions should use transliteration. */
62 unsigned int nstrings; /* Number of strings below. */
63 union locale_data_value
65 const uint32_t *wstr;
66 const char *string;
67 unsigned int word;
69 values __flexarr; /* Items, usually pointers into `filedata'. */
72 /* We know three kinds of collation sorting rules. */
73 enum coll_sort_rule
75 illegal_0__,
76 sort_forward,
77 sort_backward,
78 illegal_3__,
79 sort_position,
80 sort_forward_position,
81 sort_backward_position,
82 sort_mask
85 /* We can map the types of the entries into a few categories. */
86 enum value_type
88 none,
89 string,
90 stringarray,
91 byte,
92 bytearray,
93 word,
94 stringlist,
95 wordarray,
96 wstring,
97 wstringarray,
98 wstringlist
102 /* Definitions for `era' information from LC_TIME. */
103 #define ERA_NAME_FORMAT_MEMBERS 4
104 #define ERA_M_NAME 0
105 #define ERA_M_FORMAT 1
106 #define ERA_W_NAME 2
107 #define ERA_W_FORMAT 3
110 /* Structure to access `era' information from LC_TIME. */
111 struct era_entry
113 uint32_t direction; /* Contains '+' or '-'. */
114 int32_t offset;
115 int32_t start_date[3];
116 int32_t stop_date[3];
117 const char *era_name;
118 const char *era_format;
119 const wchar_t *era_wname;
120 const wchar_t *era_wformat;
121 int absolute_direction;
122 /* absolute direction:
123 +1 indicates that year number is higher in the future. (like A.D.)
124 -1 indicates that year number is higher in the past. (like B.C.) */
128 /* LC_CTYPE specific:
129 Hardwired indices for standard wide character translation mappings. */
130 enum
132 __TOW_toupper = 0,
133 __TOW_tolower = 1
137 /* LC_CTYPE specific:
138 Access a wide character class with a single character index.
139 _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
140 c must be an `unsigned char'. desc must be a nonzero wctype_t. */
141 #define _ISCTYPE(c, desc) \
142 (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
144 extern const char *const _nl_category_names[__LC_LAST] attribute_hidden;
145 extern const size_t _nl_category_name_sizes[__LC_LAST] attribute_hidden;
147 /* Name of the standard locales. */
148 extern const char _nl_C_name[] attribute_hidden;
149 extern const char _nl_POSIX_name[] attribute_hidden;
151 /* The standard codeset. */
152 extern const char _nl_C_codeset[] attribute_hidden;
154 /* Name of current locale for each individual category.
155 Each is malloc'd unless it is _nl_C_name. */
156 extern const char *_nl_current_names[] attribute_hidden;
158 /* This is the internal locale_t object that holds the global locale
159 controlled by calls to setlocale. A thread's TSD locale pointer
160 points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */
161 extern struct __locale_struct _nl_global_locale attribute_hidden;
163 /* This fetches the thread-local locale_t pointer, either one set with
164 uselocale or &_nl_global_locale. */
165 #define _NL_CURRENT_LOCALE ((__locale_t) __libc_tsd_get (LOCALE))
166 #include <bits/libc-tsd.h>
167 __libc_tsd_define (extern, LOCALE)
170 /* For static linking it is desireable to avoid always linking in the code
171 and data for every category when we can tell at link time that they are
172 unused. We can manage this playing some tricks with weak references.
173 But with thread-local locale settings, it becomes quite ungainly unless
174 we can use __thread variables. So only in that case do we attempt this. */
175 #if !defined SHARED && defined HAVE___THREAD && defined HAVE_WEAK_SYMBOLS
176 # include <tls.h>
177 # if USE_TLS
178 # define NL_CURRENT_INDIRECT 1
179 # endif
180 #endif
182 #ifdef NL_CURRENT_INDIRECT
184 /* For each category declare the thread-local variable for the current
185 locale data. This has an extra indirection so it points at the
186 __locales[CATEGORY] element in either _nl_global_locale or the current
187 locale object set by uselocale, which points at the actual data. The
188 reason for having these variables is so that references to particular
189 categories will link in the lc-CATEGORY.c module to define this symbol,
190 and we arrange that linking that module is what brings in all the code
191 associated with this category. */
192 #define DEFINE_CATEGORY(category, category_name, items, a) \
193 extern __thread struct locale_data *const *_nl_current_##category \
194 attribute_hidden;
195 #include "categories.def"
196 #undef DEFINE_CATEGORY
198 /* Return a pointer to the current `struct locale_data' for CATEGORY. */
199 #define _NL_CURRENT_DATA(category) (*_nl_current_##category)
201 /* Extract the current CATEGORY locale's string for ITEM. */
202 #define _NL_CURRENT(category, item) \
203 ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].string)
205 /* Extract the current CATEGORY locale's string for ITEM. */
206 #define _NL_CURRENT_WSTR(category, item) \
207 ((wchar_t *) (*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].wstr)
209 /* Extract the current CATEGORY locale's word for ITEM. */
210 #define _NL_CURRENT_WORD(category, item) \
211 ((*_nl_current_##category)->values[_NL_ITEM_INDEX (item)].word)
213 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
214 #define _NL_CURRENT_DEFINE(category) \
215 __thread struct locale_data *const *_nl_current_##category \
216 attribute_hidden = &_nl_global_locale.__locales[category]; \
217 asm (_NL_CURRENT_DEFINE_STRINGIFY (ASM_GLOBAL_DIRECTIVE) \
218 " " __SYMBOL_PREFIX "_nl_current_" #category "_used\n" \
219 _NL_CURRENT_DEFINE_ABS (_nl_current_##category##_used, 1));
220 #define _NL_CURRENT_DEFINE_STRINGIFY(x) _NL_CURRENT_DEFINE_STRINGIFY_1 (x)
221 #define _NL_CURRENT_DEFINE_STRINGIFY_1(x) #x
222 #ifdef HAVE_ASM_SET_DIRECTIVE
223 # define _NL_CURRENT_DEFINE_ABS(sym, val) ".set " #sym ", " #val
224 #else
225 # define _NL_CURRENT_DEFINE_ABS(sym, val) #sym " = " #val
226 #endif
228 #else
230 /* All categories are always loaded in the shared library, so there is no
231 point in having lots of separate symbols for linking. */
233 /* Return a pointer to the current `struct locale_data' for CATEGORY. */
234 # define _NL_CURRENT_DATA(category) \
235 (_NL_CURRENT_LOCALE->__locales[category])
237 /* Extract the current CATEGORY locale's string for ITEM. */
238 # define _NL_CURRENT(category, item) \
239 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
241 /* Extract the current CATEGORY locale's string for ITEM. */
242 # define _NL_CURRENT_WSTR(category, item) \
243 ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
245 /* Extract the current CATEGORY locale's word for ITEM. */
246 # define _NL_CURRENT_WORD(category, item) \
247 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
249 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
250 # define _NL_CURRENT_DEFINE(category) \
251 /* No per-category variable here. */
253 #endif
256 /* Default search path if no LOCPATH environment variable. */
257 extern const char _nl_default_locale_path[] attribute_hidden;
259 /* Load the locale data for CATEGORY from the file specified by *NAME.
260 If *NAME is "", use environment variables as specified by POSIX, and
261 fill in *NAME with the actual name used. If LOCALE_PATH is not null,
262 those directories are searched for the locale files. If it's null,
263 the locale archive is checked first and then _nl_default_locale_path
264 is searched for locale files. */
265 extern struct locale_data *_nl_find_locale (const char *locale_path,
266 size_t locale_path_len,
267 int category, const char **name)
268 internal_function attribute_hidden;
270 /* Try to load the file described by FILE. */
271 extern void _nl_load_locale (struct loaded_l10nfile *file, int category)
272 internal_function attribute_hidden;
274 /* Free all resource. */
275 extern void _nl_unload_locale (struct locale_data *locale)
276 internal_function attribute_hidden;
278 /* Free the locale and give back all memory if the usage count is one. */
279 extern void _nl_remove_locale (int locale, struct locale_data *data)
280 internal_function attribute_hidden;
282 /* Find the locale *NAMEP in the locale archive, and return the
283 internalized data structure for its CATEGORY data. If this locale has
284 already been loaded from the archive, just returns the existing data
285 structure. If successful, sets *NAMEP to point directly into the mapped
286 archive string table; that way, the next call can short-circuit strcmp. */
287 extern struct locale_data *_nl_load_locale_from_archive (int category,
288 const char **namep)
289 internal_function attribute_hidden;
291 /* Subroutine of setlocale's __libc_subfreeres hook. */
292 extern void _nl_archive_subfreeres (void) attribute_hidden;
294 /* Validate the contents of a locale file and set up the in-core
295 data structure to point into the data. This leaves the `alloc'
296 and `name' fields uninitialized, for the caller to fill in.
297 If any bogons are detected in the data, this will refuse to
298 intern it, and return a null pointer instead. */
299 extern struct locale_data *_nl_intern_locale_data (int category,
300 const void *data,
301 size_t datasize)
302 internal_function attribute_hidden;
305 /* Return `era' entry which corresponds to TP. Used in strftime. */
306 extern struct era_entry *_nl_get_era_entry (const struct tm *tp);
308 /* Return `era' cnt'th entry . Used in strptime. */
309 extern struct era_entry *_nl_select_era_entry (int cnt);
311 /* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */
312 extern const char *_nl_get_alt_digit (unsigned int number);
314 /* Similar, but now for wide characters. */
315 extern const wchar_t *_nl_get_walt_digit (unsigned int number);
317 /* Parse string as alternative digit and return numeric value. */
318 extern int _nl_parse_alt_digit (const char **strp);
320 /* Postload processing. */
321 extern void _nl_postload_ctype (void);
322 extern void _nl_postload_time (void);
325 #endif /* localeinfo.h */