2002-08-02 Roland McGrath <roland@redhat.com>
[platform/upstream/glibc.git] / locale / localeinfo.h
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.
4
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.
9
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.
14
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.  */
19
20 #ifndef _LOCALEINFO_H
21 #define _LOCALEINFO_H 1
22
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>
30
31 #include <intl/loadinfo.h>      /* For loaded_l10nfile definition.  */
32
33 /* Magic number at the beginning of a locale data file for CATEGORY.  */
34 #define LIMAGIC(category)       ((unsigned int) (0x20000828 ^ (category)))
35
36 /* Two special weight constants for the collation data.  */
37 #define IGNORE_CHAR     2
38
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
43
44 /* Structure describing locale data in core for a category.  */
45 struct locale_data
46 {
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   int mmaped;                   /* If nonzero the data is mmaped.  */
51
52   unsigned int usage_count;     /* Counter for users.  */
53
54   int use_translit;             /* Nonzero if the mb*towv*() and wc*tomb()
55                                    functions should use transliteration.  */
56   const char *options;          /* Extra options from the locale name,
57                                    not used in the path to the locale data.  */
58
59   unsigned int nstrings;        /* Number of strings below.  */
60   union locale_data_value
61   {
62     const uint32_t *wstr;
63     const char *string;
64     unsigned int word;
65   }
66   values __flexarr;     /* Items, usually pointers into `filedata'.  */
67 };
68
69 /* We know three kinds of collation sorting rules.  */
70 enum coll_sort_rule
71 {
72   illegal_0__,
73   sort_forward,
74   sort_backward,
75   illegal_3__,
76   sort_position,
77   sort_forward_position,
78   sort_backward_position,
79   sort_mask
80 };
81
82 /* We can map the types of the entries into a few categories.  */
83 enum value_type
84 {
85   none,
86   string,
87   stringarray,
88   byte,
89   bytearray,
90   word,
91   stringlist,
92   wordarray,
93   wstring,
94   wstringarray,
95   wstringlist
96 };
97
98
99 /* Definitions for `era' information from LC_TIME.  */
100 #define ERA_NAME_FORMAT_MEMBERS 4
101 #define ERA_M_NAME   0
102 #define ERA_M_FORMAT 1
103 #define ERA_W_NAME   2
104 #define ERA_W_FORMAT 3
105
106
107 /* Structure to access `era' information from LC_TIME.  */
108 struct era_entry
109 {
110   uint32_t direction;           /* Contains '+' or '-'.  */
111   int32_t offset;
112   int32_t start_date[3];
113   int32_t stop_date[3];
114   const char *era_name;
115   const char *era_format;
116   const wchar_t *era_wname;
117   const wchar_t *era_wformat;
118   int absolute_direction;
119   /* absolute direction:
120      +1 indicates that year number is higher in the future. (like A.D.)
121      -1 indicates that year number is higher in the past. (like B.C.)  */
122 };
123
124
125 /* LC_CTYPE specific:
126    Hardwired indices for standard wide character translation mappings.  */
127 enum
128 {
129   __TOW_toupper = 0,
130   __TOW_tolower = 1
131 };
132
133
134 /* LC_CTYPE specific:
135    Access a wide character class with a single character index.
136    _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
137    c must be an `unsigned char'.  desc must be a nonzero wctype_t.  */
138 #define _ISCTYPE(c, desc) \
139   (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
140
141
142 /* For each category declare the variable for the current locale data.  */
143 /* XXX _nl_current_LC_CTYPE and _nl_current_LC_COLLATE were exported
144    but where are they used?  */
145 #define DEFINE_CATEGORY(category, category_name, items, a) \
146 extern struct locale_data *_nl_current_##category attribute_hidden;
147 #include "categories.def"
148 #undef  DEFINE_CATEGORY
149
150 extern const char *const _nl_category_names[__LC_LAST] attribute_hidden;
151 extern const size_t _nl_category_name_sizes[__LC_LAST] attribute_hidden;
152 extern struct locale_data * *const _nl_current[__LC_LAST] attribute_hidden;
153
154 /* Name of the standard locales.  */
155 extern const char _nl_C_name[] attribute_hidden;
156 extern const char _nl_POSIX_name[] attribute_hidden;
157
158 /* The standard codeset.  */
159 extern const char _nl_C_codeset[] attribute_hidden;
160
161 /* Return a pointer to the current `struct locale_data' for CATEGORY.  */
162 #define _NL_CURRENT_DATA(category)      \
163   ((const struct locale_data *) _nl_current_##category)
164
165 /* Extract the current CATEGORY locale's string for ITEM.  */
166 #define _NL_CURRENT(category, item) \
167   (_nl_current_##category->values[_NL_ITEM_INDEX (item)].string)
168
169 /* Extract the current CATEGORY locale's string for ITEM.  */
170 #define _NL_CURRENT_WSTR(category, item) \
171   ((wchar_t *) _nl_current_##category->values[_NL_ITEM_INDEX (item)].wstr)
172
173 /* Extract the current CATEGORY locale's word for ITEM.  */
174 #define _NL_CURRENT_WORD(category, item) \
175   (_nl_current_##category->values[_NL_ITEM_INDEX (item)].word)
176
177 /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY.  */
178 #define _NL_CURRENT_DEFINE(category) \
179   extern struct locale_data _nl_C_##category attribute_hidden; \
180   struct locale_data *_nl_current_##category = &_nl_C_##category
181
182 /* Load the locale data for CATEGORY from the file specified by *NAME.
183    If *NAME is "", use environment variables as specified by POSIX,
184    and fill in *NAME with the actual name used.  The directories
185    listed in LOCALE_PATH are searched for the locale files.  */
186 extern struct locale_data *_nl_find_locale (const char *locale_path,
187                                             size_t locale_path_len,
188                                             int category, const char **name);
189
190 /* Try to load the file described by FILE.  */
191 extern void _nl_load_locale (struct loaded_l10nfile *file, int category);
192
193 /* Free all resource.  */
194 extern void _nl_unload_locale (struct locale_data *locale);
195
196 /* Free the locale and give back all memory if the usage count is one.  */
197 extern void _nl_remove_locale (int locale, struct locale_data *data);
198
199
200 /* Return `era' entry which corresponds to TP.  Used in strftime.  */
201 extern struct era_entry *_nl_get_era_entry (const struct tm *tp);
202
203 /* Return `era' cnt'th entry .  Used in strptime.  */
204 extern struct era_entry *_nl_select_era_entry (int cnt);
205
206 /* Return `alt_digit' which corresponds to NUMBER.  Used in strftime.  */
207 extern const char *_nl_get_alt_digit (unsigned int number);
208
209 /* Similar, but now for wide characters.  */
210 extern const wchar_t *_nl_get_walt_digit (unsigned int number);
211
212 /* Parse string as alternative digit and return numeric value.  */
213 extern int _nl_parse_alt_digit (const char **strp);
214
215 /* Postload processing.  */
216 extern void _nl_postload_ctype (void);
217 extern void _nl_postload_time (void);
218
219
220 #endif  /* localeinfo.h */