xref: /haiku/src/system/libroot/posix/glibc/locale/localeinfo.h (revision 97f11716bfaa0f385eb0e28a52bf56a5023b9e99)
15af32e75SAxel Dörfler /* Declarations for internal libc locale interfaces
25af32e75SAxel Dörfler    Copyright (C) 1995, 96, 97, 98, 99,2000,2001 Free Software Foundation, Inc.
35af32e75SAxel Dörfler    This file is part of the GNU C Library.
45af32e75SAxel Dörfler 
55af32e75SAxel Dörfler    The GNU C Library is free software; you can redistribute it and/or
65af32e75SAxel Dörfler    modify it under the terms of the GNU Lesser General Public
75af32e75SAxel Dörfler    License as published by the Free Software Foundation; either
85af32e75SAxel Dörfler    version 2.1 of the License, or (at your option) any later version.
95af32e75SAxel Dörfler 
105af32e75SAxel Dörfler    The GNU C Library is distributed in the hope that it will be useful,
115af32e75SAxel Dörfler    but WITHOUT ANY WARRANTY; without even the implied warranty of
125af32e75SAxel Dörfler    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
135af32e75SAxel Dörfler    Lesser General Public License for more details.
145af32e75SAxel Dörfler 
155af32e75SAxel Dörfler    You should have received a copy of the GNU Lesser General Public
165af32e75SAxel Dörfler    License along with the GNU C Library; if not, write to the Free
175af32e75SAxel Dörfler    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
185af32e75SAxel Dörfler    02111-1307 USA.  */
195af32e75SAxel Dörfler 
205af32e75SAxel Dörfler #ifndef _LOCALEINFO_H
215af32e75SAxel Dörfler #define _LOCALEINFO_H 1
225af32e75SAxel Dörfler 
235af32e75SAxel Dörfler #include <stddef.h>
245af32e75SAxel Dörfler #include <langinfo.h>
255af32e75SAxel Dörfler #include <limits.h>
265af32e75SAxel Dörfler #include <time.h>
275af32e75SAxel Dörfler #include <stdint.h>
285af32e75SAxel Dörfler #include <sys/types.h>
295af32e75SAxel Dörfler 
30*d338200eSTrung Nguyen // __locale_struct
31*d338200eSTrung Nguyen #include <xlocale.h>
32*d338200eSTrung Nguyen // LC_* values
33*d338200eSTrung Nguyen #include <locale.h>
34*d338200eSTrung Nguyen 
355af32e75SAxel Dörfler /* This has to be changed whenever a new locale is defined.  */
36a3f66598SOliver Tappe #define __LC_LAST	7
375af32e75SAxel Dörfler 
385af32e75SAxel Dörfler #include <intl/loadinfo.h>	/* For loaded_l10nfile definition.  */
395af32e75SAxel Dörfler 
405af32e75SAxel Dörfler /* Magic number at the beginning of a locale data file for CATEGORY.  */
415af32e75SAxel Dörfler #define	LIMAGIC(category)	((unsigned int) (0x20000828 ^ (category)))
425af32e75SAxel Dörfler 
435af32e75SAxel Dörfler /* Two special weight constants for the collation data.  */
445af32e75SAxel Dörfler #define IGNORE_CHAR	2
455af32e75SAxel Dörfler 
465af32e75SAxel Dörfler /* We use a special value for the usage counter in `locale_data' to
475af32e75SAxel Dörfler    signal that this data must never be removed anymore.  */
485af32e75SAxel Dörfler #define MAX_USAGE_COUNT (UINT_MAX - 1)
495af32e75SAxel Dörfler #define UNDELETABLE	UINT_MAX
505af32e75SAxel Dörfler 
515af32e75SAxel Dörfler /* Structure describing locale data in core for a category.  */
525af32e75SAxel Dörfler struct locale_data
535af32e75SAxel Dörfler {
545af32e75SAxel Dörfler   const char *name;
555af32e75SAxel Dörfler   const char *filedata;		/* Region mapping the file data.  */
565af32e75SAxel Dörfler   off_t filesize;		/* Size of the file (and the region).  */
575af32e75SAxel Dörfler   int mmaped;			/* If nonzero the data is mmaped.  */
585af32e75SAxel Dörfler 
595af32e75SAxel Dörfler   unsigned int usage_count;	/* Counter for users.  */
605af32e75SAxel Dörfler 
615af32e75SAxel Dörfler   int use_translit;		/* Nonzero if the mb*towv*() and wc*tomb()
625af32e75SAxel Dörfler 				   functions should use transliteration.  */
635af32e75SAxel Dörfler   const char *options;		/* Extra options from the locale name,
645af32e75SAxel Dörfler 				   not used in the path to the locale data.  */
655af32e75SAxel Dörfler 
665af32e75SAxel Dörfler   unsigned int nstrings;	/* Number of strings below.  */
675af32e75SAxel Dörfler   union locale_data_value
685af32e75SAxel Dörfler   {
695af32e75SAxel Dörfler     const uint32_t *wstr;
705af32e75SAxel Dörfler     const char *string;
715af32e75SAxel Dörfler     unsigned int word;
725af32e75SAxel Dörfler   }
735af32e75SAxel Dörfler   values __flexarr;	/* Items, usually pointers into `filedata'.  */
745af32e75SAxel Dörfler };
755af32e75SAxel Dörfler 
765af32e75SAxel Dörfler /* We know three kinds of collation sorting rules.  */
775af32e75SAxel Dörfler enum coll_sort_rule
785af32e75SAxel Dörfler {
795af32e75SAxel Dörfler   illegal_0__,
805af32e75SAxel Dörfler   sort_forward,
815af32e75SAxel Dörfler   sort_backward,
825af32e75SAxel Dörfler   illegal_3__,
835af32e75SAxel Dörfler   sort_position,
845af32e75SAxel Dörfler   sort_forward_position,
855af32e75SAxel Dörfler   sort_backward_position,
865af32e75SAxel Dörfler   sort_mask
875af32e75SAxel Dörfler };
885af32e75SAxel Dörfler 
895af32e75SAxel Dörfler /* We can map the types of the entries into a few categories.  */
905af32e75SAxel Dörfler enum value_type
915af32e75SAxel Dörfler {
925af32e75SAxel Dörfler   none,
935af32e75SAxel Dörfler   string,
945af32e75SAxel Dörfler   stringarray,
955af32e75SAxel Dörfler   byte,
965af32e75SAxel Dörfler   bytearray,
975af32e75SAxel Dörfler   word,
985af32e75SAxel Dörfler   stringlist,
995af32e75SAxel Dörfler   wordarray,
1005af32e75SAxel Dörfler   wstring,
1015af32e75SAxel Dörfler   wstringarray,
1025af32e75SAxel Dörfler   wstringlist
1035af32e75SAxel Dörfler };
1045af32e75SAxel Dörfler 
1055af32e75SAxel Dörfler 
1065af32e75SAxel Dörfler /* Definitions for `era' information from LC_TIME.  */
1075af32e75SAxel Dörfler #define ERA_NAME_FORMAT_MEMBERS 4
1085af32e75SAxel Dörfler #define ERA_M_NAME   0
1095af32e75SAxel Dörfler #define ERA_M_FORMAT 1
1105af32e75SAxel Dörfler #define ERA_W_NAME   2
1115af32e75SAxel Dörfler #define ERA_W_FORMAT 3
1125af32e75SAxel Dörfler 
1135af32e75SAxel Dörfler 
1145af32e75SAxel Dörfler /* Structure to access `era' information from LC_TIME.  */
1155af32e75SAxel Dörfler struct era_entry
1165af32e75SAxel Dörfler {
1175af32e75SAxel Dörfler   uint32_t direction;		/* Contains '+' or '-'.  */
1185af32e75SAxel Dörfler   int32_t offset;
1195af32e75SAxel Dörfler   int32_t start_date[3];
1205af32e75SAxel Dörfler   int32_t stop_date[3];
1215af32e75SAxel Dörfler   const char *era_name;
1225af32e75SAxel Dörfler   const char *era_format;
1235af32e75SAxel Dörfler   const wchar_t *era_wname;
1245af32e75SAxel Dörfler   const wchar_t *era_wformat;
1255af32e75SAxel Dörfler   int absolute_direction;
1265af32e75SAxel Dörfler   /* absolute direction:
1275af32e75SAxel Dörfler      +1 indicates that year number is higher in the future. (like A.D.)
1285af32e75SAxel Dörfler      -1 indicates that year number is higher in the past. (like B.C.)  */
1295af32e75SAxel Dörfler };
1305af32e75SAxel Dörfler 
1315af32e75SAxel Dörfler 
1325af32e75SAxel Dörfler /* LC_CTYPE specific:
1335af32e75SAxel Dörfler    Hardwired indices for standard wide character translation mappings.  */
1345af32e75SAxel Dörfler enum
1355af32e75SAxel Dörfler {
1365af32e75SAxel Dörfler   __TOW_toupper = 0,
1375af32e75SAxel Dörfler   __TOW_tolower = 1
1385af32e75SAxel Dörfler };
1395af32e75SAxel Dörfler 
1405af32e75SAxel Dörfler 
1415af32e75SAxel Dörfler /* LC_CTYPE specific:
1425af32e75SAxel Dörfler    Access a wide character class with a single character index.
1435af32e75SAxel Dörfler    _ISCTYPE (c, desc) = iswctype (btowc (c), desc).
1445af32e75SAxel Dörfler    c must be an `unsigned char'.  desc must be a nonzero wctype_t.  */
1455af32e75SAxel Dörfler #define _ISCTYPE(c, desc) \
1465af32e75SAxel Dörfler   (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1)
1475af32e75SAxel Dörfler 
1485af32e75SAxel Dörfler 
1495af32e75SAxel Dörfler extern const char *const _nl_category_names[__LC_LAST];
1505af32e75SAxel Dörfler extern const size_t _nl_category_name_sizes[__LC_LAST];
1515af32e75SAxel Dörfler extern struct locale_data * *const _nl_current[__LC_LAST];
1525af32e75SAxel Dörfler 
1535af32e75SAxel Dörfler /* Name of the standard locales.  */
1545af32e75SAxel Dörfler extern const char _nl_C_name[];
1555af32e75SAxel Dörfler extern const char _nl_POSIX_name[];
1565af32e75SAxel Dörfler 
1575af32e75SAxel Dörfler /* The standard codeset.  */
1585af32e75SAxel Dörfler extern const char _nl_C_codeset[];
1595af32e75SAxel Dörfler 
160*d338200eSTrung Nguyen /* This is the internal locale_t object that holds the global locale
161*d338200eSTrung Nguyen    controlled by calls to setlocale.  A thread's TSD locale pointer
162*d338200eSTrung Nguyen    points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect.  */
163*d338200eSTrung Nguyen extern struct __locale_struct _nl_global_locale;
164*d338200eSTrung Nguyen 
165*d338200eSTrung Nguyen extern struct __locale_struct* _nl_current_locale();
166*d338200eSTrung Nguyen #define _NL_CURRENT_LOCALE        (_nl_current_locale())
167*d338200eSTrung Nguyen 
168*d338200eSTrung Nguyen /* Return a pointer to the current `struct __locale_data' for CATEGORY.  */
169*d338200eSTrung Nguyen #define _NL_CURRENT_DATA(category) \
170*d338200eSTrung Nguyen   (_NL_CURRENT_LOCALE->__locales[category])
171*d338200eSTrung Nguyen 
1725af32e75SAxel Dörfler /* Extract the current CATEGORY locale's string for ITEM.  */
1735af32e75SAxel Dörfler #define _NL_CURRENT(category, item) \
174*d338200eSTrung Nguyen   (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string)
1755af32e75SAxel Dörfler 
1765af32e75SAxel Dörfler /* Extract the current CATEGORY locale's string for ITEM.  */
1775af32e75SAxel Dörfler #define _NL_CURRENT_WSTR(category, item) \
178*d338200eSTrung Nguyen   ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr)
1795af32e75SAxel Dörfler 
1805af32e75SAxel Dörfler /* Extract the current CATEGORY locale's word for ITEM.  */
1815af32e75SAxel Dörfler #define _NL_CURRENT_WORD(category, item) \
182*d338200eSTrung Nguyen   ((uint32_t) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word)
1835af32e75SAxel Dörfler 
1845af32e75SAxel Dörfler /* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY.  */
1855af32e75SAxel Dörfler #define _NL_CURRENT_DEFINE(category) \
186*d338200eSTrung Nguyen   /* No per-category variable here. */
1875af32e75SAxel Dörfler 
1885af32e75SAxel Dörfler /* Load the locale data for CATEGORY from the file specified by *NAME.
1895af32e75SAxel Dörfler    If *NAME is "", use environment variables as specified by POSIX,
1905af32e75SAxel Dörfler    and fill in *NAME with the actual name used.  The directories
1915af32e75SAxel Dörfler    listed in LOCALE_PATH are searched for the locale files.  */
1925af32e75SAxel Dörfler extern struct locale_data *_nl_find_locale (const char *locale_path,
1935af32e75SAxel Dörfler 					    size_t locale_path_len,
1945af32e75SAxel Dörfler 					    int category, const char **name);
1955af32e75SAxel Dörfler 
1965af32e75SAxel Dörfler /* Try to load the file described by FILE.  */
1975af32e75SAxel Dörfler extern void _nl_load_locale (struct loaded_l10nfile *file, int category);
1985af32e75SAxel Dörfler 
1995af32e75SAxel Dörfler /* Free all resource.  */
2005af32e75SAxel Dörfler extern void _nl_unload_locale (struct locale_data *locale);
2015af32e75SAxel Dörfler 
2025af32e75SAxel Dörfler /* Free the locale and give back all memory if the usage count is one.  */
2035af32e75SAxel Dörfler extern void _nl_remove_locale (int locale, struct locale_data *data);
2045af32e75SAxel Dörfler 
2055af32e75SAxel Dörfler 
2065af32e75SAxel Dörfler /* Return `era' entry which corresponds to TP.  Used in strftime.  */
2075af32e75SAxel Dörfler extern struct era_entry *_nl_get_era_entry (const struct tm *tp);
2085af32e75SAxel Dörfler 
2095af32e75SAxel Dörfler /* Return `era' cnt'th entry .  Used in strptime.  */
2105af32e75SAxel Dörfler extern struct era_entry *_nl_select_era_entry (int cnt);
2115af32e75SAxel Dörfler 
2125af32e75SAxel Dörfler /* Return `alt_digit' which corresponds to NUMBER.  Used in strftime.  */
2135af32e75SAxel Dörfler extern const char *_nl_get_alt_digit (unsigned int number);
2145af32e75SAxel Dörfler 
2155af32e75SAxel Dörfler /* Similar, but now for wide characters.  */
2165af32e75SAxel Dörfler extern const wchar_t *_nl_get_walt_digit (unsigned int number);
2175af32e75SAxel Dörfler 
2185af32e75SAxel Dörfler /* Parse string as alternative digit and return numeric value.  */
2195af32e75SAxel Dörfler extern int _nl_parse_alt_digit (const char **strp);
2205af32e75SAxel Dörfler 
2215af32e75SAxel Dörfler /* Postload processing.  */
2225af32e75SAxel Dörfler extern void _nl_postload_ctype (void);
2235af32e75SAxel Dörfler extern void _nl_postload_time (void);
2245af32e75SAxel Dörfler 
2255af32e75SAxel Dörfler 
2265af32e75SAxel Dörfler #endif	/* localeinfo.h */
227