xref: /haiku/src/system/libroot/posix/glibc/locale/localeinfo.h (revision 5af32e752606778be5dd7379f319fe43cb3f6b8c)
1*5af32e75SAxel Dörfler /* Declarations for internal libc locale interfaces
2*5af32e75SAxel Dörfler    Copyright (C) 1995, 96, 97, 98, 99,2000,2001 Free Software Foundation, Inc.
3*5af32e75SAxel Dörfler    This file is part of the GNU C Library.
4*5af32e75SAxel Dörfler 
5*5af32e75SAxel Dörfler    The GNU C Library is free software; you can redistribute it and/or
6*5af32e75SAxel Dörfler    modify it under the terms of the GNU Lesser General Public
7*5af32e75SAxel Dörfler    License as published by the Free Software Foundation; either
8*5af32e75SAxel Dörfler    version 2.1 of the License, or (at your option) any later version.
9*5af32e75SAxel Dörfler 
10*5af32e75SAxel Dörfler    The GNU C Library is distributed in the hope that it will be useful,
11*5af32e75SAxel Dörfler    but WITHOUT ANY WARRANTY; without even the implied warranty of
12*5af32e75SAxel Dörfler    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13*5af32e75SAxel Dörfler    Lesser General Public License for more details.
14*5af32e75SAxel Dörfler 
15*5af32e75SAxel Dörfler    You should have received a copy of the GNU Lesser General Public
16*5af32e75SAxel Dörfler    License along with the GNU C Library; if not, write to the Free
17*5af32e75SAxel Dörfler    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18*5af32e75SAxel Dörfler    02111-1307 USA.  */
19*5af32e75SAxel Dörfler 
20*5af32e75SAxel Dörfler #ifndef _LOCALEINFO_H
21*5af32e75SAxel Dörfler #define _LOCALEINFO_H 1
22*5af32e75SAxel Dörfler 
23*5af32e75SAxel Dörfler #include <stddef.h>
24*5af32e75SAxel Dörfler #include <langinfo.h>
25*5af32e75SAxel Dörfler #include <limits.h>
26*5af32e75SAxel Dörfler #include <time.h>
27*5af32e75SAxel Dörfler #include <stdint.h>
28*5af32e75SAxel Dörfler #include <sys/types.h>
29*5af32e75SAxel Dörfler 
30*5af32e75SAxel Dörfler /* This has to be changed whenever a new locale is defined.  */
31*5af32e75SAxel Dörfler #define __LC_LAST	13
32*5af32e75SAxel Dörfler 
33*5af32e75SAxel Dörfler #include <intl/loadinfo.h>	/* For loaded_l10nfile definition.  */
34*5af32e75SAxel Dörfler 
35*5af32e75SAxel Dörfler /* Magic number at the beginning of a locale data file for CATEGORY.  */
36*5af32e75SAxel Dörfler #define	LIMAGIC(category)	((unsigned int) (0x20000828 ^ (category)))
37*5af32e75SAxel Dörfler 
38*5af32e75SAxel Dörfler /* Two special weight constants for the collation data.  */
39*5af32e75SAxel Dörfler #define IGNORE_CHAR	2
40*5af32e75SAxel Dörfler 
41*5af32e75SAxel Dörfler /* We use a special value for the usage counter in `locale_data' to
42*5af32e75SAxel Dörfler    signal that this data must never be removed anymore.  */
43*5af32e75SAxel Dörfler #define MAX_USAGE_COUNT (UINT_MAX - 1)
44*5af32e75SAxel Dörfler #define UNDELETABLE	UINT_MAX
45*5af32e75SAxel Dörfler 
46*5af32e75SAxel Dörfler /* Structure describing locale data in core for a category.  */
47*5af32e75SAxel Dörfler struct locale_data
48*5af32e75SAxel Dörfler {
49*5af32e75SAxel Dörfler   const char *name;
50*5af32e75SAxel Dörfler   const char *filedata;		/* Region mapping the file data.  */
51*5af32e75SAxel Dörfler   off_t filesize;		/* Size of the file (and the region).  */
52*5af32e75SAxel Dörfler   int mmaped;			/* If nonzero the data is mmaped.  */
53*5af32e75SAxel Dörfler 
54*5af32e75SAxel Dörfler   unsigned int usage_count;	/* Counter for users.  */
55*5af32e75SAxel Dörfler 
56*5af32e75SAxel Dörfler   int use_translit;		/* Nonzero if the mb*towv*() and wc*tomb()
57*5af32e75SAxel Dörfler 				   functions should use transliteration.  */
58*5af32e75SAxel Dörfler   const char *options;		/* Extra options from the locale name,
59*5af32e75SAxel Dörfler 				   not used in the path to the locale data.  */
60*5af32e75SAxel Dörfler 
61*5af32e75SAxel Dörfler   unsigned int nstrings;	/* Number of strings below.  */
62*5af32e75SAxel Dörfler   union locale_data_value
63*5af32e75SAxel Dörfler   {
64*5af32e75SAxel Dörfler     const uint32_t *wstr;
65*5af32e75SAxel Dörfler     const char *string;
66*5af32e75SAxel Dörfler     unsigned int word;
67*5af32e75SAxel Dörfler   }
68*5af32e75SAxel Dörfler   values __flexarr;	/* Items, usually pointers into `filedata'.  */
69*5af32e75SAxel Dörfler };
70*5af32e75SAxel Dörfler 
71*5af32e75SAxel Dörfler /* We know three kinds of collation sorting rules.  */
72*5af32e75SAxel Dörfler enum coll_sort_rule
73*5af32e75SAxel Dörfler {
74*5af32e75SAxel Dörfler   illegal_0__,
75*5af32e75SAxel Dörfler   sort_forward,
76*5af32e75SAxel Dörfler   sort_backward,
77*5af32e75SAxel Dörfler   illegal_3__,
78*5af32e75SAxel Dörfler   sort_position,
79*5af32e75SAxel Dörfler   sort_forward_position,
80*5af32e75SAxel Dörfler   sort_backward_position,
81*5af32e75SAxel Dörfler   sort_mask
82*5af32e75SAxel Dörfler };
83*5af32e75SAxel Dörfler 
84*5af32e75SAxel Dörfler /* We can map the types of the entries into a few categories.  */
85*5af32e75SAxel Dörfler enum value_type
86*5af32e75SAxel Dörfler {
87*5af32e75SAxel Dörfler   none,
88*5af32e75SAxel Dörfler   string,
89*5af32e75SAxel Dörfler   stringarray,
90*5af32e75SAxel Dörfler   byte,
91*5af32e75SAxel Dörfler   bytearray,
92*5af32e75SAxel Dörfler   word,
93*5af32e75SAxel Dörfler   stringlist,
94*5af32e75SAxel Dörfler   wordarray,
95*5af32e75SAxel Dörfler   wstring,
96*5af32e75SAxel Dörfler   wstringarray,
97*5af32e75SAxel Dörfler   wstringlist
98*5af32e75SAxel Dörfler };
99*5af32e75SAxel Dörfler 
100*5af32e75SAxel Dörfler 
101*5af32e75SAxel Dörfler /* Definitions for `era' information from LC_TIME.  */
102*5af32e75SAxel Dörfler #define ERA_NAME_FORMAT_MEMBERS 4
103*5af32e75SAxel Dörfler #define ERA_M_NAME   0
104*5af32e75SAxel Dörfler #define ERA_M_FORMAT 1
105*5af32e75SAxel Dörfler #define ERA_W_NAME   2
106*5af32e75SAxel Dörfler #define ERA_W_FORMAT 3
107*5af32e75SAxel Dörfler 
108*5af32e75SAxel Dörfler 
109*5af32e75SAxel Dörfler /* Structure to access `era' information from LC_TIME.  */
110*5af32e75SAxel Dörfler struct era_entry
111*5af32e75SAxel Dörfler {
112*5af32e75SAxel Dörfler   uint32_t direction;		/* Contains '+' or '-'.  */
113*5af32e75SAxel Dörfler   int32_t offset;
114*5af32e75SAxel Dörfler   int32_t start_date[3];
115*5af32e75SAxel Dörfler   int32_t stop_date[3];
116*5af32e75SAxel Dörfler   const char *era_name;
117*5af32e75SAxel Dörfler   const char *era_format;
118*5af32e75SAxel Dörfler   const wchar_t *era_wname;
119*5af32e75SAxel Dörfler   const wchar_t *era_wformat;
120*5af32e75SAxel Dörfler   int absolute_direction;
121*5af32e75SAxel Dörfler   /* absolute direction:
122*5af32e75SAxel Dörfler      +1 indicates that year number is higher in the future. (like A.D.)
123*5af32e75SAxel Dörfler      -1 indicates that year number is higher in the past. (like B.C.)  */
124*5af32e75SAxel Dörfler };
125*5af32e75SAxel Dörfler 
126*5af32e75SAxel Dörfler 
127*5af32e75SAxel Dörfler /* LC_CTYPE specific:
128*5af32e75SAxel Dörfler    Hardwired indices for standard wide character translation mappings.  */
129*5af32e75SAxel Dörfler enum
130*5af32e75SAxel Dörfler {
131*5af32e75SAxel Dörfler   __TOW_toupper = 0,
132*5af32e75SAxel Dörfler   __TOW_tolower = 1
133*5af32e75SAxel Dörfler };
134*5af32e75SAxel Dörfler 
135*5af32e75SAxel Dörfler 
136*5af32e75SAxel Dörfler /* LC_CTYPE specific:
137*5af32e75SAxel Dörfler    Access a wide character class with a single character index.
138*5af32e75SAxel Dörfler    _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
139*5af32e75SAxel Dörfler    c must be an `unsigned char'.  desc must be a nonzero wctype_t.  */
140*5af32e75SAxel Dörfler #define _ISCTYPE(c, desc) \
141*5af32e75SAxel Dörfler   (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
142*5af32e75SAxel Dörfler 
143*5af32e75SAxel Dörfler 
144*5af32e75SAxel Dörfler /* For each category declare the variable for the current locale data.  */
145*5af32e75SAxel Dörfler #define DEFINE_CATEGORY(category, category_name, items, a) \
146*5af32e75SAxel Dörfler extern struct locale_data *_nl_current_##category;
147*5af32e75SAxel Dörfler #include "categories.def"
148*5af32e75SAxel Dörfler #undef	DEFINE_CATEGORY
149*5af32e75SAxel Dörfler 
150*5af32e75SAxel Dörfler extern const char *const _nl_category_names[__LC_LAST];
151*5af32e75SAxel Dörfler extern const size_t _nl_category_name_sizes[__LC_LAST];
152*5af32e75SAxel Dörfler extern struct locale_data * *const _nl_current[__LC_LAST];
153*5af32e75SAxel Dörfler 
154*5af32e75SAxel Dörfler /* Name of the standard locales.  */
155*5af32e75SAxel Dörfler extern const char _nl_C_name[];
156*5af32e75SAxel Dörfler extern const char _nl_POSIX_name[];
157*5af32e75SAxel Dörfler 
158*5af32e75SAxel Dörfler /* The standard codeset.  */
159*5af32e75SAxel Dörfler extern const char _nl_C_codeset[];
160*5af32e75SAxel Dörfler 
161*5af32e75SAxel Dörfler /* Extract the current CATEGORY locale's string for ITEM.  */
162*5af32e75SAxel Dörfler #define _NL_CURRENT(category, item) \
163*5af32e75SAxel Dörfler   (_nl_current_##category->values[_NL_ITEM_INDEX (item)].string)
164*5af32e75SAxel Dörfler 
165*5af32e75SAxel Dörfler /* Extract the current CATEGORY locale's string for ITEM.  */
166*5af32e75SAxel Dörfler #define _NL_CURRENT_WSTR(category, item) \
167*5af32e75SAxel Dörfler   ((wchar_t *) (_nl_current_##category->values[_NL_ITEM_INDEX (item)].wstr))
168*5af32e75SAxel Dörfler 
169*5af32e75SAxel Dörfler /* Extract the current CATEGORY locale's word for ITEM.  */
170*5af32e75SAxel Dörfler #define _NL_CURRENT_WORD(category, item) \
171*5af32e75SAxel Dörfler   (_nl_current_##category->values[_NL_ITEM_INDEX (item)].word)
172*5af32e75SAxel Dörfler 
173*5af32e75SAxel Dörfler /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY.  */
174*5af32e75SAxel Dörfler #define _NL_CURRENT_DEFINE(category) \
175*5af32e75SAxel Dörfler   extern struct locale_data _nl_C_##category; \
176*5af32e75SAxel Dörfler   struct locale_data *_nl_current_##category = &_nl_C_##category
177*5af32e75SAxel Dörfler 
178*5af32e75SAxel Dörfler /* Load the locale data for CATEGORY from the file specified by *NAME.
179*5af32e75SAxel Dörfler    If *NAME is "", use environment variables as specified by POSIX,
180*5af32e75SAxel Dörfler    and fill in *NAME with the actual name used.  The directories
181*5af32e75SAxel Dörfler    listed in LOCALE_PATH are searched for the locale files.  */
182*5af32e75SAxel Dörfler extern struct locale_data *_nl_find_locale (const char *locale_path,
183*5af32e75SAxel Dörfler 					    size_t locale_path_len,
184*5af32e75SAxel Dörfler 					    int category, const char **name);
185*5af32e75SAxel Dörfler 
186*5af32e75SAxel Dörfler /* Try to load the file described by FILE.  */
187*5af32e75SAxel Dörfler extern void _nl_load_locale (struct loaded_l10nfile *file, int category);
188*5af32e75SAxel Dörfler 
189*5af32e75SAxel Dörfler /* Free all resource.  */
190*5af32e75SAxel Dörfler extern void _nl_unload_locale (struct locale_data *locale);
191*5af32e75SAxel Dörfler 
192*5af32e75SAxel Dörfler /* Free the locale and give back all memory if the usage count is one.  */
193*5af32e75SAxel Dörfler extern void _nl_remove_locale (int locale, struct locale_data *data);
194*5af32e75SAxel Dörfler 
195*5af32e75SAxel Dörfler 
196*5af32e75SAxel Dörfler /* Return `era' entry which corresponds to TP.  Used in strftime.  */
197*5af32e75SAxel Dörfler extern struct era_entry *_nl_get_era_entry (const struct tm *tp);
198*5af32e75SAxel Dörfler 
199*5af32e75SAxel Dörfler /* Return `era' cnt'th entry .  Used in strptime.  */
200*5af32e75SAxel Dörfler extern struct era_entry *_nl_select_era_entry (int cnt);
201*5af32e75SAxel Dörfler 
202*5af32e75SAxel Dörfler /* Return `alt_digit' which corresponds to NUMBER.  Used in strftime.  */
203*5af32e75SAxel Dörfler extern const char *_nl_get_alt_digit (unsigned int number);
204*5af32e75SAxel Dörfler 
205*5af32e75SAxel Dörfler /* Similar, but now for wide characters.  */
206*5af32e75SAxel Dörfler extern const wchar_t *_nl_get_walt_digit (unsigned int number);
207*5af32e75SAxel Dörfler 
208*5af32e75SAxel Dörfler /* Parse string as alternative digit and return numeric value.  */
209*5af32e75SAxel Dörfler extern int _nl_parse_alt_digit (const char **strp);
210*5af32e75SAxel Dörfler 
211*5af32e75SAxel Dörfler /* Postload processing.  */
212*5af32e75SAxel Dörfler extern void _nl_postload_ctype (void);
213*5af32e75SAxel Dörfler extern void _nl_postload_time (void);
214*5af32e75SAxel Dörfler 
215*5af32e75SAxel Dörfler 
216*5af32e75SAxel Dörfler #endif	/* localeinfo.h */
217