Update.
[glibc.git] / locale / localeinfo.h
blobced96ac4a960d1694710340941baec7f440418d7
1 /* Declarations for internal libc locale interfaces
2 Copyright (C) 1995, 1996, 1997, 1998, 1999 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 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 <time.h>
27 #include <stdint.h>
28 #include <sys/types.h>
30 /* This has to be changed whenever a new locale is defined. */
31 #define __LC_LAST 13
33 #include <intl/loadinfo.h> /* For loaded_l10nfile definition. */
35 /* Magic number at the beginning of a locale data file for CATEGORY. */
36 #define LIMAGIC(category) (0x980505 ^ (category))
38 /* Two special weight constants for the collation data. */
39 #define IGNORE_CHAR 2
41 /* We use a special value for the usage counter in `locale_data' to
42 signal that this data must never be removed anymore. */
43 #define MAX_USAGE_COUNT (UINT_MAX - 1)
44 #define UNDELETABLE UINT_MAX
46 /* Structure describing locale data in core for a category. */
47 struct locale_data
49 const char *name;
50 const char *filedata; /* Region mapping the file data. */
51 off_t filesize; /* Size of the file (and the region). */
52 int mmaped; /* If nonzero the data is mmaped. */
54 unsigned int usage_count; /* Counter for users. */
56 unsigned int nstrings; /* Number of strings below. */
57 union locale_data_value
59 const uint32_t *wstr;
60 const char *string;
61 unsigned int word;
63 values[0]; /* Items, usually pointers into `filedata'. */
66 /* We know three kinds of collation sorting rules. */
67 enum coll_sort_rule
69 illegal_0__,
70 sort_forward,
71 sort_backward,
72 illegal_3__,
73 sort_position,
74 sort_forward_position,
75 sort_backward_position,
76 sort_mask
79 /* We can map the types of the entries into a few categories. */
80 enum value_type
82 none,
83 string,
84 stringarray,
85 byte,
86 bytearray,
87 word,
88 stringlist,
89 wordarray
93 /* Definitions for `era' information from LC_TIME. */
94 #define ERA_NAME_FORMAT_MEMBERS 4
95 #define ERA_M_NAME 0
96 #define ERA_M_FORMAT 1
97 #define ERA_W_NAME 2
98 #define ERA_W_FORMAT 3
101 /* Structure to access `era' information from LC_TIME. */
102 struct era_entry
104 uint32_t direction; /* Contains '+' or '-'. */
105 int32_t offset;
106 int32_t start_date[3];
107 int32_t stop_date[3];
108 const char *era_name;
109 const char *era_format;
110 const wchar_t *era_wname;
111 const wchar_t *era_wformat;
112 int absolute_direction;
113 /* absolute direction:
114 +1 indicates that year number is higher in the future. (like A.D.)
115 -1 indicates that year number is higher in the past. (like B.C.) */
119 /* For each category declare the variable for the current locale data. */
120 #define DEFINE_CATEGORY(category, category_name, items, a) \
121 extern struct locale_data *_nl_current_##category;
122 #include "categories.def"
123 #undef DEFINE_CATEGORY
125 extern const char *const _nl_category_names[__LC_LAST];
126 extern const size_t _nl_category_name_sizes[__LC_LAST];
127 extern struct locale_data * *const _nl_current[__LC_LAST];
129 /* Name of the standard locales. */
130 extern const char _nl_C_name[];
131 extern const char _nl_POSIX_name[];
133 /* Extract the current CATEGORY locale's string for ITEM. */
134 #define _NL_CURRENT(category, item) \
135 (_nl_current_##category->values[_NL_ITEM_INDEX (item)].string)
137 /* Extract the current CATEGORY locale's string for ITEM. */
138 #define _NL_CURRENT_WSTR(category, item) \
139 ((wchar_t *) (_nl_current_##category->values[_NL_ITEM_INDEX (item)].wstr))
141 /* Extract the current CATEGORY locale's word for ITEM. */
142 #define _NL_CURRENT_WORD(category, item) \
143 (_nl_current_##category->values[_NL_ITEM_INDEX (item)].word)
145 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */
146 #define _NL_CURRENT_DEFINE(category) \
147 extern struct locale_data _nl_C_##category; \
148 struct locale_data *_nl_current_##category = &_nl_C_##category
150 /* Load the locale data for CATEGORY from the file specified by *NAME.
151 If *NAME is "", use environment variables as specified by POSIX,
152 and fill in *NAME with the actual name used. The directories
153 listed in LOCALE_PATH are searched for the locale files. */
154 extern struct locale_data *_nl_find_locale (const char *locale_path,
155 size_t locale_path_len,
156 int category, const char **name);
158 /* Try to load the file described by FILE. */
159 extern void _nl_load_locale (struct loaded_l10nfile *file, int category);
161 /* Free all resource. */
162 extern void _nl_unload_locale (struct locale_data *locale);
164 /* Free the locale and give back all memory if the usage count is one. */
165 extern void _nl_remove_locale (int locale, struct locale_data *data);
168 /* Return `era' entry which corresponds to TP. Used in strftime. */
169 extern struct era_entry *_nl_get_era_entry (const struct tm *tp);
171 /* Return `era' cnt'th entry . Used in strptime. */
172 extern struct era_entry *_nl_select_era_entry (int cnt);
174 /* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */
175 extern const char *_nl_get_alt_digit (unsigned int number);
177 /* Similar, but now for wide characters. */
178 extern const wchar_t *_nl_get_walt_digit (unsigned int number);
180 #endif /* localeinfo.h */