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
21 #define _LOCALEINFO_H 1
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. */
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. */
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. */
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
69 values __flexarr
; /* Items, usually pointers into `filedata'. */
72 /* We know three kinds of collation sorting rules. */
80 sort_forward_position
,
81 sort_backward_position
,
85 /* We can map the types of the entries into a few categories. */
102 /* Definitions for `era' information from LC_TIME. */
103 #define ERA_NAME_FORMAT_MEMBERS 4
105 #define ERA_M_FORMAT 1
107 #define ERA_W_FORMAT 3
110 /* Structure to access `era' information from LC_TIME. */
113 uint32_t direction
; /* Contains '+' or '-'. */
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. */
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
;
161 /* For each category declare the variable for the current locale data. */
162 /* XXX _nl_current_LC_CTYPE and _nl_current_LC_COLLATE were exported
163 but where are they used? */
164 #define DEFINE_CATEGORY(category, category_name, items, a) \
165 extern struct locale_data *_nl_current_##category attribute_hidden;
166 #include "categories.def"
167 #undef DEFINE_CATEGORY
168 extern struct locale_data
* *const _nl_current
[__LC_LAST
] attribute_hidden
;
170 /* Return a pointer to the current `struct locale_data' for CATEGORY. */
171 #define _NL_CURRENT_DATA(category) _nl_current_##category
172 /* Hackety hack, don't talk back. */
173 #define _nl_current_category (*_nl_current[category])
175 /* Extract the current CATEGORY locale's string for ITEM. */
176 #define _NL_CURRENT(category, item) \
177 (_nl_current_##category->values[_NL_ITEM_INDEX (item)].string)
179 /* Extract the current CATEGORY locale's string for ITEM. */
180 #define _NL_CURRENT_WSTR(category, item) \
181 ((wchar_t *) _nl_current_##category->values[_NL_ITEM_INDEX (item)].wstr)
183 /* Extract the current CATEGORY locale's word for ITEM. */
184 #define _NL_CURRENT_WORD(category, item) \
185 (_nl_current_##category->values[_NL_ITEM_INDEX (item)].word)
187 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
188 #define _NL_CURRENT_DEFINE(category) \
189 extern struct locale_data _nl_C_##category attribute_hidden; \
190 struct locale_data *_nl_current_##category = &_nl_C_##category
194 /* All categories are always loaded in the shared library, so there is no
195 point in having lots of separate symbols for linking. */
197 # include <bits/libc-tsd.h>
199 __libc_tsd_define (extern, LOCALE
)
201 extern struct __locale_struct _nl_global_locale attribute_hidden
;
203 # define _NL_CURRENT_LOCALE \
204 ((__locale_t) __libc_tsd_get (LOCALE))
206 /* Return a pointer to the current `struct locale_data' for CATEGORY. */
207 # define _NL_CURRENT_DATA(category) \
208 (_NL_CURRENT_LOCALE->__locales[category])
210 /* Extract the current CATEGORY locale's string for ITEM. */
211 # define _NL_CURRENT(category, item) \
212 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
214 /* Extract the current CATEGORY locale's string for ITEM. */
215 # define _NL_CURRENT_WSTR(category, item) \
216 ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
218 /* Extract the current CATEGORY locale's word for ITEM. */
219 # define _NL_CURRENT_WORD(category, item) \
220 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
222 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
223 # define _NL_CURRENT_DEFINE(category) \
224 /* No per-category variable here. */
229 /* Default search path if no LOCPATH environment variable. */
230 extern const char _nl_default_locale_path
[] attribute_hidden
;
232 /* Load the locale data for CATEGORY from the file specified by *NAME.
233 If *NAME is "", use environment variables as specified by POSIX, and
234 fill in *NAME with the actual name used. If LOCALE_PATH is not null,
235 those directories are searched for the locale files. If it's null,
236 the locale archive is checked first and then _nl_default_locale_path
237 is searched for locale files. */
238 extern struct locale_data
*_nl_find_locale (const char *locale_path
,
239 size_t locale_path_len
,
240 int category
, const char **name
)
241 internal_function attribute_hidden
;
243 /* Try to load the file described by FILE. */
244 extern void _nl_load_locale (struct loaded_l10nfile
*file
, int category
)
245 internal_function attribute_hidden
;
247 /* Free all resource. */
248 extern void _nl_unload_locale (struct locale_data
*locale
)
249 internal_function attribute_hidden
;
251 /* Free the locale and give back all memory if the usage count is one. */
252 extern void _nl_remove_locale (int locale
, struct locale_data
*data
)
253 internal_function attribute_hidden
;
255 /* Find the locale *NAMEP in the locale archive, and return the
256 internalized data structure for its CATEGORY data. If this locale has
257 already been loaded from the archive, just returns the existing data
258 structure. If successful, sets *NAMEP to point directly into the mapped
259 archive string table; that way, the next call can short-circuit strcmp. */
260 extern struct locale_data
*_nl_load_locale_from_archive (int category
,
262 internal_function attribute_hidden
;
264 /* Validate the contents of a locale file and set up the in-core
265 data structure to point into the data. This leaves the `alloc'
266 and `name' fields uninitialized, for the caller to fill in.
267 If any bogons are detected in the data, this will refuse to
268 intern it, and return a null pointer instead. */
269 extern struct locale_data
*_nl_intern_locale_data (int category
,
272 internal_function attribute_hidden
;
275 /* Return `era' entry which corresponds to TP. Used in strftime. */
276 extern struct era_entry
*_nl_get_era_entry (const struct tm
*tp
);
278 /* Return `era' cnt'th entry . Used in strptime. */
279 extern struct era_entry
*_nl_select_era_entry (int cnt
);
281 /* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */
282 extern const char *_nl_get_alt_digit (unsigned int number
);
284 /* Similar, but now for wide characters. */
285 extern const wchar_t *_nl_get_walt_digit (unsigned int number
);
287 /* Parse string as alternative digit and return numeric value. */
288 extern int _nl_parse_alt_digit (const char **strp
);
290 /* Postload processing. */
291 extern void _nl_postload_ctype (void);
292 extern void _nl_postload_time (void);
295 #endif /* localeinfo.h */